CorbaInboundConnectionCacheImpl.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.corba.se.impl.transport;
27
28import java.util.ArrayList;
29import java.util.Collection;
30
31import com.sun.corba.se.pept.broker.Broker;
32import com.sun.corba.se.pept.transport.Acceptor;
33import com.sun.corba.se.pept.transport.Connection;
34import com.sun.corba.se.pept.transport.InboundConnectionCache;
35
36import com.sun.corba.se.spi.monitoring.LongMonitoredAttributeBase;
37import com.sun.corba.se.spi.monitoring.MonitoringConstants;
38import com.sun.corba.se.spi.monitoring.MonitoringFactories;
39import com.sun.corba.se.spi.monitoring.MonitoredObject;
40import com.sun.corba.se.spi.orb.ORB;
41import com.sun.corba.se.spi.transport.CorbaConnectionCache;
42import com.sun.corba.se.spi.transport.CorbaAcceptor;
43
44import com.sun.corba.se.impl.orbutil.ORBUtility;
45
46/**
47 * @author Harold Carr
48 */
49public class CorbaInboundConnectionCacheImpl
50    extends
51        CorbaConnectionCacheBase
52    implements
53        InboundConnectionCache
54{
55    protected Collection connectionCache;
56
57    public CorbaInboundConnectionCacheImpl(ORB orb, Acceptor acceptor)
58    {
59        super(orb, acceptor.getConnectionCacheType(),
60              ((CorbaAcceptor)acceptor).getMonitoringName());
61        this.connectionCache = new ArrayList();
62    }
63
64    ////////////////////////////////////////////////////
65    //
66    // pept.transport.InboundConnectionCache
67    //
68
69    public Connection get(Acceptor acceptor)
70    {
71        throw wrapper.methodShouldNotBeCalled();
72    }
73
74    public void put(Acceptor acceptor, Connection connection)
75    {
76        if (orb.transportDebugFlag) {
77            dprint(".put: " + acceptor + " " + connection);
78        }
79        synchronized (backingStore()) {
80            connectionCache.add(connection);
81            connection.setConnectionCache(this);
82            dprintStatistics();
83        }
84    }
85
86    public void remove(Connection connection)
87    {
88        if (orb.transportDebugFlag) {
89            dprint(".remove: " +  connection);
90        }
91        synchronized (backingStore()) {
92            connectionCache.remove(connection);
93            dprintStatistics();
94        }
95    }
96
97    ////////////////////////////////////////////////////
98    //
99    // Implementation
100    //
101
102    public Collection values()
103    {
104        return connectionCache;
105    }
106
107    protected Object backingStore()
108    {
109        return connectionCache;
110    }
111
112    protected void registerWithMonitoring()
113    {
114        // ORB
115        MonitoredObject orbMO =
116            orb.getMonitoringManager().getRootMonitoredObject();
117
118        // REVISIT - add ORBUtil mkdir -p like operation for this.
119
120        // CONNECTION
121        MonitoredObject connectionMO =
122            orbMO.getChild(MonitoringConstants.CONNECTION_MONITORING_ROOT);
123        if (connectionMO == null) {
124            connectionMO =
125                MonitoringFactories.getMonitoredObjectFactory()
126                    .createMonitoredObject(
127                        MonitoringConstants.CONNECTION_MONITORING_ROOT,
128                        MonitoringConstants.CONNECTION_MONITORING_ROOT_DESCRIPTION);
129            orbMO.addChild(connectionMO);
130        }
131
132        // INBOUND CONNECTION
133        MonitoredObject inboundConnectionMO =
134            connectionMO.getChild(
135                MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT);
136        if (inboundConnectionMO == null) {
137            inboundConnectionMO =
138                MonitoringFactories.getMonitoredObjectFactory()
139                    .createMonitoredObject(
140                        MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT,
141                        MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT_DESCRIPTION);
142            connectionMO.addChild(inboundConnectionMO);
143        }
144
145        // NODE FOR THIS CACHE
146        MonitoredObject thisMO =
147            inboundConnectionMO.getChild(getMonitoringName());
148        if (thisMO == null) {
149            thisMO =
150                MonitoringFactories.getMonitoredObjectFactory()
151                    .createMonitoredObject(
152                        getMonitoringName(),
153                        MonitoringConstants.CONNECTION_MONITORING_DESCRIPTION);
154            inboundConnectionMO.addChild(thisMO);
155        }
156
157        LongMonitoredAttributeBase attribute;
158
159        // ATTRIBUTE
160        attribute = new
161            LongMonitoredAttributeBase(
162                MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS,
163                MonitoringConstants.CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS_DESCRIPTION)
164            {
165                public Object getValue() {
166                    return new Long(CorbaInboundConnectionCacheImpl.this.numberOfConnections());
167                }
168            };
169        thisMO.addAttribute(attribute);
170
171        // ATTRIBUTE
172        attribute = new
173            LongMonitoredAttributeBase(
174                MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS,
175                MonitoringConstants.CONNECTION_NUMBER_OF_IDLE_CONNECTIONS_DESCRIPTION)
176            {
177                public Object getValue() {
178                    return new Long(CorbaInboundConnectionCacheImpl.this.numberOfIdleConnections());
179                }
180            };
181        thisMO.addAttribute(attribute);
182
183        // ATTRIBUTE
184        attribute = new
185            LongMonitoredAttributeBase(
186                MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS,
187                MonitoringConstants.CONNECTION_NUMBER_OF_BUSY_CONNECTIONS_DESCRIPTION)
188            {
189                public Object getValue() {
190                    return new Long(CorbaInboundConnectionCacheImpl.this.numberOfBusyConnections());
191                }
192            };
193        thisMO.addAttribute(attribute);
194    }
195
196    protected void dprint(String msg)
197    {
198        ORBUtility.dprint("CorbaInboundConnectionCacheImpl", msg);
199    }
200}
201
202// End of file.
203