Search in sources :

Example 1 with EzyStreamingApi

use of com.tvd12.ezyfoxserver.api.EzyStreamingApi in project ezyfox-server by youngmonkeys.

the class EzyStreamBytesImplTest method exceptionCaseTest.

@Test
public void exceptionCaseTest() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    settings.setDebug(true);
    EzyStreamingApi streamingApi = spy(EzyStreamingApi.class);
    doThrow(new IllegalArgumentException()).when(streamingApi).response(any(EzyBytesPackage.class));
    EzySimpleServer server = new EzySimpleServer();
    server.setStreamingApi(streamingApi);
    server.setSettings(settings);
    EzyStreamBytesImpl cmd = new EzyStreamBytesImpl(server);
    EzySession recipient = spy(EzyAbstractSession.class);
    cmd.execute(new byte[] { 1, 2, 3 }, recipient);
    cmd.execute(new byte[] { 1, 2, 3 }, Lists.newArrayList(recipient));
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyBytesPackage(com.tvd12.ezyfoxserver.response.EzyBytesPackage) EzyStreamBytesImpl(com.tvd12.ezyfoxserver.command.impl.EzyStreamBytesImpl) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 2 with EzyStreamingApi

use of com.tvd12.ezyfoxserver.api.EzyStreamingApi in project ezyfox-server by youngmonkeys.

the class EzyStreamBytesImplTest method normalCaseTest.

@Test
public void normalCaseTest() {
    EzySimpleSettings settings = new EzySimpleSettings();
    settings.setDebug(true);
    EzyStreamingApi streamingApi = spy(EzyAbstractStreamingApi.class);
    EzySimpleServer server = new EzySimpleServer();
    server.setStreamingApi(streamingApi);
    server.setSettings(settings);
    EzyStreamBytesImpl cmd = new EzyStreamBytesImpl(server);
    EzySession recipient = spy(EzyAbstractSession.class);
    cmd.execute(new byte[] { 1, 2, 3 }, recipient);
    cmd.execute(new byte[] { 1, 2, 3 }, Lists.newArrayList(recipient));
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyStreamBytesImpl(com.tvd12.ezyfoxserver.command.impl.EzyStreamBytesImpl) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 3 with EzyStreamingApi

use of com.tvd12.ezyfoxserver.api.EzyStreamingApi in project ezyfox-server by youngmonkeys.

the class EzyStreamBytesImpl method execute.

@Override
public void execute(byte[] bytes, EzySession recipient, EzyTransportType transportType) {
    EzyStreamingApi streamingApi = server.getStreamingApi();
    EzySimpleBytesPackage pack = newPackage(bytes, transportType);
    pack.addRecipient(recipient);
    try {
        streamingApi.response(pack);
    } catch (Exception e) {
        logger.warn("send {} bytes {}, to client: {} error", bytes.length, recipient.getName(), e);
    } finally {
        pack.release();
    }
}
Also used : EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzySimpleBytesPackage(com.tvd12.ezyfoxserver.socket.EzySimpleBytesPackage)

Example 4 with EzyStreamingApi

use of com.tvd12.ezyfoxserver.api.EzyStreamingApi in project ezyfox-server by youngmonkeys.

the class EzyNioServerBootstrapTest method test.

@Test
public void test() throws Exception {
    SSLContext sslContext = SSLContext.getDefault();
    EzyResponseApi responseApi = mock(EzyResponseApi.class);
    EzyStreamingApi streamingApi = mock(EzyStreamingApi.class);
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
    EzySessionTicketsQueue socketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionTicketsQueue websocketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    EzySocketDisconnectionQueue socketDisconnectionQueue = new EzySocketDisconnectionQueue() {

        final BlockingQueue<EzySocketDisconnection> queue = new LinkedBlockingQueue<>();

        @Override
        public EzySocketDisconnection take() throws InterruptedException {
            return queue.take();
        }

        @Override
        public int size() {
            return 0;
        }

        @Override
        public void remove(EzySocketDisconnection disconnection) {
        }

        @Override
        public boolean isEmpty() {
            return false;
        }

        @Override
        public void clear() {
        }

        @Override
        public boolean add(EzySocketDisconnection disconnection) {
            return false;
        }
    };
    EzySimpleConfig config = new EzySimpleConfig();
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleStreamingSetting streaming = settings.getStreaming();
    streaming.setEnable(true);
    settings.getUdp().setActive(true);
    EzySimpleServer server = new EzySimpleServer();
    EzyServerControllers serverControllers = EzyServerControllersImpl.builder().build();
    server.setControllers(serverControllers);
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    server.setEventControllers(eventControllers);
    server.setConfig(config);
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setProperty(EzySocketUserRemovalQueue.class, new EzyBlockingSocketUserRemovalQueue());
    serverContext.setServer(server);
    serverContext.init();
    ExBootstrap localBootstrap = new ExBootstrap(new EzyBootstrap.Builder().context(serverContext));
    EzyNioServerBootstrap bootstrap = new EzyNioServerBootstrap();
    bootstrap.setContext(serverContext);
    bootstrap.setLocalBootstrap(localBootstrap);
    bootstrap.setSslContext(sslContext);
    bootstrap.setResponseApi(responseApi);
    bootstrap.setStreamingApi(streamingApi);
    bootstrap.setStreamQueue(streamQueue);
    bootstrap.setHandlerGroupManager(handlerGroupManager);
    bootstrap.setSocketSessionTicketsQueue(socketSessionTicketsQueue);
    bootstrap.setWebsocketSessionTicketsQueue(websocketSessionTicketsQueue);
    bootstrap.setSocketDisconnectionQueue(socketDisconnectionQueue);
    bootstrap.setSocketSessionTicketsRequestQueues(sessionTicketsRequestQueues);
    bootstrap.start();
    bootstrap.destroy();
    bootstrap.destroy();
}
Also used : EzyEventControllersSetting(com.tvd12.ezyfoxserver.setting.EzyEventControllersSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) EzySimpleConfig(com.tvd12.ezyfoxserver.config.EzySimpleConfig) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) SSLContext(javax.net.ssl.SSLContext) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzyNioServerBootstrap(com.tvd12.ezyfoxserver.nio.EzyNioServerBootstrap) EzySimpleEventControllersSetting(com.tvd12.ezyfoxserver.setting.EzySimpleEventControllersSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 5 with EzyStreamingApi

use of com.tvd12.ezyfoxserver.api.EzyStreamingApi in project ezyfox-server by youngmonkeys.

the class EzyStreamBytesImpl method execute.

@Override
public void execute(byte[] bytes, Collection<EzySession> recipients, EzyTransportType transportType) {
    EzyStreamingApi streamingApi = server.getStreamingApi();
    EzySimpleBytesPackage pack = newPackage(bytes, transportType);
    pack.addRecipients(recipients);
    try {
        streamingApi.response(pack);
    } catch (Exception e) {
        logger.warn("send: {} bytes, to client: {} error", bytes.length, getRecipientsNames(recipients), e);
    } finally {
        pack.release();
    }
}
Also used : EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzySimpleBytesPackage(com.tvd12.ezyfoxserver.socket.EzySimpleBytesPackage)

Aggregations

EzyStreamingApi (com.tvd12.ezyfoxserver.api.EzyStreamingApi)6 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)3 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)3 Test (org.testng.annotations.Test)3 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)2 EzyStreamBytesImpl (com.tvd12.ezyfoxserver.command.impl.EzyStreamBytesImpl)2 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)2 EzyNioServerBootstrap (com.tvd12.ezyfoxserver.nio.EzyNioServerBootstrap)2 EzyHandlerGroupManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager)2 EzySimpleBytesPackage (com.tvd12.ezyfoxserver.socket.EzySimpleBytesPackage)2 EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)1 EzySimpleConfig (com.tvd12.ezyfoxserver.config.EzySimpleConfig)1 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)1 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)1 EzySocketDataReceiver (com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver)1 EzyBytesPackage (com.tvd12.ezyfoxserver.response.EzyBytesPackage)1 EzyEventControllersSetting (com.tvd12.ezyfoxserver.setting.EzyEventControllersSetting)1 EzySimpleEventControllersSetting (com.tvd12.ezyfoxserver.setting.EzySimpleEventControllersSetting)1 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)1 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)1