1 //
2 // ========================================================================
3 // Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.websocket.common;
20
21 import java.net.InetSocketAddress;
22 import java.util.concurrent.Executor;
23
24 import org.eclipse.jetty.io.ByteBufferPool;
25 import org.eclipse.jetty.websocket.api.SuspendToken;
26 import org.eclipse.jetty.websocket.api.WebSocketPolicy;
27 import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
28 import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
29 import org.eclipse.jetty.websocket.common.io.IOState;
30
31 public interface LogicalConnection extends OutgoingFrames, SuspendToken
32 {
33 /**
34 * Send a websocket Close frame, without a status code or reason.
35 * <p>
36 * Basic usage: results in an non-blocking async write, then connection close.
37 *
38 * @see StatusCode
39 * @see #close(int, String)
40 */
41 public void close();
42
43 /**
44 * Send a websocket Close frame, with status code.
45 * <p>
46 * Advanced usage: results in an non-blocking async write, then connection close.
47 *
48 * @param statusCode
49 * the status code
50 * @param reason
51 * the (optional) reason. (can be null for no reason)
52 * @see StatusCode
53 */
54 public void close(int statusCode, String reason);
55
56 /**
57 * Terminate the connection (no close frame sent)
58 */
59 void disconnect();
60
61 /**
62 * Get the ByteBufferPool in use by the connection
63 */
64 ByteBufferPool getBufferPool();
65
66 /**
67 * Get the Executor used by this connection.
68 */
69 Executor getExecutor();
70
71 /**
72 * Get the read/write idle timeout.
73 *
74 * @return the idle timeout in milliseconds
75 */
76 public long getIdleTimeout();
77
78 /**
79 * Get the IOState of the connection.
80 *
81 * @return the IOState of the connection.
82 */
83 IOState getIOState();
84
85 /**
86 * Get the local {@link InetSocketAddress} in use for this connection.
87 * <p>
88 * Note: Non-physical connections, like during the Mux extensions, or during unit testing can result in a InetSocketAddress on port 0 and/or on localhost.
89 *
90 * @return the local address.
91 */
92 InetSocketAddress getLocalAddress();
93
94 /**
95 * Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)
96 * @return the idle timeout in milliseconds
97 */
98 long getMaxIdleTimeout();
99
100 /**
101 * The policy that the connection is running under.
102 * @return the policy for the connection
103 */
104 WebSocketPolicy getPolicy();
105
106 /**
107 * Get the remote Address in use for this connection.
108 * <p>
109 * Note: Non-physical connections, like during the Mux extensions, or during unit testing can result in a InetSocketAddress on port 0 and/or on localhost.
110 *
111 * @return the remote address.
112 */
113 InetSocketAddress getRemoteAddress();
114
115 /**
116 * Get the Session for this connection
117 *
118 * @return the Session for this connection
119 */
120 WebSocketSession getSession();
121
122 /**
123 * Test if logical connection is still open
124 *
125 * @return true if connection is open
126 */
127 public boolean isOpen();
128
129 /**
130 * Tests if the connection is actively reading.
131 *
132 * @return true if connection is actively attempting to read.
133 */
134 boolean isReading();
135
136 /**
137 * Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)
138 * <p>
139 * This idle timeout cannot be garunteed to take immediate effect for any active read/write actions.
140 * New read/write actions will have this new idle timeout.
141 *
142 * @param ms
143 * the number of milliseconds of idle timeout
144 */
145 void setMaxIdleTimeout(long ms);
146
147 /**
148 * Set where the connection should send the incoming frames to.
149 * <p>
150 * Often this is from the Parser to the start of the extension stack, and eventually on to the session.
151 *
152 * @param incoming
153 * the incoming frames handler
154 */
155 void setNextIncomingFrames(IncomingFrames incoming);
156
157 /**
158 * Set the session associated with this connection
159 *
160 * @param session
161 * the session
162 */
163 void setSession(WebSocketSession session);
164
165 /**
166 * Suspend a the incoming read events on the connection.
167 */
168 SuspendToken suspend();
169 }