1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.management.mbeans; |
12 | |
|
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
import org.mule.umo.endpoint.UMOEndpoint; |
15 | |
import org.mule.umo.provider.UMOMessageReceiver; |
16 | |
import org.mule.util.ObjectNameHelper; |
17 | |
|
18 | |
import org.apache.commons.logging.Log; |
19 | |
import org.apache.commons.logging.LogFactory; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class EndpointService implements EndpointServiceMBean |
29 | |
{ |
30 | |
|
31 | |
|
32 | |
|
33 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
34 | |
|
35 | |
private UMOEndpoint endpoint; |
36 | |
private UMOMessageReceiver receiver; |
37 | |
private String name; |
38 | |
private String componentName; |
39 | |
|
40 | |
public EndpointService(UMOEndpoint endpoint) |
41 | 0 | { |
42 | 0 | this.endpoint = endpoint; |
43 | 0 | init(); |
44 | 0 | } |
45 | |
|
46 | |
public EndpointService(UMOMessageReceiver 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.getComponent().getDescriptor().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 && !UMOEndpoint.ENDPOINT_TYPE_RECEIVER.equals(endpoint.getType())) |
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); |
71 | |
|
72 | 0 | } |
73 | |
|
74 | |
public String getAddress() |
75 | |
{ |
76 | 0 | return endpoint.getEndpointURI().getAddress(); |
77 | |
} |
78 | |
|
79 | |
public String getName() |
80 | |
{ |
81 | 0 | return name; |
82 | |
} |
83 | |
|
84 | |
public boolean isConnected() |
85 | |
{ |
86 | 0 | return receiver == null || receiver.isConnected(); |
87 | |
} |
88 | |
|
89 | |
public void connect() throws Exception |
90 | |
{ |
91 | 0 | if (receiver != null && !receiver.isConnected()) |
92 | |
{ |
93 | 0 | receiver.connect(); |
94 | |
} |
95 | 0 | else if (logger.isDebugEnabled()) |
96 | |
{ |
97 | 0 | logger.debug("Endpoint is already connected"); |
98 | |
} |
99 | 0 | } |
100 | |
|
101 | |
public void disconnect() throws Exception |
102 | |
{ |
103 | 0 | if (receiver != null && receiver.isConnected()) |
104 | |
{ |
105 | 0 | receiver.disconnect(); |
106 | |
} |
107 | 0 | else if (logger.isDebugEnabled()) |
108 | |
{ |
109 | 0 | logger.debug("Endpoint is already disconnected"); |
110 | |
} |
111 | 0 | } |
112 | |
|
113 | |
public boolean isSynchronous() |
114 | |
{ |
115 | 0 | return endpoint.isSynchronous(); |
116 | |
} |
117 | |
|
118 | |
public String getType() |
119 | |
{ |
120 | 0 | return endpoint.getType(); |
121 | |
} |
122 | |
|
123 | |
public String getComponentName() |
124 | |
{ |
125 | 0 | return componentName; |
126 | |
} |
127 | |
|
128 | |
public void setComponentName(String componentName) |
129 | |
{ |
130 | 0 | this.componentName = componentName; |
131 | 0 | } |
132 | |
|
133 | |
} |