001: package com.sun.portal.netlet.monitoring;
002:
003: import com.sun.portal.monitoring.Subsystem;
004: import com.sun.portal.monitoring.statistics.OpenStatistic;
005: import com.sun.portal.netlet.econnection.ReaderWriterLock;
006: import com.sun.portal.netlet.eproxy.NetletGroup;
007: import com.sun.portal.netlet.eproxy.RWGroupCrypt;
008: import com.sun.portal.netlet.monitoring.statistics.NetletConnectionStatisticImpl;
009: import com.sun.portal.netlet.monitoring.statistics.NetletConnectionStatisticWrapper;
010: import com.sun.portal.netlet.monitoring.util.EProxyEvent;
011: import com.sun.portal.util.SRAEventListener;
012: import com.sun.portal.util.SRAEvent;
013:
014: import javax.management.MalformedObjectNameException;
015: import javax.management.ObjectName;
016: import java.util.HashMap;
017: import java.util.Map;
018:
019: import javax.management.openmbean.OpenDataException;
020: import javax.management.openmbean.CompositeType;
021:
022: /**
023: * author: Noble Paul
024: * Date: Feb 15, 2005, 10:55:10 AM
025: */
026: public class NetletConnectionsStatistic implements SRAEventListener {
027: private Subsystem subsystem;
028: private Map ssoTokenVsmbean = new HashMap();
029:
030: public NetletConnectionsStatistic(Subsystem subsystem) {
031: this .subsystem = subsystem;
032: }
033:
034: private ObjectName getObjectName(RWGroupCrypt rwGroupCrypt)
035: throws MalformedObjectNameException {
036: String destination = rwGroupCrypt.getDestHost() + "_"
037: + rwGroupCrypt.getDestPort();
038: String upThread = rwGroupCrypt.getReaderWriterDecrypt() == null ? "NONE"
039: : rwGroupCrypt.getReaderWriterDecrypt().getThreadName();
040: String downThread = rwGroupCrypt.getReaderWriterEncrypt() == null ? "NONE"
041: : rwGroupCrypt.getReaderWriterEncrypt().getThreadName();
042: return new ObjectName(subsystem.getNamingDomain()
043: + ":type=NetletConnectionStatistic" + ",destination="
044: + destination + ",UpstreamThread=" + upThread
045: + ",DownstreamThread=" + downThread);
046: }
047:
048: public void removeServerStatistic(ObjectName name) {
049: ssoTokenVsmbean.remove(name);
050: }
051:
052: public void addNetlet(Object objects) {
053: Object[] objArr = (Object[]) objects;
054: ReaderWriterLock readerWriterLock = null;
055: NetletGroup netletGroup = null;
056: if (objArr[0] instanceof ReaderWriterLock) {
057: readerWriterLock = (ReaderWriterLock) objArr[0];
058: } else {
059: return;
060: }
061: if (objArr[1] instanceof NetletGroup) {
062: netletGroup = (NetletGroup) objArr[1];
063: } else {
064: return;
065: }
066: if (readerWriterLock instanceof RWGroupCrypt) {
067: RWGroupCrypt rwGroupCrypt = (RWGroupCrypt) readerWriterLock;
068: NetletConnectionStatisticImpl statistic = new NetletConnectionStatisticImpl(
069: netletGroup.getUserName(), rwGroupCrypt);
070: NetletConnectionStatisticWrapper statisticWrapper = new NetletConnectionStatisticWrapper();
071: statisticWrapper.setCompositeTypeName(getClass().getName());
072: statisticWrapper
073: .setResourceBundleBaseName("NetletConnectionStatistics");
074: statisticWrapper.setStatisticImpl(statistic);
075: try {
076: CompositeType compositeType = statisticWrapper
077: .getCompositeType();
078: statisticWrapper.getStatisticImpl().setDescription(
079: compositeType.getDescription("Description"));
080: statisticWrapper.getStatisticImpl().setName(
081: compositeType.getDescription("Name"));
082: statisticWrapper.getStatisticImpl().setUnit(
083: compositeType.getDescription("Unit"));
084: } catch (OpenDataException e) {
085: e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
086: }
087: try {
088: subsystem.registerMBean(new OpenStatistic(
089: statisticWrapper), getObjectName(rwGroupCrypt)
090: .toString());
091: } catch (Exception e) {
092: handleException(e);
093: }
094: }
095: }
096:
097: public void removeNetlet(Object o) {
098: if (o instanceof RWGroupCrypt) {
099: RWGroupCrypt rwGroupCrypt = (RWGroupCrypt) o;
100: try {
101: subsystem.unregisterMBean(getObjectName(rwGroupCrypt)
102: .toString());
103: } catch (Exception e) {
104: handleException(e);
105: }
106: }
107: }
108:
109: private void handleException(Exception e) {
110: e.printStackTrace();//TODO handle exception
111: }
112:
113: public void handleEvent(SRAEvent event, Object obj) {
114: if (event == EProxyEvent.NETLET_ADDED) {
115: addNetlet(obj);
116: return;
117: }
118: if (event == EProxyEvent.NETLET_REMOVED) {
119: removeNetlet(obj);
120: }
121: }
122:
123: public SRAEvent[] getInterestedEvents() {
124: return new SRAEvent[] { EProxyEvent.NETLET_ADDED,
125: EProxyEvent.NETLET_REMOVED };
126: }
127: }
|