1
package org.jboss.test.remoting.callback.pull;
3
import junit.framework.TestCase;
4
import org.jboss.remoting.Client;
5
import org.jboss.remoting.InvokerLocator;
6
import org.jboss.remoting.callback.Callback;
7
import org.jboss.remoting.callback.HandleCallbackException;
8
import org.jboss.remoting.callback.InvokerCallbackHandler;
10
import java.util.List;
13
* Tests that two separate clients with separate callback listeners
14
* can be distinguished on the server and given different callback messages.
16
* @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
18
public class CallbackTestClient extends TestCase
20
// Default locator values
21
private static String transport = "socket";
22
private static String host = "localhost";
23
private static int port = 5411;
25
private String locatorURI = transport + "://" + host + ":" + port;
27
private Client remotingClient;
28
private CallbackHandler pullCallbackHandler;
30
private Client remotingClient2;
31
private CallbackHandler pullCallbackHandler2;
33
public void createRemotingClient() throws Exception
35
InvokerLocator locator = new InvokerLocator(locatorURI);
36
System.out.println("Calling remoting server with locator uri of: " + locatorURI);
38
remotingClient = new Client(locator);
39
remotingClient.connect();
41
remotingClient2 = new Client(locator);
42
remotingClient2.connect();
46
public void setUp() throws Exception
48
createRemotingClient();
51
public void tearDown() throws Exception
53
if(remotingClient != null)
55
if(pullCallbackHandler != null)
59
remotingClient.removeListener(pullCallbackHandler);
61
catch(Throwable throwable)
63
throw new Exception(throwable);
66
remotingClient.disconnect();
68
if(remotingClient2 != null)
70
if(pullCallbackHandler2 != null)
74
remotingClient2.removeListener(pullCallbackHandler2);
76
catch(Throwable throwable)
78
throw new Exception(throwable);
81
remotingClient2.disconnect();
85
public void testPullCallback() throws Throwable
87
pullCallbackHandler = new CallbackHandler();
88
pullCallbackHandler2 = new CallbackHandler();
89
// by passing only the callback handler, will indicate pull callbacks
90
remotingClient.addListener(pullCallbackHandler);
91
remotingClient2.addListener(pullCallbackHandler2);
93
// now make invocation on server, which should cause a callback to happen
94
remotingClient.invoke("Do something");
95
remotingClient2.invoke("Do something");
99
List callbacks = remotingClient.getCallbacks(pullCallbackHandler);
100
List callbacks2 = remotingClient2.getCallbacks(pullCallbackHandler2);
102
boolean callbackWorked = false;
104
if(callbacks != null && callbacks.size() > 0)
106
for(int x = 0; x < callbacks.size(); x++)
108
Callback c = (Callback)callbacks.get(x);
109
callbackWorked = c.getCallbackObject().equals(remotingClient.getSessionId());
117
assertTrue(callbackWorked);
119
boolean callbackWorked2 = false;
121
if(callbacks2 != null && callbacks2.size() > 0)
123
for(int x = 0; x < callbacks2.size(); x++)
125
Callback c = (Callback)callbacks2.get(x);
126
callbackWorked2 = c.getCallbackObject().equals(remotingClient2.getSessionId());
134
assertTrue(callbackWorked2);
138
public class CallbackHandler implements InvokerCallbackHandler
140
public void handleCallback(Callback callback) throws HandleCallbackException