本文整理汇总了Java中org.xnio.Xnio类的典型用法代码示例。如果您正苦于以下问题:Java Xnio类的具体用法?Java Xnio怎么用?Java Xnio使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Xnio类属于org.xnio包,在下文中一共展示了Xnio类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.xnio.Xnio; //导入依赖的package包/类
public static void main(String[] args) throws ServletException, IOException {
final Xnio xnio = Xnio.getInstance("nio", Undertow.class.getClassLoader());
final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap());
final WebSocketDeploymentInfo webSockets = new WebSocketDeploymentInfo()
.addEndpoint(SocketProxy.class)
.setWorker(xnioWorker);
final DeploymentManager deployment = defaultContainer()
.addDeployment(deployment()
.setClassLoader(WebSocketServer.class.getClassLoader())
.setContextPath("/")
.setDeploymentName("embedded-websockets")
.addServletContextAttribute(ATTRIBUTE_NAME, webSockets));
deployment.deploy();
Undertow.builder().
addListener(8080, "localhost")
.setHandler(deployment.start())
.setHandler(Handlers.path().addPrefixPath("/test", Handlers.resource(new ClassPathResourceManager(WebSocketServer.class.getClassLoader(), WebSocketServer.class.getPackage())).addWelcomeFiles("index.html")))
.build()
.start();
}
示例2: main
import org.xnio.Xnio; //导入依赖的package包/类
public static void main(String[] args) throws IOException, ServletException {
final Xnio xnio = Xnio.getInstance("nio", Undertow.class.getClassLoader());
final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap());
final WebSocketDeploymentInfo webSockets = new WebSocketDeploymentInfo()
.addEndpoint(ClassProvider.class)
.setWorker(xnioWorker);
final DeploymentManager deploymentManager = Servlets.defaultContainer()
.addDeployment(Servlets.deployment()
.setClassLoader(ClassProviderStarter.class.getClassLoader())
.setContextPath("/")
.setDeploymentName("class-provider")
.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, webSockets));
deploymentManager.deploy();
//noinspection deprecation
Undertow.builder()
.addListener(5000, "localhost")
.setHandler(deploymentManager.start())
.build()
.start();
}
示例3: AnnotatedWebSocketServer
import org.xnio.Xnio; //导入依赖的package包/类
public AnnotatedWebSocketServer() throws IOException {
final Xnio xnio = Xnio.getInstance("nio", Undertow.class.getClassLoader());
final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap());
WebSocketDeploymentInfo websocket = new WebSocketDeploymentInfo()
.addEndpoint(MyAnnotatedEndpoint.class)
.setWorker(xnioWorker);
DeploymentInfo deploymentInfo = deployment()
.setClassLoader(MyAnnotatedEndpoint.class.getClassLoader())
.setContextPath("/myapp")
.setDeploymentName("websockets")
.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, websocket);
manager = defaultContainer().addDeployment(deploymentInfo);
manager.deploy();
}
示例4: ProgrammaticWebSocketServer
import org.xnio.Xnio; //导入依赖的package包/类
public ProgrammaticWebSocketServer() throws IOException {
final Xnio xnio = Xnio.getInstance("nio", Undertow.class.getClassLoader());
final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap());
WebSocketDeploymentInfo websocket = new WebSocketDeploymentInfo()
.addEndpoint(MyAnnotatedEndpoint.class)
.setWorker(xnioWorker);
DeploymentInfo deploymentInfo = deployment()
.setClassLoader(MyAnnotatedEndpoint.class.getClassLoader())
.setContextPath("/myapp")
.setDeploymentName("websockets")
.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, websocket);
manager = defaultContainer().addDeployment(deploymentInfo);
manager.deploy();
}
示例5: main
import org.xnio.Xnio; //导入依赖的package包/类
public static void main(final String... args) throws Exception {
final DeploymentManager deployment = Servlets.defaultContainer()
.addDeployment(
Servlets.deployment()
.setClassLoader(UndertowContainer.class.getClassLoader())
.setContextPath("/")
.setDeploymentName(UndertowContainer.class.getName())
.addServletContextAttribute(
WebSocketDeploymentInfo.ATTRIBUTE_NAME,
new WebSocketDeploymentInfo()
.addEndpoint(ApplicationConfig.ENDPOINT_CONFIG)
.setWorker(Xnio.getInstance().createWorker(OptionMap.builder().getMap()))
.setBuffers(new XnioByteBufferPool(new ByteBufferSlicePool(1024, 10240)))
)
);
deployment.deploy();
final HttpHandler servletHandler = deployment.start();
Undertow.builder()
.addHttpListener(Client.PORT, Client.HOST)
.setHandler(servletHandler)
.build()
.start();
}
示例6: ConnectionProviderContextImpl
import org.xnio.Xnio; //导入依赖的package包/类
public ConnectionProviderContextImpl ( OptionMap opts, String endpointName ) throws IllegalArgumentException, IOException {
this.instance = Xnio.getInstance();
this.worker = this.instance.createWorker(opts);
this.endpoint = Remoting.createEndpoint(endpointName, this.worker, opts);
this.executor = Executors.newCachedThreadPool(new ThreadFactory() {
public Thread newThread ( Runnable r ) {
Thread t = new Thread(r, "Worker");
t.setDaemon(true);
return t;
}
});
}
示例7: connectionBuilder
import org.xnio.Xnio; //导入依赖的package包/类
protected ConnectionBuilder connectionBuilder() throws XNIOException {
try {
this.worker = Xnio.getInstance().createWorker(OptionMap.EMPTY);
return new ConnectionBuilder(this.worker, new DefaultByteBufferPool(true, 1024), uri);
} catch (IOException e) {
throw new XNIOException(e);
}
}
示例8: UndertowXhrTransport
import org.xnio.Xnio; //导入依赖的package包/类
public UndertowXhrTransport(OptionMap optionMap) throws IOException {
Assert.notNull(optionMap, "OptionMap is required");
this.optionMap = optionMap;
this.httpClient = UndertowClient.getInstance();
this.worker = Xnio.getInstance().createWorker(optionMap);
this.undertowBufferSupport =
(undertow13Present ? new Undertow13BufferSupport() : new UndertowXnioBufferSupport());
}
示例9: webSocketWorker
import org.xnio.Xnio; //导入依赖的package包/类
private static XnioWorker webSocketWorker(Config wsOptions) {
XnioWorker worker = null;
try {
worker = Xnio.getInstance()
.createWorker(OptionMap.builder()
.set(Options.WORKER_IO_THREADS, wsOptions.getInt(KEY_WS_IO_THREADS))
.set(Options.WORKER_TASK_CORE_THREADS, wsOptions.getInt(KEY_WS_TASK_CORE_THREADS))
.set(Options.WORKER_TASK_MAX_THREADS, wsOptions.getInt(KEY_WS_TASK_MAX_THREADS))
.set(Options.TCP_NODELAY, wsOptions.getBoolean(KEY_WS_TCP_NO_DELAY))
.getMap());
} catch (IOException ex) {
LoggerFactory.getLogger(Server.class).error("Can't create XnioWorker!!", ex);
}
return worker;
}
示例10: ConnectionFactory
import org.xnio.Xnio; //导入依赖的package包/类
private ConnectionFactory(URI kubernetesMasterUri) {
this.kubernetesMasterUri = kubernetesMasterUri;
undertowClient = UndertowClient.getInstance();
Xnio xnio = Xnio.getInstance(Undertow.class.getClassLoader());
try {
ssl = new UndertowXnioSsl(xnio, OptionMap.EMPTY);
} catch (Exception e) {
throw new RuntimeException(e);
}
byteBufferPool = createByteBufferPool();
}
示例11: createRuntimeAdditionalInitialization
import org.xnio.Xnio; //导入依赖的package包/类
private AdditionalInitialization createRuntimeAdditionalInitialization() {
return new AdditionalInitialization() {
@Override
protected void setupController(ControllerInitializer controllerInitializer) {
controllerInitializer.addSocketBinding("remoting", 27258);
controllerInitializer.addRemoteOutboundSocketBinding("dummy-outbound-socket", "localhost", 6799);
controllerInitializer.addRemoteOutboundSocketBinding("other-outbound-socket", "localhost", 1234);
}
@Override
protected void addExtraServices(ServiceTarget target) {
//Needed for initialization of the RealmAuthenticationProviderService
AbsolutePathService.addService(ServerEnvironment.CONTROLLER_TEMP_DIR, new File("target/temp" + System.currentTimeMillis()).getAbsolutePath(), target);
target.addService(IOServices.WORKER.append("default"), new WorkerService(Xnio.getInstance().createWorkerBuilder().setWorkerIoThreads(2)))
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
target.addService(IOServices.WORKER.append("default-remoting"), new WorkerService(Xnio.getInstance().createWorkerBuilder().setWorkerIoThreads(2)))
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
}
@Override
protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource, ManagementResourceRegistration rootRegistration, RuntimeCapabilityRegistry capabilityRegistry) {
super.initializeExtraSubystemsAndModel(extensionRegistry, rootResource, rootRegistration, capabilityRegistry);
Map<String, Class> capabilities = new HashMap<>();
capabilities.put(buildDynamicCapabilityName(RemotingSubsystemRootResource.IO_WORKER_CAPABILITY,
RemotingSubsystemRootResource.WORKER.getDefaultValue().asString()), XnioWorker.class);
capabilities.put(buildDynamicCapabilityName(RemotingSubsystemRootResource.IO_WORKER_CAPABILITY,
"default-remoting"), XnioWorker.class);
AdditionalInitialization.registerServiceCapabilities(capabilityRegistry, capabilities);
}
};
}
示例12: createRuntimeAdditionalInitialization
import org.xnio.Xnio; //导入依赖的package包/类
private AdditionalInitialization createRuntimeAdditionalInitialization(final boolean legacyParser) {
return new AdditionalInitialization() {
@Override
protected void setupController(ControllerInitializer controllerInitializer) {
controllerInitializer.addSocketBinding("test", 27258);
controllerInitializer.addRemoteOutboundSocketBinding("dummy-outbound-socket", "localhost", 6799);
controllerInitializer.addRemoteOutboundSocketBinding("other-outbound-socket", "localhost", 1234);
}
@Override
protected void addExtraServices(ServiceTarget target) {
//Needed for initialization of the RealmAuthenticationProviderService
AbsolutePathService.addService(ServerEnvironment.CONTROLLER_TEMP_DIR, new File("target/temp" + System.currentTimeMillis()).getAbsolutePath(), target);
if (!legacyParser) {
target.addService(IOServices.WORKER.append("default"), new WorkerService(Xnio.getInstance().createWorkerBuilder().setWorkerIoThreads(2)))
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
}
}
@Override
protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource, ManagementResourceRegistration rootRegistration, RuntimeCapabilityRegistry capabilityRegistry) {
super.initializeExtraSubystemsAndModel(extensionRegistry, rootResource, rootRegistration, capabilityRegistry);
Map<String, Class> capabilities = new HashMap<>();
capabilities.put(buildDynamicCapabilityName(RemotingSubsystemRootResource.IO_WORKER_CAPABILITY,
"default-remoting"), XnioWorker.class);
if (legacyParser) {
// Deal with the fact that legacy parsers will add the io extension/subsystem
RemotingSubsystemTestUtil.registerIOExtension(extensionRegistry, rootRegistration);
} else {
capabilities.put(buildDynamicCapabilityName(RemotingSubsystemRootResource.IO_WORKER_CAPABILITY,
RemotingSubsystemRootResource.WORKER.getDefaultValue().asString()), XnioWorker.class);
}
AdditionalInitialization.registerServiceCapabilities(capabilityRegistry, capabilities);
}
};
}
示例13: start
import org.xnio.Xnio; //导入依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
final Xnio xnio = Xnio.getInstance();
try {
worker = xnio.createWorker(null, options, this::stopDone);
} catch (IOException e) {
throw new StartException(e);
}
}
示例14: before
import org.xnio.Xnio; //导入依赖的package包/类
@BeforeClass
public static void before() throws Exception {
Xnio xnio = Xnio.getInstance(WebSocketTest.class.getClassLoader());
worker = xnio.createWorker(OptionMap.builder()
.set(Options.WORKER_IO_THREADS, 2)
.set(Options.CONNECTION_HIGH_WATER, 1000000)
.set(Options.CONNECTION_LOW_WATER, 1000000)
.set(Options.WORKER_TASK_CORE_THREADS, 30)
.set(Options.WORKER_TASK_MAX_THREADS, 30)
.set(Options.TCP_NODELAY, true).set(Options.CORK, true)
.getMap());
}
示例15: main
import org.xnio.Xnio; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final OptionMap options = OptionMap.builder()
.set(WORKER_IO_THREADS, 8)
.set(TCP_NODELAY, true)
.set(KEEP_ALIVE, true)
.set(WORKER_NAME, "Client")
.getMap();
final Xnio xnio = Xnio.getInstance();
final XnioWorker worker = xnio.createWorker(null, options);
final UndertowClient client = UndertowClient.getInstance();
final URI serverAddress = new URI(SERVER_URL);
final ClientConnection connection = client.connect(serverAddress, worker, new ByteBufferSlicePool(1024, 1024), EMPTY).get();
final CountDownLatch latch = new CountDownLatch(1);
try {
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(GET).setPath("/");
request.getRequestHeaders().add(UPGRADE, HORNETQ_REMOTING);
String secretKey = HandshakeUtil.createSecretKey();
request.getRequestHeaders().add(HttpString.tryFromString(HandshakeUtil.SEC_HORNETQ_REMOTING_KEY), secretKey);
connection.sendRequest(request, createClientCallback(latch, secretKey));
}
});
latch.await(10, TimeUnit.MINUTES);
if (connection.isUpgraded()) {
StreamConnection streamConnection = connection.performUpgrade();
switchToHornetQProtocol(streamConnection);
}
} finally {
IoUtils.safeClose(connection);
worker.shutdown();
}
}