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 java.util.HashMap;
37
import org.jboss.remoting.Client;
38
import org.jboss.remoting.InvokerLocator;
39
import org.jboss.remoting.callback.Callback;
40
import org.jboss.remoting.callback.HandleCallbackException;
41
import org.jboss.remoting.callback.InvokerCallbackHandler;
42
import org.jboss.remoting.transport.Connector;
43
import org.jboss.remoting.transport.multiplex.Multiplex;
47
* @author <a href="mailto:r.sigal@computer.org">Ron Sigal</a>
49
public class Client3Server1
51
private Client client;
52
private SampleCallbackHandler handler;
53
private Connector connector;
54
private InvokerLocator locator;
58
* This will create the Client.
64
String locatorURI = "multiplex://localhost:9090";
65
InvokerLocator locator = new InvokerLocator(locatorURI);
66
Map configuration = new HashMap();
67
configuration.put(Multiplex.CLIENT_MULTIPLEX_ID, "client3server1");
68
client = new Client(locator, "sample", configuration);
78
* This will be used to create callback server
84
private InvokerLocator initServer() throws Exception
86
String locatorURI = "multiplex://localhost:8080";
87
InvokerLocator locator = new InvokerLocator(locatorURI);
88
Map configuration = new HashMap();
89
configuration.put(Multiplex.SERVER_MULTIPLEX_ID, "client3server1");
90
connector = new Connector(locator.getLocatorURI(), configuration);
93
System.out.println("Started callback server at: " + connector.getInvokerLocator());
94
return connector.getLocator();
98
public void setUp() throws Exception
101
locator = initServer();
103
System.out.println("Connected client to server at: " + client.getInvoker().getLocator().getLocatorURI());
106
public void tearDown() throws Throwable
108
while (!handler.gotCallbacks)
111
client.removeListener(handler);
113
if(connector != null)
128
public void makeClientCall() throws Throwable
130
handler = new SampleCallbackHandler();
132
// Need to add callback listener to get callback
133
client.addListener(handler, locator, client.getSessionId());
136
Object answer = client.invoke(new Integer(17));
138
System.out.println("invocation returns: " + ((Integer) answer).intValue());
142
public static void main(String[] args)
144
Client3Server1 test = new Client3Server1();
149
test.makeClientCall();
152
catch(Throwable throwable)
154
throwable.printStackTrace();
159
public static class SampleCallbackHandler implements InvokerCallbackHandler
162
boolean gotCallbacks;
164
public void handleCallback(Callback callback) throws HandleCallbackException
166
Object ret = callback.getCallbackObject();
167
System.out.println("callback value: " + ret);
169
if (++callbackCounter == 2)
173
public boolean gotCallbacks()