本文整理汇总了Java中org.xnio.BufferAllocator类的典型用法代码示例。如果您正苦于以下问题:Java BufferAllocator类的具体用法?Java BufferAllocator怎么用?Java BufferAllocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BufferAllocator类属于org.xnio包,在下文中一共展示了BufferAllocator类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.xnio.BufferAllocator; //导入依赖的package包/类
private static ManagementHttpServer create(Builder builder) {
SSLContext sslContext = null;
SslClientAuthMode sslClientAuthMode = builder.sslClientAuthMode;
if (builder.secureBindAddress != null) {
sslContext = getSSLContext(builder);
if (sslContext == null) {
throw ROOT_LOGGER.sslRequestedNoSslContext();
}
}
HttpOpenListener openListener = new HttpOpenListener(new ByteBufferSlicePool(BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR, 4096, 10 * 4096));
int secureRedirectPort = builder.secureBindAddress != null ? builder.secureBindAddress.getPort() : -1;
// WFLY-2870 -- redirect not supported if bindAddress and secureBindAddress are using different InetAddress
boolean redirectSupported = (builder.bindAddress == null || builder.secureBindAddress == null || builder.bindAddress.getAddress().equals(builder.secureBindAddress.getAddress()));
if (!redirectSupported && secureRedirectPort > 0) {
HttpServerLogger.ROOT_LOGGER.httpsRedirectNotSupported(builder.bindAddress.getAddress(), builder.secureBindAddress.getAddress());
secureRedirectPort = -1;
}
final ExtensionHandlers extensionHandlers = setupOpenListener(openListener, secureRedirectPort, builder);
return new ManagementHttpServer(openListener, builder.bindAddress, builder.secureBindAddress, sslContext, sslClientAuthMode, builder.worker, extensionHandlers);
}
示例2: DirectBufferCache
import org.xnio.BufferAllocator; //导入依赖的package包/类
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, final BufferAllocator<ByteBuffer> bufferAllocator, int maxAge) {
this.sliceSize = sliceSize;
this.pool = new LimitedBufferSlicePool(bufferAllocator, sliceSize, sliceSize * slicesPerPage, maxMemory / (sliceSize * slicesPerPage));
this.cache = new ConcurrentHashMap<>(16);
this.accessQueue = ConcurrentDirectDeque.newInstance();
this.maxAge = maxAge;
}
示例3: LimitedBufferSlicePool
import org.xnio.BufferAllocator; //导入依赖的package包/类
/**
* Construct a new instance.
*
* @param allocator the buffer allocator to use
* @param bufferSize the size of each buffer
* @param maxRegionSize the maximum region size for each backing buffer
* @param maxRegions the maximum regions to create, zero for unlimited
*/
public LimitedBufferSlicePool(final BufferAllocator<ByteBuffer> allocator, final int bufferSize, final int maxRegionSize, final int maxRegions) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("Buffer size must be greater than zero");
}
if (maxRegionSize < bufferSize) {
throw new IllegalArgumentException("Maximum region size must be greater than or equal to the buffer size");
}
buffersPerRegion = maxRegionSize / bufferSize;
this.bufferSize = bufferSize;
this.allocator = allocator;
this.maxRegions = maxRegions;
}
示例4: createByteBufferPool
import org.xnio.BufferAllocator; //导入依赖的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);
}
示例5: getResourceManager
import org.xnio.BufferAllocator; //导入依赖的package包/类
private ResourceManager getResourceManager(File warFile, Long transferMinSize, String cfmlDirs, File internalCFMLServerRoot) {
MappedResourceManager mappedResourceManager = new MappedResourceManager(warFile, transferMinSize, cfmlDirs, internalCFMLServerRoot);
if(serverOptions.isDirectoryListingRefreshEnabled()) return mappedResourceManager;
final DirectBufferCache dataCache = new DirectBufferCache(1000, 10, 1000 * 10 * 1000, BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR, METADATA_MAX_AGE);
final int metadataCacheSize = 100;
final long maxFileSize = 10000;
return new CachingResourceManager(metadataCacheSize,maxFileSize, dataCache, mappedResourceManager, METADATA_MAX_AGE);
}
示例6: upgradeConnection
import org.xnio.BufferAllocator; //导入依赖的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");
}
}
示例7: dispatchMockRequest
import org.xnio.BufferAllocator; //导入依赖的package包/类
@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);
}
}
示例8: createSpdyChannel
import org.xnio.BufferAllocator; //导入依赖的package包/类
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);
}
示例9: start
import org.xnio.BufferAllocator; //导入依赖的package包/类
@Override
public void start(StartContext context) throws StartException {
bufferPool = new ByteBufferSlicePool(directBuffers ? BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR : BufferAllocator.BYTE_BUFFER_ALLOCATOR, bufferSize, buffersPerSlice * bufferSize);
}
示例10: setUp
import org.xnio.BufferAllocator; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.app = new App();
this.buffer = new ByteBufferSlicePool(
BufferAllocator.BYTE_BUFFER_ALLOCATOR, 256, 256);
}