01: package com.coldcore.coloradoftp.connection;
02:
03: import java.nio.channels.SocketChannel;
04:
05: /**
06: * Data or control connection.
07: * Connections read and write data from and to users.
08: *
09: * Life cycle of a connection is very simple. When it is accepted and configured it is then
10: * added to a connection pool which calls on it service method. When connection dies, the
11: * connection pool removes it from its internal list and the connection will be garbage
12: * collected.
13: *
14: * When poisoned, connection must die as soon as it has nothing to read/write to/from user.
15: * This is mainly for control connections as data connections do not use it. But since
16: * connection pool's specification requires it to poison all connections as soon as server's
17: * core becomes poisoned (before shutdown to let everyone finish and leave), the methods are
18: * located in this class.
19: *
20: *
21: * ColoradoFTP - The Open Source FTP Server (http://cftp.coldcore.com)
22: */
23: public interface Connection {
24:
25: /** Kill connection (free resources) */
26: public void destroy();
27:
28: /** Get connection's channel
29: * @return Channel
30: */
31: public SocketChannel getSocketChannel();
32:
33: /** Initialize connection (acquire resources)
34: * @param channel Channel
35: */
36: public void initialize(SocketChannel channel);
37:
38: /** Test if connection is destroyed
39: * @return TRUE if destroyed, FALSE otherwise
40: */
41: public boolean isDestroyed();
42:
43: /** Poison connection (when there is nothing more to read/write it must die,
44: * data connections output/input data and die, control connections are not allowed to
45: * read user input and die when all output is done)
46: */
47: public void poison();
48:
49: /** Test if connection is poisoned (will be destroyed shortly)
50: * @return TRUE if poisoned, FALSE otherwise
51: */
52: public boolean isPoisoned();
53:
54: /** Get bytes user sent so far
55: * @return Bytes count
56: */
57: public long getBytesRead();
58:
59: /** Get bytes server sent so far
60: * @return Bytes count
61: */
62: public long getBytesWrote();
63:
64: /** Self-service routine */
65: public void service() throws Exception;
66: }
|