/** * Alternate constructor providing additional control over the * {@link ConnectionBuilder} for each WebSocket connection. * @param worker the Xnio worker to use to create {@code ConnectionBuilder}'s * @param builderConsumer a consumer to configure {@code ConnectionBuilder}'s */ public UndertowWebSocketClient(XnioWorker worker, Consumer<ConnectionBuilder> builderConsumer) { this(worker, new DefaultByteBufferPool(false, DEFAULT_POOL_BUFFER_SIZE), builderConsumer); }
throw UndertowMessages.MESSAGES.poolIsClosed(); cleanupThreadLocalData(); threadLocalDataList.add(new WeakReference<>(local)); threadLocalCache.set(local);
@Override protected void finalize() throws Throwable { super.finalize(); close(); }
private void freeInternal(ByteBuffer buffer) { if (closed) { DirectByteBufferDeallocator.free(buffer); return; //GC will take care of it } ThreadLocalData local = threadLocalCache.get(); if(local != null) { if(local.allocationDepth > 0) { local.allocationDepth--; if (local.buffers.size() < threadLocalCacheSize) { local.buffers.add(buffer); return; } } } queueIfUnderMax(buffer); }
private void freeInternal(ByteBuffer buffer) { if (closed) { DirectByteBufferDeallocator.free(buffer); return; //GC will take care of it } ThreadLocalData local = threadLocalCache.get(); if(local != null) { if(local.allocationDepth > 0) { local.allocationDepth--; if (local.buffers.size() < threadLocalCacheSize) { local.buffers.add(buffer); return; } } } queueIfUnderMax(buffer); }
@Override public void start(StartContext startContext) throws StartException { pool = new DefaultByteBufferPool(direct, size, maxSize, threadLocalCacheSize, leakDetectionPercent); }
@Override protected void finalize() throws Throwable { super.finalize(); close(); }
private void freeInternal(ByteBuffer buffer) { if (closed) { DirectByteBufferDeallocator.free(buffer); return; //GC will take care of it } ThreadLocalData local = threadLocalCache.get(); if(local != null) { if(local.allocationDepth > 0) { local.allocationDepth--; if (local.buffers.size() < threadLocalCacheSize) { local.buffers.add(buffer); return; } } } queueIfUnderMax(buffer); }
throw UndertowMessages.MESSAGES.poolIsClosed(); cleanupThreadLocalData(); threadLocalDataList.add(new WeakReference<>(local)); threadLocalCache.set(local);
/** * @param direct If this implementation should use direct buffers * @param bufferSize The buffer size to use * @param maximumPoolSize The maximum pool size, in number of buffers, it does not include buffers in thread local caches * @param threadLocalCacheSize The maximum number of buffers that can be stored in a thread local cache */ public DefaultByteBufferPool(boolean direct, int bufferSize, int maximumPoolSize, int threadLocalCacheSize, int leakDecetionPercent) { this.direct = direct; this.bufferSize = bufferSize; this.maximumPoolSize = maximumPoolSize; this.threadLocalCacheSize = threadLocalCacheSize; this.leakDectionPercent = leakDecetionPercent; if(direct) { arrayBackedPool = new DefaultByteBufferPool(false, bufferSize, maximumPoolSize, 0, leakDecetionPercent); } else { arrayBackedPool = this; } }
@Override protected void finalize() throws Throwable { super.finalize(); close(); }
throw UndertowMessages.MESSAGES.poolIsClosed(); cleanupThreadLocalData(); threadLocalDataList.add(new WeakReference<>(local)); threadLocalCache.set(local);
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.bufferPool = new DefaultByteBufferPool(false, 1024, -1, 2); }
public XnioByteBufferPool(Pool<ByteBuffer> pool) { this.pool = pool; Pooled<ByteBuffer> buf = pool.allocate(); bufferSize = buf.getResource().remaining(); direct = !buf.getResource().hasArray(); buf.free(); if(direct) { arrayBackedPool = new DefaultByteBufferPool(false, bufferSize); } else { arrayBackedPool = this; } }
WildflyHttpContext build() { XnioWorker worker = XnioWorker.getContextManager().get(); ByteBufferPool pool; if(bufferConfig == null) { pool=new DefaultByteBufferPool(true, 1024, 100, 0, LEAK_DETECTION); //TODO } else { pool = new DefaultByteBufferPool(bufferConfig.isDirect(), bufferConfig.getBufferSize(), bufferConfig.getMaxSize(), bufferConfig.getThreadLocalSize(), LEAK_DETECTION); } //TODO: ssl config ConfigSection[] connections = new ConfigSection[this.targets.size()]; long idleTimout = this.idleTimeout > 0 ? this.idleTimeout : 60000; int maxConnections = this.maxConnections > 0 ? this.maxConnections : 10; int maxStreamsPerConnection = this.maxStreamsPerConnection > 0 ? this.maxStreamsPerConnection : 10; for (int i = 0; i < this.targets.size(); ++i) { HttpConfigBuilder sb = this.targets.get(i); HostPool hp = new HostPool(sb.getUri()); boolean eager = this.eagerlyAcquireSession == null ? false : this.eagerlyAcquireSession; if (sb.getEagerlyAcquireSession() != null && sb.getEagerlyAcquireSession()) { eager = true; } boolean http2 = this.enableHttp2 == null ? true : this.enableHttp2; if(sb.getEnableHttp2() != null) { http2 = sb.getEnableHttp2(); } ConfigSection connection = new ConfigSection(new HttpTargetContext(new HttpConnectionPool(sb.getMaxConnections() > 0 ? sb.getMaxConnections() : maxConnections, sb.getMaxStreamsPerConnection() > 0 ? sb.getMaxStreamsPerConnection() : maxStreamsPerConnection, worker, pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, http2), hp, sb.getIdleTimeout() > 0 ? sb.getIdleTimeout() : idleTimout), eager, sb.getUri()), sb.getUri()); connections[i] = connection; } return new WildflyHttpContext(connections, maxConnections, maxStreamsPerConnection, idleTimeout, eagerlyAcquireSession == null ? false : eagerlyAcquireSession, worker, pool, enableHttp2 == null ? true : enableHttp2); }
buffers = new DefaultByteBufferPool(directBuffers, bufferSize, -1, 4);
@Override public void start(StartContext startContext) throws StartException { pool = new DefaultByteBufferPool(direct, size, maxSize, threadLocalCacheSize, leakDetectionPercent); }
@Override public void start(StartContext startContext) throws StartException { pool = new DefaultByteBufferPool(direct, size, maxSize, threadLocalCacheSize, leakDetectionPercent); }
protected DefaultByteBufferPool createByteBufferPool() { return new DefaultByteBufferPool(false, 2048); }
/** * @param direct If this implementation should use direct buffers * @param bufferSize The buffer size to use * @param maximumPoolSize The maximum pool size, in number of buffers, it does not include buffers in thread local caches * @param threadLocalCacheSize The maximum number of buffers that can be stored in a thread local cache */ public DefaultByteBufferPool(boolean direct, int bufferSize, int maximumPoolSize, int threadLocalCacheSize, int leakDecetionPercent) { this.direct = direct; this.bufferSize = bufferSize; this.maximumPoolSize = maximumPoolSize; this.threadLocalCacheSize = threadLocalCacheSize; this.leakDectionPercent = leakDecetionPercent; if(direct) { arrayBackedPool = new DefaultByteBufferPool(false, bufferSize, maximumPoolSize, 0, leakDecetionPercent); } else { arrayBackedPool = this; } }