File: MulticastDetectorClient.java

package info (click to toggle)
libjboss-remoting-java 2.4.0~Beta2-1
  • links: PTS, VCS
  • area: contrib
  • in suites: lenny
  • size: 10,268 kB
  • ctags: 15,262
  • sloc: java: 115,889; xml: 1,019; makefile: 14; sh: 11
file content (197 lines) | stat: -rw-r--r-- 5,620 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package org.jboss.test.remoting.detection.multicast.deadlock;

import junit.framework.TestCase;
import org.jboss.remoting.Client;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.ServerInvocationHandler;
import org.jboss.remoting.ServerInvoker;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import org.jboss.remoting.detection.multicast.MulticastDetector;
import org.jboss.remoting.network.NetworkInstance;
import org.jboss.remoting.network.NetworkRegistry;
import org.jboss.remoting.security.SSLSocketBuilder;
import org.jboss.remoting.transport.Connector;

import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import java.util.HashMap;
import java.util.Map;

/**
 * Test for JBREM-553
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 */
public class MulticastDetectorClient extends TestCase
{
   private MulticastDetector detector;
   private NetworkRegistry registry;
   private Connector connector;

   private Client remotingClient = null;

   public void setUp() throws Exception
   {
      detector = new MulticastDetector();

      System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
      System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));

      MBeanServer server = MBeanServerFactory.createMBeanServer();

      registry = NetworkRegistry.getInstance();
      server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));

      //Need to set new domain for identity
      server.registerMBean(detector, new ObjectName("remoting:type=JNDIDetector"));
   }

   public void testDetection() throws Exception
   {
      detector.start();
      long start = System.currentTimeMillis();
      NetworkInstance[] instances = detector.forceDetection();
      long end = System.currentTimeMillis();

      System.out.println("instance = " + instances);
      System.out.println("force detection took " + (end - start) + " milliseconds.");

//      assertEquals(1, instances.length);

      // now create a client
      NetworkInstance ni = instances[0];
      InvokerLocator[] locator = ni.getLocators();
      InvokerLocator serverLocator = locator[0];

      Map config = new HashMap();
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
      String trustStoreFilePath = this.getClass().getResource("ssl/.truststore").getFile();
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
      String keyStoreFilePath = this.getClass().getResource("ssl/.keystore").getFile();
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
      config.put(SSLSocketBuilder.REMOTING_CLIENT_AUTH_MODE, SSLSocketBuilder.CLIENT_AUTH_MODE_WANT);

      remotingClient = new Client(serverLocator, config);
      remotingClient.connect();

      String invokerLocatorurl = "sslsocket://localhost:8700";
      connector = new Connector(invokerLocatorurl, config);
      connector.create();

      connector.addInvocationHandler("test", new LocalHandler());
      connector.start();

      try
      {
         Object ret = remotingClient.invoke(invokerLocatorurl);
         System.out.println("return from calling server is " + ret);
      }
      catch (Throwable throwable)
      {
         throwable.printStackTrace();
         throw new Exception(throwable.getMessage());
      }

//      Thread.currentThread().sleep(20000);
//
//      System.out.println("Disconnecting.");
//
//      remotingClient.disconnect();
//
//      System.out.println("Disconnected.");
   }

   public void disconnect() throws InterruptedException
   {
      Thread.currentThread().sleep(30000);

      System.out.println("Disconnecting.");

      remotingClient.disconnect();

      System.out.println("Disconnected.");

      remotingClient = null;

   }

   public void tearDown() throws Exception
   {
      if (remotingClient != null)
      {
         remotingClient.disconnect();
      }
      if (detector != null)
      {
         detector.stop();
      }
      if(connector != null)
      {
         connector.stop();
         connector.destroy();
      }
   }

   public static void main(String[] args)
   {
      MulticastDetectorClient client = new MulticastDetectorClient();
      try
      {
         client.setUp();
         client.testDetection();
         client.disconnect();
         Thread.sleep(5000);
         System.out.println("done testing.");
      }
      catch(Throwable t)
      {
         t.printStackTrace();
      }
      finally
      {
         try
         {
            client.tearDown();
         }
         catch (Exception e)
         {
            e.printStackTrace();
         }
      }
   }


   public class LocalHandler implements ServerInvocationHandler
   {

      public void setMBeanServer(MBeanServer server)
      {
         //TODO: -TME Implement
      }

      public void setInvoker(ServerInvoker invoker)
      {
         //TODO: -TME Implement
      }

      public Object invoke(InvocationRequest invocation) throws Throwable
      {
         return "foo";
      }

      public void addListener(InvokerCallbackHandler callbackHandler)
      {
         //TODO: -TME Implement
      }

      public void removeListener(InvokerCallbackHandler callbackHandler)
      {
         //TODO: -TME Implement
      }
   }


}