01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.net.protocol.transport;
06:
07: import com.tc.util.Assert;
08:
09: public class ConnectionPolicyImpl implements ConnectionPolicy {
10:
11: private int maxConnections;
12: private int connectionCount;
13:
14: public ConnectionPolicyImpl(int maxConnections) {
15: Assert.assertTrue("negative maxConnections",
16: maxConnections >= 0);
17: this .maxConnections = maxConnections;
18: }
19:
20: public synchronized String toString() {
21: return "ConnectionPolicy[maxConnections=" + maxConnections
22: + ", connectionCount=" + connectionCount + "]";
23: }
24:
25: public synchronized void clientConnected() {
26: connectionCount++;
27: }
28:
29: public synchronized void clientDisconnected() {
30: if (connectionCount > 0) {
31: connectionCount--;
32: }
33: }
34:
35: public synchronized boolean maxConnectionsExceeded() {
36: return connectionCount > maxConnections;
37: }
38:
39: public synchronized int getMaxConnections() {
40: return maxConnections;
41: }
42:
43: public synchronized void setMaxConnections(int i) {
44: this.maxConnections = i;
45: }
46: }
|