diff --git a/src/main/java/org/java_websocket/AbstractWrappedByteChannel.java b/src/main/java/org/java_websocket/AbstractWrappedByteChannel.java index 33e6ddcc9..3fa401a6e 100644 --- a/src/main/java/org/java_websocket/AbstractWrappedByteChannel.java +++ b/src/main/java/org/java_websocket/AbstractWrappedByteChannel.java @@ -34,7 +34,7 @@ * @deprecated */ @Deprecated -public class AbstractWrappedByteChannel implements WrappedByteChannel { +public class AbstractWrappedByteChannel implements WrappedByteChannel, WrappedMoreWrittenChannel { private final ByteChannel channel; diff --git a/src/main/java/org/java_websocket/SSLSocketChannel.java b/src/main/java/org/java_websocket/SSLSocketChannel.java index b4024505b..56e93243a 100644 --- a/src/main/java/org/java_websocket/SSLSocketChannel.java +++ b/src/main/java/org/java_websocket/SSLSocketChannel.java @@ -501,11 +501,6 @@ public boolean isNeedWrite() { return false; } - @Override - public void writeMore() throws IOException { - //Nothing to do since we write out all the data in a while loop - } - @Override public boolean isNeedRead() { return peerNetData.hasRemaining() || peerAppData.hasRemaining(); diff --git a/src/main/java/org/java_websocket/SSLSocketChannel2.java b/src/main/java/org/java_websocket/SSLSocketChannel2.java index c0ea28e3f..e8eeb9100 100644 --- a/src/main/java/org/java_websocket/SSLSocketChannel2.java +++ b/src/main/java/org/java_websocket/SSLSocketChannel2.java @@ -53,7 +53,7 @@ /** * Implements the relevant portions of the SocketChannel interface with the SSLEngine wrapper. */ -public class SSLSocketChannel2 implements ByteChannel, WrappedByteChannel, ISSLChannel { +public class SSLSocketChannel2 implements ByteChannel, WrappedByteChannel, WrappedMoreWrittenChannel, ISSLChannel { /** * This object is used to feed the {@link SSLEngine}'s wrap and unwrap methods during the diff --git a/src/main/java/org/java_websocket/WebSocketServerFactory.java b/src/main/java/org/java_websocket/WebSocketServerFactory.java index 825aa2165..fdf333359 100644 --- a/src/main/java/org/java_websocket/WebSocketServerFactory.java +++ b/src/main/java/org/java_websocket/WebSocketServerFactory.java @@ -54,8 +54,4 @@ public interface WebSocketServerFactory extends WebSocketFactory { */ ByteChannel wrapChannel(SocketChannel channel, SelectionKey key) throws IOException; - /** - * Allows to shutdown the websocket factory for a clean shutdown - */ - void close(); } diff --git a/src/main/java/org/java_websocket/WebSocketServerFactoryClosing.java b/src/main/java/org/java_websocket/WebSocketServerFactoryClosing.java new file mode 100644 index 000000000..5ef8aa2d1 --- /dev/null +++ b/src/main/java/org/java_websocket/WebSocketServerFactoryClosing.java @@ -0,0 +1,18 @@ +package org.java_websocket; + +import java.io.IOException; +import java.nio.channels.ByteChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.SocketChannel; +import java.util.List; +import org.java_websocket.drafts.Draft; + +/** + * Interface to encapsulate the required methods for a websocket factory + */ +public interface WebSocketServerFactoryClosing extends WebSocketFactory { + /** + * Allows to shutdown the websocket factory for a clean shutdown + */ + void close(); +} \ No newline at end of file diff --git a/src/main/java/org/java_websocket/WrappedByteChannel.java b/src/main/java/org/java_websocket/WrappedByteChannel.java index 8dee57db0..ac4a38230 100644 --- a/src/main/java/org/java_websocket/WrappedByteChannel.java +++ b/src/main/java/org/java_websocket/WrappedByteChannel.java @@ -38,13 +38,6 @@ public interface WrappedByteChannel extends ByteChannel { */ boolean isNeedWrite(); - /** - * Gets called when {@link #isNeedWrite()} ()} requires a additional rite - * - * @throws IOException may be thrown due to an error while writing - */ - void writeMore() throws IOException; - /** * returns whether readMore should be called to fetch data which has been decoded but not yet been * returned. diff --git a/src/main/java/org/java_websocket/WrappedMoreWrittenChannel.java b/src/main/java/org/java_websocket/WrappedMoreWrittenChannel.java new file mode 100644 index 000000000..c8a9f47b9 --- /dev/null +++ b/src/main/java/org/java_websocket/WrappedMoreWrittenChannel.java @@ -0,0 +1,14 @@ +package org.java_websocket; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.ByteChannel; + +public interface WrappedMoreWrittenChannel extends ByteChannel { + /** + * Gets called when {@link #isNeedWrite()} ()} requires a additional rite + * + * @throws IOException may be thrown due to an error while writing + */ + void writeMore() throws IOException; +} \ No newline at end of file diff --git a/src/main/java/org/java_websocket/extensions/DefaultExtension.java b/src/main/java/org/java_websocket/extensions/DefaultExtension.java index 3892990c1..f1d41e71e 100644 --- a/src/main/java/org/java_websocket/extensions/DefaultExtension.java +++ b/src/main/java/org/java_websocket/extensions/DefaultExtension.java @@ -38,16 +38,6 @@ */ public class DefaultExtension implements IExtension { - @Override - public void decodeFrame(Framedata inputFrame) throws InvalidDataException { - //Nothing to do here - } - - @Override - public void encodeFrame(Framedata inputFrame) { - //Nothing to do here - } - @Override public boolean acceptProvidedExtensionAsServer(String inputExtension) { return true; @@ -82,10 +72,6 @@ public IExtension copyInstance() { return new DefaultExtension(); } - public void reset() { - //Nothing to do here. No internal stats. - } - @Override public String toString() { return getClass().getSimpleName(); diff --git a/src/main/java/org/java_websocket/extensions/IEncoderExtension.java b/src/main/java/org/java_websocket/extensions/IEncoderExtension.java new file mode 100644 index 000000000..02919524f --- /dev/null +++ b/src/main/java/org/java_websocket/extensions/IEncoderExtension.java @@ -0,0 +1,34 @@ +package org.java_websocket.extensions; + +import org.java_websocket.exceptions.InvalidDataException; +import org.java_websocket.framing.Framedata; + +/** + * Interface which specifies all required methods to develop a websocket extension. + * + * @since 1.3.5 + */ +public interface IEncoderExtension { + + /** + * Decode a frame with a extension specific algorithm. The algorithm is subject to be implemented + * by the specific extension. The resulting frame will be used in the application + * + * @param inputFrame the frame, which has do be decoded to be used in the application + * @throws InvalidDataException Throw InvalidDataException if the received frame is not correctly + * implemented by the other endpoint or there are other protocol + * errors/decoding errors + * @since 1.3.5 + */ + void decodeFrame(Framedata inputFrame) throws InvalidDataException; + + /** + * Encode a frame with a extension specific algorithm. The algorithm is subject to be implemented + * by the specific extension. The resulting frame will be send to the other endpoint. + * + * @param inputFrame the frame, which has do be encoded to be used on the other endpoint + * @since 1.3.5 + */ + void encodeFrame(Framedata inputFrame); + +} \ No newline at end of file diff --git a/src/main/java/org/java_websocket/extensions/IExtension.java b/src/main/java/org/java_websocket/extensions/IExtension.java index 02bf581a4..d19fecf82 100644 --- a/src/main/java/org/java_websocket/extensions/IExtension.java +++ b/src/main/java/org/java_websocket/extensions/IExtension.java @@ -35,27 +35,6 @@ */ public interface IExtension { - /** - * Decode a frame with a extension specific algorithm. The algorithm is subject to be implemented - * by the specific extension. The resulting frame will be used in the application - * - * @param inputFrame the frame, which has do be decoded to be used in the application - * @throws InvalidDataException Throw InvalidDataException if the received frame is not correctly - * implemented by the other endpoint or there are other protocol - * errors/decoding errors - * @since 1.3.5 - */ - void decodeFrame(Framedata inputFrame) throws InvalidDataException; - - /** - * Encode a frame with a extension specific algorithm. The algorithm is subject to be implemented - * by the specific extension. The resulting frame will be send to the other endpoint. - * - * @param inputFrame the frame, which has do be encoded to be used on the other endpoint - * @since 1.3.5 - */ - void encodeFrame(Framedata inputFrame); - /** * Check if the received Sec-WebSocket-Extensions header field contains a offer for the specific * extension if the endpoint is in the role of a server @@ -120,13 +99,6 @@ public interface IExtension { */ IExtension copyInstance(); - /** - * Cleaning up internal stats when the draft gets reset. - * - * @since 1.3.5 - */ - void reset(); - /** * Return a string which should contain the class name as well as additional information about the * current configurations for this extension (DEBUG purposes) diff --git a/src/main/java/org/java_websocket/extensions/IResetExtension.java b/src/main/java/org/java_websocket/extensions/IResetExtension.java new file mode 100644 index 000000000..dd9fd860d --- /dev/null +++ b/src/main/java/org/java_websocket/extensions/IResetExtension.java @@ -0,0 +1,19 @@ +package org.java_websocket.extensions; + +import org.java_websocket.exceptions.InvalidDataException; +import org.java_websocket.framing.Framedata; + +/** + * Interface which specifies all required methods to develop a websocket extension. + * + * @since 1.3.5 + */ +public interface IResetExtension { + + /** + * Cleaning up internal stats when the draft gets reset. + * + * @since 1.3.5 + */ + void reset(); +} \ No newline at end of file diff --git a/src/main/java/org/java_websocket/server/DefaultSSLWebSocketServerFactory.java b/src/main/java/org/java_websocket/server/DefaultSSLWebSocketServerFactory.java index f2732030c..fa6ef4e85 100644 --- a/src/main/java/org/java_websocket/server/DefaultSSLWebSocketServerFactory.java +++ b/src/main/java/org/java_websocket/server/DefaultSSLWebSocketServerFactory.java @@ -40,9 +40,10 @@ import org.java_websocket.WebSocketAdapter; import org.java_websocket.WebSocketImpl; import org.java_websocket.WebSocketServerFactory; +import org.java_websocket.WebSocketServerFactoryClosing; import org.java_websocket.drafts.Draft; -public class DefaultSSLWebSocketServerFactory implements WebSocketServerFactory { +public class DefaultSSLWebSocketServerFactory implements WebSocketServerFactory, WebSocketServerFactoryClosing { protected SSLContext sslcontext; protected ExecutorService exec; diff --git a/src/main/java/org/java_websocket/server/DefaultWebSocketServerFactory.java b/src/main/java/org/java_websocket/server/DefaultWebSocketServerFactory.java index 80527e8e7..91be48906 100644 --- a/src/main/java/org/java_websocket/server/DefaultWebSocketServerFactory.java +++ b/src/main/java/org/java_websocket/server/DefaultWebSocketServerFactory.java @@ -49,9 +49,5 @@ public WebSocketImpl createWebSocket(WebSocketAdapter a, List d) { public SocketChannel wrapChannel(SocketChannel channel, SelectionKey key) { return channel; } - - @Override - public void close() { - //Nothing to do for a normal ws factory - } + } \ No newline at end of file diff --git a/src/test/java/org/java_websocket/issues/Issue900Test.java b/src/test/java/org/java_websocket/issues/Issue900Test.java index 952dca8ee..29e2772e0 100644 --- a/src/test/java/org/java_websocket/issues/Issue900Test.java +++ b/src/test/java/org/java_websocket/issues/Issue900Test.java @@ -35,6 +35,7 @@ import org.java_websocket.WebSocket; import org.java_websocket.WebSocketImpl; import org.java_websocket.WrappedByteChannel; +import org.java_websocket.WrappedMoreWrittenChannel; import org.java_websocket.client.WebSocketClient; import org.java_websocket.handshake.ClientHandshake; import org.java_websocket.handshake.ServerHandshake; @@ -104,7 +105,7 @@ public void onStart() { closeCalledLatch.await(); } - class ExceptionThrowingByteChannel implements WrappedByteChannel { + class ExceptionThrowingByteChannel implements WrappedByteChannel, WrappedMoreWrittenChannel { @Override public boolean isNeedWrite() {