use of com.tvd12.ezyfox.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();
}
use of com.tvd12.ezyfox.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();
}
}
use of com.tvd12.ezyfox.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);
}
use of com.tvd12.ezyfox.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);
}
use of com.tvd12.ezyfox.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);
}
Aggregations