Issue #3290 async onOpen, onClose and onError

Fixed OSGi tests.

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-01-29 13:08:35 +11:00
parent cf0eaecbdc
commit f5751618bd
3 changed files with 50 additions and 38 deletions

View File

@ -90,6 +90,16 @@ public interface FrameHandler extends IncomingFrames
*/
void onFrame(Frame frame, Callback callback);
/**
* An error has occurred or been detected in websocket-core and being reported to FrameHandler.
* A call to onError will be followed by a call to {@link #onClosed(CloseStatus, Callback)} giving the close status
* derived from the error.
*
* @param cause the reason for the error
* @param callback the callback to indicate success in processing (or failure)
*/
void onError(Throwable cause, Callback callback);
/**
* This is the Close Handshake Complete event.
* <p>
@ -102,15 +112,6 @@ public interface FrameHandler extends IncomingFrames
*/
void onClosed(CloseStatus closeStatus, Callback callback);
/**
* An error has occurred or been detected in websocket-core and being reported to FrameHandler.
* A call to onError will be followed by a call to {@link #onClosed(CloseStatus, Callback)} giving the close status
* derived from the error.
*
* @param cause the reason for the error
* @param callback the callback to indicate success in processing (or failure)
*/
void onError(Throwable cause, Callback callback);
/**
* Does the FrameHandler manage it's own demand?
@ -216,22 +217,6 @@ public interface FrameHandler extends IncomingFrames
*/
boolean isSecure();
/**
* Issue a harsh abort of the underlying connection.
* <p>
* This will terminate the connection, without sending a websocket close frame.
* No WebSocket Protocol close handshake will be performed.
* </p>
* <p>
* Once called, any read/write activity on the websocket from this point will be indeterminate.
* This can result in the {@link #onError(Throwable,Callback)} event being called indicating any issue that arises.
* </p>
* <p>
* Once the underlying connection has been determined to be closed, the {@link #onClosed(CloseStatus,Callback)} event will be called.
* </p>
*/
void abort();
/**
* @return Client or Server behaviour
*/
@ -294,6 +279,22 @@ public interface FrameHandler extends IncomingFrames
*/
void close(int statusCode, String reason, Callback callback);
/**
* Issue a harsh abort of the underlying connection.
* <p>
* This will terminate the connection, without sending a websocket close frame.
* No WebSocket Protocol close handshake will be performed.
* </p>
* <p>
* Once called, any read/write activity on the websocket from this point will be indeterminate.
* This can result in the {@link #onError(Throwable,Callback)} event being called indicating any issue that arises.
* </p>
* <p>
* Once the underlying connection has been determined to be closed, the {@link #onClosed(CloseStatus,Callback)} event will be called.
* </p>
*/
void abort();
/**
* Manage flow control by indicating demand for handling Frames. A call to
* {@link FrameHandler#onFrame(Frame, Callback)} will only be made if a

View File

@ -58,23 +58,23 @@ public class WebSocketChannelState
{
synchronized (this)
{
if (_channelState != State.CONNECTED)
throw new IllegalStateException(_channelState.toString());
switch(_channelState)
{
case CONNECTED:
_channelState = State.OPEN;
break;
_channelState = State.OPEN;
case OSHUT:
case CLOSED:
// Already closed in onOpen handler
break;
default:
throw new IllegalStateException(_channelState.toString());
}
}
}
@Override
public String toString()
{
return String.format("%s@%x{%s,i=%s,o=%s,c=%s}",getClass().getSimpleName(),hashCode(),
_channelState,
OpCode.name(_incomingContinuation),
OpCode.name(_outgoingContinuation),
_closeStatus);
}
public State getState()
{
@ -205,6 +205,16 @@ public class WebSocketChannelState
}
@Override
public String toString()
{
return String.format("%s@%x{%s,i=%s,o=%s,c=%s}",getClass().getSimpleName(),hashCode(),
_channelState,
OpCode.name(_incomingContinuation),
OpCode.name(_outgoingContinuation),
_closeStatus);
}
private static byte checkDataSequence(byte opcode, boolean fin, byte lastOpCode) throws ProtocolException
{
switch (opcode)

View File

@ -113,6 +113,7 @@ public class WebSocketClientServerTest
{
LOG.info("channel aborted");
getCoreSession().abort();
callback.failed(new Exception());
}
else
{