001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.desktop.mfwk;
006:
007: import com.sun.cmm.cim.OperationalStatus;
008: import com.sun.mfwk.instrum.me.CIM_ManagedElementInstrum;
009: import com.sun.mfwk.instrum.me.CMM_ServiceAccessURIInstrum;
010: import com.sun.mfwk.instrum.me.MfManagedElementInstrumException;
011: import com.sun.mfwk.instrum.me.settings.CMM_ServiceAccessURISettingInstrum;
012: import com.sun.mfwk.instrum.me.statistics.CMM_ServiceAccessURIStatsInstrum;
013: import com.sun.mfwk.instrum.me.statistics.MfTransactionInstrum;
014: import com.sun.mfwk.instrum.me.statistics.MfTransactionInstrumConstants;
015: import com.sun.mfwk.instrum.me.statistics.MfTransactionType;
016: import com.sun.mfwk.instrum.relations.MfRelationInstrumException;
017: import com.sun.mfwk.instrum.server.MfManagedElementInfo;
018: import com.sun.mfwk.instrum.server.MfManagedElementServer;
019: import com.sun.mfwk.instrum.server.MfManagedElementServerException;
020: import com.sun.mfwk.instrum.server.MfManagedElementType;
021: import com.sun.mfwk.instrum.server.MfRelationType;
022: import com.sun.portal.log.common.PortalLogger;
023: import java.util.Arrays;
024: import java.util.HashSet;
025: import java.util.logging.Level;
026: import java.util.logging.LogRecord;
027: import java.util.logging.Logger;
028:
029: public class MfwkPSServiceAccessURIAdaptor {
030: private static final Logger logger = PortalLogger
031: .getLogger(MfwkPSServiceAccessURIAdaptor.class);
032:
033: private static LogRecord getLogRecord(Level level, String message,
034: Object[] parameters, Throwable t) {
035: LogRecord result = new LogRecord(level, message);
036: result.setLoggerName(logger.getName());
037: result.setParameters(parameters);
038: result.setThrown(t);
039: return result;
040: }
041:
042: private String name;
043: private String settingName;
044: private String statsName;
045: private String labeledURI;
046: private boolean secured;
047:
048: public MfwkPSServiceAccessURIAdaptor(String name,
049: String settingName, String statsName, String labeledURI,
050: boolean secured) {
051: setName(name);
052: setSettingName(settingName);
053: setStatsName(statsName);
054: setLabeledURI(labeledURI);
055: setSecured(secured);
056: }
057:
058: public String getName() {
059: return name;
060: }
061:
062: public void setName(String name) {
063: this .name = name;
064: }
065:
066: public String getSettingName() {
067: return settingName;
068: }
069:
070: public void setSettingName(String settingName) {
071: this .settingName = settingName;
072: }
073:
074: public String getStatsName() {
075: return statsName;
076: }
077:
078: public void setStatsName(String statsName) {
079: this .statsName = statsName;
080: }
081:
082: public String getLabeledURI() {
083: return labeledURI;
084: }
085:
086: public void setLabeledURI(String labeledURI) {
087: this .labeledURI = labeledURI;
088: }
089:
090: public boolean isSecured() {
091: return secured;
092: }
093:
094: public void setSecured(boolean secured) {
095: this .secured = secured;
096: }
097:
098: private boolean gearedUp = false;
099: private MfManagedElementInfo info;
100: private MfManagedElementInfo settingInfo;
101: private MfManagedElementInfo statsInfo;
102: private MfwkPSRelationAdaptor relation;
103: private MfwkPSRelationAdaptor settingRelation;
104: private MfwkPSRelationAdaptor statsRelation;
105: private ThreadLocal transactionInstrum = new ThreadLocal();
106:
107: public boolean isGearedUp() {
108: return gearedUp;
109: }
110:
111: public void setGearedUp(boolean gearedUp) {
112: this .gearedUp = gearedUp;
113: }
114:
115: public MfManagedElementInfo getInfo() {
116: return info;
117: }
118:
119: public void setInfo(MfManagedElementInfo info) {
120: this .info = info;
121: }
122:
123: public MfManagedElementInfo getSettingInfo() {
124: return settingInfo;
125: }
126:
127: public void setSettingInfo(MfManagedElementInfo settingInfo) {
128: this .settingInfo = settingInfo;
129: }
130:
131: public MfManagedElementInfo getStatsInfo() {
132: return statsInfo;
133: }
134:
135: public void setStatsInfo(MfManagedElementInfo statsInfo) {
136: this .statsInfo = statsInfo;
137: }
138:
139: public MfwkPSRelationAdaptor getRelation() {
140: return relation;
141: }
142:
143: public void setRelation(MfwkPSRelationAdaptor relation) {
144: this .relation = relation;
145: }
146:
147: public MfwkPSRelationAdaptor getSettingRelation() {
148: return settingRelation;
149: }
150:
151: public void setSettingRelation(MfwkPSRelationAdaptor settingRelation) {
152: this .settingRelation = settingRelation;
153: }
154:
155: public MfwkPSRelationAdaptor getStatsRelation() {
156: return statsRelation;
157: }
158:
159: public void setStatsRelation(MfwkPSRelationAdaptor statsRelation) {
160: this .statsRelation = statsRelation;
161: }
162:
163: public MfTransactionInstrum getTransactionInstrum() {
164: return (MfTransactionInstrum) transactionInstrum.get();
165: }
166:
167: public void setTransactionInstrum(
168: MfTransactionInstrum transactionInstrum) {
169: this .transactionInstrum.set(transactionInstrum);
170: }
171:
172: public CMM_ServiceAccessURIInstrum getInstrum()
173: throws MfRelationInstrumException {
174: return (CMM_ServiceAccessURIInstrum) getRelation().getInstrum()
175: .getDestination();
176: }
177:
178: public CMM_ServiceAccessURISettingInstrum getSettingInstrum()
179: throws MfRelationInstrumException {
180: return (CMM_ServiceAccessURISettingInstrum) getSettingRelation()
181: .getInstrum().getDestination();
182: }
183:
184: public CMM_ServiceAccessURIStatsInstrum getStatsInstrum()
185: throws MfRelationInstrumException {
186: return (CMM_ServiceAccessURIStatsInstrum) getStatsRelation()
187: .getInstrum().getDestination();
188: }
189:
190: public void gearUp(MfManagedElementServer mfmeServer,
191: MfRelationType relationType,
192: CIM_ManagedElementInstrum sourceManagedElementInstrum)
193: throws MfManagedElementInstrumException,
194: MfManagedElementServerException, MfRelationInstrumException {
195: setInfo(mfmeServer.makeManagedElementInfo());
196: getInfo().setName(getName());
197: getInfo().setType(MfManagedElementType.CMM_SERVICE_ACCESS_URI);
198: setRelation(new MfwkPSRelationAdaptor(relationType,
199: sourceManagedElementInstrum));
200: getRelation().gearUp(mfmeServer, getInfo());
201: getInstrum().setLabeledURI(getLabeledURI());
202: getInstrum().setSecured(isSecured());
203: OperationalStatus[] operationalStatus = new OperationalStatus[] { OperationalStatus.OK };
204: getInstrum().setOperationalStatus(
205: new HashSet(Arrays.asList(operationalStatus)));
206:
207: setSettingInfo(mfmeServer.makeManagedElementInfo());
208: getSettingInfo().setName(getSettingName());
209: getSettingInfo().setType(
210: MfManagedElementType.CMM_SERVICE_ACCESS_URI_SETTING);
211: setSettingRelation(new MfwkPSRelationAdaptor(
212: MfRelationType.CMM_SCOPED_SETTING, getInstrum()));
213: getSettingRelation().gearUp(mfmeServer, getSettingInfo());
214:
215: setStatsInfo(mfmeServer.makeManagedElementInfo());
216: getStatsInfo().setName(getStatsName());
217: getStatsInfo().setType(
218: MfManagedElementType.CMM_SERVICE_ACCESS_URI_STATS);
219: setStatsRelation(new MfwkPSRelationAdaptor(
220: MfRelationType.CMM_ELEMENT_STATISTICAL_DATA,
221: getInstrum()));
222: getStatsRelation().gearUp(mfmeServer, getStatsInfo());
223:
224: setGearedUp(true);
225: }
226:
227: public void startTransaction() {
228: if (!isGearedUp()) {
229: return;
230: }
231:
232: startTransaction(null);
233: }
234:
235: public void startTransaction(MfTransactionInstrum parent) {
236: if (!isGearedUp()) {
237: return;
238: }
239:
240: try {
241: if (!getInstrum().isMonitoringEnabled()) {
242: return;
243: }
244:
245: if (getTransactionInstrum() == null) {
246: if (parent == null) {
247: setTransactionInstrum(getStatsInstrum()
248: .getTransaction(
249: MfTransactionType.REQUEST_TYPE));
250: } else {
251: setTransactionInstrum(getStatsInstrum()
252: .getTransaction(
253: MfTransactionType.REQUEST_TYPE,
254: parent));
255: }
256: }
257:
258: if (getTransactionInstrum().start() == MfTransactionInstrumConstants.NOT_OK) {
259: if (logger.isLoggable(Level.SEVERE)) {
260: logger.log(getLogRecord(Level.SEVERE,
261: "PSDT_CSPDMF0002",
262: new Object[] { getTransactionInstrum()
263: .getErrorMessage(
264: getTransactionInstrum()
265: .getErrorCode()) },
266: null));
267: }
268: }
269: } catch (MfRelationInstrumException e) {
270: if (logger.isLoggable(Level.SEVERE)) {
271: logger.log(getLogRecord(Level.SEVERE,
272: "PSDT_CSPDMF0001", new Object[] { e
273: .getLocalizedMessage() }, e));
274: }
275: } catch (MfManagedElementInstrumException e) {
276: if (logger.isLoggable(Level.SEVERE)) {
277: logger.log(getLogRecord(Level.SEVERE,
278: "PSDT_CSPDMF0001", new Object[] { e
279: .getLocalizedMessage() }, e));
280: }
281: }
282: }
283:
284: public void stopTransaction() {
285: if (!isGearedUp()) {
286: return;
287: }
288:
289: if (getTransactionInstrum() == null) {
290: // Monitoring is possibly disabled.
291: return;
292: }
293:
294: if (getTransactionInstrum().stop(
295: MfTransactionInstrumConstants.STATUS_GOOD) == MfTransactionInstrumConstants.NOT_OK) {
296: if (logger.isLoggable(Level.SEVERE)) {
297: logger.log(getLogRecord(Level.SEVERE,
298: "PSDT_CSPDMF0003",
299: new Object[] { getTransactionInstrum()
300: .getErrorMessage(
301: getTransactionInstrum()
302: .getErrorCode()) },
303: null));
304: }
305: }
306:
307: // Get NPE to help debugging
308: setTransactionInstrum(null);
309: }
310: }
|