Search in sources :

Example 1 with EzySocketStream

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();
    }
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 2 with EzySocketStream

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());
    }
}
Also used : EzySimpleSocketStream(com.tvd12.ezyfoxserver.socket.EzySimpleSocketStream) EzySocketStream(com.tvd12.ezyfoxserver.socket.EzySocketStream)

Example 3 with EzySocketStream

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();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 4 with EzySocketStream

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();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 5 with EzySocketStream

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();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)4 Test (org.testng.annotations.Test)4 EzySocketStream (com.tvd12.ezyfoxserver.socket.EzySocketStream)3 EzySimpleSocketStream (com.tvd12.ezyfoxserver.socket.EzySimpleSocketStream)2 EzyBlockingSocketStreamQueue (com.tvd12.ezyfoxserver.socket.EzyBlockingSocketStreamQueue)1