final String address = ip + ":" + port;
final int timeout = 500; // 500 ms RemoteAPIImpl if need detailed
// version...
final DiscoveryManager newClient = Proxies.newClient(EXPORT_NAME, address, RemoteDiscoveryImpl.class.getClassLoader(), DiscoveryManager.class);
/*
* TODO: With this one we still get the message:
*
* "org.freshvanilla.net.VanillaDataSocket allocateBuffer
* INFO: DiscoveryManager: Running low on memory, pausing..."
*
* but, there is no TimeoutException....
*
* @sa DiscoveredPluginTest.testMultiplePlugins()
*/
@SuppressWarnings("unused")
int pingRes = newClient.ping(123321);
// Execute collection asynchronously (TODO: cache pool usage could be
// improved)
final ExecutorService cachePool = Executors.newCachedThreadPool();
final ExecutorCompletionService<String> ecs = new ExecutorCompletionService(cachePool);
final Future<String> future = ecs.submit(new Callable<String>() {
public String call() throws Exception {
return AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
return newClient.toString();
}
});
}
});
// Wait at most half a second (TODO: Make this configurable)
try {
final String string = future.get(timeout, TimeUnit.MILLISECONDS);
/*
* TODO: Probably it is possible to put here some conversion routines... Because it looks like that
* only the ExportInfo makes trouble.... Or just make the ExportInfo much better, ie downwards compatible
*/
if (string == null || newClient.getVersion() != this.localManager.getVersion()) { return null; }
return newClient;
} catch (final InterruptedException e) {
// TODO: This one is not an error anymore.
// Interruption is called because we are running cache thread.