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 * Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received) 78 * @return the idle timeout in milliseconds 79 */ 80 long getMaxIdleTimeout(); 81 82 /** 83 * The policy that the connection is running under. 84 * @return the policy for the connection 85 */ 86 WebSocketPolicy getPolicy(); 87 88 /** 89 * Get the remote Address 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 remote address. 94 */ 95 InetSocketAddress getRemoteAddress(); 96 97 /** 98 * Get the Session for this connection 99 * 100 * @return the Session for this connection 101 */ 102 WebSocketSession getSession(); 103 104 /** 105 * Test if logical connection is still open 106 * 107 * @return true if connection is open 108 */ 109 public boolean isOpen(); 110 111 /** 112 * Tests if the connection is actively reading. 113 * 114 * @return true if connection is actively attempting to read. 115 */ 116 boolean isReading(); 117 118 /** 119 * Set the maximum number of milliseconds of idleness before the connection is closed/disconnected, (ie no frames are either sent or received) 120 * 121 * @param ms 122 * the number of milliseconds of idle timeout 123 */ 124 void setMaxIdleTimeout(long ms); 125 126 /** 127 * Set where the connection should send the incoming frames to. 128 * <p> 129 * Often this is from the Parser to the start of the extension stack, and eventually on to the session. 130 * 131 * @param incoming 132 * the incoming frames handler 133 */ 134 void setNextIncomingFrames(IncomingFrames incoming); 135 136 /** 137 * Set the session associated with this connection 138 * 139 * @param session 140 * the session 141 */ 142 void setSession(WebSocketSession session); 143 144 /** 145 * Suspend a the incoming read events on the connection. 146 * 147 * @return 148 */ 149 SuspendToken suspend(); 150 }