Skip to content

Commit a55b11c

Browse files
committed
smoothed signatures out
1 parent 8669096 commit a55b11c

9 files changed

Lines changed: 106 additions & 82 deletions

File tree

‎example/AutobahnClientTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ public void onMessage( String message ) {
135135
}
136136

137137
@Override
138-
public void onMessage( WebSocket conn, byte[] blob ) {
138+
public void onMessage( byte[] blob ) {
139139
try {
140-
conn.send( blob );
140+
getConnection().send( blob );
141141
} catch ( InterruptedException e ) {
142142
e.printStackTrace();
143143
}

‎example/AutobahnServerTest.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@ public AutobahnServerTest( InetSocketAddress address, Draft d ) {
1919
}
2020

2121
@Override
22-
public void onClientOpen( WebSocket conn, Handshakedata handshake ) {
22+
public void onOpen( WebSocket conn, Handshakedata handshake ) {
2323
counter++;
2424
System.out.println( "///////////Opened connection number" + counter );
2525
}
2626

2727
@Override
28-
public void onClientClose( WebSocket conn, int code, String reason, boolean remote ) {
29-
}
30-
31-
@Override
32-
public void onClientMessage( WebSocket conn, String message ) {
28+
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {
3329
}
3430

3531
@Override

‎example/ChatServer.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ChatServer( InetSocketAddress address ) {
2222
super( address );
2323
}
2424

25-
public void onClientOpen( WebSocket conn, Handshakedata handshake ) {
25+
public void onOpen( WebSocket conn, Handshakedata handshake ) {
2626
try {
2727
this.sendToAll( conn + " entered the room!" );
2828
} catch ( InterruptedException ex ) {
@@ -31,7 +31,7 @@ public void onClientOpen( WebSocket conn, Handshakedata handshake ) {
3131
System.out.println( conn + " entered the room!" );
3232
}
3333

34-
public void onClientClose( WebSocket conn, int code, String reason, boolean remote ) {
34+
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {
3535
try {
3636
this.sendToAll( conn + " has left the room!" );
3737
} catch ( InterruptedException ex ) {
@@ -40,7 +40,7 @@ public void onClientClose( WebSocket conn, int code, String reason, boolean remo
4040
System.out.println( conn + " has left the room!" );
4141
}
4242

43-
public void onClientMessage( WebSocket conn, String message ) {
43+
public void onMessage( WebSocket conn, String message ) {
4444
try {
4545
this.sendToAll( conn + ": " + message );
4646
} catch ( InterruptedException ex ) {

‎src/net/tootallnate/websocket/Draft.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import net.tootallnate.websocket.exeptions.InvalidHandshakeException;
1212
import net.tootallnate.websocket.exeptions.LimitExedeedException;
1313

14+
/**
15+
* Base class for everything of a websocket specification which is not common such as the way the handshake is read or frames are transfered.
16+
**/
1417
public abstract class Draft {
1518

1619
public enum HandshakeState {
@@ -20,12 +23,11 @@ public enum HandshakeState {
2023
NOT_MATCHED ,
2124
/** Handshake matches this Draft but is not complete */
2225
MATCHING
23-
// ,/**Can not yet say anything*/
24-
// PENDING not yet in use
2526
}
2627

2728
public static final byte[] FLASH_POLICY_REQUEST = Charsetfunctions.utf8Bytes( "<policy-file-request/>\0" );
2829

30+
/** In some cases the handshake will be parsed different depending on whether */
2931
protected Role role = null;
3032

3133
public static ByteBuffer readLine( ByteBuffer buf ) {

‎src/net/tootallnate/websocket/WebSocket.java‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private void init( WebSocketListener listener, Draft draft, SocketChannel sockch
170170
if( handshakestate == HandshakeState.MATCHED ) {
171171
HandshakeBuilder response;
172172
try {
173-
response = wsl.onHandshakeRecievedAsServer( this, d, handshake );
173+
response = wsl.onWebsocketHandshakeRecievedAsServer( this, d, handshake );
174174
} catch ( InvalidDataException e ) {
175175
closeConnection( e.getCloseCode(), e.getMessage(), false );
176176
return;
@@ -221,7 +221,7 @@ private void init( WebSocketListener listener, Draft draft, SocketChannel sockch
221221
handshakestate = draft.acceptHandshakeAsClient( handshakerequest, handshake );
222222
if( handshakestate == HandshakeState.MATCHED ) {
223223
try {
224-
wsl.onHandshakeRecievedAsClient( this, handshakerequest, handshake );
224+
wsl.onWebsocketHandshakeRecievedAsClient( this, handshakerequest, handshake );
225225
} catch ( InvalidDataException e ) {
226226
closeConnection( e.getCloseCode(), e.getMessage(), false );
227227
return;
@@ -264,10 +264,10 @@ private void init( WebSocketListener listener, Draft draft, SocketChannel sockch
264264
}
265265
continue;
266266
} else if( curop == Opcode.PING ) {
267-
wsl.onPing( this, f );
267+
wsl.onWebsocketPing( this, f );
268268
continue;
269269
} else if( curop == Opcode.PONG ) {
270-
wsl.onPong( this, f );
270+
wsl.onWebsocketPong( this, f );
271271
continue;
272272
} else {
273273
// process non control frames
@@ -293,7 +293,7 @@ private void init( WebSocketListener listener, Draft draft, SocketChannel sockch
293293
}
294294
}
295295
} catch ( InvalidDataException e1 ) {
296-
wsl.onError( this, e1 );
296+
wsl.onWebsocketError( this, e1 );
297297
close( e1 );
298298
return;
299299
}
@@ -328,7 +328,7 @@ public void closeDirect( int code, String message ) throws IOException {
328328
try {
329329
sendFrameDirect( new CloseFrameBuilder( code, message ) );
330330
} catch ( InvalidDataException e ) {
331-
wsl.onError( this, e );
331+
wsl.onWebsocketError( this, e );
332332
closeConnection( CloseFrame.ABNROMAL_CLOSE, "generated frame is invalid", false );
333333
}
334334
} else {
@@ -365,9 +365,9 @@ public void closeConnection( int code, String message, boolean remote ) {
365365
try {
366366
sockchannel.close();
367367
} catch ( IOException e ) {
368-
wsl.onError( this, e );
368+
wsl.onWebsocketError( this, e );
369369
}
370-
this.wsl.onClose( this, code, message, remote );
370+
this.wsl.onWebsocketClose( this, code, message, remote );
371371
if( draft != null )
372372
draft.reset();
373373
currentframe = null;
@@ -496,9 +496,9 @@ private void writeDirect( List<ByteBuffer> bufs ) throws IOException {
496496
}
497497
private void deliverMessage( Framedata d ) throws InvalidDataException {
498498
if( d.getOpcode() == Opcode.TEXT ) {
499-
wsl.onMessage( this, Charsetfunctions.stringUtf8( d.getPayloadData() ) );
499+
wsl.onWebsocketMessage( this, Charsetfunctions.stringUtf8( d.getPayloadData() ) );
500500
} else if( d.getOpcode() == Opcode.BINARY ) {
501-
wsl.onMessage( this, d.getPayloadData() );
501+
wsl.onWebsocketMessage( this, d.getPayloadData() );
502502
} else {
503503
if( DEBUG )
504504
System.out.println( "Ignoring frame:" + d.toString() );
@@ -510,7 +510,7 @@ private void open( Handshakedata d ) throws IOException {
510510
if( DEBUG )
511511
System.out.println( "open using draft: " + draft.getClass().getSimpleName() );
512512
handshakeComplete = true;
513-
wsl.onOpen( this, d );
513+
wsl.onWebsocketOpen( this, d );
514514
}
515515

516516
public InetSocketAddress getRemoteSocketAddress() {
@@ -525,6 +525,11 @@ public boolean isClosed() {
525525
return connectionClosed;
526526
}
527527

528+
@Override
529+
public int hashCode() {
530+
return super.hashCode();
531+
}
532+
528533
@Override
529534
public String toString() {
530535
return super.toString(); // its nice to be able to set breakpoints here

‎src/net/tootallnate/websocket/WebSocketAdapter.java‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,66 +8,66 @@ public abstract class WebSocketAdapter implements WebSocketListener {
88
/**
99
* This default implementation does not do anything. Go ahead and overwrite it.
1010
*
11-
* @see net.tootallnate.websocket.WebSocketListener#onHandshakeRecievedAsServer(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Draft, net.tootallnate.websocket.Handshakedata)
11+
* @see net.tootallnate.websocket.WebSocketListener#onWebsocketHandshakeRecievedAsServer(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Draft, net.tootallnate.websocket.Handshakedata)
1212
*/
1313
@Override
14-
public HandshakeBuilder onHandshakeRecievedAsServer( WebSocket conn, Draft draft, Handshakedata request ) throws InvalidDataException {
14+
public HandshakeBuilder onWebsocketHandshakeRecievedAsServer( WebSocket conn, Draft draft, Handshakedata request ) throws InvalidDataException {
1515
return new HandshakedataImpl1();
1616
}
1717

1818
/**
1919
* This default implementation does not do anything which will cause connections to be accepted. Go ahead and overwrite it.
2020
*
21-
* @see net.tootallnate.websocket.WebSocketListener#onHandshakeRecievedAsClient(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Handshakedata, net.tootallnate.websocket.Handshakedata)
21+
* @see net.tootallnate.websocket.WebSocketListener#onWebsocketHandshakeRecievedAsClient(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Handshakedata, net.tootallnate.websocket.Handshakedata)
2222
*/
2323
@Override
24-
public void onHandshakeRecievedAsClient( WebSocket conn, Handshakedata request, Handshakedata response ) throws InvalidDataException {
24+
public void onWebsocketHandshakeRecievedAsClient( WebSocket conn, Handshakedata request, Handshakedata response ) throws InvalidDataException {
2525
}
2626

2727
/**
2828
* This default implementation does not do anything. Go ahead and overwrite it.
2929
*
30-
* @see net.tootallnate.websocket.WebSocketListener#onMessage(net.tootallnate.websocket.WebSocket, java.lang.String)
30+
* @see net.tootallnate.websocket.WebSocketListener#onWebsocketMessage(net.tootallnate.websocket.WebSocket, java.lang.String)
3131
*/
3232
@Override
33-
public void onMessage( WebSocket conn, String message ) {
33+
public void onWebsocketMessage( WebSocket conn, String message ) {
3434
}
3535

3636
/**
3737
* This default implementation does not do anything. Go ahead and overwrite it.
3838
*
39-
* @see net.tootallnate.websocket.WebSocketListener#onOpen(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Handshakedata)
39+
* @see net.tootallnate.websocket.WebSocketListener#onWebsocketOpen(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Handshakedata)
4040
*/
4141
@Override
42-
public void onOpen( WebSocket conn, Handshakedata handshake ) {
42+
public void onWebsocketOpen( WebSocket conn, Handshakedata handshake ) {
4343
}
4444

4545
/**
4646
* This default implementation does not do anything. Go ahead and overwrite it.
4747
*
48-
* @see net.tootallnate.websocket.WebSocketListener#onClose(net.tootallnate.websocket.WebSocket, int, java.lang.String, boolean)
48+
* @see net.tootallnate.websocket.WebSocketListener#onWebsocketClose(net.tootallnate.websocket.WebSocket, int, java.lang.String, boolean)
4949
*/
5050
@Override
51-
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {
51+
public void onWebsocketClose( WebSocket conn, int code, String reason, boolean remote ) {
5252
}
5353

5454
/**
5555
* This default implementation does not do anything. Go ahead and overwrite it.
5656
*
57-
* @see net.tootallnate.websocket.WebSocketListener#onMessage(net.tootallnate.websocket.WebSocket, byte[])
57+
* @see net.tootallnate.websocket.WebSocketListener#onWebsocketMessage(net.tootallnate.websocket.WebSocket, byte[])
5858
*/
5959
@Override
60-
public void onMessage( WebSocket conn, byte[] blob ) {
60+
public void onWebsocketMessage( WebSocket conn, byte[] blob ) {
6161
}
6262

6363
/**
6464
* This default implementation will send a pong in response to the received ping.
6565
* The pong frame will have the same payload as the ping frame.
6666
*
67-
* @see net.tootallnate.websocket.WebSocketListener#onPing(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Framedata)
67+
* @see net.tootallnate.websocket.WebSocketListener#onWebsocketPing(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Framedata)
6868
*/
6969
@Override
70-
public void onPing( WebSocket conn, Framedata f ) {
70+
public void onWebsocketPing( WebSocket conn, Framedata f ) {
7171
FramedataImpl1 resp = new FramedataImpl1 ( f );
7272
resp.setOptcode( Opcode.PONG );
7373
try {
@@ -80,10 +80,10 @@ public void onPing( WebSocket conn, Framedata f ) {
8080
/**
8181
* This default implementation does not do anything. Go ahead and overwrite it.
8282
*
83-
* @see net.tootallnate.websocket.WebSocketListener#onPong(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Framedata)
83+
* @see net.tootallnate.websocket.WebSocketListener#onWebsocketPong(net.tootallnate.websocket.WebSocket, net.tootallnate.websocket.Framedata)
8484
*/
8585
@Override
86-
public void onPong( WebSocket conn, Framedata f ) {
86+
public void onWebsocketPong( WebSocket conn, Framedata f ) {
8787
}
8888

8989
/**
@@ -106,10 +106,10 @@ public String getFlashPolicy( WebSocket conn ) {
106106

107107
/**
108108
* This default implementation does not do anything. Go ahead and overwrite it.
109-
* @see net.tootallnate.websocket.WebSocketListener#onError(net.tootallnate.websocket.WebSocket, java.lang.Exception)
109+
* @see net.tootallnate.websocket.WebSocketListener#onWebsocketError(net.tootallnate.websocket.WebSocket, java.lang.Exception)
110110
*/
111111
@Override
112-
public void onError( WebSocket conn, Exception ex ) {
112+
public void onWebsocketError( WebSocket conn, Exception ex ) {
113113
}
114114

115115
}

0 commit comments

Comments
 (0)