• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Pooled类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.xnio.Pooled的典型用法代码示例。如果您正苦于以下问题:Java Pooled类的具体用法?Java Pooled怎么用?Java Pooled使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Pooled类属于org.xnio包,在下文中一共展示了Pooled类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:AjpClientChannel.java


示例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;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:HttpResponseConduit.java


示例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();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:SpdyOpenListener.java


示例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();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:SpdyPlainOpenListener.java


示例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();
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:AbstractFramedStreamSourceChannel.java


示例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();
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:WebSocket07FrameSinkChannel.java


示例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();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:MultipartParser.java


示例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();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:StringReadChannelListener.java


示例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();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:StringReadChannelListener.java


示例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);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:AsyncSenderImpl.java


示例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);
}
 
开发者ID:aeshell,项目名称:aesh-readline,代码行数:22,代码来源:WebSocketTtyConnection.java


示例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();
        }
    }
}
 
开发者ID:vkorenev,项目名称:xnio-redis-client,代码行数:22,代码来源:ByteBufferBundle.java


示例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);
}
 
开发者ID:termd,项目名称:termd,代码行数:21,代码来源:WebSocketTtyConnection.java


示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:AjpClientResponseStreamSourceChannel.java


示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:SpdyStreamStreamSinkChannel.java


示例16: getExtraBytes

import org.xnio.Pooled; //导入依赖的package包/类
public Pooled<ByteBuffer> getExtraBytes() {
    if(extraBytes != null && !extraBytes.getResource().hasRemaining()) {
        extraBytes.free();
        extraBytes = null;
        return null;
    }
    return extraBytes;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:AbstractServerConnection.java


示例17: AjpOpenListener

import org.xnio.Pooled; //导入依赖的package包/类
public AjpOpenListener(final Pool<ByteBuffer> pool, final OptionMap undertowOptions) {
    this.undertowOptions = undertowOptions;
    this.bufferPool = pool;
    Pooled<ByteBuffer> buf = pool.allocate();
    this.bufferSize = buf.getResource().remaining();
    buf.free();
    parser = new AjpRequestParser(undertowOptions.get(URL_CHARSET, UTF_8), undertowOptions.get(DECODE_URL, true));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:AjpOpenListener.java


示例18: HttpOpenListener

import org.xnio.Pooled; //导入依赖的package包/类
public HttpOpenListener(final Pool<ByteBuffer> pool, final OptionMap undertowOptions) {
    this.undertowOptions = undertowOptions;
    this.bufferPool = pool;
    Pooled<ByteBuffer> buf = pool.allocate();
    this.bufferSize = buf.getResource().remaining();
    buf.free();
    parser = HttpRequestParser.instance(undertowOptions);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:HttpOpenListener.java


示例19: ungetRequestBytes

import org.xnio.Pooled; //导入依赖的package包/类
/**
 * Pushes back the given data. This should only be used by transfer coding handlers that have read past
 * the end of the request when handling pipelined requests
 *
 * @param unget The buffer to push back
 */
public void ungetRequestBytes(final Pooled<ByteBuffer> unget) {
    if (getExtraBytes() == null) {
        setExtraBytes(unget);
    } else {
        Pooled<ByteBuffer> eb = getExtraBytes();
        ByteBuffer buf = eb.getResource();
        final ByteBuffer ugBuffer = unget.getResource();

        if (ugBuffer.limit() - ugBuffer.remaining() > buf.remaining()) {
            //stuff the existing data after the data we are ungetting
            ugBuffer.compact();
            ugBuffer.put(buf);
            ugBuffer.flip();
            eb.free();
            setExtraBytes(unget);
        } else {
            //TODO: this is horrible, but should not happen often
            final byte[] data = new byte[ugBuffer.remaining() + buf.remaining()];
            int first = ugBuffer.remaining();
            ugBuffer.get(data, 0, ugBuffer.remaining());
            buf.get(data, first, buf.remaining());
            eb.free();
            unget.free();
            final ByteBuffer newBuffer = ByteBuffer.wrap(data);
            setExtraBytes(new ImmediatePooled<>(newBuffer));
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:HttpServerConnection.java


示例20: handleEvent

import org.xnio.Pooled; //导入依赖的package包/类
public void handleEvent(final StreamConnection channel, Pooled<ByteBuffer> buffer) {

        //cool, we have a spdy connection.
        SpdyChannel spdyChannel = new SpdyChannel(channel, bufferPool, buffer, heapBufferPool, false);
        Integer idleTimeout = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT);
        if (idleTimeout != null && idleTimeout > 0) {
            spdyChannel.setIdleTimeout(idleTimeout);
        }

        spdyChannel.getReceiveSetter().set(new SpdyReceiveListener(rootHandler, getUndertowOptions(), bufferSize));
        spdyChannel.resumeReceives();
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:SpdyOpenListener.java



注:本文中的org.xnio.Pooled类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EchoRequestProto类代码示例发布时间:2022-05-22
下一篇:
Java VCFFormatHeaderLine类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap