1 7 8 package com.sun.corba.se.impl.transport; 9 10 import java.util.Collection ; 11 import java.util.Hashtable ; 12 import java.util.Iterator ; 13 14 import com.sun.corba.se.pept.broker.Broker; 15 import com.sun.corba.se.pept.transport.ContactInfo; 16 import com.sun.corba.se.pept.transport.Connection; 17 import com.sun.corba.se.pept.transport.OutboundConnectionCache; 18 19 import com.sun.corba.se.spi.monitoring.LongMonitoredAttributeBase; 20 import com.sun.corba.se.spi.monitoring.MonitoringConstants; 21 import com.sun.corba.se.spi.monitoring.MonitoringFactories; 22 import com.sun.corba.se.spi.monitoring.MonitoredObject; 23 import com.sun.corba.se.spi.orb.ORB; 24 import com.sun.corba.se.spi.transport.CorbaConnectionCache; 25 import com.sun.corba.se.spi.transport.CorbaContactInfo; 26 27 import com.sun.corba.se.impl.orbutil.ORBUtility; 28 29 32 public class CorbaOutboundConnectionCacheImpl 33 extends 34 CorbaConnectionCacheBase 35 implements 36 OutboundConnectionCache 37 { 38 protected Hashtable connectionCache; 39 40 public CorbaOutboundConnectionCacheImpl(ORB orb, ContactInfo contactInfo) 41 { 42 super(orb, contactInfo.getConnectionCacheType(), 43 ((CorbaContactInfo)contactInfo).getMonitoringName()); 44 this.connectionCache = new Hashtable (); 45 } 46 47 52 public Connection get(ContactInfo contactInfo) 53 { 54 if (orb.transportDebugFlag) { 55 dprint(".get: " + contactInfo + " " + contactInfo.hashCode()); 56 } 57 synchronized (backingStore()) { 58 dprintStatistics(); 59 return (Connection) connectionCache.get(contactInfo); 60 } 61 } 62 63 public void put(ContactInfo contactInfo, Connection connection) 64 { 65 if (orb.transportDebugFlag) { 66 dprint(".put: " + contactInfo + " " + contactInfo.hashCode() + " " 67 + connection); 68 } 69 synchronized (backingStore()) { 70 connectionCache.put(contactInfo, connection); 71 connection.setConnectionCache(this); 72 dprintStatistics(); 73 } 74 } 75 76 public void remove(ContactInfo contactInfo) 77 { 78 if (orb.transportDebugFlag) { 79 dprint(".remove: " + contactInfo + " " + contactInfo.hashCode()); 80 } 81 synchronized (backingStore()) { 82 if (contactInfo != null) { 83 connectionCache.remove(contactInfo); 84 } 85 dprintStatistics(); 86 } 87 } 88 89 94 public Collection values() 95 { 96 return connectionCache.values(); 97 } 98 99 protected Object backingStore() 100 { 101 return connectionCache; 102 } 103 104 protected void registerWithMonitoring() 105 { 106 MonitoredObject orbMO = 108 orb.getMonitoringManager().getRootMonitoredObject(); 109 110 MonitoredObject connectionMO = 112 orbMO.getChild(MonitoringConstants.CONNECTION_MONITORING_ROOT); 113 if (connectionMO == null) { 114 connectionMO = 115 MonitoringFactories.getMonitoredObjectFactory() 116 .createMonitoredObject( 117 MonitoringConstants.CONNECTION_MONITORING_ROOT, 118 MonitoringConstants.CONNECTION_MONITORING_ROOT_DESCRIPTION); 119 orbMO.addChild(connectionMO); 120 } 121 122 MonitoredObject outboundConnectionMO = 124 connectionMO.getChild( 125 MonitoringConstants.OUTBOUND_CONNECTION_MONITORING_ROOT); 126 if (outboundConnectionMO == null) { 127 outboundConnectionMO = 128 MonitoringFactories.getMonitoredObjectFactory() 129 .createMonitoredObject( 130 MonitoringConstants.OUTBOUND_CONNECTION_MONITORING_ROOT, 131 MonitoringConstants.OUTBOUND_CONNECTION_MONITORING_ROOT_DESCRIPTION); 132 connectionMO.addChild(outboundConnectionMO); 133 } 134 135 MonitoredObject thisMO = 137 outboundConnectionMO.getChild(getMonitoringName()); 138 if (thisMO == null) { 139 thisMO = 140 MonitoringFactories.getMonitoredObjectFactory() 141 .createMonitoredObject( 142 getMonitoringName(), 143 MonitoringConstants.CONNECTION_MONITORING_DESCRIPTION); 144 outboundConnectionMO.addChild(thisMO); 145 } 146 147 LongMonitoredAttributeBase attribute; 148 149 attribute = new 151 LongMonitoredAttributeBase( 152 MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS, 153 MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS_DESCRIPTION) 154 { 155 public Object getValue() { 156 return new Long (CorbaOutboundConnectionCacheImpl.this.numberOfConnections()); 157 } 158 }; 159 thisMO.addAttribute(attribute); 160 161 attribute = new 163 LongMonitoredAttributeBase( 164 MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS, 165 MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS_DESCRIPTION) 166 { 167 public Object getValue() { 168 return new Long (CorbaOutboundConnectionCacheImpl.this.numberOfIdleConnections()); 169 } 170 }; 171 thisMO.addAttribute(attribute); 172 173 attribute = new 175 LongMonitoredAttributeBase( 176 MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS, 177 MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS_DESCRIPTION) 178 { 179 public Object getValue() { 180 return new Long (CorbaOutboundConnectionCacheImpl.this.numberOfBusyConnections()); 181 } 182 }; 183 thisMO.addAttribute(attribute); 184 } 185 186 protected void dprint(String msg) 187 { 188 ORBUtility.dprint("CorbaOutboundConnectionCacheImpl", msg); 189 } 190 } 191 192 | Popular Tags |