001: package com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging;
002:
003: import java.util.Vector;
004:
005: import javax.jbi.messaging.MessageExchange.Role;
006:
007: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.notification.JMSNotification;
008: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.notification.MessageProcessNotification;
009: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.notification.StateChangeNotification;
010:
011: public abstract class LifeCycleEndpoint extends EndpointProcessor {
012:
013: protected String currentState = StatusConstants.STATUS_UNKNOWN;
014: protected String detailedStatus = "";
015: protected static long notificationSequence;
016: protected boolean forceShutdown;
017:
018: public String getState() {
019: return currentState;
020: }
021:
022: public void setState(String s) {
023: sendStateChangeNotification(currentState, s);
024: currentState = s;
025: }
026:
027: public void setState(String s, String detail) {
028: detailedStatus = detail;
029: setState(s);
030: }
031:
032: public String[] getDisplayParameterTitles() {
033: return new String[] {};
034: }
035:
036: public String[] getDisplayParameters() {
037: return new String[] {};
038: }
039:
040: public void stop() throws Exception {
041: setState(StatusConstants.STATUS_CLOSING);
042: /**
043: * The estimation of activated is important for the first deactivate time
044: */
045: if (activated != null) {
046: if (getRole() == Role.PROVIDER) {
047:
048: providerProc.stop();
049: } else {
050:
051: providerProc.stop();
052: consumerProc.stop();
053: }
054: }
055: setState(StatusConstants.STATUS_DOWN);
056:
057: }
058:
059: public void start() throws Exception {
060: setState(StatusConstants.STATUS_OPENING);
061: /**
062: * The estimation of activated is important for the first activate time
063: */
064: if (activated != null) {
065:
066: if (getRole() == Role.PROVIDER) {
067: providerProc.start();
068: } else {
069: consumerProc.start();
070: // The consumer endpoint also needs an provider processor for accept the MessageExchange in DONE or ERROR status
071: // It is not meaned to handle the ACTIVE MessageExchange
072: providerProc.start();
073: }
074: }
075: setState(StatusConstants.STATUS_UP);
076:
077: }
078:
079: /*
080: * This returns a list of all properties that can be read
081: */
082: public String[] getGetableProperties() {
083: return new String[] {};
084: }
085:
086: /*
087: * This returns a list of all properties that may be set.
088: */
089: public String[] getSetableProperties() {
090: return new String[] {};
091: }
092:
093: /* This broadcasts a JMX notification from the LifeCycleExtension that indicates a state change
094: * on the endpoint.
095: */
096: protected void sendStateChangeNotification(String oldState,
097: String newState) {
098: CbExtendedComponent comp = (CbExtendedComponent) getServiceUnit()
099: .getComponent();
100: CbExtendedLifeCycle elc = (CbExtendedLifeCycle) comp
101: .getLifeCycle();
102: LifeCycleExtension lcext = (LifeCycleExtension) elc
103: .getExtensionMBean();
104: StateChangeNotification notification = new StateChangeNotification(
105: comp.getComponentName() + "EndpointNotification", elc
106: .getExtensionMBeanName(),
107: notificationSequence++, System.currentTimeMillis(),
108: comp.getComponentName(), this .getEndpoint(), oldState,
109: newState);
110: lcext.sendNotification(notification);
111: }
112:
113: public void sendMessageProcessedNotification(long latency) {
114: CbExtendedComponent comp = (CbExtendedComponent) getServiceUnit()
115: .getComponent();
116: CbExtendedLifeCycle elc = (CbExtendedLifeCycle) comp
117: .getLifeCycle();
118: LifeCycleExtension lcext = (LifeCycleExtension) elc
119: .getExtensionMBean();
120: MessageProcessNotification notification = new MessageProcessNotification(
121: MessageProcessNotification.TYPE_MESSAGEPROCESSED, elc
122: .getExtensionMBeanName(),
123: notificationSequence++, System.currentTimeMillis(),
124: this .getSaName(), this .getServiceUnit().getName(), this
125: .getEndpoint(),
126: getRole() == Role.PROVIDER ? "provider" : "consumer",
127: latency);
128: lcext.sendNotification(notification);
129: }
130:
131: public void sendJMSDLQNotification() {
132: CbExtendedComponent comp = (CbExtendedComponent) getServiceUnit()
133: .getComponent();
134: CbExtendedLifeCycle elc = (CbExtendedLifeCycle) comp
135: .getLifeCycle();
136: LifeCycleExtension lcext = (LifeCycleExtension) elc
137: .getExtensionMBean();
138: JMSNotification notification = new JMSNotification(
139: JMSNotification.TYPE_DLQ, elc.getExtensionMBeanName(),
140: notificationSequence++, System.currentTimeMillis(),
141: this .getSaName(), this .getServiceUnit().getName(), this
142: .getEndpoint(),
143: getRole() == Role.PROVIDER ? "provider" : "consumer");
144: notification.setPutOneToDLQ(true);
145: lcext.sendNotification(notification);
146: }
147:
148: public void sendJMSRetryCountExceededNotification() {
149: CbExtendedComponent comp = (CbExtendedComponent) getServiceUnit()
150: .getComponent();
151: CbExtendedLifeCycle elc = (CbExtendedLifeCycle) comp
152: .getLifeCycle();
153: LifeCycleExtension lcext = (LifeCycleExtension) elc
154: .getExtensionMBean();
155: JMSNotification notification = new JMSNotification(
156: JMSNotification.TYPE_RETRY_COUNT_EXCEEDED, elc
157: .getExtensionMBeanName(),
158: notificationSequence++, System.currentTimeMillis(),
159: this .getSaName(), this .getServiceUnit().getName(), this
160: .getEndpoint(),
161: getRole() == Role.PROVIDER ? "provider" : "consumer");
162: notification.setRetryCountExceeded(true);
163: lcext.sendNotification(notification);
164: }
165:
166: public void sendJMSTransactionRollBackNotification() {
167: CbExtendedComponent comp = (CbExtendedComponent) getServiceUnit()
168: .getComponent();
169: CbExtendedLifeCycle elc = (CbExtendedLifeCycle) comp
170: .getLifeCycle();
171: LifeCycleExtension lcext = (LifeCycleExtension) elc
172: .getExtensionMBean();
173: JMSNotification notification = new JMSNotification(
174: JMSNotification.TYPE_TRANSACTION_ROLL_BACK, elc
175: .getExtensionMBeanName(),
176: notificationSequence++, System.currentTimeMillis(),
177: this .getSaName(), this .getServiceUnit().getName(), this
178: .getEndpoint(),
179: getRole() == Role.PROVIDER ? "provider" : "consumer");
180: notification.setTransactionRollback(true);
181: lcext.sendNotification(notification);
182: }
183:
184: public String[][] getGetablePropertyObjects() {
185: Vector<String[]> properties = new Vector<String[]>();
186: for (int i = 0; i < getGetableProperties().length; i++) {
187: properties.add(new String[] { getGetableProperties()[i],
188: getProperty(i) });
189: }
190: return properties.toArray(new String[][] {});
191: }
192:
193: /*
194: * This gets one property from the list above.
195: */
196: public String getProperty(String property) {
197: int found = -1;
198: for (int i = 0; i < getGetableProperties().length; i++)
199: if (property.equals(getGetableProperties()[i])) {
200: found = i;
201: break;
202: }
203:
204: return getProperty(found);
205: }
206:
207: /*
208: * This sets one property from the list above.
209: */
210: public void setProperty(String property, String value) {
211: int found = -1;
212: for (int i = 0; i < getSetableProperties().length; i++)
213: if (property.equals(getSetableProperties()[i])) {
214: found = i;
215: break;
216: }
217: setProperty(found, value);
218: }
219:
220: public void setProperty(int index, String value) {
221:
222: }
223:
224: public String getProperty(int index) {
225: return null;
226: }
227:
228: protected void postProcess(long startProcessTime) {
229:
230: sendMessageProcessedNotification(System.currentTimeMillis()
231: - startProcessTime);
232:
233: }
234: }
|