}
@Override
public void run()
{
ByteBufferPool bufferPool = conn.getBufferPool();
ByteBuffer buf = bufferPool.acquire(BUFFER_SIZE,false);
BufferUtil.clearToFill(buf);
try
{
while (active)
{
BufferUtil.clearToFill(buf);
int len = conn.read(buf);
if (len > 0)
{
LOG.debug("Read {} bytes",len);
BufferUtil.flipToFlush(buf,0);
conn.getParser().parse(buf);
}
Queue<WebSocketFrame> frames = conn.getIncomingFrames().getFrames();
WebSocketFrame frame;
while ((frame = frames.poll()) != null)
{
frameCount.incrementAndGet();
if (frame.getOpCode() == OpCode.CLOSE)
{
active = false;
// automatically response to close frame
CloseInfo close = new CloseInfo(frame);
conn.close(close.getStatusCode());
}
expectedMessageCount.countDown();
}
if (slowness > 0)
{
TimeUnit.MILLISECONDS.sleep(getSlowness());
}
}
}
catch (IOException | InterruptedException e)
{
LOG.warn(e);
}
finally
{
bufferPool.release(buf);
}
}