KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)CorbaOutboundConnectionCacheImpl.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.Collection JavaDoc;
11 import java.util.Hashtable JavaDoc;
12 import java.util.Iterator JavaDoc;
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 /**
30  * @author Harold Carr
31  */

32 public class CorbaOutboundConnectionCacheImpl
33     extends
34     CorbaConnectionCacheBase
35     implements
36     OutboundConnectionCache
37 {
38     protected Hashtable JavaDoc connectionCache;
39
40     public CorbaOutboundConnectionCacheImpl(ORB orb, ContactInfo contactInfo)
41     {
42     super(orb, contactInfo.getConnectionCacheType(),
43           ((CorbaContactInfo)contactInfo).getMonitoringName());
44     this.connectionCache = new Hashtable JavaDoc();
45     }
46
47     ////////////////////////////////////////////////////
48
//
49
// pept.transport.OutboundConnectionCache
50
//
51

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     ////////////////////////////////////////////////////
90
//
91
// Implementation
92
//
93

94     public Collection JavaDoc values()
95     {
96     return connectionCache.values();
97     }
98
99     protected Object JavaDoc backingStore()
100     {
101     return connectionCache;
102     }
103
104     protected void registerWithMonitoring()
105     {
106     // ORB
107
MonitoredObject orbMO =
108         orb.getMonitoringManager().getRootMonitoredObject();
109
110     // CONNECTION
111
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     // OUTBOUND CONNECTION
123
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     // NODE FOR THIS CACHE
136
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
150
attribute = new
151         LongMonitoredAttributeBase(
152                 MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS,
153         MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS_DESCRIPTION)
154         {
155         public Object JavaDoc getValue() {
156             return new Long JavaDoc(CorbaOutboundConnectionCacheImpl.this.numberOfConnections());
157         }
158         };
159     thisMO.addAttribute(attribute);
160
161     // ATTRIBUTE
162
attribute = new
163         LongMonitoredAttributeBase(
164                 MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS,
165         MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS_DESCRIPTION)
166         {
167         public Object JavaDoc getValue() {
168             return new Long JavaDoc(CorbaOutboundConnectionCacheImpl.this.numberOfIdleConnections());
169         }
170         };
171     thisMO.addAttribute(attribute);
172
173     // ATTRIBUTE
174
attribute = new
175         LongMonitoredAttributeBase(
176                 MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS,
177         MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS_DESCRIPTION)
178         {
179         public Object JavaDoc getValue() {
180             return new Long JavaDoc(CorbaOutboundConnectionCacheImpl.this.numberOfBusyConnections());
181         }
182         };
183     thisMO.addAttribute(attribute);
184     }
185
186     protected void dprint(String JavaDoc msg)
187     {
188     ORBUtility.dprint("CorbaOutboundConnectionCacheImpl", msg);
189     }
190 }
191
192 // End of file.
193
Popular Tags