1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.common;
20
21 import java.net.SocketAddress;
22 import java.util.Set;
23
24 /***
25 * A handle which represents connection between two endpoints regardless of
26 * transport types.
27 * <p>
28 * Session provides user-defined attributes. User-defined attributes are
29 * application-specific data which is associated with a session.
30 * It often contains objects that represents the state of a higher-level protocol
31 * and becomes a way to exchange data between filters and handlers.
32 *
33 * @author The Apache Directory Project (dev@directory.apache.org)
34 * @version $Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $
35 */
36 public interface Session {
37
38 /***
39 * Closes this session immediately. Calling method is identical with
40 * calling <tt>close( false )</tt>.
41 */
42 void close();
43
44 /***
45 * Closes this session immediately.
46 *
47 * @param wait <tt>true</tt> if you want to wait until closing process is
48 * complete.
49 */
50 void close( boolean wait );
51
52 /***
53 * Returns an attachment of this session.
54 * This method is identical with <tt>getAttribute( "" )</tt>.
55 */
56 Object getAttachment();
57
58 /***
59 * Sets an attachment of this session.
60 * This method is identical with <tt>setAttribute( "", attachment )</tt>.
61 *
62 * @return Old attachment. <tt>null</tt> if it is new.
63 */
64 Object setAttachment( Object attachment );
65
66 /***
67 * Returns the value of user-defined attribute of this session.
68 *
69 * @param key the key of the attribute
70 * @return <tt>null</tt> if there is no attribute with the specified key
71 */
72 Object getAttribute( String key );
73
74 /***
75 * Sets a user-defined attribute.
76 *
77 * @param key the key of the attribute
78 * @param value the value of the attribute
79 * @return The old value of the attribute. <tt>null</tt> if it is new.
80 */
81 Object setAttribute( String key, Object value );
82
83 /***
84 * Removes a user-defined attribute with the specified key.
85 *
86 * @return The old value of the attribute. <tt>null</tt> if not found.
87 */
88 Object removeAttribute( String key );
89
90 /***
91 * Returns the set of keys of all user-defined attributes.
92 */
93 Set getAttributeKeys();
94
95 /***
96 * Returns transport type of this session.
97 */
98 TransportType getTransportType();
99
100 /***
101 * Returns <code>true</code> if this session is connected with remote peer.
102 */
103 boolean isConnected();
104
105 /***
106 * Returns the configuration of this session.
107 */
108 SessionConfig getConfig();
109
110 /***
111 * Returns the socket address of remote peer.
112 */
113 SocketAddress getRemoteAddress();
114
115 /***
116 * Returns the socket address of local machine which is associated with this
117 * session.
118 */
119 SocketAddress getLocalAddress();
120
121 /***
122 * Returns the total number of bytes which were read from this session.
123 */
124 long getReadBytes();
125
126 /***
127 * Returns the total number of bytes which were written to this session.
128 */
129 long getWrittenBytes();
130
131 /***
132 * Returns the total number of write requests which were written to this session.
133 */
134 long getWrittenWriteRequests();
135
136 /***
137 * Returns the number of write requests which are scheduled to be written
138 * to this session.
139 */
140 int getScheduledWriteRequests();
141
142 /***
143 * Returns the time in millis when this session is created.
144 */
145 long getCreationTime();
146
147 /***
148 * Returns the time in millis when I/O occurred lastly.
149 */
150 long getLastIoTime();
151
152 /***
153 * Returns the time in millis when read operation occurred lastly.
154 */
155 long getLastReadTime();
156
157 /***
158 * Returns the time in millis when write operation occurred lastly.
159 */
160 long getLastWriteTime();
161
162 /***
163 * Returns <code>true</code> if this session is idle for the specified
164 * {@link IdleStatus}.
165 */
166 boolean isIdle( IdleStatus status );
167
168 /***
169 * Returns the number of the fired continuous <tt>sessionIdle</tt> events
170 * for the specified {@link IdleStatus}.
171 * <p>
172 * If <tt>sessionIdle</tt> event is fired first after some time after I/O,
173 * <tt>idleCount</tt> becomes <tt>1</tt>. <tt>idleCount</tt> resets to
174 * <tt>0</tt> if any I/O occurs again, otherwise it increases to
175 * <tt>2</tt> and so on if <tt>sessionIdle</tt> event is fired again without
176 * any I/O between two (or more) <tt>sessionIdle</tt> events.
177 */
178 int getIdleCount( IdleStatus status );
179
180 /***
181 * Returns the time in millis when the last <tt>sessionIdle</tt> event
182 * is fired for the specified {@link IdleStatus}.
183 */
184 long getLastIdleTime( IdleStatus status );
185 }