Skip to content

Commit 5aefeb7

Browse files
authored
Merge pull request TooTallNate#541 from marci4/master
Code cleanups
2 parents 21663de + 3b5739a commit 5aefeb7

File tree

4 files changed

+66
-29
lines changed

4 files changed

+66
-29
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,11 @@ long getLastPong() {
763763
return lastPong;
764764
}
765765

766-
public void setLastPong( long lastPong ) {
767-
this.lastPong = lastPong;
766+
/**
767+
* Update the timestamp when the last pong was received
768+
*/
769+
public void updateLastPong() {
770+
this.lastPong = System.currentTimeMillis();
768771
}
769772

770773
/**
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2010-2017 Nathan Rajlich
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use,
8+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following
11+
* conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
* OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
package org.java_websocket;
27+
28+
import org.java_websocket.drafts.Draft;
29+
30+
import java.io.IOException;
31+
import java.nio.channels.ByteChannel;
32+
import java.nio.channels.SelectionKey;
33+
import java.nio.channels.SocketChannel;
34+
import java.util.List;
35+
36+
/**
37+
* Interface to encapsulate the required methods for a websocket factory
38+
*/
39+
public interface WebSocketServerFactory extends WebSocketFactory {
40+
@Override
41+
WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d);
42+
43+
@Override
44+
WebSocketImpl createWebSocket( WebSocketAdapter a, List<Draft> drafts );
45+
46+
/**
47+
* Allows to wrap the Socketchannel( key.channel() ) to insert a protocol layer( like ssl or proxy authentication) beyond the ws layer.
48+
*
49+
* @param channel The SocketChannel to wrap
50+
* @param key a SelectionKey of an open SocketChannel.
51+
* @return The channel on which the read and write operations will be performed.<br>
52+
* @throws IOException may be thrown while writing on the channel
53+
*/
54+
ByteChannel wrapChannel(SocketChannel channel, SelectionKey key ) throws IOException;
55+
56+
/**
57+
* Allows to shutdown the websocket factory for a clean shutdown
58+
*/
59+
void close();
60+
}

src/main/java/org/java_websocket/drafts/Draft_6455.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public void processFrame( WebSocketImpl webSocketImpl, Framedata frame ) throws
378378
webSocketImpl.getWebSocketListener().onWebsocketPing( webSocketImpl, frame );
379379
return;
380380
} else if( curop == Framedata.Opcode.PONG ) {
381-
webSocketImpl.setLastPong( System.currentTimeMillis() );
381+
webSocketImpl.updateLastPong();
382382
webSocketImpl.getWebSocketListener().onWebsocketPong( webSocketImpl, frame );
383383
return;
384384
} else if( !frame.isFin() || curop == Framedata.Opcode.CONTINUOUS ) {

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -827,30 +827,4 @@ public void run() {
827827
}
828828
}
829829
}
830-
831-
/**
832-
* Interface to encapsulate the required methods for a websocket factory
833-
*/
834-
public interface WebSocketServerFactory extends WebSocketFactory {
835-
@Override
836-
WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d);
837-
838-
@Override
839-
WebSocketImpl createWebSocket( WebSocketAdapter a, List<Draft> drafts );
840-
841-
/**
842-
* Allows to wrap the Socketchannel( key.channel() ) to insert a protocol layer( like ssl or proxy authentication) beyond the ws layer.
843-
*
844-
* @param channel The SocketChannel to wrap
845-
* @param key a SelectionKey of an open SocketChannel.
846-
* @return The channel on which the read and write operations will be performed.<br>
847-
* @throws IOException may be thrown while writing on the channel
848-
*/
849-
ByteChannel wrapChannel( SocketChannel channel, SelectionKey key ) throws IOException;
850-
851-
/**
852-
* Allows to shutdown the websocket factory for a clean shutdown
853-
*/
854-
void close();
855-
}
856830
}

0 commit comments

Comments
 (0)