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_ThreadPoolInstrum;
010: import com.sun.mfwk.instrum.me.MfManagedElementInstrumException;
011: import com.sun.mfwk.instrum.me.settings.CMM_ThreadPoolSettingInstrum;
012: import com.sun.mfwk.instrum.me.statistics.CMM_ThreadPoolStatsInstrum;
013: import com.sun.mfwk.instrum.me.statistics.MfTransactionInstrum;
014: import com.sun.mfwk.instrum.relations.MfRelationInstrumException;
015: import com.sun.mfwk.instrum.server.MfManagedElementInfo;
016: import com.sun.mfwk.instrum.server.MfManagedElementServer;
017: import com.sun.mfwk.instrum.server.MfManagedElementServerException;
018: import com.sun.mfwk.instrum.server.MfManagedElementType;
019: import com.sun.mfwk.instrum.server.MfRelationType;
020: import com.sun.portal.log.common.PortalLogger;
021: import java.util.Arrays;
022: import java.util.HashSet;
023: import java.util.logging.Level;
024: import java.util.logging.LogRecord;
025: import java.util.logging.Logger;
026:
027: public class MfwkPSThreadPoolAdaptor {
028: private static final Logger logger = PortalLogger
029: .getLogger(MfwkPSThreadPoolAdaptor.class);
030:
031: private static LogRecord getLogRecord(Level level, String message,
032: Object[] parameters, Throwable t) {
033: LogRecord result = new LogRecord(level, message);
034: result.setLoggerName(logger.getName());
035: result.setParameters(parameters);
036: result.setThrown(t);
037: return result;
038: }
039:
040: private String name;
041: private String settingName;
042: private String statsName;
043: private String id;
044: private long maxSize;
045: private long minSize;
046: private long numberOfWorkQueues; // ObjectPool partitions
047:
048: public MfwkPSThreadPoolAdaptor(String name, String settingName,
049: String statsName, String id, long maxSize, long minSize,
050: long numberOfWorkQueues) {
051: setName(name);
052: setSettingName(settingName);
053: setStatsName(statsName);
054: setId(id);
055: setMaxSize(maxSize);
056: setMinSize(minSize);
057: setNumberOfWorkQueues(numberOfWorkQueues);
058: }
059:
060: public String getName() {
061: return name;
062: }
063:
064: public void setName(String name) {
065: this .name = name;
066: }
067:
068: public String getSettingName() {
069: return settingName;
070: }
071:
072: public void setSettingName(String settingName) {
073: this .settingName = settingName;
074: }
075:
076: public String getStatsName() {
077: return statsName;
078: }
079:
080: public void setStatsName(String statsName) {
081: this .statsName = statsName;
082: }
083:
084: public String getId() {
085: return id;
086: }
087:
088: public void setId(String id) {
089: this .id = id;
090: }
091:
092: public long getMaxSize() {
093: return maxSize;
094: }
095:
096: public void setMaxSize(long maxSize) {
097: this .maxSize = maxSize;
098: }
099:
100: public long getMinSize() {
101: return minSize;
102: }
103:
104: public void setMinSize(long minSize) {
105: this .minSize = minSize;
106: }
107:
108: public long getNumberOfWorkQueues() {
109: return numberOfWorkQueues;
110: }
111:
112: public void setNumberOfWorkQueues(long numberOfWorkQueues) {
113: this .numberOfWorkQueues = numberOfWorkQueues;
114: }
115:
116: private boolean gearedUp = false;
117: private MfManagedElementInfo info;
118: private MfManagedElementInfo settingInfo;
119: private MfManagedElementInfo statsInfo;
120: private MfwkPSRelationAdaptor relation;
121: private MfwkPSRelationAdaptor settingRelation;
122: private MfwkPSRelationAdaptor statsRelation;
123: private MfTransactionInstrum transactionInstrum;
124:
125: public boolean isGearedUp() {
126: return gearedUp;
127: }
128:
129: public void setGearedUp(boolean gearedUp) {
130: this .gearedUp = gearedUp;
131: }
132:
133: public MfManagedElementInfo getInfo() {
134: return info;
135: }
136:
137: public void setInfo(MfManagedElementInfo info) {
138: this .info = info;
139: }
140:
141: public MfManagedElementInfo getSettingInfo() {
142: return settingInfo;
143: }
144:
145: public void setSettingInfo(MfManagedElementInfo settingInfo) {
146: this .settingInfo = settingInfo;
147: }
148:
149: public MfManagedElementInfo getStatsInfo() {
150: return statsInfo;
151: }
152:
153: public void setStatsInfo(MfManagedElementInfo statsInfo) {
154: this .statsInfo = statsInfo;
155: }
156:
157: public MfwkPSRelationAdaptor getRelation() {
158: return relation;
159: }
160:
161: public void setRelation(MfwkPSRelationAdaptor relation) {
162: this .relation = relation;
163: }
164:
165: public MfwkPSRelationAdaptor getSettingRelation() {
166: return settingRelation;
167: }
168:
169: public void setSettingRelation(MfwkPSRelationAdaptor settingRelation) {
170: this .settingRelation = settingRelation;
171: }
172:
173: public MfwkPSRelationAdaptor getStatsRelation() {
174: return statsRelation;
175: }
176:
177: public void setStatsRelation(MfwkPSRelationAdaptor statsRelation) {
178: this .statsRelation = statsRelation;
179: }
180:
181: public MfTransactionInstrum getTransactionInstrum() {
182: return transactionInstrum;
183: }
184:
185: public void setTransactionInstrum(
186: MfTransactionInstrum transactionInstrum) {
187: this .transactionInstrum = transactionInstrum;
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_THREAD_POOL);
198: setRelation(new MfwkPSRelationAdaptor(relationType,
199: sourceManagedElementInstrum));
200: getRelation().gearUp(mfmeServer, getInfo());
201: OperationalStatus[] operationalStatus = new OperationalStatus[] { OperationalStatus.OK };
202: getInstrum().setOperationalStatus(
203: new HashSet(Arrays.asList(operationalStatus)));
204:
205: setSettingInfo(mfmeServer.makeManagedElementInfo());
206: getSettingInfo().setName(getSettingName());
207: getSettingInfo().setType(
208: MfManagedElementType.CMM_THREAD_POOL_SETTING);
209: setSettingRelation(new MfwkPSRelationAdaptor(
210: MfRelationType.CMM_SCOPED_SETTING, getInstrum()));
211: getSettingRelation().gearUp(mfmeServer, getSettingInfo());
212: getSettingInstrum().setIdleThreadTimeoutInSeconds(0); // play safe, we really don't care about this attribute
213: getSettingInstrum().setMaxThreadPoolSize(getMaxSize());
214: getSettingInstrum().setMinThreadPoolSize(getMinSize());
215: getSettingInstrum().setNumWorkQueues(getNumberOfWorkQueues());
216: getSettingInstrum().setThreadPoolId(getId());
217:
218: setStatsInfo(mfmeServer.makeManagedElementInfo());
219: getStatsInfo().setName(getStatsName());
220: getStatsInfo().setType(
221: MfManagedElementType.CMM_THREAD_POOL_STATS);
222: setStatsRelation(new MfwkPSRelationAdaptor(
223: MfRelationType.CMM_ELEMENT_STATISTICAL_DATA,
224: getInstrum()));
225: getStatsRelation().gearUp(mfmeServer, getStatsInfo());
226: getStatsInstrum().setAverageTimeInQueue(0); // play safe, we really don't care about this attribute
227: getStatsInstrum().setAverageWorkCompletionTime(0); // play safe, we really don't care about this attribute
228: getStatsInstrum().setCurrentNumberOfThreads(
229: new Long(getMinSize()).longValue());
230: getStatsInstrum().setCurrentNumberOfThreadsLowerBound(
231: new Long(getMinSize()).longValue());
232: getStatsInstrum().setCurrentNumberOfThreadsUpperBound(
233: new Long(getMinSize()).longValue());
234: getStatsInstrum().setNumberOfAvailableThreads(
235: new Long(getMinSize()).longValue());
236: getStatsInstrum().setNumberOfBusyThreads(0);
237: getStatsInstrum().setSampleInterval(0); // play safe, we really don't care about this attribute
238:
239: setGearedUp(true);
240: }
241:
242: public CMM_ThreadPoolInstrum getInstrum()
243: throws MfRelationInstrumException {
244: return (CMM_ThreadPoolInstrum) getRelation().getInstrum()
245: .getDestination();
246: }
247:
248: public CMM_ThreadPoolSettingInstrum getSettingInstrum()
249: throws MfRelationInstrumException {
250: return (CMM_ThreadPoolSettingInstrum) getSettingRelation()
251: .getInstrum().getDestination();
252: }
253:
254: public CMM_ThreadPoolStatsInstrum getStatsInstrum()
255: throws MfRelationInstrumException {
256: return (CMM_ThreadPoolStatsInstrum) getStatsRelation()
257: .getInstrum().getDestination();
258: }
259: }
|