File: CallbackPushTestServer.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 (92 lines) | stat: -rw-r--r-- 2,301 bytes parent folder | download | duplicates (3)
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
package org.jboss.test.remoting.callback.push.unidirectional;

import org.jboss.jrunit.extensions.ServerTestCase;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.ServerInvocationHandler;
import org.jboss.remoting.ServerInvoker;
import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import org.jboss.remoting.transport.Connector;

import javax.management.MBeanServer;
import java.util.ArrayList;
import java.util.List;

/**
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 */
public abstract class CallbackPushTestServer extends ServerTestCase
{
   private Connector connector = null;

   public void setUp() throws Exception
   {
      connector = new Connector(getLocatorUri());
      connector.create();
      connector.addInvocationHandler("test", new TestInvocationHandler());
      connector.start();
   }

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

   private String getLocatorUri()
   {
      return getTransport() + "://" + getHost() + ":" + getPort();
   }

   public abstract String getTransport();

   public String getHost()
   {
      return "localhost";
   }

   public int getPort()
   {
      return 6999;
   }

   public class TestInvocationHandler implements ServerInvocationHandler
   {

      private List listeners = new ArrayList();

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

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

      public Object invoke(InvocationRequest invocation) throws Throwable
      {
         for (int x = 0; x < listeners.size(); x++)
         {
            InvokerCallbackHandler callbackHandler = (InvokerCallbackHandler) listeners.get(x);
            callbackHandler.handleCallback(new Callback("This is callback payload"));
         }
         return "barfoo";
      }

      public void addListener(InvokerCallbackHandler callbackHandler)
      {
         listeners.add(callbackHandler);
      }

      public void removeListener(InvokerCallbackHandler callbackHandler)
      {
         listeners.remove(callbackHandler);
      }
   }

}