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.
23
package org.jboss.test.remoting.lease;
25
import org.jboss.jrunit.extensions.ServerTestCase;
26
import org.jboss.remoting.Client;
27
import org.jboss.remoting.ConnectionListener;
28
import org.jboss.remoting.InvocationRequest;
29
import org.jboss.remoting.ServerInvocationHandler;
30
import org.jboss.remoting.ServerInvoker;
31
import org.jboss.remoting.callback.InvokerCallbackHandler;
32
import org.jboss.remoting.transport.Connector;
33
import org.w3c.dom.Document;
35
import javax.management.MBeanServer;
36
import javax.xml.parsers.DocumentBuilderFactory;
37
import java.io.ByteArrayInputStream;
40
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
42
public abstract class LeaseTestServer extends ServerTestCase implements ConnectionListener
44
// Default locator values
45
private static String host = "localhost";
46
private static int port = 5400;
48
private boolean error = false;
49
private boolean disconnect = false;
51
private Connector connector = null;
53
public boolean isRunning = true;
55
// String to be returned from invocation handler upon client invocation calls.
56
private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation";
58
protected abstract String getTransport();
60
public void setupServer() throws Exception
62
connector = new Connector();
63
StringBuffer buf = new StringBuffer();
64
buf.append("<?xml version=\"1.0\"?>\n");
65
buf.append("<config>");
66
buf.append("<invoker transport=\"" + getTransport() + "\">");
67
buf.append("<attribute name=\"clientLeasePeriod\">3000</attribute>");
68
buf.append("<attribute name=\"serverBindAddress\">" + host + "</attribute>");
69
buf.append("<attribute name=\"serverBindPort\">" + port + "</attribute>");
70
buf.append("</invoker>");
71
buf.append("<handlers>");
72
buf.append(" <handler subsystem=\"mock\">" + SampleInvocationHandler.class.getName() + "</handler>\n");
73
buf.append("</handlers>");
74
buf.append("</config>");
75
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
76
//connector.setInvokerLocator(locator.getLocatorURI());
77
connector.setConfiguration(xml.getDocumentElement());
79
connector.addConnectionListener(this);
84
public void testForError()
88
assertTrue("Received connection failure from client that was not due to disconnect.", !error);
91
Thread.currentThread().sleep(1000);
93
catch(InterruptedException e)
100
public void setUp() throws Exception
105
public void tearDown() throws Exception
108
if(connector != null)
115
throw new RuntimeException("Never got disconnect notification from any of the clients.");
119
public void handleConnectionException(Throwable throwable, Client client)
121
System.out.println("received connection exception from " + client + " (session id = " + client.getSessionId() + ") " +
122
"with exception of " + throwable + " and configuration of " + client.getConfiguration());
123
if(throwable == null)
125
// since there was not an exception (will be one if was from a disconnect),
126
// need to indicate error.
136
* Simple invocation handler implementation.
138
public static class SampleInvocationHandler implements ServerInvocationHandler
141
* called to handle a specific invocation
147
public Object invoke(InvocationRequest invocation) throws Throwable
149
// Print out the invocation request
150
System.out.println("Invocation request is: " + invocation.getParameter());
152
// Just going to return static string as this is just simple example code.
153
return RESPONSE_VALUE;
157
* Adds a callback handler that will listen for callbacks from
158
* the server invoker handler.
160
* @param callbackHandler
162
public void addListener(InvokerCallbackHandler callbackHandler)
164
// NO OP as do not handling callback listeners in this example
168
* Removes the callback handler that was listening for callbacks
169
* from the server invoker handler.
171
* @param callbackHandler
173
public void removeListener(InvokerCallbackHandler callbackHandler)
175
// NO OP as do not handling callback listeners in this example
179
* set the mbean server that the handler can reference
183
public void setMBeanServer(MBeanServer server)
185
// NO OP as do not need reference to MBeanServer for this handler
189
* set the invoker that owns this handler
193
public void setInvoker(ServerInvoker invoker)
195
// NO OP as do not need reference back to the server invoker
b'\\ No newline at end of file'