httpdns 缓存策略,特殊接口获取 httpdns 服务
This commit is contained in:
@@ -5,16 +5,19 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.network.SubscribeImpl;
|
||||
import com.mogo.httpdns.IHttpDnsCallback;
|
||||
import com.mogo.httpdns.IMogoHttpDns;
|
||||
import com.mogo.httpdns.MogoHttpDnsHandler;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
import com.mogo.utils.network.RequestOptions;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
@@ -24,6 +27,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private IMogoHttpDns httpDns;
|
||||
|
||||
private View send;
|
||||
private View fresh;
|
||||
private TextView content;
|
||||
|
||||
@Override
|
||||
@@ -32,9 +36,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
setContentView( R.layout.activity_main );
|
||||
|
||||
send = findViewById( R.id.send );
|
||||
fresh = findViewById( R.id.fresh );
|
||||
content = findViewById( R.id.content );
|
||||
|
||||
httpDns = ARouter.getInstance().navigation( IMogoHttpDns.class );
|
||||
httpDns = MogoHttpDnsHandler.getHttpDnsApi();
|
||||
apiServices = MogoApisHandler.getInstance().getApis().getNetworkApi().create( ApiServices.class, "https://dnstest.zhidaozhixing.com" );
|
||||
|
||||
send.setOnClickListener( new View.OnClickListener() {
|
||||
@@ -62,16 +67,36 @@ public class MainActivity extends AppCompatActivity {
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
fresh.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
WorkThreadHandler.getInstance().post( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
httpDns.getHttpDnsIp( "dnstest.zhidaozhixing.com", false, new IHttpDnsCallback() {
|
||||
@Override
|
||||
public void onParsed( @Nullable String ip ) {
|
||||
StringBuilder sb = new StringBuilder( "httpDns ip:\n" );
|
||||
sb.append( ip ).append( "\n" );
|
||||
UiThreadHandler.post( new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
content.setText( sb.toString() );
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
private void renderResponse( ResponseBody body ) {
|
||||
StringBuilder sb = new StringBuilder( "httpDns ip:\n" );
|
||||
Collection< String > ips = httpDns.getHttpDnsIps( "dnstest.zhidaozhixing.com" );
|
||||
if ( ips != null && !ips.isEmpty() ) {
|
||||
for ( String ip : ips ) {
|
||||
sb.append( ip ).append( "\n" );
|
||||
}
|
||||
}
|
||||
String ip = httpDns.getCachedHttpDnsIps( "dnstest.zhidaozhixing.com" );
|
||||
sb.append( ip ).append( "\n" );
|
||||
sb.append( "\nserverIp: \n" ).append( body.result.serverIp ).append( "\n" );
|
||||
content.setText( sb.toString() );
|
||||
}
|
||||
|
||||
@@ -6,12 +6,24 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/send"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="20dp"
|
||||
android:text="发起请求" />
|
||||
android:padding="20dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/send"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="发起接口请求" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/fresh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="发起dns请求" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user