1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.management.mbean;
12
13 import org.mule.api.endpoint.ImmutableEndpoint;
14 import org.mule.api.endpoint.InboundEndpoint;
15 import org.mule.api.endpoint.OutboundEndpoint;
16 import org.mule.api.transport.MessageReceiver;
17 import org.mule.config.i18n.CoreMessages;
18 import org.mule.util.ObjectNameHelper;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23
24
25
26
27 public class EndpointService implements EndpointServiceMBean
28 {
29
30
31
32
33 protected transient Log logger = LogFactory.getLog(getClass());
34
35 private ImmutableEndpoint endpoint;
36 private MessageReceiver receiver;
37 private String name;
38 private String componentName;
39
40 public EndpointService(ImmutableEndpoint endpoint)
41 {
42 this.endpoint = endpoint;
43 init();
44 }
45
46 public EndpointService(MessageReceiver receiver)
47 {
48 if (receiver == null)
49 {
50 throw new IllegalArgumentException(CoreMessages.objectIsNull("Receiver").getMessage());
51 }
52 this.endpoint = receiver.getEndpoint();
53 this.receiver = receiver;
54 this.componentName = receiver.getService().getName();
55 init();
56 }
57
58 private void init()
59 {
60 if (endpoint == null)
61 {
62 throw new IllegalArgumentException(CoreMessages.objectIsNull("Endpoint").getMessage());
63 }
64 if (receiver == null && endpoint instanceof InboundEndpoint)
65 {
66 throw new IllegalArgumentException(
67 "Recevier is null for Endpoint MBean but the endpoint itself is a receiving endpoint");
68 }
69
70 name = ObjectNameHelper.getEndpointName(endpoint.getEndpointURI());
71 }
72
73 public String getAddress()
74 {
75 return endpoint.getEndpointURI().getAddress();
76 }
77
78 public String getName()
79 {
80 return name;
81 }
82
83 public boolean isConnected()
84 {
85 return receiver == null || receiver.isConnected();
86 }
87
88 public void connect() throws Exception
89 {
90 if (receiver != null && !receiver.isConnected())
91 {
92 receiver.connect();
93 }
94 else if (logger.isDebugEnabled())
95 {
96 logger.debug("Endpoint is already connected");
97 }
98 }
99
100 public void disconnect() throws Exception
101 {
102 if (receiver != null && receiver.isConnected())
103 {
104 receiver.disconnect();
105 }
106 else if (logger.isDebugEnabled())
107 {
108 logger.debug("Endpoint is already disconnected");
109 }
110 }
111
112 public boolean isInbound()
113 {
114 return endpoint instanceof InboundEndpoint;
115 }
116
117 public boolean isOutbound()
118 {
119 return endpoint instanceof OutboundEndpoint;
120 }
121
122 public boolean isSynchronous()
123 {
124 return endpoint.isSynchronous();
125 }
126
127 public String getComponentName()
128 {
129 return componentName;
130 }
131
132 public void setComponentName(String componentName)
133 {
134 this.componentName = componentName;
135 }
136
137 }