Search in sources :

Example 91 with EzyArray

use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.

the class EzySimpleResponse method serialize.

@Override
public final EzyArray serialize() {
    EzyArrayBuilder arrayBuilder = newArrayBuilder();
    arrayBuilder.append(command.getId());
    serialize(arrayBuilder);
    return arrayBuilder.build();
}
Also used : EzyArrayBuilder(com.tvd12.ezyfox.builder.EzyArrayBuilder)

Example 92 with EzyArray

use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandler method processRequest.

private void processRequest(EzySocketRequest request) throws Exception {
    try {
        EzyArray data = request.getData();
        EzySession session = request.getSession();
        EzySocketDataHandlerGroup handlerGroup = getDataHandlerGroup(session);
        if (handlerGroup != null) {
            handlerGroup.fireChannelRead(request.getCommand(), data);
        } else {
            logger.warn("has no handler group with session: {}, drop request: {}", session, request);
        }
    } finally {
        request.release();
    }
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 93 with EzyArray

use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntryTest method handleClientRequest.

private void handleClientRequest(EzyPluginContext context) {
    EzySimplePlugin plugin = (EzySimplePlugin) context.getPlugin();
    EzyPluginRequestController requestController = plugin.getRequestController();
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    EzySimpleUser user = new EzySimpleUser();
    EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    EzyUserRequestPluginEvent event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("chat").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
    data = EzyEntityFactory.newArrayBuilder().append("exception").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    try {
        requestController.handle(context, event);
    } catch (Exception e) {
        assert e instanceof IllegalStateException;
    }
    data = EzyEntityFactory.newArrayBuilder().append("plugin").build();
    event = new EzySimpleUserRequestPluginEvent(user, session, data);
    requestController.handle(context, event);
}
Also used : EzySimpleUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRequestPluginEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)

Example 94 with EzyArray

use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.

the class EzyAbstractHandlerGroupTest method hasMaxRequestPerSecondTest.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void hasMaxRequestPerSecondTest() throws Exception {
    // given
    ExHandlerGroup sut = newHandlerGroup();
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    when(session.addReceivedRequests(1)).thenReturn(true);
    EzyNioDataHandler handler = FieldUtil.getFieldValue(sut, "handler");
    EzySessionManager sessionManager = FieldUtil.getFieldValue(handler, "sessionManager");
    EzySimpleMaxRequestPerSecond maxRequestPerSecond = FieldUtil.getFieldValue(handler, "maxRequestPerSecond");
    maxRequestPerSecond.setAction(EzyMaxRequestPerSecondAction.DISCONNECT_SESSION);
    EzyArray data = EzyEntityFactory.newArray();
    // when
    MethodInvoker.create().object(sut).method("handleReceivedData").param(Object.class, data).param(int.class, 100).call();
    // then
    verify(sessionManager, times(1)).removeSession(session, MAX_REQUEST_PER_SECOND);
}
Also used : EzySimpleMaxRequestPerSecond(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond) EzyNioDataHandler(com.tvd12.ezyfoxserver.nio.handler.EzyNioDataHandler) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 95 with EzyArray

use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.

the class EzySimpleNioUdpDataHandler method response.

protected void response(EzySession recipient, int responseCode) throws Exception {
    EzyArray responseData = EzyEntityFactory.newArray();
    responseData.add(responseCode);
    EzyArray responseCommand = EzyEntityFactory.newArray();
    responseCommand.add(EzyCommand.UDP_HANDSHAKE.getId());
    responseCommand.add(responseData);
    EzySimplePackage response = new EzySimplePackage();
    response.addRecipient(recipient);
    response.setTransportType(EzyTransportType.UDP);
    response.setData(responseCommand);
    responseApi.response(response);
    logger.debug("response udp handshake to: {}, code: {}", recipient, responseCode);
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray)

Aggregations

EzyArray (com.tvd12.ezyfox.entity.EzyArray)80 Test (org.testng.annotations.Test)45 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)30 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)17 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)15 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)14 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)13 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)13 FieldSetting (com.tvd12.dahlia.core.setting.FieldSetting)12 EzyObject (com.tvd12.ezyfox.entity.EzyObject)12 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)11 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)9 CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)8 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8 Collection (com.tvd12.dahlia.core.entity.Collection)7 EzyArray (com.tvd12.ezyfoxserver.client.entity.EzyArray)7 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)7 Record (com.tvd12.dahlia.core.entity.Record)5