View Javadoc

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  import java.util.concurrent.Executor;
23  
24  import org.eclipse.jetty.io.ByteBufferPool;
25  import org.eclipse.jetty.websocket.api.StatusCode;
26  import org.eclipse.jetty.websocket.api.SuspendToken;
27  import org.eclipse.jetty.websocket.api.WebSocketPolicy;
28  import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
29  import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
30  import org.eclipse.jetty.websocket.common.io.IOState;
31  
32  public interface LogicalConnection extends OutgoingFrames, SuspendToken
33  {
34      /**
35       * Send a websocket Close frame, without a status code or reason.
36       * <p>
37       * Basic usage: results in an non-blocking async write, then connection close.
38       * 
39       * @see StatusCode
40       * @see #close(int, String)
41       */
42      public void close();
43  
44      /**
45       * Send a websocket Close frame, with status code.
46       * <p>
47       * Advanced usage: results in an non-blocking async write, then connection close.
48       * 
49       * @param statusCode
50       *            the status code
51       * @param reason
52       *            the (optional) reason. (can be null for no reason)
53       * @see StatusCode
54       */
55      public void close(int statusCode, String reason);
56  
57      /**
58       * Terminate the connection (no close frame sent)
59       */
60      void disconnect();
61  
62      /**
63       * Get the ByteBufferPool in use by the connection
64       */
65      ByteBufferPool getBufferPool();
66      
67      /**
68       * Get the Executor used by this connection.
69       */
70      Executor getExecutor();
71  
72      /**
73       * Get the read/write idle timeout.
74       * 
75       * @return the idle timeout in milliseconds
76       */
77      public long getIdleTimeout();
78  
79      /**
80       * Get the IOState of the connection.
81       * 
82       * @return the IOState of the connection.
83       */
84      IOState getIOState();
85  
86      /**
87       * Get the local {@link InetSocketAddress} in use for this connection.
88       * <p>
89       * 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.
90       * 
91       * @return the local address.
92       */
93      InetSocketAddress getLocalAddress();
94  
95      /**
96       * Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)
97       * @return the idle timeout in milliseconds
98       */
99      long getMaxIdleTimeout();
100 
101     /**
102      * The policy that the connection is running under.
103      * @return the policy for the connection
104      */
105     WebSocketPolicy getPolicy();
106 
107     /**
108      * Get the remote Address in use for this connection.
109      * <p>
110      * 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.
111      * 
112      * @return the remote address.
113      */
114     InetSocketAddress getRemoteAddress();
115 
116     /**
117      * Get the Session for this connection
118      * 
119      * @return the Session for this connection
120      */
121     WebSocketSession getSession();
122 
123     /**
124      * Test if logical connection is still open
125      * 
126      *  @return true if connection is open
127      */
128     public boolean isOpen();
129 
130     /**
131      * Tests if the connection is actively reading.
132      * 
133      * @return true if connection is actively attempting to read.
134      */
135     boolean isReading();
136 
137     /**
138      * Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)
139      * <p>
140      * This idle timeout cannot be garunteed to take immediate effect for any active read/write actions.
141      * New read/write actions will have this new idle timeout.
142      * 
143      * @param ms
144      *            the number of milliseconds of idle timeout
145      */
146     void setMaxIdleTimeout(long ms);
147 
148     /**
149      * Set where the connection should send the incoming frames to.
150      * <p>
151      * Often this is from the Parser to the start of the extension stack, and eventually on to the session.
152      * 
153      * @param incoming
154      *            the incoming frames handler
155      */
156     void setNextIncomingFrames(IncomingFrames incoming);
157 
158     /**
159      * Set the session associated with this connection
160      * 
161      * @param session
162      *            the session
163      */
164     void setSession(WebSocketSession session);
165 
166     /**
167      * Suspend a the incoming read events on the connection.
168      */
169     SuspendToken suspend();
170 }