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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/detection/multicast/startup/MulticastDetectorServer.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
package org.jboss.test.remoting.detection.multicast.startup;
 
23
 
 
24
import java.net.InetAddress;
 
25
 
 
26
import org.apache.log4j.Level;
 
27
import org.jboss.jrunit.extensions.ServerTestCase;
 
28
import org.jboss.remoting.InvocationRequest;
 
29
import org.jboss.remoting.InvokerLocator;
 
30
import org.jboss.remoting.ServerInvocationHandler;
 
31
import org.jboss.remoting.ServerInvoker;
 
32
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
33
import org.jboss.remoting.detection.multicast.MulticastDetector;
 
34
import org.jboss.remoting.network.NetworkRegistry;
 
35
import org.jboss.remoting.transport.Connector;
 
36
import org.jboss.test.remoting.TestUtil;
 
37
import javax.management.MBeanServer;
 
38
import javax.management.MBeanServerFactory;
 
39
import javax.management.ObjectName;
 
40
 
 
41
/**
 
42
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
43
 */
 
44
public class MulticastDetectorServer extends ServerTestCase
 
45
{
 
46
   private MulticastDetector detector;
 
47
   private Connector connector;
 
48
   private NetworkRegistry registry;
 
49
 
 
50
   public void setUp() throws Exception
 
51
   {
 
52
      detector = new MulticastDetector();
 
53
 
 
54
      System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
 
55
      System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));
 
56
 
 
57
      MBeanServer server = MBeanServerFactory.createMBeanServer();
 
58
 
 
59
      registry = NetworkRegistry.getInstance();
 
60
      server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));
 
61
 
 
62
      int port = TestUtil.getRandomPort();
 
63
      System.out.println("port = " + port);
 
64
 
 
65
      String host = InetAddress.getLocalHost().getHostAddress();
 
66
      String bindAddr = System.getProperty("jrunit.bind_addr", host);
 
67
      InvokerLocator locator = new InvokerLocator("socket://" + bindAddr + ":" + port);
 
68
 
 
69
      System.out.println("Starting remoting server with locator uri of: " + locator.getLocatorURI());
 
70
      connector = new Connector();
 
71
      connector.setInvokerLocator(locator.getLocatorURI());
 
72
      connector.create();
 
73
 
 
74
      TestInvocationHandler handler = new TestInvocationHandler();
 
75
      connector.addInvocationHandler("mock", handler);
 
76
 
 
77
      ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + locator.getProtocol());
 
78
      server.registerMBean(connector, obj);
 
79
      //connector.create();
 
80
      connector.start();
 
81
 
 
82
      //Need to set new domain for identity
 
83
      server.registerMBean(detector, new ObjectName("remoting:type=MulticastDetector"));
 
84
 
 
85
      detector.start();
 
86
 
 
87
   }
 
88
 
 
89
   public void tearDown() throws Exception
 
90
   {
 
91
      if (detector != null)
 
92
      {
 
93
         detector.stop();
 
94
      }
 
95
      if (connector != null)
 
96
      {
 
97
         connector.stop();
 
98
         connector.destroy();
 
99
      }
 
100
   }
 
101
 
 
102
   public static void main(String[] args)
 
103
   {
 
104
      org.apache.log4j.BasicConfigurator.configure();
 
105
      org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
 
106
 
 
107
      try
 
108
      {
 
109
         MulticastDetectorServer test = new MulticastDetectorServer();
 
110
         test.setUp();
 
111
      }
 
112
      catch (Exception e)
 
113
      {
 
114
         e.printStackTrace();
 
115
      }
 
116
 
 
117
   }
 
118
 
 
119
   static class TestInvocationHandler implements ServerInvocationHandler
 
120
   {
 
121
      public void addListener(InvokerCallbackHandler callbackHandler) {}
 
122
      public Object invoke(final InvocationRequest invocation) throws Throwable
 
123
      {
 
124
         return "MulticastDetectorServer";
 
125
      }
 
126
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
127
      public void setMBeanServer(MBeanServer server) {}
 
128
      public void setInvoker(ServerInvoker invoker) {}
 
129
   }
 
130
}
 
 
b'\\ No newline at end of file'