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.
22
package org.jboss.test.remoting.detection.jndi;
24
import org.apache.log4j.Level;
25
import org.apache.log4j.Logger;
26
import org.jboss.jrunit.extensions.ServerTestCase;
27
import org.jboss.remoting.InvocationRequest;
28
import org.jboss.remoting.InvokerLocator;
29
import org.jboss.remoting.ServerInvocationHandler;
30
import org.jboss.remoting.ServerInvoker;
31
import org.jboss.remoting.callback.InvokerCallbackHandler;
32
import org.jboss.remoting.detection.jndi.JNDIDetector;
33
import org.jboss.remoting.transport.Connector;
35
import javax.management.MBeanServer;
36
import javax.management.MBeanServerFactory;
37
import javax.management.ObjectName;
38
import java.net.InetAddress;
39
import java.net.UnknownHostException;
42
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
43
* @author Michael Voss
45
public class Server extends ServerTestCase
47
private static Connector connector = null;
48
private MBeanServer server;
49
private JNDIDetector detector;
50
private Logger logger;
52
private String jndiAddress = null;
53
private int jndiPort = 2410;
54
private String port = "3001";
59
String localHost = "";
62
jndiAddress = localHost = InetAddress.getLocalHost().getHostAddress();
64
catch (UnknownHostException uhe)
66
uhe.printStackTrace();
74
connector = new Connector();
75
InvokerLocator locator = new InvokerLocator("multiplex://" + localHost + ":" + port);
76
connector.setInvokerLocator(locator.getLocatorURI());
80
connector.addInvocationHandler("sample", new SampleInvocationHandler());
89
server.registerMBean(connector, new ObjectName("jboss.remoting:type=Connector"));
102
private void registerJNDI()
105
detector = new JNDIDetector();
109
server.registerMBean(detector, new ObjectName("remoting:type=JNDIDetector"));
111
catch (Exception ignored)
115
detector.setPort(jndiPort);
116
detector.setHost(jndiAddress);
131
logger = Logger.getLogger(getClass());
132
logger.setLevel((Level) Level.DEBUG);
134
server = MBeanServerFactory.createMBeanServer();
142
public void tearDown()
147
server.unregisterMBean(new ObjectName("remoting:type=JNDIDetector"));
148
if (detector != null)
154
catch (Exception ignored)
158
if (connector != null)
164
catch (Exception ignored)
169
server.unregisterMBean(new ObjectName("jboss.remoting:type=Connector"));
181
public static void main(String[] args)
184
Server server = new Server();
201
public static class SampleInvocationHandler implements ServerInvocationHandler
204
public Object invoke(InvocationRequest invocation) throws Throwable
210
public void addListener(InvokerCallbackHandler callbackHandler)
216
public void removeListener(InvokerCallbackHandler callbackHandler)
222
public void setMBeanServer(MBeanServer server)
227
public void setInvoker(ServerInvoker invoker)
b'\\ No newline at end of file'