use of org.xnio.XnioWorker in project undertow by undertow-io.
the class AbstractLoadBalancingProxyTestCase method teardown.
@AfterClass
public static void teardown() {
XnioWorker worker1 = null, worker2 = null;
int countDown = 0;
try {
if (server1 != null) {
final XnioWorker worker = server1.getWorker();
server1.stop();
// if stop did not shutdown the worker, we need to run the latch to prevent a Address already in use (UNDERTOW-1960)
if (worker != null && !worker.isShutdown()) {
countDown++;
worker1 = worker;
}
}
} finally {
try {
if (server2 != null) {
final XnioWorker worker = server2.getWorker();
server2.stop();
// if stop did not shutdown the worker, we need to run the latch to prevent a Address already in use (UNDERTOW-1960)
if (worker != null && !worker.isShutdown() && worker != worker1) {
worker2 = worker;
countDown++;
}
}
} finally {
if (countDown != 0) {
// TODO this is needed solely for ssl servers; replace this by the mechanism described in UNDERTOW-1648 once it is implemented
final CountDownLatch latch = new CountDownLatch(countDown);
if (worker1 != null)
worker1.getIoThread().execute(latch::countDown);
if (worker2 != null)
worker2.getIoThread().execute(latch::countDown);
try {
latch.await();
// double protection, we need to guarantee that the servers have stopped, and some environments seem to need a small delay to re-bind the socket
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
}
}
}
}
use of org.xnio.XnioWorker in project undertow by undertow-io.
the class ProgramaticAutobahnServer method run.
public void run() {
Xnio xnio = Xnio.getInstance();
try {
XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8192);
HttpOpenListener openListener = new HttpOpenListener(pool);
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
server.resumeAccepts();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(ProgramaticAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).setDispatchToWorkerThread(true).addEndpoint(new ServerEndpointConfigImpl(ProgramaticAutobahnEndpoint.class, "/")).addExtension(new PerMessageDeflateHandshake()));
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
openListener.setRootHandler(deploymentManager.start());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.xnio.XnioWorker in project undertow by undertow-io.
the class AnnotatedAutobahnServer method run.
public void run() {
Xnio xnio = Xnio.getInstance();
DeploymentManager deploymentManager = null;
try {
XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_WRITE_THREADS, 4).set(Options.WORKER_READ_THREADS, 4).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8024);
HttpOpenListener openListener = new HttpOpenListener(pool);
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
server.resumeAccepts();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(AnnotatedAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).addEndpoint(AutobahnAnnotatedEndpoint.class).setDispatchToWorkerThread(true).addExtension(new PerMessageDeflateHandshake())).addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST);
deploymentManager = container.addDeployment(builder);
deploymentManager.deploy();
openListener.setRootHandler(deploymentManager.start());
} catch (Exception e) {
log.error("failed to start server", e);
} finally {
if (deploymentManager != null) {
deploymentManager.undeploy();
try {
deploymentManager.stop();
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
}
}
use of org.xnio.XnioWorker in project spring-boot by spring-projects.
the class AccessLogHttpHandlerFactory method getHandler.
@Override
public HttpHandler getHandler(HttpHandler next) {
try {
createAccessLogDirectoryIfNecessary();
XnioWorker worker = createWorker();
String baseName = (this.prefix != null) ? this.prefix : "access_log.";
String formatString = (this.pattern != null) ? this.pattern : "common";
return new ClosableAccessLogHandler(next, worker, new DefaultAccessLogReceiver(worker, this.directory, baseName, this.suffix, this.rotate), formatString);
} catch (IOException ex) {
throw new IllegalStateException("Failed to create AccessLogHandler", ex);
}
}
use of org.xnio.XnioWorker in project wildfly by wildfly.
the class ModClusterService method start.
@Override
public synchronized void start(StartContext context) throws StartException {
super.start(context);
SSLContext sslContext = this.sslContext != null ? this.sslContext.get() : null;
// TODO: SSL support for the client
final ModCluster.Builder modClusterBuilder;
final XnioWorker worker = this.worker.get();
if (sslContext == null) {
modClusterBuilder = ModCluster.builder(worker);
} else {
OptionMap.Builder builder = OptionMap.builder();
builder.set(Options.USE_DIRECT_BUFFERS, true);
OptionMap combined = builder.getMap();
XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), combined, sslContext);
modClusterBuilder = ModCluster.builder(worker, UndertowClient.getInstance(), xnioSsl);
}
modClusterBuilder.setMaxRetries(maxRetries).setClientOptions(clientOptions).setHealthCheckInterval(healthCheckInterval).setMaxRequestTime(maxRequestTime).setCacheConnections(cachedConnections).setQueueNewRequests(requestQueueSize > 0).setRequestQueueSize(requestQueueSize).setRemoveBrokenNodes(removeBrokenNodes).setTtl(connectionIdleTimeout).setMaxConnections(connectionsPerThread).setUseAlias(useAlias).setRouteParsingStrategy(routeParsingStrategy).setRankedAffinityDelimiter(routeDelimiter);
if (FailoverStrategy.DETERMINISTIC.equals(failoverStrategy)) {
modClusterBuilder.setDeterministicFailover(true);
}
modCluster = modClusterBuilder.build();
MCMPConfig.Builder builder = MCMPConfig.builder();
final SocketBinding advertiseBinding = advertiseSocketBinding != null ? advertiseSocketBinding.get() : null;
if (advertiseBinding != null) {
InetAddress multicastAddress = advertiseBinding.getMulticastAddress();
if (multicastAddress == null) {
throw UndertowLogger.ROOT_LOGGER.advertiseSocketBindingRequiresMulticastAddress();
}
if (advertiseFrequency > 0) {
builder.enableAdvertise().setAdvertiseAddress(advertiseBinding.getSocketAddress().getAddress().getHostAddress()).setAdvertiseGroup(multicastAddress.getHostAddress()).setAdvertisePort(advertiseBinding.getMulticastPort()).setAdvertiseFrequency(advertiseFrequency).setPath(advertisePath).setProtocol(advertiseProtocol).setSecurityKey(securityKey);
}
}
builder.setManagementHost(managementSocketBinding.get().getSocketAddress().getHostString());
builder.setManagementPort(managementSocketBinding.get().getSocketAddress().getPort());
config = builder.build();
if (advertiseBinding != null && advertiseFrequency > 0) {
try {
modCluster.advertise(config);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
modCluster.start();
}
Aggregations