HashMap config = new HashMap();
config.put(InvokerLocator.FORCE_REMOTE, "true");
config.put(ServerInvoker.TIMEOUT, "60000");
config.put(Client.ENABLE_LEASE, "true");
addClientConfig(config);
final Client client = new Client(locator, config);
try
{
client.connect();
}
catch (Exception e)
{
e.printStackTrace();
}
log.info("making first invocation");
Object response = client.invoke("test");
assertEquals("test", response);
log.info("first invocation succeeds");
final InvokerCallbackHandler callbackHandler = new TestCallbackHandler();
client.addListener(callbackHandler, new HashMap(), null, true);
final Holder removeListener = new Holder();
new Thread()
{
public void run()
{
try
{
// Wait for the server to be disabled.
Thread.sleep(10000);
try
{
// This invocation may use up a listening connection,
// depending on transport.
HashMap metadata = new HashMap();
metadata.put("timeout", shortTimeoutString());
log.info("making invocation");
client.invoke("test", metadata);
log.info("made invocation");
}
catch (Exception e)
{
log.info("client.invoke(\"test\") failed (that's OK)");
}
// Set disconnectTimeout to 1 second.
client.setDisconnectTimeout(shortTimeout());
log.info("calling client.removeListener()");
client.removeListener(callbackHandler);
removeListener.done = true;
log.info("returned from client.removeListener()");
}
catch (Throwable e)
{