KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > interceptor > ServerInterceptorTest


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.interceptor;
8
9 import javax.management.MBeanServer JavaDoc;
10 import javax.management.MBeanServerFactory JavaDoc;
11 import javax.management.ObjectName JavaDoc;
12 import org.apache.log4j.Level;
13 import org.jboss.remoting.InvokerLocator;
14 import org.jboss.remoting.ident.Identity;
15 import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
16 import org.jboss.remoting.network.NetworkRegistry;
17 import org.jboss.remoting.transport.Connector;
18
19 /**
20  * @author <a HREF="mailto:tom@jboss.org">Tom Elrod</a>
21  */

22 public class ServerInterceptorTest
23 {
24    private InvokerLocator locator;
25
26    public void setLocator(InvokerLocator locator)
27    {
28       this.locator = locator;
29    }
30
31    protected void setup()
32    {
33       try
34       {
35          System.setProperty("jboss.identity", Identity.createUniqueID());
36          MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
37
38          System.out.println("my identity is: " + Identity.get(server));
39
40
41          NetworkRegistry registry = NetworkRegistry.getInstance();
42          server.registerMBean(registry, new ObjectName JavaDoc("remoting:type=NetworkRegistry"));
43
44          //int port = PortUtil.findFreePort();
45

46          Connector connector = new Connector();
47          connector.setInvokerLocator(locator.getLocatorURI());
48          ObjectName JavaDoc obj = new ObjectName JavaDoc("jboss.remoting:type=Connector,transport=" + locator.getProtocol());
49          server.registerMBean(connector, obj);
50
51          connector.start();
52
53          connector.addInvocationHandler("test", new TestInvocationHandler());
54
55 // MulticastDetector detector = new MulticastDetector();
56
// server.registerMBean(detector, new ObjectName("remoting:type=Detector,transport=multicast"));
57
// detector.start();
58

59          // TODO: -TME Not needed unless want to make jmx invocation within handler
60
// TestTarget target = new TestTarget();
61
// ObjectName objName = new ObjectName("test:type=UnifiedInvoker");
62
// server.registerMBean(target, objName);
63
// Registry.bind("test:type=UnifiedInvoker", objName);
64

65       }
66       catch(Throwable JavaDoc e)
67       {
68          e.printStackTrace();
69       }
70
71    }
72
73    public static void main(String JavaDoc[] args)
74    {
75       try
76       {
77          //org.apache.log4j.BasicConfigurator.configure();
78

79          int port = 8081;
80          String JavaDoc transport = "socket";
81 // InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port + "/?" +
82
// InvokerLocator.DATATYPE + "=" + SerializableUnMarshaller.DATATYPE);
83
InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port + "/?" +
84                                                      InvokerLocator.DATATYPE + "=" + SerializableUnMarshaller.DATATYPE);
85
86          ServerInterceptorTest server = new ServerInterceptorTest();
87          server.setLocator(locator);
88          server.setup();
89
90          while(true)
91          {
92             Thread.sleep(1000);
93          }
94       }
95       catch(Exception JavaDoc e)
96       {
97          e.printStackTrace();
98       }
99    }
100
101    /**
102     * When an object implementing interface <code>Runnable</code> is used
103     * to create a thread, starting the thread causes the object's
104     * <code>run</code> method to be called in that separately executing
105     * thread.
106     * <p/>
107     * The general contract of the method <code>run</code> is that it may
108     * take any action whatsoever.
109     *
110     * @see Thread#run()
111     */

112    public void run()
113    {
114       setup();
115    }
116 }
Popular Tags