~ubuntu-branches/ubuntu/wily/libjboss-remoting-java/wily

« back to all changes in this revision

Viewing changes to examples/org/jboss/remoting/samples/simple/SimpleServer.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
* JBoss, Home of Professional Open Source
3
 
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
 
* by the @authors tag. See the copyright.txt in the distribution for a
5
 
* full listing of individual contributors.
6
 
*
7
 
* This is free software; you can redistribute it and/or modify it
8
 
* under the terms of the GNU Lesser General Public License as
9
 
* published by the Free Software Foundation; either version 2.1 of
10
 
* the License, or (at your option) any later version.
11
 
*
12
 
* This software is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
 
* Lesser General Public License for more details.
16
 
*
17
 
* You should have received a copy of the GNU Lesser General Public
18
 
* License along with this software; if not, write to the Free
19
 
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
 
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21
 
*/
22
 
 
23
 
package org.jboss.remoting.samples.simple;
24
 
 
25
 
import javax.management.MBeanServer;
26
 
import org.jboss.remoting.InvocationRequest;
27
 
import org.jboss.remoting.InvokerLocator;
28
 
import org.jboss.remoting.ServerInvocationHandler;
29
 
import org.jboss.remoting.ServerInvoker;
30
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
31
 
import org.jboss.remoting.transport.Connector;
32
 
 
33
 
/**
34
 
 * Simple remoting server.  Uses inner class SampleInvocationHandler
35
 
 * as the invocation target handler class.
36
 
 *
37
 
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
38
 
 */
39
 
public class SimpleServer
40
 
{
41
 
   // Default locator values
42
 
   private static String transport = "socket";
43
 
   private static String host = "localhost";
44
 
   private static int port = 5400;
45
 
 
46
 
   // String to be returned from invocation handler upon client invocation calls.
47
 
   private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation";
48
 
 
49
 
 
50
 
   public void setupServer(String locatorURI) throws Exception
51
 
   {
52
 
      // create the InvokerLocator based on url string format
53
 
      // to indicate the transport, host, and port to use for the
54
 
      // server invoker.
55
 
      InvokerLocator locator = new InvokerLocator(locatorURI);
56
 
      System.out.println("Starting remoting server with locator uri of: " + locatorURI);
57
 
      Connector connector = new Connector(locator);
58
 
      // creates all the connector's needed resources, such as the server invoker
59
 
      connector.create();
60
 
 
61
 
      // create the handler to receive the invocation request from the client for processing
62
 
      SampleInvocationHandler invocationHandler = new SampleInvocationHandler();
63
 
      // first parameter is sub-system name.  can be any String value.
64
 
      connector.addInvocationHandler("sample", invocationHandler);
65
 
 
66
 
      // start with a new non daemon thread so
67
 
      // server will wait for request and not exit
68
 
      connector.start();
69
 
 
70
 
   }
71
 
 
72
 
   /**
73
 
    * Can pass transport and port to be used as parameters.
74
 
    * Valid transports are 'rmi' and 'socket'.
75
 
    *
76
 
    * @param args
77
 
    */
78
 
   public static void main(String[] args)
79
 
   {
80
 
      if(args != null && args.length == 3)
81
 
      {
82
 
         transport = args[0];
83
 
         host = args[1];
84
 
         port = Integer.parseInt(args[2]);
85
 
      }
86
 
      String locatorURI = transport + "://" + host + ":" + port;
87
 
      SimpleServer server = new SimpleServer();
88
 
      try
89
 
      {
90
 
         server.setupServer(locatorURI);
91
 
 
92
 
         // wait forever, let the user kill us at any point (at which point, the client will detect we went down)
93
 
         while(true)
94
 
         {
95
 
            Thread.sleep(1000);
96
 
         }
97
 
 
98
 
      }
99
 
      catch(Exception e)
100
 
      {
101
 
         e.printStackTrace();
102
 
      }
103
 
   }
104
 
 
105
 
   /**
106
 
    * Simple invocation handler implementation.
107
 
    * This is the code that will be called with the invocation payload from the client.
108
 
    */
109
 
   public static class SampleInvocationHandler implements ServerInvocationHandler
110
 
   {
111
 
      /**
112
 
       * called to handle a specific invocation
113
 
       *
114
 
       * @param invocation
115
 
       * @return
116
 
       * @throws Throwable
117
 
       */
118
 
      public Object invoke(InvocationRequest invocation) throws Throwable
119
 
      {
120
 
         // Print out the invocation request
121
 
         System.out.println("Invocation request is: " + invocation.getParameter());
122
 
         System.out.println("Returning response of: " + RESPONSE_VALUE);
123
 
         // Just going to return static string as this is just simple example code.
124
 
         return RESPONSE_VALUE;
125
 
      }
126
 
 
127
 
      /**
128
 
       * Adds a callback handler that will listen for callbacks from
129
 
       * the server invoker handler.
130
 
       *
131
 
       * @param callbackHandler
132
 
       */
133
 
      public void addListener(InvokerCallbackHandler callbackHandler)
134
 
      {
135
 
         // NO OP as do not handling callback listeners in this example
136
 
      }
137
 
 
138
 
      /**
139
 
       * Removes the callback handler that was listening for callbacks
140
 
       * from the server invoker handler.
141
 
       *
142
 
       * @param callbackHandler
143
 
       */
144
 
      public void removeListener(InvokerCallbackHandler callbackHandler)
145
 
      {
146
 
         // NO OP as do not handling callback listeners in this example
147
 
      }
148
 
 
149
 
      /**
150
 
       * set the mbean server that the handler can reference
151
 
       *
152
 
       * @param server
153
 
       */
154
 
      public void setMBeanServer(MBeanServer server)
155
 
      {
156
 
         // NO OP as do not need reference to MBeanServer for this handler
157
 
      }
158
 
 
159
 
      /**
160
 
       * set the invoker that owns this handler
161
 
       *
162
 
       * @param invoker
163
 
       */
164
 
      public void setInvoker(ServerInvoker invoker)
165
 
      {
166
 
         // NO OP as do not need reference back to the server invoker
167
 
      }
168
 
 
169
 
   }
170
 
}
 
 
b'\\ No newline at end of file'