01: package vicazh.hyperpool.stream;
02:
03: import java.io.*;
04:
05: /**
06: * This class is the superclass of all connections
07: *
08: * @author Victor Zhigunov
09: * @version 0.4.0
10: */
11: public class Connection {
12: public Connection() {
13: }
14:
15: private Stream client;
16:
17: /**
18: * Set the client stream
19: */
20: public void setClient(Stream client) {
21: this .client = client;
22: }
23:
24: /**
25: * Get the client stream
26: */
27: public Stream getClient() {
28: return client;
29: }
30:
31: private Stream server;
32:
33: /**
34: * Set the server stream
35: */
36: public void setServer(Stream server) {
37: this .server = server;
38: }
39:
40: /**
41: * Get the server stream
42: */
43: public Stream getServer() {
44: return server;
45: }
46:
47: /**
48: * The parent element
49: */
50: public Element element;
51:
52: /**
53: * @param element
54: * parent element
55: */
56: public Connection(Element element) {
57: this .element = element;
58: }
59:
60: /**
61: * Set client stream
62: *
63: * @param outputstream
64: * next element client stream
65: */
66: public void setClient(OutputStream outputstream) throws IOException {
67: setClient(new Stream(this , outputstream));
68: }
69:
70: /**
71: * Set server stream
72: *
73: * @param outputstream
74: * previous element server stream
75: */
76: public void setServer(OutputStream outputstream) throws IOException {
77: setServer(new Stream(this , outputstream));
78: }
79:
80: void close(Stream stream) {
81: if (stream == client)
82: close();
83: }
84:
85: /**
86: * Close this connection
87: */
88: public void close() {
89: element.remove(this);
90: }
91: }
|