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

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/samples/transporter/custom/server/SocketServer.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
package org.jboss.remoting.samples.transporter.custom.server;
 
2
 
 
3
import org.jboss.remoting.detection.jndi.JNDIDetector;
 
4
import org.jboss.remoting.network.NetworkRegistry;
 
5
import org.jboss.remoting.samples.transporter.basic.CustomerProcessor;
 
6
import org.jboss.remoting.samples.transporter.basic.CustomerProcessorImpl;
 
7
import org.jboss.remoting.transporter.InternalTransporterServices;
 
8
import org.jboss.remoting.transporter.TransporterServer;
 
9
 
 
10
import javax.management.MBeanServer;
 
11
import javax.management.MBeanServerFactory;
 
12
import javax.management.ObjectName;
 
13
import java.net.InetAddress;
 
14
import java.util.HashMap;
 
15
import java.util.Map;
 
16
 
 
17
/**
 
18
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
19
 */
 
20
public class SocketServer
 
21
{
 
22
   public static String locatorURI = "socket://localhost:5400";
 
23
   private TransporterServer server = null;
 
24
 
 
25
   public void start() throws Exception
 
26
   {
 
27
      initTransporterServices();
 
28
 
 
29
      Map config = getConnectorConfig();
 
30
 
 
31
      server = TransporterServer.createTransporterServer(getLocatorURI(), new CustomerProcessorImpl(),
 
32
                                                         CustomerProcessor.class.getName(), config, true);
 
33
   }
 
34
 
 
35
   private Map getConnectorConfig()
 
36
   {
 
37
      Map config = new HashMap();
 
38
      // setting socket timeout to 5 seconds
 
39
      config.put("timeout", "5000");
 
40
      return config;
 
41
   }
 
42
 
 
43
   protected String getLocatorURI()
 
44
   {
 
45
      return SocketServer.locatorURI;
 
46
   }
 
47
 
 
48
   public void stop()
 
49
   {
 
50
      if (server != null)
 
51
      {
 
52
         server.stop();
 
53
      }
 
54
   }
 
55
 
 
56
   private void initTransporterServices() throws Exception
 
57
   {
 
58
      // create MBeanServer
 
59
      MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
 
60
 
 
61
      NetworkRegistry registry = NetworkRegistry.getInstance();
 
62
 
 
63
      String host = InetAddress.getLocalHost().getHostAddress();
 
64
      JNDIDetector jndiDetector = new JNDIDetector();
 
65
      jndiDetector.setPort(JNDIServer.JNDI_PORT);
 
66
      jndiDetector.setHost(host);
 
67
      jndiDetector.setContextFactory("org.jnp.interfaces.NamingContextFactory");
 
68
      jndiDetector.setURLPackage("org.jboss.naming:org.jnp.interfaces");
 
69
 
 
70
 
 
71
      InternalTransporterServices transporterService = InternalTransporterServices.getInstance();
 
72
 
 
73
      transporterService.setup(mbeanServer,
 
74
                               jndiDetector, new ObjectName("remoting:type=Detector,transport=jndi"),
 
75
                               registry, new ObjectName("remoting:type=NetworkRegistry"),
 
76
                               true, true);
 
77
 
 
78
      //TODO: -TME Have to start the detector after setup() call?
 
79
      jndiDetector.start();
 
80
 
 
81
   }
 
82
 
 
83
   public static void main(String[] args)
 
84
   {
 
85
      SocketServer server = new SocketServer();
 
86
      try
 
87
      {
 
88
         server.start();
 
89
 
 
90
         Thread.currentThread().sleep(60000);
 
91
 
 
92
      }
 
93
      catch (Exception e)
 
94
      {
 
95
         e.printStackTrace();
 
96
      }
 
97
      finally
 
98
      {
 
99
         server.stop();
 
100
      }
 
101
   }
 
102
}