JSR-356 Making PongMessage work with @OnMessage annotation

This commit is contained in:
Joakim Erdfelt 2013-08-06 13:15:13 -07:00
parent 3e070f929e
commit eb0d7da7f2
4 changed files with 42 additions and 1 deletions

View File

@ -161,6 +161,21 @@ public class JsrEvents<T extends Annotation, C extends EndpointConfig>
onOpen.call(websocket,config);
}
public void callPong(RemoteEndpoint.Async endpoint, Object websocket, ByteBuffer pong) throws DecodeException, IOException
{
if (onPong == null)
{
return;
}
Object ret = onPong.call(websocket,pong);
if (ret != null)
{
LOG.debug("returning: {}",ret);
endpoint.sendObject(ret);
}
}
public void callText(RemoteEndpoint.Async endpoint, Object websocket, String text, boolean fin) throws DecodeException
{
if (onText == null)

View File

@ -213,6 +213,19 @@ public class JsrAnnotatedEventDriver extends AbstractJsrEventDriver implements E
}
}
@Override
public void onPong(ByteBuffer buffer)
{
try
{
events.callPong(jsrsession.getAsyncRemote(),websocket,buffer);
}
catch (DecodeException | IOException e)
{
onFatalError(e);
}
}
@Override
public void onReader(Reader reader)
{

View File

@ -140,10 +140,15 @@ public abstract class AbstractEventDriver implements IncomingFrames, EventDriver
{
pongBuf = ByteBuffer.allocate(0);
}
onPong(pongBuf);
onPing(frame.getPayload());
session.getRemote().sendPong(pongBuf);
break;
}
case OpCode.PONG:
{
onPong(frame.getPayload());
break;
}
case OpCode.BINARY:
{
onBinaryFrame(frame.getPayload(),frame.isFin());
@ -195,6 +200,12 @@ public abstract class AbstractEventDriver implements IncomingFrames, EventDriver
{
/* TODO: provide annotation in future */
}
@Override
public void onPing(ByteBuffer buffer)
{
/* TODO: provide annotation in future */
}
@Override
public void openSession(WebSocketSession session)

View File

@ -51,6 +51,8 @@ public interface EventDriver extends IncomingFrames
public void onInputStream(InputStream stream);
public void onPing(ByteBuffer buffer);
public void onPong(ByteBuffer buffer);
public void onReader(Reader reader);