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
31 package org.apache.commons.httpclient.server;
32
33 import java.util.ArrayList;
34 import java.util.Iterator;
35 import java.util.List;
36
37 /***
38 * A simple list of connections.
39 *
40 * @author Oleg Kalnichevski
41 */
42 public class SimpleConnList {
43
44 private List connections = new ArrayList();
45
46 public SimpleConnList() {
47 super();
48 }
49
50 public synchronized void addConnection(final SimpleHttpServerConnection conn) {
51 this.connections.add(conn);
52 }
53
54 public synchronized void removeConnection(final SimpleHttpServerConnection conn) {
55 this.connections.remove(conn);
56 }
57
58 public synchronized SimpleHttpServerConnection removeLast() {
59 int s = this.connections.size();
60 if (s > 0) {
61 return (SimpleHttpServerConnection)this.connections.remove(s - 1);
62 } else {
63 return null;
64 }
65 }
66
67 public synchronized SimpleHttpServerConnection removeFirst() {
68 int s = this.connections.size();
69 if (s > 0) {
70 return (SimpleHttpServerConnection)this.connections.remove(0);
71 } else {
72 return null;
73 }
74 }
75
76 public synchronized void shutdown() {
77 for (Iterator i = this.connections.iterator(); i.hasNext();) {
78 SimpleHttpServerConnection conn = (SimpleHttpServerConnection) i.next();
79 conn.close();
80 }
81 this.connections.clear();
82 }
83
84 }