View Javadoc

1   /*
2    * $Id: JbiConnector.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.jbi;
12  
13  import org.mule.providers.AbstractConnector;
14  import org.mule.umo.UMOException;
15  import org.mule.umo.lifecycle.InitialisationException;
16  
17  import javax.jbi.JBIException;
18  import javax.jbi.component.ComponentContext;
19  import javax.jbi.component.ComponentLifeCycle;
20  import javax.jbi.messaging.DeliveryChannel;
21  import javax.jbi.messaging.MessageExchangeFactory;
22  import javax.management.ObjectName;
23  
24  /**
25   * <code>JbiConnector</code> can bind to a JBI container allowing components to
26   * send events via Mule.
27   */
28  public class JbiConnector extends AbstractConnector implements ComponentLifeCycle
29  {
30      private ObjectName extensionMBeanName;
31      private ComponentContext context;
32      private DeliveryChannel deliveryChannel;
33      private MessageExchangeFactory exchangeFactory;
34  
35  
36      protected void doInitialise() throws InitialisationException
37      {
38          // template method, nothing to do
39      }
40  
41      protected void doDispose()
42      {
43          // template method
44      }
45  
46      protected void doConnect() throws Exception
47      {
48          // template method
49      }
50  
51      protected void doDisconnect() throws Exception
52      {
53          // template method
54      }
55  
56      protected void doStart() throws UMOException
57      {
58          // template method
59      }
60  
61      protected void doStop() throws UMOException
62      {
63          // template method
64      }
65  
66      public String getProtocol()
67      {
68          return "jbi";
69      }
70  
71      public ObjectName getExtensionMBeanName()
72      {
73          return extensionMBeanName;
74      }
75  
76      public void setExtensionMBeanName(ObjectName extensionMBeanName)
77      {
78          this.extensionMBeanName = extensionMBeanName;
79      }
80  
81      public ComponentContext getComponentContext()
82      {
83          return context;
84      }
85  
86      public DeliveryChannel getDeliveryChannel()
87      {
88          return deliveryChannel;
89      }
90  
91      public MessageExchangeFactory getExchangeFactory()
92      {
93          return exchangeFactory;
94      }
95  
96      /**
97       * @see ComponentLifeCycle#init(ComponentContext)
98       */
99      // TODO the start/stop/shutdown JBI lifecycle methods are rather picky,
100     // we should probably review the spec here again
101     public void init(ComponentContext componentContext) throws JBIException
102     {
103         this.context = componentContext;
104         this.deliveryChannel = context.getDeliveryChannel();
105         this.exchangeFactory = deliveryChannel.createExchangeFactory();
106     }
107 
108     /**
109      * @see ComponentLifeCycle#start()
110      */
111     public void start()
112     {
113         try
114         {
115             startConnector();
116         }
117         catch (UMOException e)
118         {
119             handleException(e);
120         }
121     }
122 
123     /**
124      * @see ComponentLifeCycle#stop()
125      */
126     public void stop()
127     {
128         try
129         {
130             stopConnector();
131         }
132         catch (UMOException e)
133         {
134             handleException(e);
135         }
136     }
137 
138     /**
139      * @see ComponentLifeCycle#shutDown()
140      */
141     public void shutDown() throws JBIException
142     {
143         // nothing to do (for now?)
144     }
145 
146 }