1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.apache.commons.httpclient.server;
31
32 import java.util.ArrayList;
33 import java.util.Iterator;
34 import java.util.List;
35
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38
39 /***
40 * A simple list of connections.
41 *
42 * @author Oleg Kalnichevski
43 */
44 public class SimpleConnList {
45
46 private static final Log LOG = LogFactory.getLog(SimpleConnList.class);
47
48 private List connections = new ArrayList();
49
50 public SimpleConnList() {
51 super();
52 }
53
54 public synchronized void addConnection(final SimpleHttpServerConnection conn) {
55 this.connections.add(conn);
56 }
57
58 public synchronized void removeConnection(final SimpleHttpServerConnection conn) {
59 this.connections.remove(conn);
60 }
61
62 public synchronized SimpleHttpServerConnection removeLast() {
63 int s = this.connections.size();
64 if (s > 0) {
65 return (SimpleHttpServerConnection)this.connections.remove(s - 1);
66 } else {
67 return null;
68 }
69 }
70
71 public synchronized SimpleHttpServerConnection removeFirst() {
72 int s = this.connections.size();
73 if (s > 0) {
74 return (SimpleHttpServerConnection)this.connections.remove(0);
75 } else {
76 return null;
77 }
78 }
79
80 public synchronized void shutdown() {
81 for (Iterator i = this.connections.iterator(); i.hasNext();) {
82 SimpleHttpServerConnection conn = (SimpleHttpServerConnection) i.next();
83 conn.close();
84 }
85 this.connections.clear();
86 }
87
88 }