KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > protocol > transport > ConnectionPolicyImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.net.protocol.transport;
6
7 import com.tc.util.Assert;
8
9 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", maxConnections >= 0);
16     this.maxConnections = maxConnections;
17   }
18
19   public synchronized String JavaDoc toString() {
20     return "ConnectionPolicy[maxConnections=" + maxConnections + ", connectionCount=" + connectionCount + "]";
21   }
22
23   public synchronized void clientConnected() {
24     connectionCount++;
25   }
26
27   public synchronized void clientDisconnected() {
28     if (connectionCount > 0) {
29       connectionCount--;
30     }
31   }
32
33   public synchronized boolean maxConnectionsExceeded() {
34     return connectionCount > maxConnections;
35   }
36
37   public synchronized int getMaxConnections() {
38     return maxConnections;
39   }
40
41   public synchronized void setMaxConnections(int i) {
42     this.maxConnections = i;
43   }
44 }
45
Popular Tags