Search in sources :

Example 1 with EzyData

use of com.tvd12.ezyfox.entity.EzyData in project ezyfox-server-example by tvd12.

the class HelloWorldClient method setup.

protected EzyClient setup() {
    EzyClientConfig clientConfig = EzyClientConfig.builder().zoneName(ZONE_NAME).enableSSL().enableDebug().build();
    EzyClients clients = EzyClients.getInstance();
    EzyClient client = new EzyUTClient(clientConfig);
    clients.addClient(client);
    EzySetup setup = client.setup();
    setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS, new EzyConnectionSuccessHandler());
    setup.addEventHandler(EzyEventType.CONNECTION_FAILURE, new EzyConnectionFailureHandler());
    setup.addDataHandler(EzyCommand.HANDSHAKE, new ExHandshakeEventHandler());
    setup.addDataHandler(EzyCommand.LOGIN, new ExLoginSuccessHandler());
    setup.addDataHandler(EzyCommand.APP_ACCESS, new ExAccessAppHandler());
    EzyAppSetup appSetup = setup.setupApp(APP_NAME);
    appSetup.addDataHandler("greet", new ChatGreetResponseHandler());
    appSetup.addDataHandler("secureChat", new SecureChatResponseHandler());
    appSetup.addDataHandler("chatAll", new EzyAppDataHandler<EzyData>() {

        @Override
        public void handle(EzyApp app, EzyData data) {
            System.out.println("chatAll: " + data);
        }
    });
    appSetup.addDataHandler("chat1", new EzyAppDataHandler<EzyData>() {

        @Override
        public void handle(EzyApp app, EzyData data) {
            System.out.println("chat1: " + data);
        }
    });
    appSetup.addDataHandler("chatToMe", new EzyAppDataHandler<EzyData>() {

        @Override
        public void handle(EzyApp app, EzyData data) {
            System.out.println("chatToMe: " + data);
        }
    });
    appSetup.addDataHandler("err", new EzyAppDataHandler<EzyData>() {

        @Override
        public void handle(EzyApp app, EzyData data) {
            System.out.println("error: " + data);
        }
    });
    return client;
}
Also used : EzyAppSetup(com.tvd12.ezyfoxserver.client.setup.EzyAppSetup) EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyClient(com.tvd12.ezyfoxserver.client.EzyClient) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyUTClient(com.tvd12.ezyfoxserver.client.EzyUTClient) EzyApp(com.tvd12.ezyfoxserver.client.entity.EzyApp) EzySetup(com.tvd12.ezyfoxserver.client.setup.EzySetup) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients)

Example 2 with EzyData

use of com.tvd12.ezyfox.entity.EzyData in project ezyfox-server-example by tvd12.

the class HelloWorldClientUdp method setup.

protected EzyClient setup() {
    EzyClientConfig clientConfig = EzyClientConfig.builder().zoneName(ZONE_NAME).enableSSL().enableDebug().build();
    EzyClients clients = EzyClients.getInstance();
    EzyClient client = new EzyUTClient(clientConfig);
    clients.addClient(client);
    EzySetup setup = client.setup();
    setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS, new EzyConnectionSuccessHandler());
    setup.addEventHandler(EzyEventType.CONNECTION_FAILURE, new EzyConnectionFailureHandler());
    setup.addDataHandler(EzyCommand.HANDSHAKE, new ExHandshakeEventHandler());
    setup.addDataHandler(EzyCommand.LOGIN, new ExLoginSuccessHandler());
    setup.addDataHandler(EzyCommand.UDP_HANDSHAKE, new ExHandshakeSuccessHandler());
    setup.addDataHandler(EzyCommand.APP_ACCESS, new ExAccessAppHandler());
    EzyAppSetup appSetup = setup.setupApp(APP_NAME);
    appSetup.addDataHandler("greet", new ChatGreetResponseHandler());
    appSetup.addDataHandler("udpGreet", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("udpGreet: " + data));
    appSetup.addDataHandler("secureChat", new SecureChatResponseHandler());
    appSetup.addDataHandler("chatAll", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("chatAll: " + data));
    appSetup.addDataHandler("chat1", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("chat1: " + data));
    appSetup.addDataHandler("chatToMe", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("chatToMe: " + data));
    appSetup.addDataHandler("err", (EzyAppDataHandler<EzyData>) (app, data) -> System.out.println("error: " + data));
    return client;
}
Also used : EzyApp(com.tvd12.ezyfoxserver.client.entity.EzyApp) com.tvd12.ezyfoxserver.client.handler(com.tvd12.ezyfoxserver.client.handler) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients) EzyRequest(com.tvd12.ezyfoxserver.client.request.EzyRequest) EzyAppAccessRequest(com.tvd12.ezyfoxserver.client.request.EzyAppAccessRequest) EzyStrings(com.tvd12.ezyfox.io.EzyStrings) HashMap(java.util.HashMap) EzySetup(com.tvd12.ezyfoxserver.client.setup.EzySetup) EzyUTClient(com.tvd12.ezyfoxserver.client.EzyUTClient) EzyLoginRequest(com.tvd12.ezyfoxserver.client.request.EzyLoginRequest) PostRequest(com.tvd12.ezyhttp.client.request.PostRequest) EzyClient(com.tvd12.ezyfoxserver.client.EzyClient) EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyAppSetup(com.tvd12.ezyfoxserver.client.setup.EzyAppSetup) EzyEventType(com.tvd12.ezyfoxserver.client.event.EzyEventType) EzyMainEventsLoop(com.tvd12.ezyfoxserver.client.socket.EzyMainEventsLoop) EzyObject(com.tvd12.ezyfox.entity.EzyObject) Map(java.util.Map) EzyEntityObjects(com.tvd12.ezyfox.util.EzyEntityObjects) EzyCommand(com.tvd12.ezyfoxserver.client.constant.EzyCommand) HttpClient(com.tvd12.ezyhttp.client.HttpClient) EzyAppSetup(com.tvd12.ezyfoxserver.client.setup.EzyAppSetup) EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyClient(com.tvd12.ezyfoxserver.client.EzyClient) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyUTClient(com.tvd12.ezyfoxserver.client.EzyUTClient) EzySetup(com.tvd12.ezyfoxserver.client.setup.EzySetup) EzyClients(com.tvd12.ezyfoxserver.client.EzyClients)

Example 3 with EzyData

use of com.tvd12.ezyfox.entity.EzyData in project ezyfox-server by youngmonkeys.

the class EzySimpleAppContextTest method sendMultiTest.

@Test
public void sendMultiTest() {
    // given
    EzyData data = mock(EzyData.class);
    EzySession recipient = mock(EzySession.class);
    List<EzySession> recipients = Collections.singletonList(recipient);
    boolean encrypted = RandomUtil.randomBoolean();
    EzyAppSendResponse sendResponse = mock(EzyAppSendResponse.class);
    doNothing().when(sendResponse).execute(data, recipients, encrypted, EzyTransportType.TCP);
    EzySimpleAppContext sut = new EzySimpleAppContext();
    FieldUtil.setFieldValue(sut, "sendResponse", sendResponse);
    // when
    sut.send(data, recipients, encrypted, EzyTransportType.TCP);
    // then
    verify(sendResponse, times(1)).execute(data, recipients, encrypted, EzyTransportType.TCP);
}
Also used : EzyAppSendResponse(com.tvd12.ezyfoxserver.command.EzyAppSendResponse) EzyData(com.tvd12.ezyfox.entity.EzyData) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 4 with EzyData

use of com.tvd12.ezyfox.entity.EzyData in project ezyfox-server by youngmonkeys.

the class EzySimplePluginContextTest method sendMultiTest.

@Test
public void sendMultiTest() {
    // given
    EzyData data = mock(EzyData.class);
    EzySession recipient = mock(EzySession.class);
    List<EzySession> recipients = Collections.singletonList(recipient);
    boolean encrypted = RandomUtil.randomBoolean();
    EzyPluginSendResponse sendResponse = mock(EzyPluginSendResponse.class);
    doNothing().when(sendResponse).execute(data, recipients, encrypted, EzyTransportType.TCP);
    EzySimplePluginContext sut = new EzySimplePluginContext();
    FieldUtil.setFieldValue(sut, "sendResponse", sendResponse);
    // when
    sut.send(data, recipients, encrypted, EzyTransportType.TCP);
    // then
    verify(sendResponse, times(1)).execute(data, recipients, encrypted, EzyTransportType.TCP);
}
Also used : EzySimplePluginContext(com.tvd12.ezyfoxserver.context.EzySimplePluginContext) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyPluginSendResponse(com.tvd12.ezyfoxserver.command.EzyPluginSendResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 5 with EzyData

use of com.tvd12.ezyfox.entity.EzyData in project ezyfox-server by youngmonkeys.

the class EzyAppSendResponseImpl method newResponse.

protected EzyResponse newResponse(EzyData data) {
    EzyAppSetting setting = context.getApp().getSetting();
    EzyRequestAppResponseParams params = new EzyRequestAppResponseParams();
    params.setAppId(setting.getId());
    params.setData(data);
    return new EzyRequestAppResponse(params);
}
Also used : EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyRequestAppResponse(com.tvd12.ezyfoxserver.response.EzyRequestAppResponse) EzyRequestAppResponseParams(com.tvd12.ezyfoxserver.response.EzyRequestAppResponseParams)

Aggregations

EzyData (com.tvd12.ezyfox.entity.EzyData)12 BaseTest (com.tvd12.test.base.BaseTest)7 Test (org.testng.annotations.Test)7 EzyArray (com.tvd12.ezyfox.entity.EzyArray)4 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)4 EzyApp (com.tvd12.ezyfoxserver.client.entity.EzyApp)3 EzyData (com.tvd12.ezyfoxserver.client.entity.EzyData)3 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)3 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)3 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)3 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)3 EzyBadRequestException (com.tvd12.ezyfox.core.exception.EzyBadRequestException)2 EzyObject (com.tvd12.ezyfox.entity.EzyObject)2 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)2 EzyClient (com.tvd12.ezyfoxserver.client.EzyClient)2 EzyClients (com.tvd12.ezyfoxserver.client.EzyClients)2 EzyUTClient (com.tvd12.ezyfoxserver.client.EzyUTClient)2 EzyClientConfig (com.tvd12.ezyfoxserver.client.config.EzyClientConfig)2 EzyAppSetup (com.tvd12.ezyfoxserver.client.setup.EzyAppSetup)2 EzySetup (com.tvd12.ezyfoxserver.client.setup.EzySetup)2