Methods Summary |
---|
protected org.gudy.azureus2.core3.ipchecker.extipchecker.impl.ExternalIPCheckerServiceImpl | _clone()
try{
return((ExternalIPCheckerServiceImpl)clone());
}catch( CloneNotSupportedException e){
Debug.printStackTrace( e );
return( null );
}
|
public void | addListener(ExternalIPCheckerServiceListener l)
try{
this_mon.enter();
listeners.addElement( l );
}finally{
this_mon.exit();
}
|
protected java.lang.String | extractIPAddress(java.lang.String str)
int pos = 0;
while(pos < str.length()){
int p1 = str.indexOf( '.", pos );
if ( p1 == -1 ){
informFailure( "ipnotfound" );
return( null );
}
if ( p1 > 0 ){
if ( Character.isDigit(str.charAt(p1-1))){
int p2 = p1-1;
while(p2>=0&&Character.isDigit(str.charAt(p2))){
p2--;
}
p2++;
int p3 = p2+1;
int dots = 0;
while(p3<str.length()){
char c = str.charAt(p3);
if ( c == '." ){
dots++;
}else if ( Character.isDigit( c )){
}else{
break;
}
p3++;
}
if ( dots == 3 ){
return( str.substring(p2,p3));
}
}
}
pos = p1+1;
}
informFailure( "ipnotfound" );
return( null );
|
public java.lang.String | getDescription()
return( description );
|
public java.lang.String | getName()
return( name );
|
public java.lang.String | getURL()
return( url );
|
protected void | informFailure(java.lang.String msg_key)
try{
this_mon.enter();
informFailure( msg_key, null );
}finally{
this_mon.exit();
}
|
protected void | informFailure(java.lang.String msg_key, java.lang.String extra)
try{
this_mon.enter();
if ( !completed ){
timeout_sem.releaseForever();
String message = MessageText.getString( MSG_KEY_ROOT + "." + msg_key );
if ( extra != null ){
message += ": " + extra;
}
for ( int i=0;i<listeners.size();i++){
((ExternalIPCheckerServiceListener)listeners.elementAt(i)).checkFailed( this, message );
}
}
}finally{
this_mon.exit();
}
|
protected void | informSuccess(java.lang.String ip)
try{
this_mon.enter();
if ( !completed ){
timeout_sem.releaseForever();
for ( int i=0;i<listeners.size();i++){
((ExternalIPCheckerServiceListener)listeners.elementAt(i)).checkComplete( this, ip );
}
}
}finally{
this_mon.exit();
}
|
public void | initiateCheck(long timeout)
_clone().initiateCheckSupport(timeout);
|
protected void | initiateCheckSupport(long timeout)
Thread t =
new AEThread("IPChecker")
{
public void
runSupport()
{
try{
initiateCheckSupport();
}finally{
setComplete();
}
}
};
t.setDaemon( true );
t.start();
if ( timeout > 0 ){
Thread t2 =
new AEThread("IPChecker2")
{
public void
runSupport()
{
try{
if ( !timeout_sem.reserve( timeout )){
if ( !completed ){
informFailure( "timeout" );
setComplete();
}
}
}catch( Throwable e ){
Debug.printStackTrace( e );
}
}
};
t2.setDaemon( true );
t2.start();
}
|
protected abstract void | initiateCheckSupport()
|
protected java.lang.String | loadPage(java.lang.String url_string)
try{
URL url = new URL( url_string );
HttpURLConnection connection = null;
InputStream is = null;
try{
connection = (HttpURLConnection)url.openConnection();
int response = connection.getResponseCode();
if( response == HttpURLConnection.HTTP_ACCEPTED || response == HttpURLConnection.HTTP_OK ){
is = connection.getInputStream();
String page = "";
while( page.length() < MAX_PAGE_SIZE ){
byte[] buffer = new byte[2048];
int len = is.read( buffer );
if ( len < 0 ){
break;
}
page += new String(buffer, 0, len);
}
return( page );
}else{
informFailure( "httpinvalidresponse", "" + response );
return( null );
}
}finally{
try{
if ( is != null ){
is.close();
}
if ( connection != null ){
connection.disconnect();
}
}catch( Throwable e){
Debug.printStackTrace( e );
}
}
}catch( Throwable e ){
informFailure( "httploadfail", e.toString());
return( null );
}
|
public void | removeListener(ExternalIPCheckerServiceListener l)
try{
this_mon.enter();
listeners.removeElement( l );
}finally{
this_mon.exit();
}
|
protected void | reportProgress(java.lang.String msg_key)
try{
this_mon.enter();
reportProgress( msg_key, null );
}finally{
this_mon.exit();
}
|
protected void | reportProgress(java.lang.String msg_key, java.lang.String extra)
try{
this_mon.enter();
if ( !completed ){
String message = MessageText.getString( MSG_KEY_ROOT.concat(".").concat(msg_key) );
if ( extra != null ){
message = message.concat(": ").concat(extra);
}
for ( int i=0;i<listeners.size();i++){
((ExternalIPCheckerServiceListener)listeners.elementAt(i)).reportProgress( this, message );
}
}
}finally{
this_mon.exit();
}
|
protected void | setComplete()
completed = true;
|