File: DispatcherDelegate.java

package info (click to toggle)
libjboss-web-services-java 0.0%2Bsvn5660%2Bdak2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,252 kB
  • ctags: 12,475
  • sloc: java: 79,207; xml: 29; makefile: 19; sh: 16
file content (89 lines) | stat: -rw-r--r-- 2,538 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
package org.jboss.ws.extensions.eventing.mgmt;

import java.net.URI;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.StringRefAddr;

import org.jboss.ws.WSException;
import org.w3c.dom.Element;

/**
 * Event dispatching delegate that will be bound to JNDI.
 *
 * @see DispatcherFactory
 * 
 * @author Heiko Braun, <heiko@openj.net>
 * @since 11-Jan-2006
 */
public class DispatcherDelegate implements EventDispatcher, Referenceable
{
   private String hostname;
   public final static String MANAGER_HOSTNAME = "manager.hostname";
   private SubscriptionManagerMBean subscriptionManager = null;

   public DispatcherDelegate()
   {
   }

   public DispatcherDelegate(String hostname)
   {
      setHostname(hostname);
   }

   public void dispatch(URI eventSourceNS, Element payload)
   {
      getSubscriptionManager().dispatch(eventSourceNS, payload);
   }

   public Reference getReference() throws NamingException
   {

      Reference myRef = new Reference(DispatcherDelegate.class.getName(), DispatcherFactory.class.getName(), null);

      // let the delegate now where to find the subscription manager
      myRef.add(new StringRefAddr(MANAGER_HOSTNAME, hostname));

      return myRef;
   }

   private SubscriptionManagerMBean getSubscriptionManager()
   {
      if (null == subscriptionManager)
      {
         try
         {
            ObjectName objectName = SubscriptionManager.OBJECT_NAME;
            subscriptionManager = (SubscriptionManagerMBean)MBeanServerInvocationHandler.newProxyInstance(getServer(), objectName, SubscriptionManagerMBean.class,
                  false);
         }
         catch (Exception e)
         {
            throw new WSException("Failed to access subscription manager: " + e.getMessage());
         }
      }

      return subscriptionManager;
   }

   private MBeanServerConnection getServer() throws NamingException
   {
      // todo: bypass rmi adapter when used locally
      InitialContext iniCtx = new InitialContext();
      MBeanServerConnection server = (MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
      return server;
   }

   void setHostname(String hostname)
   {
      if (null == hostname)
         throw new IllegalArgumentException("Hostname may not be null");
      this.hostname = hostname;
   }
}