Skip to content

Commit 827bf43

Browse files
committed
Cleanups & JavaDocs
Cleaned up old unused arguments Added some additional java docs comments
1 parent 2ee3196 commit 827bf43

File tree

9 files changed

+150
-52
lines changed

9 files changed

+150
-52
lines changed

src/main/java/org/java_websocket/WebSocketFactory.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@
66
import org.java_websocket.drafts.Draft;
77

88
public interface WebSocketFactory {
9-
public WebSocket createWebSocket( WebSocketAdapter a, Draft d, Socket s );
10-
public WebSocket createWebSocket( WebSocketAdapter a, List<Draft> drafts, Socket s );
9+
/**
10+
* Create a new Websocket with the provided listener, drafts and socket
11+
* @param a The Listener for the WebsocketImpl
12+
* @param d The draft which should be used
13+
* @return A WebsocketImpl
14+
*/
15+
WebSocket createWebSocket( WebSocketAdapter a, Draft d);
16+
17+
/**
18+
* Create a new Websocket with the provided listener, drafts and socket
19+
* @param a The Listener for the WebsocketImpl
20+
* @param drafts The drafts which should be used
21+
* @return A WebsocketImpl
22+
*/
23+
WebSocket createWebSocket( WebSocketAdapter a, List<Draft> drafts);
1124

1225
}

src/main/java/org/java_websocket/framing/CloseFrame.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public interface CloseFrame extends Framedata {
9393
public static final int BUGGYCLOSE = -2;
9494
public static final int FLASHPOLICY = -3;
9595

96-
public int getCloseCode() throws InvalidFrameException;
97-
public String getMessage() throws InvalidDataException;
96+
/**
97+
* Getter for the close code used in this close frame
98+
* @return the used close code
99+
*/
100+
int getCloseCode();
101+
102+
/**
103+
* Getter for the close message used in this close frame
104+
* @return the used close message
105+
*/
106+
String getMessage();
98107
}

src/main/java/org/java_websocket/framing/CloseFrameBuilder.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,52 @@
77
import java.nio.ByteBuffer;
88

99
public class CloseFrameBuilder extends FramedataImpl1 implements CloseFrame {
10-
10+
/**
11+
* Attribute for just an empty ByteBuffer
12+
*/
1113
static final ByteBuffer emptybytebuffer = ByteBuffer.allocate( 0 );
1214

15+
/**
16+
* The close code used in this close frame
17+
*/
1318
private int code;
19+
20+
/**
21+
* The close message used in this close frame
22+
*/
1423
private String reason;
1524

25+
/**
26+
* Constructor for a close frame
27+
*
28+
* Using opcode closing and fin = true
29+
*/
1630
public CloseFrameBuilder() {
1731
super( Opcode.CLOSING );
1832
setFin( true );
1933
}
2034

35+
/**
36+
* Constructor for a close frame
37+
*
38+
* Using opcode closing and fin = true
39+
*
40+
* @param code The close code causing this close frame
41+
*/
2142
public CloseFrameBuilder( int code ) throws InvalidDataException {
2243
super( Opcode.CLOSING );
2344
setFin( true );
2445
setCodeAndMessage( code, "" );
2546
}
2647

48+
/**
49+
* Constructor for a close frame
50+
*
51+
* Using opcode closing and fin = true
52+
*
53+
* @param code The close code causing this close frame
54+
* @param m The close message explaining this close frame a bit more
55+
*/
2756
public CloseFrameBuilder( int code, String m ) throws InvalidDataException {
2857
super( Opcode.CLOSING );
2958
setFin( true );

src/main/java/org/java_websocket/framing/FrameBuilder.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,29 @@
66

77
public interface FrameBuilder extends Framedata {
88

9-
public abstract void setFin( boolean fin );
10-
11-
public abstract void setOptcode( Opcode optcode );
12-
13-
public abstract void setPayload( ByteBuffer payload ) throws InvalidDataException;
14-
15-
public abstract void setTransferemasked( boolean transferemasked );
9+
/**
10+
* Setter for fin to indicate if this frame is the final fragment
11+
* @param fin true, if this frame is the final fragment
12+
*/
13+
void setFin( boolean fin );
14+
15+
/**
16+
* Setter for the opcode to use, how the provided "Payload data" should be interpreted
17+
* @param optcode the interpretation as a Opcode
18+
*/
19+
void setOptcode( Opcode optcode );
20+
21+
/**
22+
* Setter for the "Payload data" to use in this frame
23+
* @param payload the "Payload data"
24+
* @throws InvalidDataException indicates that the provided "Payload data" is not a valid data
25+
*/
26+
void setPayload( ByteBuffer payload ) throws InvalidDataException;
27+
28+
/**
29+
* Setter for the transfermask to use in this frame
30+
* @param transferemasked true, "Payload data" is masked
31+
*/
32+
void setTransferemasked( boolean transferemasked );
1633

1734
}

src/main/java/org/java_websocket/framing/Framedata.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,40 @@ public interface Framedata {
88
/**
99
* Enum which contains the different valid opcodes
1010
*/
11-
public enum Opcode {
11+
enum Opcode {
1212
CONTINUOUS, TEXT, BINARY, PING, PONG, CLOSING
1313
// more to come
1414
}
15-
public boolean isFin();
16-
public boolean getTransfereMasked();
17-
public Opcode getOpcode();
18-
public ByteBuffer getPayloadData();// TODO the separation of the application data and the extension data is yet to be done
19-
public abstract void append( Framedata nextframe ) throws InvalidFrameException;
15+
16+
/**
17+
* Indicates that this is the final fragment in a message. The first fragment MAY also be the final fragment.
18+
* @return true, if this frame is the final fragment
19+
*/
20+
boolean isFin();
21+
22+
/**
23+
* Defines whether the "Payload data" is masked.
24+
* @return true, "Payload data" is masked
25+
*/
26+
boolean getTransfereMasked();
27+
28+
/**
29+
* Defines the interpretation of the "Payload data".
30+
* @return the interpretation as a Opcode
31+
*/
32+
Opcode getOpcode();
33+
34+
/**
35+
* The "Payload data" which was sent in this frame
36+
* @return the "Payload data" as ByteBuffer
37+
*/
38+
ByteBuffer getPayloadData();// TODO the separation of the application data and the extension data is yet to be done
39+
40+
/**
41+
* Appends an additional frame to the current frame
42+
*
43+
* This methods does not override the opcode, but does override the fin
44+
* @param nextframe the additional frame
45+
*/
46+
void append( Framedata nextframe );
2047
}

src/main/java/org/java_websocket/framing/FramedataImpl1.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,40 @@
88
import org.java_websocket.util.Charsetfunctions;
99

1010
public class FramedataImpl1 implements FrameBuilder {
11-
protected static byte[] emptyarray = {};
11+
/**
12+
* Attribute for just an empty array
13+
*/
14+
private static byte[] emptyarray = {};
15+
16+
/**
17+
* Indicates that this is the final fragment in a message.
18+
*/
1219
protected boolean fin;
20+
/**
21+
* Defines the interpretation of the "Payload data".
22+
*/
1323
protected Opcode optcode;
24+
25+
/**
26+
* The unmasked "Payload data" which was sent in this frame
27+
*/
1428
private ByteBuffer unmaskedpayload;
29+
30+
/**
31+
* Defines whether the "Payload data" is masked.
32+
*/
1533
protected boolean transferemasked;
1634

35+
/**
36+
* Constructor for a FramedataImpl without any attributes set
37+
*/
1738
public FramedataImpl1() {
1839
}
1940

41+
/**
42+
* Constructor for a FramedataImpl without any attributes set apart from the opcode
43+
* @param op the opcode to use
44+
*/
2045
public FramedataImpl1( Opcode op ) {
2146
this.optcode = op;
2247
unmaskedpayload = ByteBuffer.wrap( emptyarray );
@@ -75,7 +100,7 @@ public void setTransferemasked( boolean transferemasked ) {
75100
}
76101

77102
@Override
78-
public void append( Framedata nextframe ) throws InvalidFrameException {
103+
public void append( Framedata nextframe ) {
79104
ByteBuffer b = nextframe.getPayloadData();
80105
if( unmaskedpayload == null ) {
81106
unmaskedpayload = ByteBuffer.allocate( b.remaining() );

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public ByteChannel wrapChannel( SocketChannel channel, SelectionKey key ) throws
4040
}
4141

4242
@Override
43-
public WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d, Socket c ) {
43+
public WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d) {
4444
return new WebSocketImpl( a, d );
4545
}
4646

4747
@Override
48-
public WebSocketImpl createWebSocket( WebSocketAdapter a, List<Draft> d, Socket s ) {
48+
public WebSocketImpl createWebSocket( WebSocketAdapter a, List<Draft> d) {
4949
return new WebSocketImpl( a, d );
5050
}
5151
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
public class DefaultWebSocketServerFactory implements WebSocketServerFactory {
1414
@Override
15-
public WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d, Socket s ) {
15+
public WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d) {
1616
return new WebSocketImpl( a, d );
1717
}
1818
@Override
19-
public WebSocketImpl createWebSocket( WebSocketAdapter a, List<Draft> d, Socket s ) {
19+
public WebSocketImpl createWebSocket( WebSocketAdapter a, List<Draft> d) {
2020
return new WebSocketImpl( a, d );
2121
}
2222
@Override

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

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public void run() {
361361
channel.configureBlocking( false );
362362
Socket socket = channel.socket();
363363
socket.setTcpNoDelay( tcpNoDelay );
364-
WebSocketImpl w = wsf.createWebSocket( this, drafts, socket );
364+
WebSocketImpl w = wsf.createWebSocket( this, drafts );
365365
w.key = channel.register( selector, SelectionKey.OP_READ, w );
366366
try {
367367
w.channel = wsf.wrapChannel( channel, w.key );
@@ -538,22 +538,6 @@ private void handleFatal( WebSocket conn, Exception e ) {
538538
}
539539
}
540540

541-
/**
542-
* Gets the XML string that should be returned if a client requests a Flash
543-
* security policy.
544-
*
545-
* The default implementation allows access from all remote domains, but
546-
* only on the port that this WebSocketServer is listening on.
547-
*
548-
* This is specifically implemented for gitime's WebSocket client for Flash:
549-
* http://github.com/gimite/web-socket-js
550-
*
551-
* @return An XML String that comforms to Flash's security policy. You MUST
552-
* not include the null char at the end, it is appended automatically.
553-
*/
554-
protected String getFlashSecurityPolicy() {
555-
return "<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"" + getPort() + "\" /></cross-domain-policy>";
556-
}
557541

558542
@Override
559543
public final void onWebsocketMessage( WebSocket conn, String message ) {
@@ -836,16 +820,10 @@ public void run() {
836820
*/
837821
public interface WebSocketServerFactory extends WebSocketFactory {
838822
@Override
839-
public WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d, Socket s );
823+
WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d);
840824

841-
/**
842-
* Create a new Websocket with the provided listener, drafts and socket
843-
* @param a The Listener for the WebsocketImpl
844-
* @param drafts The drafts which should be used
845-
* @param s The socket which should be used
846-
* @return A WebsocketImpl
847-
*/
848-
public WebSocketImpl createWebSocket( WebSocketAdapter a, List<Draft> drafts, Socket s );
825+
@Override
826+
WebSocketImpl createWebSocket( WebSocketAdapter a, List<Draft> drafts );
849827

850828
/**
851829
* Allows to wrap the Socketchannel( key.channel() ) to insert a protocol layer( like ssl or proxy authentication) beyond the ws layer.
@@ -855,11 +833,11 @@ public interface WebSocketServerFactory extends WebSocketFactory {
855833
* @return The channel on which the read and write operations will be performed.<br>
856834
* @throws IOException may be thrown while writing on the channel
857835
*/
858-
public ByteChannel wrapChannel( SocketChannel channel, SelectionKey key ) throws IOException;
836+
ByteChannel wrapChannel( SocketChannel channel, SelectionKey key ) throws IOException;
859837

860838
/**
861839
* Allows to shutdown the websocket factory for a clean shutdown
862840
*/
863-
public void close();
841+
void close();
864842
}
865843
}

0 commit comments

Comments
 (0)