2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
24
* Created on Oct 4, 2005
26
package org.jboss.remoting.samples.multiplex.invoker;
28
* JBoss, the OpenSource J2EE webOS
30
* Distributable under LGPL license.
31
* See terms of license at gnu.org.
34
import org.jboss.remoting.Client;
35
import org.jboss.remoting.InvokerLocator;
36
import org.jboss.remoting.callback.Callback;
37
import org.jboss.remoting.callback.HandleCallbackException;
38
import org.jboss.remoting.callback.InvokerCallbackHandler;
39
import org.jboss.remoting.transport.Connector;
43
* @author <a href="mailto:r.sigal@computer.org">Ron Sigal</a>
45
public class Server2Client1
47
private Client client;
48
private SampleCallbackHandler handler;
49
private Connector connector;
50
private InvokerLocator locator;
54
* This will create the Client.
60
String parameters = "/?multiplexBindHost=localhost&multiplexBindPort=8080&clientMultiplexId=server2client1";
61
String locatorURI = "multiplex://localhost:9090" + parameters;
62
InvokerLocator locator = new InvokerLocator(locatorURI);
63
client = new Client(locator, "sample");
65
System.out.println("Connected client to server at: " + client.getInvoker().getLocator().getLocatorURI());
75
* This will be used to create callback server
81
private InvokerLocator initServer() throws Exception
83
String parameters = "/?serverMultiplexId=server2client1";
84
String locatorURI = "multiplex://localhost:8080" + parameters;
85
InvokerLocator locator = new InvokerLocator(locatorURI);
86
connector = new Connector(locator.getLocatorURI());
89
System.out.println("Started callback server at: " + connector.getInvokerLocator());
90
return connector.getLocator();
94
public void setUp() throws Exception
96
locator = initServer();
100
public void tearDown() throws Throwable
102
while (!handler.gotCallbacks)
105
client.removeListener(handler);
107
if(connector != null)
122
public void makeClientCall() throws Throwable
124
handler = new SampleCallbackHandler();
126
// Need to add callback listener to get callback
127
client.addListener(handler, locator, client.getSessionId());
130
Object answer = client.invoke(new Integer(17));
132
System.out.println("invocation returns: " + ((Integer) answer).intValue());
136
public static void main(String[] args)
138
Server2Client1 test = new Server2Client1();
143
test.makeClientCall();
146
catch(Throwable throwable)
148
throwable.printStackTrace();
153
public static class SampleCallbackHandler implements InvokerCallbackHandler
156
boolean gotCallbacks;
158
public void handleCallback(Callback callback) throws HandleCallbackException
160
Object ret = callback.getCallbackObject();
161
System.out.println("callback value: " + ret);
163
if (++callbackCounter == 2)
167
public boolean gotCallbacks()