本文整理汇总了Java中io.undertow.server.XnioByteBufferPool类的典型用法代码示例。如果您正苦于以下问题:Java XnioByteBufferPool类的具体用法?Java XnioByteBufferPool怎么用?Java XnioByteBufferPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XnioByteBufferPool类属于io.undertow.server包,在下文中一共展示了XnioByteBufferPool类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import io.undertow.server.XnioByteBufferPool; //导入依赖的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();
}
示例2: createByteBufferPool
import io.undertow.server.XnioByteBufferPool; //导入依赖的package包/类
private ByteBufferPool createByteBufferPool() {
long maxMemory = Runtime.getRuntime().maxMemory();
boolean useDirectBuffers;
int bufferSize, buffersPerRegion;
if (maxMemory < 64 * 1024 * 1024) {
//smaller than 64mb of ram we use 512b buffers
useDirectBuffers = false;
bufferSize = 512;
buffersPerRegion = 10;
} else if (maxMemory < 128 * 1024 * 1024) {
//use 1k buffers
useDirectBuffers = true;
bufferSize = 1024;
buffersPerRegion = 10;
} else {
//use 16k buffers for best performance
//as 16k is generally the max amount of data that can be sent in a single write() call
useDirectBuffers = true;
bufferSize = 1024 * 16;
buffersPerRegion = 20;
}
BufferAllocator<ByteBuffer> allocator;
if (useDirectBuffers) {
allocator = BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR;
} else {
allocator = BufferAllocator.BYTE_BUFFER_ALLOCATOR;
}
int maxRegionSize = buffersPerRegion * bufferSize;
ByteBufferSlicePool pool = new ByteBufferSlicePool(allocator, bufferSize, maxRegionSize);
return new XnioByteBufferPool(pool);
}
示例3: PortForwardOpenListener
import io.undertow.server.XnioByteBufferPool; //导入依赖的package包/类
public PortForwardOpenListener(ClientConnection masterPortForwardConnection, final String urlPath,
final int targetPort, final AtomicInteger requestId, final Pool<ByteBuffer> pool,
final OptionMap undertowOptions) {
this.masterPortForwardConnection = masterPortForwardConnection;
this.urlPath = urlPath;
this.targetPort = targetPort;
this.requestId = requestId;
this.undertowOptions = undertowOptions;
this.bufferPool = new XnioByteBufferPool(pool);
Pooled<ByteBuffer> buf = pool.allocate();
this.bufferSize = buf.getResource().remaining();
buf.free();
}
示例4: upgradeConnection
import io.undertow.server.XnioByteBufferPool; //导入依赖的package包/类
private void upgradeConnection(ClientExchange result) throws IOException {
if (result.getResponse().getResponseCode() == 101) {
// flush response
new StringReadChannelListener(bufferPool) {
@Override
protected void stringDone(String string) {
}
@Override
protected void error(IOException e) {
}
}.setup(result.getResponseChannel());
// Create the upgraded SPDY connection
ByteBufferPool heapBufferPool =
new XnioByteBufferPool(new ByteBufferSlicePool(BufferAllocator.BYTE_BUFFER_ALLOCATOR, 8196, 8196));
SpdyChannel spdyChannel =
new SpdyChannelWithoutFlowControl(connection.performUpgrade(), bufferPool, null, heapBufferPool, true,
OptionMap.EMPTY);
Integer idleTimeout = DEFAULT_OPTIONS.get(UndertowOptions.IDLE_TIMEOUT);
if (idleTimeout != null && idleTimeout > 0) {
spdyChannel.setIdleTimeout(idleTimeout);
}
connection = new SpdyClientConnection(spdyChannel, null);
} else {
throw new IOException("Failed to upgrade connection");
}
}
示例5: main
import io.undertow.server.XnioByteBufferPool; //导入依赖的package包/类
public static void main(final String... args) throws Exception {
final DeploymentManager deployment = Servlets.defaultContainer()
.addDeployment(
Servlets.deployment()
.setClassLoader(AsyncWsConnectionTest.class.getClassLoader())
.setContextPath("/")
.setDeploymentName(AsyncWsConnectionTest.class.getName())
.addServletContextAttribute(
WebSocketDeploymentInfo.ATTRIBUTE_NAME,
new WebSocketDeploymentInfo()
.addEndpoint(serverEndpointConfig())
.setWorker(Xnio.getInstance().createWorker(OptionMap.builder().getMap()))
.setBuffers(new XnioByteBufferPool(new ByteBufferSlicePool(1024, 10240)))
)
);
deployment.deploy();
Undertow.builder()
.addHttpListener(PORT, HOST)
.setHandler(deployment.start())
.build()
.start();
TimeUnit.SECONDS.sleep(1);
if (true) {
client(new ServerWebSocketContainer(
DefaultClassIntrospector.INSTANCE,
Xnio.getInstance().createWorker(OptionMap.create(Options.THREAD_DAEMON, true)),
new XnioByteBufferPool(new ByteBufferSlicePool(1024, 10240)),
List.of(new ContextClassLoaderSetupAction(ClassLoader.getSystemClassLoader())),
true,
true
));
} else {
final ClientContainer container = new ClientContainer(); // $note: setSendTimeout not yet implemented in Jetty
container.start();
client(container);
}
}
示例6: run
import io.undertow.server.XnioByteBufferPool; //导入依赖的package包/类
protected static void run(final CountDownLatch latch) throws Exception {
final Xnio xnio = Xnio.getInstance();
final DeploymentManager deployment = Servlets.defaultContainer()
.addDeployment(
Servlets.deployment()
.setClassLoader(UndertowTest.class.getClassLoader())
.setContextPath("/")
.setDeploymentName(UndertowTest.class.getName())
.addServletContextAttribute(
WebSocketDeploymentInfo.ATTRIBUTE_NAME,
new WebSocketDeploymentInfo()
.addEndpoint(serverEndpointConfig())
.setWorker(xnio.createWorker(OptionMap.builder().getMap()))
.setBuffers(new XnioByteBufferPool(new ByteBufferSlicePool(1024, 10240)))
)
);
deployment.deploy();
final Undertow server = Undertow.builder()
.addHttpListener(PORT, "localhost")
.setHandler(deployment.start())
.build();
server.start();
connect(
new ServerWebSocketContainer(
DefaultClassIntrospector.INSTANCE,
xnio.createWorker(OptionMap.create(Options.THREAD_DAEMON, true)),
new XnioByteBufferPool(new ByteBufferSlicePool(1024, 10240)),
List.of(new ContextClassLoaderSetupAction(ClassLoader.getSystemClassLoader())),
true,
true
),
latch
);
server.stop();
}
示例7: main
import io.undertow.server.XnioByteBufferPool; //导入依赖的package包/类
public static void main(final String... args) throws Exception {
final DeploymentManager deployment = Servlets.defaultContainer()
.addDeployment(
Servlets.deployment()
.setClassLoader(UndertowAcceptor.class.getClassLoader())
.setContextPath("/")
.setDeploymentName(UndertowAcceptor.class.getName())
.addServlet(
Servlets.servlet("Xhr", XhrServlet.class)
.addMapping(XHR_PATH)
)
.addServletContextAttribute(
WebSocketDeploymentInfo.ATTRIBUTE_NAME,
new WebSocketDeploymentInfo()
.addEndpoint(ENDPOINT_CONFIG)
.setWorker(Xnio.getInstance().createWorker(OptionMap.builder().getMap()))
.setBuffers(new XnioByteBufferPool(new ByteBufferSlicePool(1024, 10240)))
)
);
deployment.deploy();
final HttpHandler servletHandler = deployment.start();
final HttpHandler fileHandler = Handlers.resource(new FileResourceManager(new File(WEB_PATH), 100));
Undertow.builder()
.addHttpListener(PORT, HOST)
.addHttpsListener(PORT + 1, HOST, SslConfig.SERVER.context) // $note: we don't know how to force client authentication
.setHandler(exchange -> {
final String path = exchange.getRequestPath();
if (WS_PATH.equals(path) || XHR_PATH.equals(path)) {
servletHandler.handleRequest(exchange);
} else {
fileHandler.handleRequest(exchange);
}
})
.build()
.start();
System.out.println("started");
}
示例8: main
import io.undertow.server.XnioByteBufferPool; //导入依赖的package包/类
public static void main(final String... args) throws Exception {
run(new ServerWebSocketContainer(
DefaultClassIntrospector.INSTANCE,
Xnio.getInstance().createWorker(OptionMap.create(Options.THREAD_DAEMON, true)),
new XnioByteBufferPool(new ByteBufferSlicePool(1024, 10240)),
List.of(new ContextClassLoaderSetupAction(ClassLoader.getSystemClassLoader())),
true,
true
));
}