Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Solid Principles Violations #1368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,7 +34,7 @@
* @deprecated
*/
@Deprecated
public class AbstractWrappedByteChannel implements WrappedByteChannel {
public class AbstractWrappedByteChannel implements WrappedByteChannel, WrappedMoreWrittenChannel {

private final ByteChannel channel;

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/java_websocket/SSLSocketChannel.java
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/java_websocket/SSLSocketChannel2.java
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/java_websocket/WebSocketServerFactory.java
Expand Up @@ -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();
}
@@ -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();
}
7 changes: 0 additions & 7 deletions src/main/java/org/java_websocket/WrappedByteChannel.java
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions 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;
}
14 changes: 0 additions & 14 deletions src/main/java/org/java_websocket/extensions/DefaultExtension.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
34 changes: 34 additions & 0 deletions 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);

}
28 changes: 0 additions & 28 deletions src/main/java/org/java_websocket/extensions/IExtension.java
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions 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();
}
Expand Up @@ -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;
Expand Down
Expand Up @@ -49,9 +49,5 @@ public WebSocketImpl createWebSocket(WebSocketAdapter a, List<Draft> d) {
public SocketChannel wrapChannel(SocketChannel channel, SelectionKey key) {
return channel;
}

@Override
public void close() {
//Nothing to do for a normal ws factory
}

}
3 changes: 2 additions & 1 deletion src/test/java/org/java_websocket/issues/Issue900Test.java
Expand Up @@ -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;
Expand Down Expand Up @@ -104,7 +105,7 @@ public void onStart() {
closeCalledLatch.await();
}

class ExceptionThrowingByteChannel implements WrappedByteChannel {
class ExceptionThrowingByteChannel implements WrappedByteChannel, WrappedMoreWrittenChannel {

@Override
public boolean isNeedWrite() {
Expand Down