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 | 0 | 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 | 0 | { |
42 | 0 | this.endpoint = endpoint; |
43 | 0 | init(); |
44 | 0 | } |
45 | |
|
46 | |
public EndpointService(MessageReceiver receiver) |
47 | 0 | { |
48 | 0 | if (receiver == null) |
49 | |
{ |
50 | 0 | throw new IllegalArgumentException(CoreMessages.objectIsNull("Receiver").getMessage()); |
51 | |
} |
52 | 0 | this.endpoint = receiver.getEndpoint(); |
53 | 0 | this.receiver = receiver; |
54 | 0 | this.componentName = receiver.getService().getName(); |
55 | 0 | init(); |
56 | 0 | } |
57 | |
|
58 | |
private void init() |
59 | |
{ |
60 | 0 | if (endpoint == null) |
61 | |
{ |
62 | 0 | throw new IllegalArgumentException(CoreMessages.objectIsNull("Endpoint").getMessage()); |
63 | |
} |
64 | 0 | if (receiver == null && endpoint instanceof InboundEndpoint) |
65 | |
{ |
66 | 0 | throw new IllegalArgumentException( |
67 | |
"Recevier is null for Endpoint MBean but the endpoint itself is a receiving endpoint"); |
68 | |
} |
69 | |
|
70 | 0 | name = ObjectNameHelper.getEndpointName(endpoint.getEndpointURI()); |
71 | 0 | } |
72 | |
|
73 | |
public String getAddress() |
74 | |
{ |
75 | 0 | return endpoint.getEndpointURI().getAddress(); |
76 | |
} |
77 | |
|
78 | |
public String getName() |
79 | |
{ |
80 | 0 | return name; |
81 | |
} |
82 | |
|
83 | |
public boolean isConnected() |
84 | |
{ |
85 | 0 | return receiver == null || receiver.isConnected(); |
86 | |
} |
87 | |
|
88 | |
public void connect() throws Exception |
89 | |
{ |
90 | 0 | if (receiver != null && !receiver.isConnected()) |
91 | |
{ |
92 | 0 | receiver.connect(); |
93 | |
} |
94 | 0 | else if (logger.isDebugEnabled()) |
95 | |
{ |
96 | 0 | logger.debug("Endpoint is already connected"); |
97 | |
} |
98 | 0 | } |
99 | |
|
100 | |
public void disconnect() throws Exception |
101 | |
{ |
102 | 0 | if (receiver != null && receiver.isConnected()) |
103 | |
{ |
104 | 0 | receiver.disconnect(); |
105 | |
} |
106 | 0 | else if (logger.isDebugEnabled()) |
107 | |
{ |
108 | 0 | logger.debug("Endpoint is already disconnected"); |
109 | |
} |
110 | 0 | } |
111 | |
|
112 | |
public boolean isInbound() |
113 | |
{ |
114 | 0 | return endpoint instanceof InboundEndpoint; |
115 | |
} |
116 | |
|
117 | |
public boolean isOutbound() |
118 | |
{ |
119 | 0 | return endpoint instanceof OutboundEndpoint; |
120 | |
} |
121 | |
|
122 | |
public boolean isSynchronous() |
123 | |
{ |
124 | 0 | return endpoint.isSynchronous(); |
125 | |
} |
126 | |
|
127 | |
public String getComponentName() |
128 | |
{ |
129 | 0 | return componentName; |
130 | |
} |
131 | |
|
132 | |
public void setComponentName(String componentName) |
133 | |
{ |
134 | 0 | this.componentName = componentName; |
135 | 0 | } |
136 | |
|
137 | |
} |