1. /*
  2. * @(#)CorbaInboundConnectionCacheImpl.java 1.5 04/06/21
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.transport;
  8. import java.util.ArrayList;
  9. import java.util.Collection;
  10. import com.sun.corba.se.pept.broker.Broker;
  11. import com.sun.corba.se.pept.transport.Acceptor;
  12. import com.sun.corba.se.pept.transport.Connection;
  13. import com.sun.corba.se.pept.transport.InboundConnectionCache;
  14. import com.sun.corba.se.spi.monitoring.LongMonitoredAttributeBase;
  15. import com.sun.corba.se.spi.monitoring.MonitoringConstants;
  16. import com.sun.corba.se.spi.monitoring.MonitoringFactories;
  17. import com.sun.corba.se.spi.monitoring.MonitoredObject;
  18. import com.sun.corba.se.spi.orb.ORB;
  19. import com.sun.corba.se.spi.transport.CorbaConnectionCache;
  20. import com.sun.corba.se.spi.transport.CorbaAcceptor;
  21. import com.sun.corba.se.impl.orbutil.ORBUtility;
  22. /**
  23. * @author Harold Carr
  24. */
  25. public class CorbaInboundConnectionCacheImpl
  26. extends
  27. CorbaConnectionCacheBase
  28. implements
  29. InboundConnectionCache
  30. {
  31. protected Collection connectionCache;
  32. public CorbaInboundConnectionCacheImpl(ORB orb, Acceptor acceptor)
  33. {
  34. super(orb, acceptor.getConnectionCacheType(),
  35. ((CorbaAcceptor)acceptor).getMonitoringName());
  36. this.connectionCache = new ArrayList();
  37. }
  38. ////////////////////////////////////////////////////
  39. //
  40. // pept.transport.InboundConnectionCache
  41. //
  42. public Connection get(Acceptor acceptor)
  43. {
  44. throw wrapper.methodShouldNotBeCalled();
  45. }
  46. public void put(Acceptor acceptor, Connection connection)
  47. {
  48. if (orb.transportDebugFlag) {
  49. dprint(".put: " + acceptor + " " + connection);
  50. }
  51. synchronized (backingStore()) {
  52. connectionCache.add(connection);
  53. connection.setConnectionCache(this);
  54. dprintStatistics();
  55. }
  56. }
  57. public void remove(Connection connection)
  58. {
  59. if (orb.transportDebugFlag) {
  60. dprint(".remove: " + connection);
  61. }
  62. synchronized (backingStore()) {
  63. connectionCache.remove(connection);
  64. dprintStatistics();
  65. }
  66. }
  67. ////////////////////////////////////////////////////
  68. //
  69. // Implementation
  70. //
  71. public Collection values()
  72. {
  73. return connectionCache;
  74. }
  75. protected Object backingStore()
  76. {
  77. return connectionCache;
  78. }
  79. protected void registerWithMonitoring()
  80. {
  81. // ORB
  82. MonitoredObject orbMO =
  83. orb.getMonitoringManager().getRootMonitoredObject();
  84. // REVISIT - add ORBUtil mkdir -p like operation for this.
  85. // CONNECTION
  86. MonitoredObject connectionMO =
  87. orbMO.getChild(MonitoringConstants.CONNECTION_MONITORING_ROOT);
  88. if (connectionMO == null) {
  89. connectionMO =
  90. MonitoringFactories.getMonitoredObjectFactory()
  91. .createMonitoredObject(
  92. MonitoringConstants.CONNECTION_MONITORING_ROOT,
  93. MonitoringConstants.CONNECTION_MONITORING_ROOT_DESCRIPTION);
  94. orbMO.addChild(connectionMO);
  95. }
  96. // INBOUND CONNECTION
  97. MonitoredObject inboundConnectionMO =
  98. connectionMO.getChild(
  99. MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT);
  100. if (inboundConnectionMO == null) {
  101. inboundConnectionMO =
  102. MonitoringFactories.getMonitoredObjectFactory()
  103. .createMonitoredObject(
  104. MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT,
  105. MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT_DESCRIPTION);
  106. connectionMO.addChild(inboundConnectionMO);
  107. }
  108. // NODE FOR THIS CACHE
  109. MonitoredObject thisMO =
  110. inboundConnectionMO.getChild(getMonitoringName());
  111. if (thisMO == null) {
  112. thisMO =
  113. MonitoringFactories.getMonitoredObjectFactory()
  114. .createMonitoredObject(
  115. getMonitoringName(),
  116. MonitoringConstants.CONNECTION_MONITORING_DESCRIPTION);
  117. inboundConnectionMO.addChild(thisMO);
  118. }
  119. LongMonitoredAttributeBase attribute;
  120. // ATTRIBUTE
  121. attribute = new
  122. LongMonitoredAttributeBase(
  123. MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS,
  124. MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS_DESCRIPTION)
  125. {
  126. public Object getValue() {
  127. return new Long(CorbaInboundConnectionCacheImpl.this.numberOfConnections());
  128. }
  129. };
  130. thisMO.addAttribute(attribute);
  131. // ATTRIBUTE
  132. attribute = new
  133. LongMonitoredAttributeBase(
  134. MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS,
  135. MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS_DESCRIPTION)
  136. {
  137. public Object getValue() {
  138. return new Long(CorbaInboundConnectionCacheImpl.this.numberOfIdleConnections());
  139. }
  140. };
  141. thisMO.addAttribute(attribute);
  142. // ATTRIBUTE
  143. attribute = new
  144. LongMonitoredAttributeBase(
  145. MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS,
  146. MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS_DESCRIPTION)
  147. {
  148. public Object getValue() {
  149. return new Long(CorbaInboundConnectionCacheImpl.this.numberOfBusyConnections());
  150. }
  151. };
  152. thisMO.addAttribute(attribute);
  153. }
  154. protected void dprint(String msg)
  155. {
  156. ORBUtility.dprint("CorbaInboundConnectionCacheImpl", msg);
  157. }
  158. }
  159. // End of file.