KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > transport > CorbaInboundConnectionCacheImpl


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
8 package com.sun.corba.se.impl.transport;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.Collection JavaDoc;
12
13 import com.sun.corba.se.pept.broker.Broker;
14 import com.sun.corba.se.pept.transport.Acceptor;
15 import com.sun.corba.se.pept.transport.Connection;
16 import com.sun.corba.se.pept.transport.InboundConnectionCache;
17
18 import com.sun.corba.se.spi.monitoring.LongMonitoredAttributeBase;
19 import com.sun.corba.se.spi.monitoring.MonitoringConstants;
20 import com.sun.corba.se.spi.monitoring.MonitoringFactories;
21 import com.sun.corba.se.spi.monitoring.MonitoredObject;
22 import com.sun.corba.se.spi.orb.ORB;
23 import com.sun.corba.se.spi.transport.CorbaConnectionCache;
24 import com.sun.corba.se.spi.transport.CorbaAcceptor;
25
26 import com.sun.corba.se.impl.orbutil.ORBUtility;
27
28 /**
29  * @author Harold Carr
30  */

31 public class CorbaInboundConnectionCacheImpl
32     extends
33     CorbaConnectionCacheBase
34     implements
35     InboundConnectionCache
36 {
37     protected Collection JavaDoc connectionCache;
38
39     public CorbaInboundConnectionCacheImpl(ORB orb, Acceptor acceptor)
40     {
41     super(orb, acceptor.getConnectionCacheType(),
42           ((CorbaAcceptor)acceptor).getMonitoringName());
43     this.connectionCache = new ArrayList JavaDoc();
44     }
45
46     ////////////////////////////////////////////////////
47
//
48
// pept.transport.InboundConnectionCache
49
//
50

51     public Connection get(Acceptor acceptor)
52     {
53     throw wrapper.methodShouldNotBeCalled();
54     }
55     
56     public void put(Acceptor acceptor, Connection connection)
57     {
58     if (orb.transportDebugFlag) {
59         dprint(".put: " + acceptor + " " + connection);
60     }
61     synchronized (backingStore()) {
62         connectionCache.add(connection);
63         connection.setConnectionCache(this);
64         dprintStatistics();
65     }
66     }
67
68     public void remove(Connection connection)
69     {
70     if (orb.transportDebugFlag) {
71         dprint(".remove: " + connection);
72     }
73     synchronized (backingStore()) {
74         connectionCache.remove(connection);
75         dprintStatistics();
76     }
77     }
78
79     ////////////////////////////////////////////////////
80
//
81
// Implementation
82
//
83

84     public Collection JavaDoc values()
85     {
86     return connectionCache;
87     }
88
89     protected Object JavaDoc backingStore()
90     {
91     return connectionCache;
92     }
93
94     protected void registerWithMonitoring()
95     {
96     // ORB
97
MonitoredObject orbMO =
98         orb.getMonitoringManager().getRootMonitoredObject();
99
100     // REVISIT - add ORBUtil mkdir -p like operation for this.
101

102     // CONNECTION
103
MonitoredObject connectionMO =
104         orbMO.getChild(MonitoringConstants.CONNECTION_MONITORING_ROOT);
105     if (connectionMO == null) {
106         connectionMO =
107         MonitoringFactories.getMonitoredObjectFactory()
108             .createMonitoredObject(
109                 MonitoringConstants.CONNECTION_MONITORING_ROOT,
110             MonitoringConstants.CONNECTION_MONITORING_ROOT_DESCRIPTION);
111         orbMO.addChild(connectionMO);
112     }
113
114     // INBOUND CONNECTION
115
MonitoredObject inboundConnectionMO =
116         connectionMO.getChild(
117                 MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT);
118     if (inboundConnectionMO == null) {
119         inboundConnectionMO =
120         MonitoringFactories.getMonitoredObjectFactory()
121             .createMonitoredObject(
122                 MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT,
123             MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT_DESCRIPTION);
124         connectionMO.addChild(inboundConnectionMO);
125     }
126
127     // NODE FOR THIS CACHE
128
MonitoredObject thisMO =
129         inboundConnectionMO.getChild(getMonitoringName());
130     if (thisMO == null) {
131         thisMO =
132         MonitoringFactories.getMonitoredObjectFactory()
133             .createMonitoredObject(
134                 getMonitoringName(),
135             MonitoringConstants.CONNECTION_MONITORING_DESCRIPTION);
136         inboundConnectionMO.addChild(thisMO);
137     }
138
139     LongMonitoredAttributeBase attribute;
140
141     // ATTRIBUTE
142
attribute = new
143         LongMonitoredAttributeBase(
144                 MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS,
145         MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS_DESCRIPTION)
146         {
147         public Object JavaDoc getValue() {
148             return new Long JavaDoc(CorbaInboundConnectionCacheImpl.this.numberOfConnections());
149         }
150         };
151     thisMO.addAttribute(attribute);
152
153     // ATTRIBUTE
154
attribute = new
155         LongMonitoredAttributeBase(
156                 MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS,
157         MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS_DESCRIPTION)
158         {
159         public Object JavaDoc getValue() {
160             return new Long JavaDoc(CorbaInboundConnectionCacheImpl.this.numberOfIdleConnections());
161         }
162         };
163     thisMO.addAttribute(attribute);
164
165     // ATTRIBUTE
166
attribute = new
167         LongMonitoredAttributeBase(
168                 MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS,
169         MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS_DESCRIPTION)
170         {
171         public Object JavaDoc getValue() {
172             return new Long JavaDoc(CorbaInboundConnectionCacheImpl.this.numberOfBusyConnections());
173         }
174         };
175     thisMO.addAttribute(attribute);
176     }
177
178     protected void dprint(String JavaDoc msg)
179     {
180     ORBUtility.dprint("CorbaInboundConnectionCacheImpl", msg);
181     }
182 }
183
184 // End of file.
185
Popular Tags