本文整理汇总了Java中org.xnio.BufferAllocator.BYTE_BUFFER_ALLOCATOR属性的典型用法代码示例。如果您正苦于以下问题:Java BufferAllocator.BYTE_BUFFER_ALLOCATOR属性的具体用法?Java BufferAllocator.BYTE_BUFFER_ALLOCATOR怎么用?Java BufferAllocator.BYTE_BUFFER_ALLOCATOR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.xnio.BufferAllocator
的用法示例。
在下文中一共展示了BufferAllocator.BYTE_BUFFER_ALLOCATOR属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createByteBufferPool
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);
}
示例2: upgradeConnection
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");
}
}
示例3: dispatchMockRequest
@Override
public void dispatchMockRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {
final ByteBufferSlicePool bufferPool = new ByteBufferSlicePool(BufferAllocator.BYTE_BUFFER_ALLOCATOR, 1024, 1024);
MockServerConnection connection = new MockServerConnection(bufferPool);
HttpServerExchange exchange = new HttpServerExchange(connection);
exchange.setRequestScheme(request.getScheme());
exchange.setRequestMethod(new HttpString(request.getMethod()));
exchange.setProtocol(Protocols.HTTP_1_0);
exchange.setResolvedPath(request.getContextPath());
String relative;
if (request.getPathInfo() == null) {
relative = request.getServletPath();
} else {
relative = request.getServletPath() + request.getPathInfo();
}
exchange.setRelativePath(relative);
final ServletPathMatch info = paths.getServletHandlerByPath(request.getServletPath());
final HttpServletResponseImpl oResponse = new HttpServletResponseImpl(exchange, servletContext);
final HttpServletRequestImpl oRequest = new HttpServletRequestImpl(exchange, servletContext);
final ServletRequestContext servletRequestContext = new ServletRequestContext(servletContext.getDeployment(), oRequest, oResponse, info);
servletRequestContext.setServletRequest(request);
servletRequestContext.setServletResponse(response);
//set the max request size if applicable
if (info.getServletChain().getManagedServlet().getMaxRequestSize() > 0) {
exchange.setMaxEntitySize(info.getServletChain().getManagedServlet().getMaxRequestSize());
}
exchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext);
exchange.startBlocking(new ServletBlockingHttpExchange(exchange));
servletRequestContext.setServletPathMatch(info);
try {
dispatchRequest(exchange, servletRequestContext, info.getServletChain(), DispatcherType.REQUEST);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new ServletException(e);
}
}
示例4: createSpdyChannel
private static SpdyClientConnection createSpdyChannel(StreamConnection connection, Pool<ByteBuffer> bufferPool) {
SpdyChannel spdyChannel = new SpdyChannel(connection, bufferPool, null, new ByteBufferSlicePool(BufferAllocator.BYTE_BUFFER_ALLOCATOR, 8192, 8192), true);
return new SpdyClientConnection(spdyChannel);
}
示例5: start
@Override
public void start(StartContext context) throws StartException {
bufferPool = new ByteBufferSlicePool(directBuffers ? BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR : BufferAllocator.BYTE_BUFFER_ALLOCATOR, bufferSize, buffersPerSlice * bufferSize);
}
示例6: setUp
@Before
public void setUp() throws Exception {
this.app = new App();
this.buffer = new ByteBufferSlicePool(
BufferAllocator.BYTE_BUFFER_ALLOCATOR, 256, 256);
}