001: package org.objectweb.celtix.bus.jaxws;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: import javax.wsdl.Port;
007: import javax.wsdl.WSDLException;
008: import javax.xml.namespace.QName;
009: import javax.xml.ws.handler.Handler;
010:
011: import org.objectweb.celtix.bus.management.jmx.export.annotation.ManagedAttribute;
012: import org.objectweb.celtix.bus.management.jmx.export.annotation.ManagedOperation;
013: import org.objectweb.celtix.bus.management.jmx.export.annotation.ManagedResource;
014: import org.objectweb.celtix.management.Instrumentation;
015: import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
016:
017: @ManagedResource(componentName="Endpoint",description="The Celtix bus Endpoint",currencyTimeLimit=15,persistPolicy="OnUpdate")
018: public class EndpointInstrumentation implements Instrumentation {
019: private static final String INSTRUMENTED_NAME = "Bus.Endpoint";
020: private String objectName;
021: private EndpointImpl endPoint;
022:
023: public EndpointInstrumentation(EndpointImpl ep) {
024: endPoint = ep;
025: // setup the port name
026: objectName = ",Bus.Service=\"" + getEndpointServiceName()
027: + "\"" + ",Bus.Port=" + getEndpointPortName()
028: + ",name=Endpoint";
029: }
030:
031: public String getInstrumentationName() {
032: return INSTRUMENTED_NAME;
033: }
034:
035: public Object getComponent() {
036: return endPoint;
037: }
038:
039: public String getUniqueInstrumentationName() {
040: return objectName;
041: }
042:
043: private String getEndpointServiceName() {
044: QName serviceName = EndpointReferenceUtils
045: .getServiceName(endPoint.getEndpointReferenceType());
046: if (serviceName != null) {
047: return serviceName.toString();
048: } else {
049: return "";
050: }
051:
052: }
053:
054: private String getEndpointPortName() {
055: Port port;
056: String portName = null;
057: try {
058:
059: port = EndpointReferenceUtils.getPort(endPoint.getBus()
060: .getWSDLManager(), endPoint
061: .getEndpointReferenceType());
062: if (null != port) {
063: portName = port.getName();
064: } else {
065: portName = "";
066: }
067:
068: } catch (WSDLException e) {
069: // wsdlexception
070: // Now do nothing here
071: }
072: if (portName != null) {
073: return portName;
074: } else {
075: return "";
076: }
077: }
078:
079: @ManagedAttribute(currencyTimeLimit=30,description="The celtix bus Endpoint service name")
080: public String getServiceName() {
081: return getEndpointServiceName();
082: }
083:
084: @ManagedAttribute(currencyTimeLimit=30,description="The celtix bus Endpoint port name")
085: public String getPortName() {
086: return getEndpointPortName();
087: }
088:
089: @ManagedAttribute(currencyTimeLimit=-1,description="The state of celtix bus Endpoint")
090: public String getState() {
091: if (endPoint.isPublished()) {
092: return "ACTIVED";
093: } else {
094: return "DEACTIVED";
095: }
096: }
097:
098: @ManagedAttribute(currencyTimeLimit=30,description="The celtix bus Registed Endpoints's handlerChains")
099: public String[] getHandlerChains() {
100: List<String> strList = new ArrayList<String>();
101: List<Handler> handlers = endPoint.getServerBinding()
102: .getBinding().getHandlerChain();
103: for (Handler h : handlers) {
104: String handler = h.getClass().getName();
105: strList.add(handler);
106: }
107: String[] strings = new String[strList.size()];
108: return strList.toArray(strings);
109: }
110:
111: @ManagedOperation(currencyTimeLimit=30,description="The operation to start the celtix bus Endpoint")
112: public void start() {
113: endPoint.start();
114: }
115:
116: @ManagedOperation(currencyTimeLimit=30,description="The operation to stop the celtix bus Endpoint")
117: public void stop() {
118: endPoint.stop();
119: }
120:
121: }
|