KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > handler > mbean > ServerTest


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.remoting.handler.mbean;
8
9 import javax.management.MBeanServer JavaDoc;
10 import javax.management.MBeanServerFactory JavaDoc;
11 import javax.management.ObjectName JavaDoc;
12 import org.jboss.jrunit.extensions.ServerTestCase;
13 import org.jboss.remoting.InvokerLocator;
14 import org.jboss.remoting.transport.Connector;
15
16 /**
17  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
18  */

19 public class ServerTest extends ServerTestCase
20 {
21    // Default locator values
22
private static String JavaDoc transport = "socket";
23    private static String JavaDoc host = "localhost";
24    private static int port = 5400;
25
26    private String JavaDoc locatorURI = transport + "://" + host + ":" + port;
27    private Connector connector;
28
29    // String to be returned from invocation handler upon client invocation calls.
30
public static final String JavaDoc RESPONSE_VALUE = "This is the return from the TestServer invocation";
31
32    public void setupServer() throws Exception JavaDoc
33    {
34       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
35
36       InvokerLocator locator = new InvokerLocator(locatorURI);
37       System.out.println("Starting remoting server with locator uri of: " + locatorURI);
38       connector = new Connector();
39       connector.setInvokerLocator(locator.getLocatorURI());
40       connector.start();
41
42       server.registerMBean(connector, new ObjectName JavaDoc("test:type=connector,transport=socket"));
43
44       // now create Mbean handler and register with mbean server
45
MBeanHandler handler = new MBeanHandler();
46       ObjectName JavaDoc objName = new ObjectName JavaDoc("test:type=handler");
47       server.registerMBean(handler, objName);
48
49       connector.addInvocationHandler("test", objName);
50    }
51
52    public void setUp() throws Exception JavaDoc
53    {
54       setupServer();
55    }
56
57    public void tearDown() throws Exception JavaDoc
58    {
59       if(connector != null)
60       {
61          connector.stop();
62          connector.destroy();
63       }
64    }
65
66    /**
67     * Can pass transport and port to be used as parameters.
68     * Valid transports are 'rmi' and 'socket'.
69     *
70     * @param args
71     */

72    public static void main(String JavaDoc[] args)
73    {
74       ServerTest serverTest = new ServerTest();
75       try
76       {
77          serverTest.setUp();
78       }
79       catch(Exception JavaDoc e)
80       {
81          e.printStackTrace();
82       }
83    }
84 }
Popular Tags