KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > mbeans > EndpointService


1 /*
2  * $Id: EndpointService.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.management.mbeans;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.config.i18n.Message;
16 import org.mule.config.i18n.Messages;
17 import org.mule.umo.endpoint.UMOEndpoint;
18 import org.mule.umo.provider.UMOMessageReceiver;
19 import org.mule.util.ObjectNameHelper;
20
21 /**
22  * The EndpointServiceMBean allows you to check the confiugration of an endpoint and
23  * conect/disconnect endpoints manually.
24  *
25  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
26  * @version $Revision: 3798 $
27  */

28 public class EndpointService implements EndpointServiceMBean
29 {
30     /**
31      * logger used by this class
32      */

33     protected transient Log logger = LogFactory.getLog(getClass());
34
35     private UMOEndpoint endpoint;
36     private UMOMessageReceiver receiver;
37     private String JavaDoc name;
38     private String JavaDoc componentName;
39
40     public EndpointService(UMOEndpoint endpoint)
41     {
42         this.endpoint = endpoint;
43         init();
44     }
45
46     public EndpointService(UMOMessageReceiver receiver)
47     {
48         if (receiver == null)
49         {
50             throw new NullPointerException JavaDoc(new Message(Messages.X_IS_NULL, "Receiver").getMessage());
51         }
52         this.endpoint = receiver.getEndpoint();
53         this.receiver = receiver;
54         this.componentName = receiver.getComponent().getDescriptor().getName();
55         init();
56     }
57
58     private void init()
59     {
60         if (endpoint == null)
61         {
62             throw new NullPointerException JavaDoc(new Message(Messages.X_IS_NULL, "Endpoint").getMessage());
63         }
64         if (receiver == null && !UMOEndpoint.ENDPOINT_TYPE_RECEIVER.equals(endpoint.getType()))
65         {
66             throw new IllegalArgumentException JavaDoc(
67                 "Recevier is null for Endpoint MBean but the endpoint itself is a receiving endpoint");
68         }
69
70         name = ObjectNameHelper.getEndpointName(endpoint);
71
72     }
73
74     public String JavaDoc getAddress()
75     {
76         return endpoint.getEndpointURI().getAddress();
77     }
78
79     public String JavaDoc getName()
80     {
81         return name;
82     }
83
84     public boolean isConnected()
85     {
86         return receiver == null || receiver.isConnected();
87     }
88
89     public void connect() throws Exception JavaDoc
90     {
91         if (receiver != null && !receiver.isConnected())
92         {
93             receiver.connect();
94         }
95         else if (logger.isDebugEnabled())
96         {
97             logger.debug("Endpoint is already connected");
98         }
99     }
100
101     public void disconnect() throws Exception JavaDoc
102     {
103         if (receiver != null && receiver.isConnected())
104         {
105             receiver.disconnect();
106         }
107         else if (logger.isDebugEnabled())
108         {
109             logger.debug("Endpoint is already disconnected");
110         }
111     }
112
113     public boolean isSynchronous()
114     {
115         return endpoint.isSynchronous();
116     }
117
118     public String JavaDoc getType()
119     {
120         return endpoint.getType();
121     }
122
123     public String JavaDoc getComponentName()
124     {
125         return componentName;
126     }
127
128     public void setComponentName(String JavaDoc componentName)
129     {
130         this.componentName = componentName;
131     }
132
133 }
134
Popular Tags