KickJava   Java API By Example, From Geeks To Geeks.

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

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

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

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

66       }
67       catch(Throwable JavaDoc e)
68       {
69          e.printStackTrace();
70       }
71
72    }
73
74    public static void main(String JavaDoc[] args)
75    {
76       try
77       {
78          //org.apache.log4j.BasicConfigurator.configure();
79
org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
80
81          int port = 8081;
82          String JavaDoc transport = "socket";
83 // InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port + "/?" +
84
// InvokerLocator.DATATYPE + "=" + SerializableUnMarshaller.DATATYPE);
85
InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port + "/?" +
86                                                      InvokerLocator.DATATYPE + "=" + SerializableUnMarshaller.DATATYPE);
87
88          ServerInterceptorTest server = new ServerInterceptorTest();
89          server.setLocator(locator);
90          server.setup();
91
92          while(true)
93          {
94             Thread.sleep(1000);
95          }
96       }
97       catch(Exception JavaDoc e)
98       {
99          e.printStackTrace();
100       }
101    }
102
103    /**
104     * When an object implementing interface <code>Runnable</code> is used
105     * to create a thread, starting the thread causes the object's
106     * <code>run</code> method to be called in that separately executing
107     * thread.
108     * <p/>
109     * The general contract of the method <code>run</code> is that it may
110     * take any action whatsoever.
111     *
112     * @see Thread#run()
113     */

114    public void run()
115    {
116       setup();
117    }
118 }
Popular Tags