001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2006 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: TomcatClusterMember.java 9864 2006-11-24 10:14:22Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.management.cluster;
025:
026: import javax.management.Attribute;
027: import javax.management.AttributeList;
028: import javax.management.MalformedObjectNameException;
029: import javax.management.ObjectName;
030:
031: import org.objectweb.jonas.jmx.CatalinaObjectName;
032: import org.objectweb.jonas.management.monitoring.ServerProxy;
033: import org.objectweb.util.monolog.api.BasicLevel;
034:
035: /**
036: * A TomcatClusterMember represents a JOnAS server using web container Tomcat which is a memeber of a
037: * Tomcat cluster for session replication.
038: * @author Philippe Durieux
039: * @author Adriana Danes
040: */
041: public class TomcatClusterMember extends ClusterMember implements
042: TomcatClusterMemberMBean {
043:
044: // Tomcat ClusterReceiver MBean attributes
045: // -------------------------------------
046: // Receiver Info
047: /**
048: * tcp listener address
049: */
050: private String tcpListenAddress = null;
051: /**
052: * tcp listener port
053: */
054: private int tcpListenPort;
055: /**
056: * data received compressed
057: */
058: private boolean compress;
059: /**
060: * create received processing time stats
061: */
062: private boolean doReceivedProcessingStats;
063: /**
064: * Class version info (ClusterReceiver.info)
065: */
066: private String receiverInfo;
067: /**
068: * send ack after data received
069: */
070: private boolean sendAck;
071: /**
072: * tcp listener Selector timeout
073: */
074: private long tcpSelectorTimeout;
075:
076: // Receiver Stats
077: /**
078: * received processing time / nrOfRequests
079: */
080: private double avgReceivedProcessingTime;
081: /**
082: * received processing time / nrOfRequests
083: * - think should be double
084: */
085: //private long avgTotalReceivedBytes;
086: /**
087: * maximal received processing time
088: */
089: private long maxReceivedProcessingTime;
090: /**
091: * minimal received processing time
092: */
093: private long minReceivedProcessingTime;
094: /**
095: * number of messages received from other nodes
096: */
097: private long nrOfMsgsReceived;
098: /**
099: * received processing time
100: */
101: private long receivedProcessingTime;
102: /**
103: * total time message send time
104: */
105: private long receivedTime;
106: /**
107: * number of tcp listener worker threads
108: */
109: private int tcpThreadCount;
110: /**
111: * number of bytes received
112: */
113: private long totalReceivedBytes;
114: /**
115: * is port really started
116: */
117: private boolean doListen;
118: // Sender info
119: /* all the possible attributes:
120: "ackTimeout", "autoConnect", "avgProcessingTime", "doTransmitterProcessingStats",
121: "failureCounter", "info", "maxProcessingTime", "minProcessingTime",
122: "nrOfRequests", "processingTime", "replicationMode",
123: "totalBytes", "waitForAck"
124: */
125: // selected configuration attributes
126: /**
127: * Class version info (ClusterSender.info)
128: */
129: private String senderInfo;
130: /**
131: * acknowledge timeout
132: */
133: private long ackTimeout;
134: /**
135: * is sender disabled, fork a new socket
136: */
137: private boolean autoConnect;
138: /**
139: * create processing time stats
140: */
141: private boolean doTransmitterProcessingStats;
142: /**
143: * replication mode (synchnous,pooled.asynchnous,fastasyncqueue)
144: */
145: private String replicationMode;
146: /**
147: * Wait for ack after data send
148: */
149: private boolean waitForAck;
150:
151: // General info
152: /**
153: * tomcat cluster member's host name (virtual host)
154: */
155: private String hostName;
156: /**
157: * JOnAS management domain name
158: */
159: private String domainName;
160:
161: /**
162: * Constructor
163: * @param name memberName generated by the TomcatCluster
164: * @param hostName the virtual host name
165: * @param proxy the member's proxy
166: */
167: public TomcatClusterMember(String name, String hostName,
168: ServerProxy proxy) {
169: super (name, proxy);
170: this .hostName = hostName;
171: this .domainName = proxy.getDomain();
172: }
173:
174: /**
175: * Set attributes with values from TomcatSender
176: * and TomcatReceiver MBeans
177: */
178: public void setInfo() {
179: // Attributes for TomcatReceiver
180: ObjectName crOn = null;
181: try {
182: crOn = CatalinaObjectName.catalinaClusterReceiver(
183: domainName, hostName);
184: } catch (MalformedObjectNameException e) {
185: logger.log(BasicLevel.WARN, e);
186: return;
187: }
188: String[] attNames = new String[] { "avgReceivedProcessingTime",
189: "compress", "doReceivedProcessingStats",
190: "maxReceivedProcessingTime",
191: "minReceivedProcessingTime", "nrOfMsgsReceived",
192: "receivedProcessingTime", "receivedTime", "info",
193: "sendAck", "tcpListenAddress", "tcpListenPort",
194: "tcpSelectorTimeout", "tcpThreadCount",
195: "totalReceivedBytes" };
196: AttributeList attList = proxy.getAttributes(crOn, attNames);
197: for (int i = 0; i < attList.size(); i++) {
198: Attribute att = (Attribute) attList.get(i);
199: String attName = att.getName();
200: Object attValue = att.getValue();
201: if ("avgReceivedProcessingTime".equals(attName)) {
202: setAvgReceivedProcessingTime(((Double) attValue)
203: .doubleValue());
204: }
205: if ("compress".equals(attName)) {
206: setCompress(((Boolean) attValue).booleanValue());
207: }
208: if ("doReceivedProcessingStats".equals(attName)) {
209: setDoReceivedProcessingStats(((Boolean) attValue)
210: .booleanValue());
211: }
212: if ("maxReceivedProcessingTime".equals(attName)) {
213: setMaxReceivedProcessingTime(((Long) attValue)
214: .longValue());
215: }
216: if ("minReceivedProcessingTime".equals(attName)) {
217: setMinReceivedProcessingTime(((Long) attValue)
218: .longValue());
219: }
220: if ("nrOfMsgsReceived".equals(attName)) {
221: setNrOfMsgsReceived(((Long) attValue).longValue());
222: }
223: if ("receivedProcessingTime".equals(attName)) {
224: setReceivedProcessingTime(((Long) attValue).longValue());
225: }
226: if ("receivedTime".equals(attName)) {
227: setReceivedTime(((Long) attValue).longValue());
228: }
229: if ("info".equals(attName)) {
230: setReceiverInfo((String) attValue);
231: }
232: if ("sendAck".equals(attName)) {
233: setSendAck(((Boolean) attValue).booleanValue());
234: }
235: if ("tcpListenAddress".equals(attName)) {
236: setTcpListenAddress((String) attValue);
237: }
238: if ("tcpListenPort".equals(attName)) {
239: setTcpListenPort(((Integer) attValue).intValue());
240: }
241: if ("tcpSelectorTimeout".equals(attName)) {
242: setTcpSelectorTimeout(((Long) attValue).longValue());
243: }
244: if ("tcpThreadCount".equals(attName)) {
245: int threadCount = ((Integer) attValue).intValue();
246: //System.out.println(">>>> threadCount = " + threadCount);
247: setTcpThreadCount(threadCount);
248: }
249: if ("totalReceivedBytes".equals(attName)) {
250: setTotalReceivedBytes(((Long) attValue).longValue());
251: }
252: }
253: // Attributes from TomcatSender
254: ObjectName csOn = null;
255: try {
256: csOn = CatalinaObjectName.catalinaClusterSender(domainName,
257: hostName);
258: } catch (MalformedObjectNameException e) {
259: logger.log(BasicLevel.WARN, e);
260: return;
261: }
262: attNames = new String[] { "ackTimeout", "autoConnect",
263: "avgProcessingTime", "doTransmitterProcessingStats",
264: "failureCounter", "info", "maxProcessingTime",
265: "minProcessingTime", "nrOfRequests", "processingTime",
266: "replicationMode", "totalBytes", "waitForAck" };
267: attList = proxy.getAttributes(csOn, attNames);
268: for (int i = 0; i < attList.size(); i++) {
269: Attribute att = (Attribute) attList.get(i);
270: String attName = att.getName();
271: Object attValue = att.getValue();
272: if ("ackTimeout".equals(attName)) {
273: setAckTimeout(((Long) attValue).longValue());
274: }
275: if ("autoConnect".equals(attName)) {
276: setAutoConnect(((Boolean) attValue).booleanValue());
277: }
278: if ("doTransmitterProcessingStats".equals(attName)) {
279: setDoTransmitterProcessingStats(((Boolean) attValue)
280: .booleanValue());
281: }
282: if ("info".equals(attName)) {
283: setSenderInfo((String) attValue);
284: }
285: if ("replicationMode".equals(attName)) {
286: setReplicationMode((String) attValue);
287: }
288: if ("waitForAck".equals(attName)) {
289: setWaitForAck(((Boolean) attValue).booleanValue());
290: }
291: }
292: }
293:
294: /**
295: * @return tcp listener address
296: */
297: public String getTcpListenAddress() {
298: return tcpListenAddress;
299: }
300:
301: public void setTcpListenAddress(String tcpListenAddress) {
302: this .tcpListenAddress = tcpListenAddress;
303: }
304:
305: /**
306: *
307: * @return tcp listener port
308: */
309: public int getTcpListenPort() {
310: return tcpListenPort;
311: }
312:
313: public void setTcpListenPort(int tcpListenPort) {
314: this .tcpListenPort = tcpListenPort;
315: }
316:
317: public boolean isCompress() {
318: return compress;
319: }
320:
321: public boolean isDoReceivedProcessingStats() {
322: return doReceivedProcessingStats;
323: }
324:
325: public String getReceiverInfo() {
326: return receiverInfo;
327: }
328:
329: public boolean isSendAck() {
330: return sendAck;
331: }
332:
333: public long getTcpSelectorTimeout() {
334: return tcpSelectorTimeout;
335: }
336:
337: public String getHostName() {
338: return hostName;
339: }
340:
341: public double getAvgReceivedProcessingTime() {
342: return avgReceivedProcessingTime;
343: }
344:
345: public long getMaxReceivedProcessingTime() {
346: return maxReceivedProcessingTime;
347: }
348:
349: public void setAvgReceivedProcessingTime(
350: double avgReceivedProcessingTime) {
351: this .avgReceivedProcessingTime = avgReceivedProcessingTime;
352: }
353:
354: public void setCompress(boolean compress) {
355: this .compress = compress;
356: }
357:
358: public void setDoListen(boolean doListen) {
359: this .doListen = doListen;
360: }
361:
362: public void setDoReceivedProcessingStats(
363: boolean doReceivedProcessingStats) {
364: this .doReceivedProcessingStats = doReceivedProcessingStats;
365: }
366:
367: public void setMaxReceivedProcessingTime(
368: long maxReceivedProcessingTime) {
369: this .maxReceivedProcessingTime = maxReceivedProcessingTime;
370: }
371:
372: public void setMinReceivedProcessingTime(
373: long minReceivedProcessingTime) {
374: this .minReceivedProcessingTime = minReceivedProcessingTime;
375: }
376:
377: public void setNrOfMsgsReceived(long nrOfMsgsReceived) {
378: this .nrOfMsgsReceived = nrOfMsgsReceived;
379: }
380:
381: public void setReceivedProcessingTime(long receivedProcessingTime) {
382: this .receivedProcessingTime = receivedProcessingTime;
383: }
384:
385: public void setReceivedTime(long receivedTime) {
386: this .receivedTime = receivedTime;
387: }
388:
389: public void setReceiverInfo(String receiverInfo) {
390: this .receiverInfo = receiverInfo;
391: }
392:
393: public void setSendAck(boolean sendAck) {
394: this .sendAck = sendAck;
395: }
396:
397: public void setTcpSelectorTimeout(long tcpSelectorTimeout) {
398: this .tcpSelectorTimeout = tcpSelectorTimeout;
399: }
400:
401: public void setTcpThreadCount(int tcpThreadCount) {
402: this .tcpThreadCount = tcpThreadCount;
403: }
404:
405: public void setTotalReceivedBytes(long totalReceivedBytes) {
406: this .totalReceivedBytes = totalReceivedBytes;
407: }
408:
409: public long getMinReceivedProcessingTime() {
410: return minReceivedProcessingTime;
411: }
412:
413: public long getNrOfMsgsReceived() {
414: return nrOfMsgsReceived;
415: }
416:
417: public long getReceivedProcessingTime() {
418: return receivedProcessingTime;
419: }
420:
421: public long getReceivedTime() {
422: return receivedTime;
423: }
424:
425: public boolean isDoListen() {
426: return doListen;
427: }
428:
429: public int getTcpThreadCount() {
430: return tcpThreadCount;
431: }
432:
433: public long getTotalReceivedBytes() {
434: return totalReceivedBytes;
435: }
436:
437: public String getSenderInfo() {
438: return senderInfo;
439: }
440:
441: public void setSenderInfo(String senderInfo) {
442: this .senderInfo = senderInfo;
443: }
444:
445: public long getAckTimeout() {
446: return ackTimeout;
447: }
448:
449: public void setAckTimeout(long ackTimeout) {
450: this .ackTimeout = ackTimeout;
451: }
452:
453: public boolean isAutoConnect() {
454: return autoConnect;
455: }
456:
457: public void setAutoConnect(boolean autoConnect) {
458: this .autoConnect = autoConnect;
459: }
460:
461: public boolean isDoTransmitterProcessingStats() {
462: return doTransmitterProcessingStats;
463: }
464:
465: public void setDoTransmitterProcessingStats(
466: boolean doTransmitterProcessingStats) {
467: this .doTransmitterProcessingStats = doTransmitterProcessingStats;
468: }
469:
470: public String getReplicationMode() {
471: return replicationMode;
472: }
473:
474: public void setReplicationMode(String replicationMode) {
475: this .replicationMode = replicationMode;
476: }
477:
478: public boolean isWaitForAck() {
479: return waitForAck;
480: }
481:
482: public void setWaitForAck(boolean waitForAck) {
483: this.waitForAck = waitForAck;
484: }
485: }
|