Skip to content

Commit 51ec156

Browse files
committed
made Websocket an interface (TooTallNate#147)
1 parent d74858c commit 51ec156

File tree

10 files changed

+25
-26
lines changed

10 files changed

+25
-26
lines changed

src/main/example/ChatClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import javax.swing.JTextArea;
1414
import javax.swing.JTextField;
1515

16-
import org.java_websocket.WebSocket;
16+
import org.java_websocket.WebSocketImpl;
1717
import org.java_websocket.client.WebSocketClient;
1818
import org.java_websocket.drafts.Draft;
1919
import org.java_websocket.drafts.Draft_10;
@@ -148,7 +148,7 @@ public void onError( Exception ex ) {
148148
}
149149

150150
public static void main( String[] args ) {
151-
WebSocket.DEBUG = true;
151+
WebSocketImpl.DEBUG = true;
152152
String location;
153153
if( args.length != 0 ) {
154154
location = args[ 0 ];

src/main/example/ChatServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Collection;
77

88
import org.java_websocket.WebSocket;
9+
import org.java_websocket.WebSocketImpl;
910
import org.java_websocket.handshake.ClientHandshake;
1011
import org.java_websocket.server.WebSocketServer;
1112

@@ -41,7 +42,7 @@ public void onMessage( WebSocket conn, String message ) {
4142
}
4243

4344
public static void main( String[] args ) throws InterruptedException , IOException {
44-
WebSocket.DEBUG = true;
45+
WebSocketImpl.DEBUG = true;
4546
int port = 8887; // 843 flash policy port
4647
try {
4748
port = Integer.parseInt( args[ 0 ] );

src/main/example/SSLClientExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import javax.net.ssl.SSLContext;
1010
import javax.net.ssl.TrustManagerFactory;
1111

12-
import org.java_websocket.WebSocket;
12+
import org.java_websocket.WebSocketImpl;
1313
import org.java_websocket.client.DefaultSSLWebSocketClientFactory;
1414
import org.java_websocket.client.WebSocketClient;
1515
import org.java_websocket.handshake.ServerHandshake;
@@ -55,7 +55,7 @@ public class SSLClientExample {
5555
*keytool -genkey -validity 3650 -keystore "keystore.jks" -storepass "storepassword" -keypass "keypassword" -alias "default" -dname "CN=127.0.0.1, OU=MyOrgUnit, O=MyOrg, L=MyCity, S=MyRegion, C=MyCountry"
5656
*/
5757
public static void main( String[] args ) throws Exception {
58-
WebSocket.DEBUG = true;
58+
WebSocketImpl.DEBUG = true;
5959

6060
WebSocketChatClient chatclient = new WebSocketChatClient( new URI( "wss://localhost:8887" ) );
6161

src/main/example/SSLServerExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import javax.net.ssl.SSLContext;
99
import javax.net.ssl.TrustManagerFactory;
1010

11-
import org.java_websocket.WebSocket;
11+
import org.java_websocket.WebSocketImpl;
1212
import org.java_websocket.server.DefaultSSLWebSocketServerFactory;
1313

1414
public class SSLServerExample {
@@ -19,7 +19,7 @@ public class SSLServerExample {
1919
*keytool -genkey -validity 3650 -keystore "keystore.jks" -storepass "storepassword" -keypass "keypassword" -alias "default" -dname "CN=127.0.0.1, OU=MyOrgUnit, O=MyOrg, L=MyCity, S=MyRegion, C=MyCountry"
2020
*/
2121
public static void main( String[] args ) throws Exception {
22-
WebSocket.DEBUG = true;
22+
WebSocketImpl.DEBUG = true;
2323

2424
ChatServer chatserver = new ChatServer( 8887 ); // Firefox does allow multible ssl connection only via port 443 //tested on FF16
2525

src/main/java/org/java_websocket/WebSocket.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import java.nio.channels.NotYetConnectedException;
77

88
import org.java_websocket.drafts.Draft;
9-
import org.java_websocket.exceptions.InvalidDataException;
109
import org.java_websocket.framing.Framedata;
1110

12-
public abstract class WebSocket {
11+
public interface WebSocket {
1312
public enum Role {
1413
CLIENT, SERVER
1514
}
@@ -18,10 +17,6 @@ public enum READYSTATE {
1817
NOT_YET_CONNECTED, CONNECTING, OPEN, CLOSING, CLOSED;
1918
}
2019

21-
public static int RCVBUF = 16384;
22-
23-
public static/*final*/boolean DEBUG = false; // must be final in the future in order to take advantage of VM optimization
24-
2520
/**
2621
* The default port of WebSockets, as defined in the spec. If the nullary
2722
* constructor is used, DEFAULT_PORT will be the port the WebSocketServer
@@ -35,18 +30,16 @@ public enum READYSTATE {
3530
* sends the closing handshake.
3631
* may be send in response to an other handshake.
3732
*/
38-
public abstract void close( int code, String message );
33+
public void close( int code, String message );
3934

40-
public abstract void close( int code );
35+
public void close( int code );
4136

4237
/**
4338
* This will close the connection immediately without a proper close handshake.
4439
* The code and the message therefore won't be transfered over the wire also they will be forwarded to onClose/onWebsocketClose.
4540
**/
4641
public abstract void closeConnection( int code, String message );
4742

48-
protected abstract void close( InvalidDataException e );
49-
5043
/**
5144
* Send Text data to the other end.
5245
*

src/main/java/org/java_websocket/WebSocketImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
* text frames, and receiving frames through an event-based model.
4343
*
4444
*/
45-
public class WebSocketImpl extends WebSocket {
45+
public class WebSocketImpl implements WebSocket {
46+
47+
public static int RCVBUF = 16384;
48+
49+
public static/*final*/boolean DEBUG = false; // must be final in the future in order to take advantage of VM optimization
4650

4751
public static final List<Draft> defaultdraftlist = new ArrayList<Draft>( 4 );
4852
static {
@@ -508,7 +512,6 @@ public void close( int code ) {
508512
close( code, "", false );
509513
}
510514

511-
@Override
512515
public void close( InvalidDataException e ) {
513516
close( e.getCloseCode(), e.getMessage(), false );
514517
}

src/main/java/org/java_websocket/client/WebSocketClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private final void interruptableRun() {
224224
return;
225225
}
226226

227-
ByteBuffer buff = ByteBuffer.allocate( WebSocket.RCVBUF );
227+
ByteBuffer buff = ByteBuffer.allocate( WebSocketImpl.RCVBUF );
228228
try/*IO*/{
229229
while ( channel.isOpen() ) {
230230
if( SocketChannelIOHelper.read( buff, this.conn, wrappedchannel ) ) {

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public void run() {
280280
server = ServerSocketChannel.open();
281281
server.configureBlocking( false );
282282
ServerSocket socket = server.socket();
283-
socket.setReceiveBufferSize( WebSocket.RCVBUF );
283+
socket.setReceiveBufferSize( WebSocketImpl.RCVBUF );
284284
socket.bind( address );
285285
selector = Selector.open();
286286
server.register( selector, server.validOps() );
@@ -399,7 +399,7 @@ protected void releaseBuffers( WebSocket c ) throws InterruptedException {
399399
}
400400

401401
public ByteBuffer createBuffer() {
402-
return ByteBuffer.allocate( WebSocket.RCVBUF );
402+
return ByteBuffer.allocate( WebSocketImpl.RCVBUF );
403403
}
404404

405405
private void queue( WebSocketImpl ws ) throws InterruptedException {

src/test/java/AutobahnClientTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.nio.ByteBuffer;
66

77
import org.java_websocket.WebSocket;
8+
import org.java_websocket.WebSocketImpl;
89
import org.java_websocket.client.WebSocketClient;
910
import org.java_websocket.drafts.Draft;
1011
import org.java_websocket.drafts.Draft_17;
@@ -55,11 +56,11 @@ public static void main( String[] args ) {
5556
if( nextline != null ) {
5657
line = nextline;
5758
nextline = null;
58-
WebSocket.DEBUG = false;
59+
WebSocketImpl.DEBUG = false;
5960
} else {
6061
System.out.print( ">" );
6162
line = sysin.readLine();
62-
WebSocket.DEBUG = true;
63+
WebSocketImpl.DEBUG = true;
6364
}
6465
if( line.equals( "l" ) ) {
6566
line = perviousline;
@@ -84,7 +85,7 @@ public static void main( String[] args ) {
8485
uri = URI.create( serverlocation + "/runCase?case=" + spl[ 1 ] + "&agent=" + clientname );
8586

8687
} else if( line.startsWith( "u" ) ) {
87-
WebSocket.DEBUG = false;
88+
WebSocketImpl.DEBUG = false;
8889
uri = URI.create( serverlocation + "/updateReports?agent=" + clientname );
8990
} else if( line.startsWith( "d" ) ) {
9091
try {

src/test/java/AutobahnServerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Collections;
55

66
import org.java_websocket.WebSocket;
7+
import org.java_websocket.WebSocketImpl;
78
import org.java_websocket.drafts.Draft;
89
import org.java_websocket.drafts.Draft_17;
910
import org.java_websocket.framing.FrameBuilder;
@@ -57,7 +58,7 @@ public void onWebsocketMessageFragment( WebSocket conn, Framedata frame ) {
5758
}
5859

5960
public static void main( String[] args ) throws UnknownHostException {
60-
WebSocket.DEBUG = false;
61+
WebSocketImpl.DEBUG = false;
6162
int port;
6263
try {
6364
port = new Integer( args[ 0 ] );

0 commit comments

Comments
 (0)