KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > performance > PerformanceInvokerServer


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

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

41    public void shutdown() throws Exception JavaDoc
42    {
43       synchronized(waitObj)
44       {
45          try
46          {
47             waitObj.wait(10 * 1000); // timeout if not notified
48
}
49          catch(InterruptedException JavaDoc e)
50          {
51             System.out.println("Got interrupted exception.");
52          }
53       }
54       super.shutdown();
55    }
56
57    public PerformanceInvokerServer(String JavaDoc transport, int port)
58    {
59       super(transport, port);
60    }
61
62    public PerformanceInvokerServer(String JavaDoc transport, int port, int instances)
63    {
64       super(transport, port, instances);
65    }
66
67    protected ServerInvocationHandler getServerInvocationHandler()
68    {
69       return new TestServerInvocationHandler(this);
70    }
71
72    protected String JavaDoc getSubsystem()
73    {
74       return "test";
75    }
76
77    public static void main(String JavaDoc[] args)
78    {
79       org.apache.log4j.BasicConfigurator.configure();
80       org.apache.log4j.Category.getRoot().setLevel(Level.INFO);
81       org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO);
82       //org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG);
83
org.apache.log4j.Category.getInstance("org.jboss.remoting.performance").setLevel(Level.DEBUG);
84       org.apache.log4j.Category.getInstance("test").setLevel(Level.DEBUG);
85
86       PerformanceInvokerServer server = null;
87       if(args.length == 1)
88       {
89          int instances = Integer.parseInt(args[0]);
90          server = new PerformanceInvokerServer(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 PerformanceInvokerServer(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 PerformanceInvokerServer(transport, port, instances);
104       }
105       else
106       {
107          server = new PerformanceInvokerServer(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       }
118       catch(Exception JavaDoc e)
119       {
120          e.printStackTrace();
121          System.exit(1);
122       }
123       System.exit(0);
124    }
125
126    public void shutdownTest()
127          throws Exception JavaDoc
128    {
129       synchronized(waitObj)
130       {
131          waitObj.notify();
132       }
133    }
134
135
136 }
137
Popular Tags