public ApplicationBootstrap(ApplicationConfig config, ApplicationState state) { this.config = config; this.state = state; XioServiceLocator.buildInstance(config, state); }
public ServerChannelConfiguration serverChannelConfig() { return ChannelConfiguration.serverConfig( bossThreads, bossNameFormat, workerThreads, workerNameFormat); } }
@Override public void run() { stop(); } });
public static void main(String args[]) throws Exception { Application application = new ApplicationBootstrap("exhibitor-test") .addServer("main", bs -> bs.addToPipeline(new SmartHttpPipeline())) .build(); application .getState() .getZkClient() .getClient() .create() .creatingParentsIfNeeded() .forPath("/test/key", "value".getBytes()); } }
@Test public void buildHttp11Server() { XioServerBootstrap bootstrap = XioServerBootstrap.fromConfig("xio.testHttpsServer").addToPipeline(new SmartHttpPipeline()); XioServer server = bootstrap.build(); assertEquals("ssl-http/1.1", server.getInstrumentation().applicationProtocol()); } }
public Application build() { addServer("main", bs -> bs.addToPipeline(pipelineFragment())); return super.build(); }
public XioServerBootstrap( ApplicationState appState, XioServerConfig config, XioServerState state) { serverBootstrap = new ServerBootstrap(); pipelineAssembler = new XioPipelineAssembler(appState, config, state); this.config = config; this.state = state; if (XioServiceLocator.getInstance() == null) { XioServiceLocator.buildInstance(appState.config(), appState); } bindAddress(config.getBindAddress()); channelConfig(appState.getChannelConfiguration()); }
/** * This method will configure a worker EventLoopGroup and a Channel for use by a client. It will * try to use Epoll if it's available. * * @param workerThreads spawn int number of worker threads * @param workerNameFormat uses String to set the worker thread names * @return ClientChannelConfiguration */ public static ClientChannelConfiguration clientConfig( int workerThreads, String workerNameFormat) { EventLoopGroup workerGroup; Class<? extends Channel> channelClass; if (Epoll.isAvailable()) { workerGroup = new EpollEventLoopGroup(workerThreads, threadFactory(workerNameFormat)); channelClass = EpollSocketChannel.class; } else { workerGroup = new NioEventLoopGroup(workerThreads, threadFactory(workerNameFormat)); channelClass = NioSocketChannel.class; } return new ClientChannelConfiguration(workerGroup, channelClass); }
public ClientState(ClientConfig config, EventLoopGroup workerGroup) { this(ChannelConfiguration.clientConfig(workerGroup), config); } }
public ZkClient getZkClient() { return XioServiceLocator.getInstance().getZkClient(); } }
public static XioServerBootstrap fromConfig(String key) { return fromConfig(key, ConfigFactory.load()); }
/** * This method will configure a boss EventLoopGroup, a worker EventLoopGroup and a ServerChannel * for use by a server. It will try to use Epoll if it's available. * * @param bossThreads spawn in number of boss threads * @param bossNameFormat uses String to the boss thread names * @param workerThreads spawn int number of worker threads * @param workerNameFormat uses String to set the worker thread names * @return ClientChannelConfiguration */ public static ServerChannelConfiguration serverConfig( int bossThreads, String bossNameFormat, int workerThreads, String workerNameFormat) { EventLoopGroup bossGroup; EventLoopGroup workerGroup; Class<? extends ServerChannel> channelClass; if (Epoll.isAvailable()) { bossGroup = new EpollEventLoopGroup(bossThreads, threadFactory(bossNameFormat)); workerGroup = new EpollEventLoopGroup(workerThreads, threadFactory(workerNameFormat)); channelClass = EpollServerSocketChannel.class; } else { bossGroup = new NioEventLoopGroup(bossThreads, threadFactory(bossNameFormat)); workerGroup = new NioEventLoopGroup(workerThreads, threadFactory(workerNameFormat)); channelClass = NioServerSocketChannel.class; } return new ServerChannelConfiguration(bossGroup, workerGroup, channelClass); } }
public ChannelFuture connect() { if (connectionState == ClientConnectionState.NOT_CONNECTED) { connectionState = ClientConnectionState.CONNECTING; Bootstrap bootstrap = new Bootstrap(); bootstrap.channel(state.channelConfig.channel()); bootstrap.group(state.channelConfig.workerGroup()); bootstrap.handler(channelInitializer); ChannelFuture connectFuture = bootstrap.connect(state.remote); currentChannelFuture = connectFuture; currentChannelFuture.channel().closeFuture().addListener(releaseListener); connectFuture.addListener(connectionListener); return connectFuture; } else { return currentChannelFuture; } }
/** * This is how ApplicationBootstrap initializes the shared instance of XioServiceLocator. The * above statement is why this function is package private and XioServiceLocator is in the * bootstrap package. */ static void buildInstance( ApplicationConfig applicationConfig, ApplicationState applicationState) { XioServiceLocator.instance = new XioServiceLocator(applicationConfig, applicationState); }
@Override protected EventLoopGroup group() { return channelConfig.workerGroup(); }
@Override protected Class<? extends Channel> channel() { return channelConfig.channel(); }
public EventLoopGroup workerGroup() { return channelConfiguration.workerGroup(); }
@Before public void before() throws Exception { ApplicationConfig appConfig = ApplicationConfig.fromConfig("xio.testZipkinApplication"); application = new ApplicationBootstrap(appConfig, XioTracingDecorator::new) .addServer( "exampleServer", (bs) -> bs.addToPipeline(new SmartHttpPipeline(TestHandler::new))) .build(); }
public ClientChannelConfiguration channelConfig(ChannelHandlerContext ctx) { return ChannelConfiguration.clientConfig(ctx.channel().eventLoop()); }
@Before public void before() { application = new ApplicationBootstrap("xio.testZipkinApplication") .addServer( "exampleServer", (bs) -> bs.addToPipeline(new SmartHttpPipeline(TestHandler::new))) .build(); MetricRegistry metricRegistry = mock(MetricRegistry.class); requestsMeter = mock(Meter.class); when(metricRegistry.meter("requests")).thenReturn(requestsMeter); successMeter = mock(Meter.class); when(metricRegistry.meter("statusClassSuccess")).thenReturn(successMeter); application.getState().setMetricRegistry(metricRegistry); }