final int[] outstanding = {0};
final boolean[] lookup_complete = {false};
listener.reportActivity( getMessageText( "report.searching" ));
DistributedDatabaseListener ddb_listener =
new DistributedDatabaseListener()
{
private Set found_set = new HashSet();
public void
event(
DistributedDatabaseEvent event )
{
int type = event.getType();
if ( type == DistributedDatabaseEvent.ET_OPERATION_STARTS ){
// give live results a chance before kicking in explicit ones
if ( sources.length > 0 ){
new DelayedEvent(
"MP:sourceAdd",
10*1000,
new AERunnable()
{
public void
runSupport()
{
addExplicitSources();
}
});
}
}else if ( type == DistributedDatabaseEvent.ET_VALUE_READ ){
contactFound( event.getValue().getContact());
}else if ( type == DistributedDatabaseEvent.ET_OPERATION_COMPLETE ||
type == DistributedDatabaseEvent.ET_OPERATION_TIMEOUT ){
listener.reportActivity( getMessageText( "report.found", String.valueOf( found_set.size())));
// now inject any explicit sources
addExplicitSources();
try{
potential_contacts_mon.enter();
lookup_complete[0] = true;
}finally{
potential_contacts_mon.exit();
}
potential_contacts_sem.release();
}
}
protected void
addExplicitSources()
{
for (int i=0;i<sources.length;i++){
try{
contactFound( db.importContact(sources[i]));
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
}
public void
contactFound(
final DistributedDatabaseContact contact )
{
String key = contact.getAddress().toString();
synchronized( found_set ){
if ( found_set.contains( key )){
return;
}
found_set.add( key );
}
if ( listener.verbose()){
listener.reportActivity( getMessageText( "report.found", contact.getName()));
}
try{
potential_contacts_mon.enter();
outstanding[0]++;
}finally{
potential_contacts_mon.exit();
}
contact.isAlive(
20*1000,
new DistributedDatabaseListener()
{
public void
event(
DistributedDatabaseEvent event)
{