本文整理汇总了Java中org.xnio.Pooled类的典型用法代码示例。如果您正苦于以下问题:Java Pooled类的具体用法?Java Pooled怎么用?Java Pooled使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pooled类属于org.xnio包,在下文中一共展示了Pooled类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createChannel
import org.xnio.Pooled; //导入依赖的package包/类
@Override
protected AbstractAjpClientStreamSourceChannel createChannel(FrameHeaderData frameHeaderData, Pooled<ByteBuffer> frameData) throws IOException {
if (frameHeaderData instanceof SendHeadersResponse) {
SendHeadersResponse h = (SendHeadersResponse) frameHeaderData;
AjpClientResponseStreamSourceChannel sourceChannel = new AjpClientResponseStreamSourceChannel(this, h.headers, h.statusCode, h.reasonPhrase, frameData, (int) frameHeaderData.getFrameLength());
this.source = sourceChannel;
return sourceChannel;
} else if (frameHeaderData instanceof RequestBodyChunk) {
RequestBodyChunk r = (RequestBodyChunk) frameHeaderData;
this.sink.chunkRequested(r.getLength());
frameData.free();
return null;
} else {
frameData.free();
throw new RuntimeException("TODO: unknown frame");
}
}
示例2: transferFrom
import org.xnio.Pooled; //导入依赖的package包/类
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException {
try {
if (state != 0) {
final Pooled<ByteBuffer> pooled = exchange.getConnection().getBufferPool().allocate();
ByteBuffer buffer = pooled.getResource();
try {
int res = src.read(buffer);
if (res <= 0) {
return res;
}
buffer.flip();
return write(buffer);
} finally {
pooled.free();
}
} else {
return next.transferFrom(src, position, count);
}
} catch (IOException | RuntimeException e) {
IoUtils.safeClose(exchange.getConnection());
throw e;
}
}
示例3: SpdyOpenListener
import org.xnio.Pooled; //导入依赖的package包/类
public SpdyOpenListener(final Pool<ByteBuffer> pool, final Pool<ByteBuffer> heapBufferPool, final OptionMap undertowOptions) {
this.undertowOptions = undertowOptions;
this.bufferPool = pool;
Pooled<ByteBuffer> buf = pool.allocate();
this.bufferSize = buf.getResource().remaining();
buf.free();
this.heapBufferPool = heapBufferPool;
Pooled<ByteBuffer> buff = heapBufferPool.allocate();
try {
if (!buff.getResource().hasArray()) {
throw UndertowMessages.MESSAGES.mustProvideHeapBuffer();
}
} finally {
buff.free();
}
}
示例4: SpdyPlainOpenListener
import org.xnio.Pooled; //导入依赖的package包/类
public SpdyPlainOpenListener(final Pool<ByteBuffer> pool, final Pool<ByteBuffer> heapBufferPool, final OptionMap undertowOptions) {
this.undertowOptions = undertowOptions;
this.bufferPool = pool;
Pooled<ByteBuffer> buf = pool.allocate();
this.bufferSize = buf.getResource().remaining();
buf.free();
this.heapBufferPool = heapBufferPool;
Pooled<ByteBuffer> buff = heapBufferPool.allocate();
try {
if (!buff.getResource().hasArray()) {
throw UndertowMessages.MESSAGES.mustProvideHeapBuffer();
}
} finally {
buff.free();
}
}
示例5: dataReady
import org.xnio.Pooled; //导入依赖的package包/类
/**
* Called when data has been read from the underlying channel.
*
* @param headerData The frame header data. This may be null if the data is part of a an existing frame
* @param frameData The frame data
*/
void dataReady(FrameHeaderData headerData, Pooled<ByteBuffer> frameData) {
if(anyAreSet(state, STATE_STREAM_BROKEN)) {
frameData.free();
return;
}
synchronized (lock) {
boolean newData = pendingFrameData.isEmpty();
this.pendingFrameData.add(new FrameData(headerData, frameData));
if (newData) {
if (waiters > 0) {
lock.notifyAll();
}
}
waitingForFrame = false;
}
if (anyAreSet(state, STATE_READS_RESUMED)) {
resumeReadsInternal(true);
}
if(headerData != null) {
currentStreamSize += headerData.getFrameLength();
if(maxStreamSize > 0 && currentStreamSize > maxStreamSize) {
handleStreamTooLarge();
}
}
}
示例6: write
import org.xnio.Pooled; //导入依赖的package包/类
@Override
public int write(final ByteBuffer src) throws IOException {
if(toWrite >= 0 && src.remaining() > toWrite) {
throw WebSocketMessages.MESSAGES.messageOverflow();
}
if(masker == null) {
return super.write(src);
} else {
final Pooled<ByteBuffer> buffer = getChannel().getBufferPool().allocate();
try {
ByteBuffer copy = src.duplicate();
Buffers.copy(buffer.getResource(), copy);
buffer.getResource().flip();
masker.beforeWrite(buffer.getResource(), 0, buffer.getResource().remaining());
int written = super.write(buffer.getResource());
src.position(src.position() + written);
toWrite -= written;
return written;
} finally {
buffer.free();
}
}
}
示例7: handle
import org.xnio.Pooled; //导入依赖的package包/类
@Override
public void handle(final PartHandler handler, final ByteBuffer rawData) throws IOException {
Pooled<ByteBuffer> resource = bufferPool.allocate();
ByteBuffer buf = resource.getResource();
try {
do {
buf.clear();
try {
decoder.decode(rawData, buf);
} catch (IOException e) {
throw new RuntimeException(e);
}
buf.flip();
handler.data(buf);
} while (rawData.hasRemaining());
} finally {
resource.free();
}
}
示例8: setup
import org.xnio.Pooled; //导入依赖的package包/类
public void setup(final StreamSourceChannel channel) {
Pooled<ByteBuffer> resource = bufferPool.allocate();
ByteBuffer buffer = resource.getResource();
try {
int r = 0;
do {
r = channel.read(buffer);
if (r == 0) {
channel.getReadSetter().set(this);
channel.resumeReads();
} else if (r == -1) {
stringDone(string.extract());
IoUtils.safeClose(channel);
} else {
buffer.flip();
string.write(buffer);
}
} while (r > 0);
} catch (IOException e) {
error(e);
} finally {
resource.free();
}
}
示例9: handleEvent
import org.xnio.Pooled; //导入依赖的package包/类
@Override
public void handleEvent(final StreamSourceChannel channel) {
Pooled<ByteBuffer> resource = bufferPool.allocate();
ByteBuffer buffer = resource.getResource();
try {
int r = 0;
do {
r = channel.read(buffer);
if (r == 0) {
return;
} else if (r == -1) {
stringDone(string.extract());
IoUtils.safeClose(channel);
} else {
buffer.flip();
string.write(buffer);
}
} while (r > 0);
} catch (IOException e) {
error(e);
} finally {
resource.free();
}
}
示例10: send
import org.xnio.Pooled; //导入依赖的package包/类
@Override
public void send(final String data, final Charset charset, final IoCallback callback) {
ByteBuffer bytes = ByteBuffer.wrap(data.getBytes(charset));
if (bytes.remaining() == 0) {
callback.onComplete(exchange, this);
} else {
int i = 0;
ByteBuffer[] bufs = null;
while (bytes.hasRemaining()) {
Pooled<ByteBuffer> pooled = exchange.getConnection().getBufferPool().allocate();
if (bufs == null) {
int noBufs = (bytes.remaining() + pooled.getResource().remaining() - 1) / pooled.getResource().remaining(); //round up division trick
pooledBuffers = new Pooled[noBufs];
bufs = new ByteBuffer[noBufs];
}
pooledBuffers[i] = pooled;
bufs[i] = pooled.getResource();
Buffers.copy(pooled.getResource(), bytes);
pooled.getResource().flip();
++i;
}
send(bufs, callback);
}
}
示例11: registerWebSocketChannelListener
import org.xnio.Pooled; //导入依赖的package包/类
private void registerWebSocketChannelListener(WebSocketChannel webSocketChannel) {
ChannelListener<WebSocketChannel> listener = new AbstractReceiveListener() {
@Override
protected void onFullBinaryMessage(WebSocketChannel channel, BufferedBinaryMessage message) throws IOException {
log.log(Level.FINE, "Server received full binary message");
Pooled<ByteBuffer[]> pulledData = message.getData();
try {
ByteBuffer[] resource = pulledData.getResource();
ByteBuffer byteBuffer = WebSockets.mergeBuffers(resource);
String msg = new String(byteBuffer.array());
log.log(Level.FINE, "Sending message to decoder: "+ msg);
writeToDecoder(msg);
}
finally {
pulledData.discard();
}
}
};
webSocketChannel.getReceiveSetter().set(listener);
}
示例12: startWriting
import org.xnio.Pooled; //导入依赖的package包/类
void startWriting() {
Iterator<Pooled<ByteBuffer>> iterator = allocated.iterator();
while (iterator.hasNext()) {
Pooled<ByteBuffer> pooledBuffer = iterator.next();
ByteBuffer byteBuffer = pooledBuffer.getResource();
if (!byteBuffer.hasRemaining()) {
byteBuffer.clear();
pooledBuffer.free();
iterator.remove();
} else {
break;
}
}
Pooled<ByteBuffer> lastPooledBuffer = allocated.peekLast();
if (lastPooledBuffer != null) {
ByteBuffer lastBuffer = lastPooledBuffer.getResource();
if (lastBuffer.limit() < lastBuffer.capacity()) {
currentWriteBuffer = lastBuffer.compact();
}
}
}
示例13: registerWebSocketChannelListener
import org.xnio.Pooled; //导入依赖的package包/类
private void registerWebSocketChannelListener(WebSocketChannel webSocketChannel) {
ChannelListener<WebSocketChannel> listener = new AbstractReceiveListener() {
@Override
protected void onFullBinaryMessage(WebSocketChannel channel, BufferedBinaryMessage message) throws IOException {
log.trace("Server received full binary message");
Pooled<ByteBuffer[]> pulledData = message.getData();
try {
ByteBuffer[] resource = pulledData.getResource();
ByteBuffer byteBuffer = WebSockets.mergeBuffers(resource);
String msg = new String(byteBuffer.array());
log.trace("Sending message to decoder: {}", msg);
writeToDecoder(msg);
} finally {
pulledData.discard();
}
}
};
webSocketChannel.getReceiveSetter().set(listener);
}
示例14: handleFrameData
import org.xnio.Pooled; //导入依赖的package包/类
protected long handleFrameData(Pooled<ByteBuffer> frameData, long frameDataRemaining) {
if(frameDataRemaining > 0 && frameData.getResource().remaining() == frameDataRemaining) {
//there is a null terminator on the end
frameData.getResource().limit(frameData.getResource().limit() - 1);
return frameDataRemaining - 1;
}
return frameDataRemaining;
}
示例15: allocateAll
import org.xnio.Pooled; //导入依赖的package包/类
protected Pooled<ByteBuffer>[] allocateAll(Pooled<ByteBuffer>[] allHeaderBuffers, Pooled<ByteBuffer> currentBuffer) {
Pooled<ByteBuffer>[] ret;
if (allHeaderBuffers == null) {
ret = new Pooled[2];
ret[0] = currentBuffer;
ret[1] = getChannel().getBufferPool().allocate();
} else {
ret = new Pooled[allHeaderBuffers.length + 1];
System.arraycopy(allHeaderBuffers, 0, ret, 0, allHeaderBuffers.length);
ret[ret.length - 1] = getChannel().getBufferPool().allocate();
}
return ret;
}