Search in sources :

Example 1 with EzyRequestQueue

use of com.tvd12.ezyfoxserver.socket.EzyRequestQueue in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandler method handleEvent.

@Override
public void handleEvent() {
    EzySocketRequest request = null;
    try {
        EzySession session = sessionTicketsQueue.take();
        EzyRequestQueue requestQueue = getRequestQueue(session);
        // noinspection SynchronizationOnLocalVariableOrMethodParameter
        synchronized (requestQueue) {
            request = requestQueue.take();
            if (requestQueue.size() > 0) {
                sessionTicketsQueue.add(session);
            }
        }
        processRequest(request);
    } catch (InterruptedException e) {
        logger.info("{}-request-handler thread interrupted", getRequestType());
    } catch (Throwable throwable) {
        logger.warn("problems in {}-request-handler", getRequestType(), throwable);
    } finally {
        if (request != null) {
            request.release();
        }
    }
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 2 with EzyRequestQueue

use of com.tvd12.ezyfoxserver.socket.EzyRequestQueue in project ezyfox-server by youngmonkeys.

the class EzySessionTicketsRequestQueues method addRequest.

public boolean addRequest(EzySocketRequest request) {
    EzyRequestQueue queue;
    EzySessionTicketsQueue ticketsQueue;
    EzySession session = request.getSession();
    if (request.isSystemRequest()) {
        ticketsQueue = systemQueue;
        queue = session.getSystemRequestQueue();
    } else {
        ticketsQueue = extensionQueue;
        queue = session.getExtensionRequestQueue();
    }
    boolean success;
    // noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (queue) {
        boolean empty = queue.isEmpty();
        success = queue.add(request);
        if (empty && success) {
            ticketsQueue.add(session);
        }
    }
    return success;
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 3 with EzyRequestQueue

use of com.tvd12.ezyfoxserver.socket.EzyRequestQueue in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandlerTest method test.

@Test
public void test() {
    ExEzySocketRequestHandler handler = new ExEzySocketRequestHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    EzySocketDataHandlerGroup handlerGroup = mock(EzySocketDataHandlerGroup.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(handlerGroup);
    EzySession session = spy(EzyAbstractSession.class);
    session.setActivated(true);
    EzyRequestQueue requestQueue = new EzyNonBlockingRequestQueue();
    when(session.getExtensionRequestQueue()).thenReturn(requestQueue);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(10).build();
    EzySocketRequest request = new EzySimpleSocketRequest(session, array);
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    handler.setSessionTicketsQueue(sessionTicketsRequestQueues.getExtensionQueue());
    sessionTicketsRequestQueues.addRequest(request);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 4 with EzyRequestQueue

use of com.tvd12.ezyfoxserver.socket.EzyRequestQueue in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandlerTest method processRequestQueue0RemainTest.

@Test
public void processRequestQueue0RemainTest() {
    // given
    ExEzySocketRequestHandler handler = new ExEzySocketRequestHandler();
    EzySocketDataHandlerGroup handlerGroup = mock(EzySocketDataHandlerGroup.class);
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(handlerGroup);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.isActivated()).thenReturn(Boolean.TRUE);
    EzyRequestQueue requestQueue = new EzyNonBlockingRequestQueue();
    when(session.getExtensionRequestQueue()).thenReturn(requestQueue);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(10).build();
    EzySocketRequest request = new EzySimpleSocketRequest(session, array);
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    handler.setSessionTicketsQueue(sessionTicketsRequestQueues.getExtensionQueue());
    sessionTicketsRequestQueues.addRequest(request);
    sessionTicketsRequestQueues.addRequest(request);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    // when
    handler.handleEvent();
    // then
    Asserts.assertEquals(sessionTicketsRequestQueues.getExtensionQueue().size(), 1);
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 5 with EzyRequestQueue

use of com.tvd12.ezyfoxserver.socket.EzyRequestQueue in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandlerTest method handleGroupNullCaseTest.

@Test
public void handleGroupNullCaseTest() {
    ExEzySocketRequestHandler handler = new ExEzySocketRequestHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(null);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.isActivated()).thenReturn(Boolean.TRUE);
    EzyRequestQueue requestQueue = new EzyNonBlockingRequestQueue();
    when(session.getExtensionRequestQueue()).thenReturn(requestQueue);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(10).build();
    EzySocketRequest request = new EzySimpleSocketRequest(session, array);
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    handler.setSessionTicketsQueue(sessionTicketsRequestQueues.getExtensionQueue());
    sessionTicketsRequestQueues.addRequest(request);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)10 Test (org.testng.annotations.Test)9 EzyArray (com.tvd12.ezyfox.entity.EzyArray)6 EzyRequestQueue (com.tvd12.ezyfoxserver.socket.EzyRequestQueue)4 EzySessionTicketsRequestQueues (com.tvd12.ezyfoxserver.socket.EzySessionTicketsRequestQueues)2 EzySimpleSocketRequest (com.tvd12.ezyfoxserver.socket.EzySimpleSocketRequest)2 EzySocketRequest (com.tvd12.ezyfoxserver.socket.EzySocketRequest)2 EzyDroppedPackets (com.tvd12.ezyfoxserver.entity.EzyDroppedPackets)1 EzyImmediateDeliver (com.tvd12.ezyfoxserver.entity.EzyImmediateDeliver)1 EzySocketExtensionRequestHandler (com.tvd12.ezyfoxserver.socket.EzySocketExtensionRequestHandler)1 EzySocketSystemRequestHandler (com.tvd12.ezyfoxserver.socket.EzySocketSystemRequestHandler)1 EzyRequestFrameSecond (com.tvd12.ezyfoxserver.statistics.EzyRequestFrameSecond)1 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)1 MyTestSession (com.tvd12.ezyfoxserver.testing.MyTestSession)1 InetSocketAddress (java.net.InetSocketAddress)1