Search in sources :

Example 6 with EzyCodecFactory

use of com.tvd12.ezyfoxserver.codec.EzyCodecFactory in project ezyfox-server by youngmonkeys.

the class EzySimpleCodecFactoryTest method test.

@Test
public void test() {
    EzySimpleSocketSetting socketSetting = new EzySimpleSocketSetting();
    socketSetting.setActive(false);
    EzySimpleWebSocketSetting webSocketSetting = new EzySimpleWebSocketSetting();
    webSocketSetting.setActive(false);
    EzyCodecFactory factory = EzySimpleCodecFactory.builder().socketSetting(socketSetting).websocketSetting(webSocketSetting).build();
    assert factory.newEncoder(EzyConnectionType.SOCKET) == null;
    assert factory.newEncoder(EzyConnectionType.WEBSOCKET) == null;
    assert factory.newDecoder(EzyConnectionType.SOCKET) == null;
    assert factory.newDecoder(EzyConnectionType.WEBSOCKET) == null;
    socketSetting.setActive(true);
    socketSetting.setCodecCreator(ExBytesCodecCreator.class.getName());
    webSocketSetting.setActive(true);
    webSocketSetting.setCodecCreator(ExStringCodecCreator.class.getName());
    factory = EzySimpleCodecFactory.builder().socketSetting(socketSetting).websocketSetting(webSocketSetting).build();
    assert factory.newEncoder(EzyConnectionType.SOCKET) != null;
    assert factory.newEncoder(EzyConnectionType.WEBSOCKET) != null;
    assert factory.newDecoder(EzyConnectionType.SOCKET) != null;
    assert factory.newDecoder(EzyConnectionType.WEBSOCKET) != null;
}
Also used : EzySimpleWebSocketSetting(com.tvd12.ezyfoxserver.setting.EzySimpleWebSocketSetting) EzySimpleSocketSetting(com.tvd12.ezyfoxserver.setting.EzySimpleSocketSetting) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 7 with EzyCodecFactory

use of com.tvd12.ezyfoxserver.codec.EzyCodecFactory in project ezyfox-server by youngmonkeys.

the class EzyProxyResponseApiTest method test.

@Test
public void test() throws Exception {
    EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
    EzyProxyResponseApi api = new EzyProxyResponseApi(codecFactory);
    EzyPackage pack = mock(EzyPackage.class);
    api.response(pack);
    EzyObjectToByteEncoder byteEncoder = mock(EzyObjectToByteEncoder.class);
    EzyObjectToStringEncoder stringEncoder = mock(EzyObjectToStringEncoder.class);
    when(codecFactory.newEncoder(EzyConnectionType.SOCKET)).thenReturn(byteEncoder);
    when(codecFactory.newEncoder(EzyConnectionType.WEBSOCKET)).thenReturn(stringEncoder);
    api = new EzyProxyResponseApi(codecFactory);
    api.response(pack);
    api.response(pack, true);
    EzyImmediateDeliver immediateDeliver = mock(EzyImmediateDeliver.class);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    session.setImmediateDeliver(immediateDeliver);
    when(pack.getRecipients(any(EzyConstant.class))).thenReturn(Lists.newArrayList(session));
    api.response(pack);
    api.response(pack, true);
}
Also used : EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzyProxyResponseApi(com.tvd12.ezyfoxserver.api.EzyProxyResponseApi) EzyPackage(com.tvd12.ezyfoxserver.response.EzyPackage) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzyObjectToStringEncoder(com.tvd12.ezyfox.codec.EzyObjectToStringEncoder) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzyImmediateDeliver(com.tvd12.ezyfoxserver.entity.EzyImmediateDeliver) EzyObjectToByteEncoder(com.tvd12.ezyfox.codec.EzyObjectToByteEncoder) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 8 with EzyCodecFactory

use of com.tvd12.ezyfoxserver.codec.EzyCodecFactory in project ezyfox-server by youngmonkeys.

the class EzySimpleNioHandlerGroupTest method newHandlerGroup.

@SuppressWarnings("rawtypes")
private EzySimpleNioHandlerGroup newHandlerGroup(boolean streamEnable) throws IOException {
    EzySessionTicketsQueue socketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionTicketsQueue webSocketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionManager sessionManager = EzyNioSessionManagerImpl.builder().maxRequestPerSecond(new EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond()).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
    EzyStatistics statistics = new EzySimpleStatistics();
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleStreamingSetting streaming = settings.getStreaming();
    streaming.setEnable(streamEnable);
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    server.setSessionManager(sessionManager);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzyChannel channel = mock(EzyChannel.class);
    when(channel.isConnected()).thenReturn(true);
    when(channel.getConnection()).thenReturn(SocketChannel.open());
    when(channel.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
    EzySimpleSession session = mock(EzySimpleSession.class);
    when(session.getChannel()).thenReturn(channel);
    ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    SelectionKey selectionKey = mock(SelectionKey.class);
    when(selectionKey.isValid()).thenReturn(true);
    when(session.getProperty(EzyNioSession.SELECTION_KEY)).thenReturn(selectionKey);
    EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
    EzyByteToObjectDecoder decoder = mock(EzyByteToObjectDecoder.class);
    when(codecFactory.newDecoder(any())).thenReturn(decoder);
    EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).serverContext(serverContext).statsThreadPool(statsThreadPool).codecFactory(codecFactory).sessionTicketsRequestQueues(sessionTicketsRequestQueues).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).build();
    return (EzySimpleNioHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.SOCKET).session(session).decoder(decoder).serverContext(serverContext).statsThreadPool(statsThreadPool).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
}
Also used : SelectionKey(java.nio.channels.SelectionKey) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleSessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting) EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleNioHandlerGroup(com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioHandlerGroup) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzySimpleSession(com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)

Example 9 with EzyCodecFactory

use of com.tvd12.ezyfoxserver.codec.EzyCodecFactory in project ezyfox-server by youngmonkeys.

the class EzyNioServerBootstrapBuilderImpl method newServerBootstrap.

@Override
protected EzyServerBootstrap newServerBootstrap() {
    ExecutorService statsThreadPool = newStatsThreadPool();
    EzyCodecFactory codecFactory = newCodecFactory();
    EzyStreamingApi streamingApi = newStreamingApi();
    EzyResponseApi responseApi = newResponseApi(codecFactory);
    EzySocketStreamQueue streamQueue = newStreamQueue();
    EzySessionTicketsQueue socketSessionTicketsQueue = newSocketSessionTicketsQueue();
    EzySessionTicketsQueue websocketSessionTicketsQueue = newWebSocketSessionTicketsQueue();
    EzySocketDisconnectionQueue socketDisconnectionQueue = newSocketDisconnectionQueue();
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = newSessionTicketsRequestQueues();
    EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = newHandlerGroupBuilderFactory(statsThreadPool, codecFactory, streamQueue, socketDisconnectionQueue, socketSessionTicketsQueue, websocketSessionTicketsQueue, sessionTicketsRequestQueues);
    EzyHandlerGroupManager handlerGroupManager = newHandlerGroupManager(handlerGroupBuilderFactory);
    EzySocketDataReceiver socketDataReceiver = newSocketDataReceiver(handlerGroupManager);
    EzyNioServerBootstrap bootstrap = new EzyNioServerBootstrap();
    bootstrap.setResponseApi(responseApi);
    bootstrap.setStreamingApi(streamingApi);
    bootstrap.setStreamQueue(streamQueue);
    bootstrap.setSocketDataReceiver(socketDataReceiver);
    bootstrap.setHandlerGroupManager(handlerGroupManager);
    bootstrap.setSocketDisconnectionQueue(socketDisconnectionQueue);
    bootstrap.setSocketSessionTicketsQueue(socketSessionTicketsQueue);
    bootstrap.setWebsocketSessionTicketsQueue(websocketSessionTicketsQueue);
    bootstrap.setSocketSessionTicketsRequestQueues(sessionTicketsRequestQueues);
    bootstrap.setSslContext(newSslContext(getWebsocketSetting().getSslConfig()));
    return bootstrap;
}
Also used : EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) ExecutorService(java.util.concurrent.ExecutorService) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzyNioServerBootstrap(com.tvd12.ezyfoxserver.nio.EzyNioServerBootstrap)

Aggregations

EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)9 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)7 ExecutorService (java.util.concurrent.ExecutorService)7 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)6 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)6 EzySimpleSessionTokenGenerator (com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)6 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)6 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)6 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)6 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)6 EzyNioSessionManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager)5 BaseTest (com.tvd12.test.base.BaseTest)4 Test (org.testng.annotations.Test)4 EzyHandlerGroupManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager)3 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)2 EzySocketDataReceiver (com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver)2 EzySimpleSessionManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting)2 Session (org.eclipse.jetty.websocket.api.Session)2 EzyObjectToByteEncoder (com.tvd12.ezyfox.codec.EzyObjectToByteEncoder)1 EzyObjectToStringEncoder (com.tvd12.ezyfox.codec.EzyObjectToStringEncoder)1