001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)LinkedEndpoint.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.messaging;
030:
031: import com.sun.jbi.messaging.stats.Value;
032: import com.sun.jbi.messaging.stats.METimestamps;
033:
034: import javax.management.openmbean.CompositeData;
035: import javax.management.openmbean.CompositeDataSupport;
036: import javax.management.openmbean.CompositeType;
037: import javax.management.openmbean.SimpleType;
038: import javax.management.openmbean.OpenType;
039:
040: import javax.xml.namespace.QName;
041:
042: /**
043: * @author Sun Microsystems, Inc.
044: */
045: public class LinkedEndpoint extends RegisteredEndpoint {
046: /** Linked endpoints are global in scope and are activated as a result of
047: * service connection information in a service assembly. Therefore they
048: * are not 'owned' by a single component. This constant is provided so
049: * to avoid a null ownerId var in RegisteredEndpoint.
050: */
051: private static final String OWNER_ID = "<NotKnownYet>";
052:
053: private QName mServiceLink;
054: private String mEndpointLink;
055: private Link mLinkType;
056:
057: /** Creates a new MappedEndpoint.
058: * @param service service name
059: * @param endpoint endpoint name
060: * @param linkType link type for connection mapping
061: * @param reference endpoint reference for this endpoint
062: * @param type endpoint type
063: */
064: public LinkedEndpoint(QName fromService, String fromEndpoint,
065: QName toService, String toEndpoint, Link linkType) {
066: super (fromService, fromEndpoint, OWNER_ID);
067:
068: mLinkType = linkType;
069: mServiceLink = toService;
070: mEndpointLink = toEndpoint;
071: }
072:
073: public int getType() {
074: return LINKED;
075: }
076:
077: public String getEndpointLink() {
078: return mEndpointLink;
079: }
080:
081: public QName getServiceLink() {
082: return mServiceLink;
083: }
084:
085: public void setInUse(String ownerId) {
086: mActiveExchanges.incrementAndGet();
087: if (mOwnerId.equals(OWNER_ID)) {
088: mOwnerId = ownerId;
089: }
090: }
091:
092: /** Compares two LinkedEndpoint instances for equality. */
093: public boolean equals(Object obj) {
094: LinkedEndpoint le;
095: boolean isEqual = false;
096:
097: if (obj instanceof LinkedEndpoint) {
098: le = (LinkedEndpoint) obj;
099: isEqual = (mLinkType == le.mLinkType)
100: && (mEndpointLink.equals(le.mEndpointLink))
101: && (mServiceLink.equals(le.mServiceLink))
102: && (getEndpointName().equals(le.getEndpointName()))
103: && (getServiceName().equals(le.getServiceName()))
104: && (getOwnerId().equals(le.getOwnerId()));
105: }
106:
107: return isEqual;
108: }
109:
110: /** Using to->service, to->endpoint, and from->service to produce hashcode.
111: */
112: public int hashCode() {
113: return (mServiceLink.toString() + mEndpointLink + getServiceName())
114: .hashCode();
115: }
116:
117: synchronized void updateStatistics(MessageExchangeProxy me) {
118: int mask = me.getPhaseMask();
119: METimestamps ts = me.getTimestamps();
120:
121: if ((mask & MessageExchangeProxy.PM_RECEIVE_REPLY) != 0) {
122: mReceiveReply++;
123: }
124: if ((mask & MessageExchangeProxy.PM_SEND_FAULT) != 0) {
125: mSendFault++;
126: mLastFaultTime = System.currentTimeMillis();
127: }
128: if ((mask & MessageExchangeProxy.PM_SEND_DONE) != 0) {
129: mSendDONE++;
130: mLastDONETime = System.currentTimeMillis();
131: }
132: if ((mask & MessageExchangeProxy.PM_SEND_ERROR) != 0) {
133: mSendERROR++;
134: mLastERRORTime = System.currentTimeMillis();
135: }
136: if ((mask & MessageExchangeProxy.PM_SEND_REQUEST) != 0) {
137: mSendRequest++;
138: }
139: if ((mask & MessageExchangeProxy.PM_RECEIVE_FAULT) != 0) {
140: mReceiveFault++;
141: mLastFaultTime = System.currentTimeMillis();
142: }
143: if ((mask & MessageExchangeProxy.PM_RECEIVE_DONE) != 0) {
144: mReceiveDONE++;
145: mLastDONETime = System.currentTimeMillis();
146: }
147: if ((mask & MessageExchangeProxy.PM_RECEIVE_ERROR) != 0) {
148: mReceiveERROR++;
149: mLastERRORTime = System.currentTimeMillis();
150: }
151: if (ts != null) {
152: mStatusTime.addSample(ts.mStatusTime);
153: mNMRTime.addSample(ts.mNMRTime);
154: mChannelTime.addSample(ts.mProviderChannelTime);
155: mComponentTime.addSample(ts.mProviderTime);
156: }
157: }
158:
159: //-------------------------EndpointStatistics-------------------------------
160:
161: public String getName() {
162: return (toExternalName());
163: }
164:
165: /**
166: * List of item names for CompositeData construction.
167: */
168: private static final String[] ITEM_NAMES = { "OwningChannel",
169: "ActiveExchanges", "SendRequest", "ReceiveReply",
170: "SendFault", "ReceiveFault", "LastFaultTime", "SendDONE",
171: "ReceiveDONE", "LastDONETime", "SendERROR", "ReceiveERROR",
172: "LastERRORTime", "StatusTimeMin (ns)",
173: "StatusTimeAvg (ns)", "StatusTimeMax (ns)",
174: "StatusTimeStd (ns)", "NMRTimeMin (ns)", "NMRTimeAvg (ns)",
175: "NMRTimeMax (ns)", "NMRTimeStd (ns)",
176: "ComponentTimeMin (ns)", "ComponentTimeAvg (ns)",
177: "ComponentTimeMax (ns)", "ComponentTimeStd (ns)",
178: "ChannelTimeMin (ns)", "ChannelTimeAvg (ns)",
179: "ChannelTimeMax (ns)", "ChannelTimeStd (ns)" };
180:
181: /**
182: * List of descriptions of items for ComponsiteData construction.
183: */
184: private static final String ITEM_DESCRIPTIONS[] = {
185: "Owning DeliveryChannel", "Active Exchanges",
186: "Number of requests sent", "Number of replies received",
187: "Number of faults sent", "Number of faults received",
188: "Timestamp of last fault", "Number of DONE requests sent",
189: "Number of DONE requests received",
190: "Timestamp of last DONE", "Number of ERROR requests sent",
191: "Number of ERROR requests received",
192: "Timestamp of last ERROR", "Status Time Min",
193: "Status Time Avg", "Status Time Max", "Status Time Std",
194: "NMR Time Min", "NMR Time Avg", "NMR Time Max",
195: "NMR Time Std", "Component Time Min", "Component Time Avg",
196: "Component Time Max", "Component Time Std",
197: "Channel Time Min", "Channel Time Avg", "Channel Time Max",
198: "Channel Time Std" };
199:
200: /**
201: * List of types of items for CompositeData construction.
202: */
203: private static final OpenType ITEM_TYPES[] = { SimpleType.STRING,
204: SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
205: SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
206: SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
207: SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
208: SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
209: SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
210: SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
211: SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
212: SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
213: SimpleType.LONG };
214:
215: public CompositeData getStatistics() {
216: try {
217: Object values[] = { mOwnerId, mActiveExchanges.get(),
218: mSendRequest, mReceiveReply, mSendFault,
219: mReceiveFault, mLastFaultTime, mSendDONE,
220: mReceiveDONE, mLastDONETime, mSendERROR,
221: mReceiveERROR, mLastERRORTime,
222: mStatusTime.getMin(),
223: (long) mStatusTime.getAverage(),
224: mStatusTime.getMax(), (long) mStatusTime.getSd(),
225: mNMRTime.getMin(), (long) mNMRTime.getAverage(),
226: mNMRTime.getMax(), (long) mNMRTime.getSd(),
227: mComponentTime.getMin(),
228: (long) mComponentTime.getAverage(),
229: mComponentTime.getMax(),
230: (long) mComponentTime.getSd(),
231: mChannelTime.getMin(),
232: (long) mChannelTime.getAverage(),
233: mChannelTime.getMax(), (long) mChannelTime.getSd() };
234:
235: return new CompositeDataSupport(new CompositeType(
236: "EndpointStatistics", "Endpoint statistics",
237: ITEM_NAMES, ITEM_DESCRIPTIONS, ITEM_TYPES),
238: ITEM_NAMES, values);
239: } catch (javax.management.openmbean.OpenDataException odEx) {
240: ; // ignore this for now
241: }
242: return (null);
243: }
244:
245: public String toStringBrief() {
246: StringBuilder sb = new StringBuilder();
247:
248: sb.append(" EndPoint Type: Linked(Endpoint=");
249: sb.append(mEndpointLink == null ? "Null" : mEndpointLink);
250: sb.append(",Service=");
251: sb.append(mServiceLink == null ? "Null" : mServiceLink);
252: sb.append(")\n");
253: sb.append(super .toStringBrief());
254: return (sb.toString());
255: }
256:
257: public String toString() {
258: StringBuilder sb = new StringBuilder();
259:
260: sb.append(toStringBrief());
261: sb.append(" SendRequest: " + mSendRequest);
262: sb.append(" ReceiveReply: " + mReceiveReply);
263: sb.append("\n RecvDONE: " + mReceiveDONE);
264: sb.append(" SendDONE: " + mSendDONE);
265: sb.append("\n RecvERROR: " + mReceiveERROR);
266: sb.append(" SendERROR: " + mSendERROR);
267: sb.append("\n RecvFault: " + mReceiveFault);
268: sb.append(" SendFault: " + mSendFault);
269: if (mStatusTime != null) {
270: sb.append("\n StatusTime: "
271: + mStatusTime.toString());
272: sb.append("\n ComponentTime: "
273: + mComponentTime.toString());
274: sb.append("\n ChannelTime: "
275: + mChannelTime.toString());
276: sb.append("\n NMRTime: "
277: + mNMRTime.toString());
278: sb.append("\n");
279: }
280: return (sb.toString());
281: }
282: }
|