View Javadoc

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.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       * @return the buffer pool
65       */
66      ByteBufferPool getBufferPool();
67      
68      /**
69       * Get the Executor used by this connection.
70       * @return the executor
71       */
72      Executor getExecutor();
73  
74      /**
75       * Get the read/write idle timeout.
76       * 
77       * @return the idle timeout in milliseconds
78       */
79      public long getIdleTimeout();
80  
81      /**
82       * Get the IOState of the connection.
83       * 
84       * @return the IOState of the connection.
85       */
86      IOState getIOState();
87  
88      /**
89       * Get the local {@link InetSocketAddress} in use for this connection.
90       * <p>
91       * 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.
92       * 
93       * @return the local address.
94       */
95      InetSocketAddress getLocalAddress();
96  
97      /**
98       * Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)
99       * @return the idle timeout in milliseconds
100      */
101     long getMaxIdleTimeout();
102 
103     /**
104      * The policy that the connection is running under.
105      * @return the policy for the connection
106      */
107     WebSocketPolicy getPolicy();
108 
109     /**
110      * Get the remote Address in use for this connection.
111      * <p>
112      * 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.
113      * 
114      * @return the remote address.
115      */
116     InetSocketAddress getRemoteAddress();
117 
118     /**
119      * Test if logical connection is still open
120      * 
121      *  @return true if connection is open
122      */
123     public boolean isOpen();
124 
125     /**
126      * Tests if the connection is actively reading.
127      * 
128      * @return true if connection is actively attempting to read.
129      */
130     boolean isReading();
131 
132     /**
133      * Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received)
134      * <p>
135      * This idle timeout cannot be garunteed to take immediate effect for any active read/write actions.
136      * New read/write actions will have this new idle timeout.
137      * 
138      * @param ms
139      *            the number of milliseconds of idle timeout
140      */
141     void setMaxIdleTimeout(long ms);
142 
143     /**
144      * Set where the connection should send the incoming frames to.
145      * <p>
146      * Often this is from the Parser to the start of the extension stack, and eventually on to the session.
147      * 
148      * @param incoming
149      *            the incoming frames handler
150      */
151     void setNextIncomingFrames(IncomingFrames incoming);
152 
153     /**
154      * Suspend a the incoming read events on the connection.
155      * @return the suspend token
156      */
157     SuspendToken suspend();
158 }