01: package vicazh.hyperpool.stream;
02:
03: import java.io.*;
04: import java.util.*;
05: import vicazh.hyperpool.Start;
06:
07: /**
08: * This class is the superclass of all stream selectors
09: *
10: * @author Victor Zhigunov
11: * @version 0.4.0
12: */
13: public class Selector extends vicazh.hyperpool.Selector implements
14: Element {
15: public OutputStream get(OutputStream outputstream)
16: throws IOException {
17: Connection connection = getConnection();
18: connection.setServer(outputstream);
19: connection.setClient((OutputStream) null);
20: add(connection);
21: return connection.getClient();
22: }
23:
24: /**
25: * Return client stream
26: *
27: * @param outputstream
28: * server stream
29: * @param index
30: * line index
31: * @return client stream
32: */
33: public OutputStream get(OutputStream outputstream, int index)
34: throws IOException {
35: return ((Element) getGroup().getObjects().get(index)
36: .getObject()).get(outputstream);
37: }
38:
39: public Connection getConnection() {
40: return new Connection(this );
41: }
42:
43: transient private List<Connection> connections = new ArrayList<Connection>();
44:
45: public void add(Connection connection) {
46: connections.add(connection);
47: Start.logger.finest(getClass().getName() + ":connections.size:"
48: + connections.size());
49: }
50:
51: public List<Connection> getConnections() {
52: return connections;
53: }
54:
55: public void remove(Connection connection) {
56: connections.remove(connection);
57: Start.logger.finest(getClass().getName() + ":connections.size:"
58: + connections.size());
59: }
60: }
|