Search in sources :

Example 1 with EzyServerBootstrap

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

the class EzyServerBootstrapTest method test.

@SuppressWarnings("rawtypes")
@Test
public void test() throws Exception {
    EzyServerBootstrap bt = new MyTestServerBootstrapBuilder().server(newServer()).build();
    bt.destroy();
    assert MethodInvoker.create().object(bt).method("getServer").invoke() != null;
    assert MethodInvoker.create().object(bt).method("getServerSettings").invoke() != null;
    assert MethodInvoker.create().object(bt).method("getHttpSetting").invoke() != null;
    assert MethodInvoker.create().object(bt).method("getSocketSetting").invoke() != null;
    assert MethodInvoker.create().object(bt).method("getWebSocketSetting").invoke() != null;
    EzyServerBootstrap bootstrap = new EzyServerBootstrap() {

        @Override
        protected void startOtherBootstraps(Runnable callback) {
            callback.run();
        }
    };
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzySimpleServer server = new EzySimpleServer();
    EzySimpleConfig config = new EzySimpleConfig();
    server.setConfig(config);
    when(serverContext.getServer()).thenReturn(server);
    EzySimpleSettings settings = new EzySimpleSettings();
    server.setSettings(settings);
    EzySessionManager sessionManager = new ExEzySimpleSessionManager.Builder().objectFactory(() -> spy(EzyAbstractSession.class)).build();
    server.setSessionManager(sessionManager);
    EzyBootstrap localBootstrap = EzyBootstrap.builder().context(serverContext).build();
    bootstrap.setContext(serverContext);
    bootstrap.setLocalBootstrap(localBootstrap);
    bootstrap.start();
}
Also used : EzySimpleConfig(com.tvd12.ezyfoxserver.config.EzySimpleConfig) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyBootstrap(com.tvd12.ezyfoxserver.EzyBootstrap) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyServerBootstrap(com.tvd12.ezyfoxserver.EzyServerBootstrap) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) Test(org.testng.annotations.Test)

Example 2 with EzyServerBootstrap

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

the class EzyStarter method startEzyFox.

protected void startEzyFox(EzyServer server) throws Exception {
    EzyConfig config = server.getConfig();
    if (config.isPrintSettings()) {
        getLogger().info("settings: \n{}", server);
    }
    EzyServerBootstrap serverBoostrap = newServerBoostrap(server);
    serverBoostrap.start();
    serverContext = serverBoostrap.getContext();
    serverContext.setProperty(EzyServerBootstrap.class, serverBoostrap);
}
Also used : EzyConfig(com.tvd12.ezyfoxserver.config.EzyConfig)

Example 3 with EzyServerBootstrap

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

the class EzyAbstractServerBootstrapBuilder method buildServerBootstrap.

protected EzyServerBootstrap buildServerBootstrap() {
    EzyServerBootstrap answer = newServerBootstrap();
    answer.setContext(serverContext);
    answer.setLocalBootstrap(newLocalBoostrap());
    return answer;
}
Also used : EzyServerBootstrap(com.tvd12.ezyfoxserver.EzyServerBootstrap)

Example 4 with EzyServerBootstrap

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

the class EzyServerBootstrapTest method commonTest.

@Test
public void commonTest() {
    // given
    EzySimpleConfig config = new EzySimpleConfig();
    config.setPrintBanner(false);
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    server.setConfig(config);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getServer()).thenReturn(server);
    EzyServerBootstrap sut = new EzyServerBootstrap() {

        @Override
        protected void startOtherBootstraps(Runnable callback) {
            callback.run();
        }
    };
    sut.setContext(serverContext);
    // when
    ReflectMethodUtil.invokeMethod("printBanner", sut);
    EzyUdpSetting udpSetting = (EzyUdpSetting) ReflectMethodUtil.invokeMethod("getUdpSetting", sut);
    EzyThreadPoolSizeSetting threadPoolSizeSetting = (EzyThreadPoolSizeSetting) ReflectMethodUtil.invokeMethod("getThreadPoolSizeSetting", sut);
    // then
    Asserts.assertEquals(server.getSettings().getUdp(), udpSetting);
    Asserts.assertEquals(server.getSettings().getThreadPoolSize(), threadPoolSizeSetting);
}
Also used : EzySimpleConfig(com.tvd12.ezyfoxserver.config.EzySimpleConfig) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyThreadPoolSizeSetting(com.tvd12.ezyfoxserver.setting.EzyThreadPoolSizeSetting) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyUdpSetting(com.tvd12.ezyfoxserver.setting.EzyUdpSetting) EzyServerBootstrap(com.tvd12.ezyfoxserver.EzyServerBootstrap) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) Test(org.testng.annotations.Test)

Example 5 with EzyServerBootstrap

use of com.tvd12.ezyfoxserver.EzyServerBootstrap 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

EzyServerBootstrap (com.tvd12.ezyfoxserver.EzyServerBootstrap)3 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)2 EzySimpleConfig (com.tvd12.ezyfoxserver.config.EzySimpleConfig)2 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)2 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)2 Test (org.testng.annotations.Test)2 EzyBootstrap (com.tvd12.ezyfoxserver.EzyBootstrap)1 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)1 EzyStreamingApi (com.tvd12.ezyfoxserver.api.EzyStreamingApi)1 EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)1 EzyConfig (com.tvd12.ezyfoxserver.config.EzyConfig)1 EzyNioServerBootstrap (com.tvd12.ezyfoxserver.nio.EzyNioServerBootstrap)1 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)1 EzySocketDataReceiver (com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver)1 EzyHandlerGroupManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager)1 EzyThreadPoolSizeSetting (com.tvd12.ezyfoxserver.setting.EzyThreadPoolSizeSetting)1 EzyUdpSetting (com.tvd12.ezyfoxserver.setting.EzyUdpSetting)1 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)1 ExecutorService (java.util.concurrent.ExecutorService)1