1 //
2 // ========================================================================
3 // Copyright (c) 1995-2013 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
23 import org.eclipse.jetty.websocket.api.StatusCode;
24 import org.eclipse.jetty.websocket.api.SuspendToken;
25 import org.eclipse.jetty.websocket.api.WebSocketPolicy;
26 import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
27 import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
28 import org.eclipse.jetty.websocket.common.io.IOState;
29
30 public interface LogicalConnection extends OutgoingFrames, SuspendToken
31 {
32 /**
33 * Send a websocket Close frame, without a status code or reason.
34 * <p>
35 * Basic usage: results in an non-blocking async write, then connection close.
36 *
37 * @see StatusCode
38 * @see #close(int, String)
39 */
40 public void close();
41
42 /**
43 * Send a websocket Close frame, with status code.
44 * <p>
45 * Advanced usage: results in an non-blocking async write, then connection close.
46 *
47 * @param statusCode
48 * the status code
49 * @param reason
50 * the (optional) reason. (can be null for no reason)
51 * @see StatusCode
52 */
53 public void close(int statusCode, String reason);
54
55 /**
56 * Terminate the connection (no close frame sent)
57 */
58 void disconnect();
59
60 /**
61 * Get the IOState of the connection.
62 *
63 * @return the IOState of the connection.
64 */
65 IOState getIOState();
66
67 /**
68 * Get the local {@link InetSocketAddress} in use for this connection.
69 * <p>
70 * 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.
71 *
72 * @return the local address.
73 */
74 InetSocketAddress getLocalAddress();
75
76 /**
77 * The policy that the connection is running under.
78 * @return the policy for the connection
79 */
80 WebSocketPolicy getPolicy();
81
82 /**
83 * Get the remote Address in use for this connection.
84 * <p>
85 * 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.
86 *
87 * @return the remote address.
88 */
89 InetSocketAddress getRemoteAddress();
90
91 /**
92 * Get the Session for this connection
93 *
94 * @return the Session for this connection
95 */
96 WebSocketSession getSession();
97
98 /**
99 * Test if logical connection is still open
100 *
101 * @return true if connection is open
102 */
103 public boolean isOpen();
104
105 /**
106 * Tests if the connection is actively reading.
107 *
108 * @return true if connection is actively attempting to read.
109 */
110 boolean isReading();
111
112 /**
113 * Set where the connection should send the incoming frames to.
114 * <p>
115 * Often this is from the Parser to the start of the extension stack, and eventually on to the session.
116 *
117 * @param incoming
118 * the incoming frames handler
119 */
120 void setNextIncomingFrames(IncomingFrames incoming);
121
122 /**
123 * Set the session associated with this connection
124 *
125 * @param session
126 * the session
127 */
128 void setSession(WebSocketSession session);
129
130 /**
131 * Suspend a the incoming read events on the connection.
132 *
133 * @return
134 */
135 SuspendToken suspend();
136 }