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