use of com.tvd12.ezyfoxserver.socket.EzySocketStream in project ezyfox-server by youngmonkeys.
the class EzySocketStreamHandler method processStream.
private void processStream(EzySocketStream stream) throws Exception {
try {
byte[] bytes = stream.getBytes();
EzySession session = stream.getSession();
EzySocketDataHandlerGroup handlerGroup = getDataHandlerGroup(session);
if (handlerGroup != null) {
handlerGroup.fireStreamBytesReceived(bytes);
} else {
logger.warn("has no handler group with session: {}, drop: {} bytes", session, bytes.length);
}
} finally {
stream.release();
}
}
use of com.tvd12.ezyfoxserver.socket.EzySocketStream in project ezyfox-server by youngmonkeys.
the class EzySimpleNioHandlerGroup method handleReceivedMessage.
private void handleReceivedMessage(EzyMessage message) {
try {
EzyMessageHeader header = message.getHeader();
if (header.isRawBytes()) {
boolean sessionStreamingEnable = session.isStreamingEnable();
if (!streamingEnable || !sessionStreamingEnable) {
return;
}
byte[] rawBytes = message.getContent();
EzySocketStream stream = new EzySimpleSocketStream(session, rawBytes);
streamQueue.add(stream);
} else {
Object data = decodeMessage(message);
int dataSize = message.getByteCount();
handleReceivedData(data, dataSize);
}
} catch (Exception e) {
fireExceptionCaught(e);
} finally {
executeAddReadBytes(message.getByteCount());
}
}
use of com.tvd12.ezyfoxserver.socket.EzySocketStream in project ezyfox-server by youngmonkeys.
the class EzySocketStreamHandlerTest method test.
@Test
public void test() {
EzySocketStreamHandler handler = new EzySocketStreamHandler();
EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
EzySocketDataHandlerGroup dataHandlerGroup = mock(EzySocketDataHandlerGroup.class);
when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(dataHandlerGroup);
EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
EzySession session = spy(EzyAbstractSession.class);
EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
streamQueue.add(stream);
handler.setStreamQueue(streamQueue);
handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
handler.handleEvent();
handler.destroy();
}
use of com.tvd12.ezyfoxserver.socket.EzySocketStream in project ezyfox-server by youngmonkeys.
the class EzySocketStreamHandlerTest method hasNoHandlerGroupCaseTest.
@Test
public void hasNoHandlerGroupCaseTest() {
EzySocketStreamHandler handler = new EzySocketStreamHandler();
EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(null);
EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
EzySession session = spy(EzyAbstractSession.class);
EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
streamQueue.add(stream);
handler.setStreamQueue(streamQueue);
handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
handler.handleEvent();
}
use of com.tvd12.ezyfoxserver.socket.EzySocketStream in project ezyfox-server by youngmonkeys.
the class EzySocketStreamHandlerTest method doProcessStreamQueueExceptionCaseTest.
@Test
public void doProcessStreamQueueExceptionCaseTest() {
EzySocketStreamHandler handler = new EzySocketStreamHandler();
EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenThrow(new IllegalArgumentException());
EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
EzySession session = spy(EzyAbstractSession.class);
EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
streamQueue.add(stream);
handler.setStreamQueue(streamQueue);
handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
handler.handleEvent();
}
Aggregations