KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > oneway > OnewayInvokerServer


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.oneway;
8
9 import org.apache.log4j.Level;
10 import org.jboss.remoting.ServerInvocationHandler;
11 import org.jboss.remoting.ShutdownListener;
12 import org.jboss.remoting.performance.TestServerInvocationHandler;
13 import org.jboss.remoting.transport.socket.InvokerServerTest;
14
15 /**
16  * @author <a HREF="mailto:telrod@vocalocity.net">Tom Elrod</a>
17  * @version $Revision: 1.1.2.2 $
18  */

19 public class OnewayInvokerServer extends InvokerServerTest implements ShutdownListener
20 {
21    public boolean timeToShutdown = false;
22
23    private final Object JavaDoc waitObj = new Object JavaDoc();
24
25
26    public OnewayInvokerServer(int instances)
27    {
28       super(instances);
29    }
30
31    public OnewayInvokerServer(String JavaDoc name)
32    {
33       super(name);
34    }
35
36    /**
37     * Should be called when ready to shutdown. Will notify all other remote test
38     * instances and will then block until all other instances have made the same call.
39     *
40     * @throws Exception
41     */

42    public void shutdown() throws Exception JavaDoc
43    {
44       synchronized(waitObj)
45       {
46          try
47          {
48             waitObj.wait(10 * 1000); // timeout if not notified
49
}
50          catch(InterruptedException JavaDoc e)
51          {
52             System.out.println("Got interrupted exception.");
53          }
54       }
55       super.shutdown();
56    }
57
58    public OnewayInvokerServer(String JavaDoc transport, int port)
59    {
60       super(transport, port);
61    }
62
63    public OnewayInvokerServer(String JavaDoc transport, int port, int instances)
64    {
65       super(transport, port, instances);
66    }
67
68    protected ServerInvocationHandler getServerInvocationHandler()
69    {
70       return new TestServerInvocationHandler(this);
71    }
72
73    protected String JavaDoc getSubsystem()
74    {
75       return "test";
76    }
77
78    public static void main(String JavaDoc[] args)
79    {
80       org.apache.log4j.BasicConfigurator.configure();
81       org.apache.log4j.Category.getRoot().setLevel(Level.INFO);
82       org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO);
83       org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG);
84       org.apache.log4j.Category.getInstance("test").setLevel(Level.DEBUG);
85
86       OnewayInvokerServer server = null;
87       if(args.length == 1)
88       {
89          int instances = Integer.parseInt(args[0]);
90          server = new OnewayInvokerServer(instances);
91       }
92       else if(args.length == 2)
93       {
94          String JavaDoc transport = args[0];
95          int port = Integer.parseInt(args[1]);
96          server = new OnewayInvokerServer(transport, port);
97       }
98       else if(args.length == 3)
99       {
100          String JavaDoc transport = args[0];
101          int port = Integer.parseInt(args[1]);
102          int instances = Integer.parseInt(args[2]);
103          server = new OnewayInvokerServer(transport, port, instances);
104       }
105       else
106       {
107          server = new OnewayInvokerServer(InvokerServerTest.class.getName());
108          System.out.println("Using default transport (" + server.getTransport() +
109                             ") and default port (" + server.getPort() + ") and " +
110                             "default number of instances (" + server.getNumberOfInstances() + ")" +
111                             "\nCan enter transport, port, and instances via command line.");
112       }
113
114       try
115       {
116          server.serverTest();
117          Thread.currentThread().sleep(5000);
118       }
119       catch(Exception JavaDoc e)
120       {
121          e.printStackTrace();
122          System.exit(1);
123       }
124       System.exit(0);
125    }
126
127    public void shutdownTest()
128          throws Exception JavaDoc
129    {
130       synchronized(waitObj)
131       {
132          waitObj.notify();
133       }
134    }
135
136
137 }
138
Popular Tags