List of usage examples for io.netty.buffer ByteBuf nioBuffer
public abstract ByteBuffer nioBuffer();
From source file:org.wso2.carbon.transport.http.netty.sender.websocket.WebSocketTargetHandler.java
License:Open Source License
private void notifyPongMessage(PongWebSocketFrame pongWebSocketFrame, ChannelHandlerContext ctx) throws ServerConnectorException { //Control message for WebSocket is Pong Message ByteBuf byteBuf = pongWebSocketFrame.content(); ByteBuffer byteBuffer = byteBuf.nioBuffer(); WebSocketMessageImpl webSocketControlMessage = new WebSocketControlMessageImpl(WebSocketControlSignal.PONG, byteBuffer);/*from w w w . java2 s . com*/ webSocketControlMessage = setupCommonProperties(webSocketControlMessage, ctx); connectorListener.onMessage((WebSocketControlMessage) webSocketControlMessage); }
From source file:qunar.tc.qmq.delay.sync.slave.DispatchLogSyncProcessor.java
License:Apache License
private void appendLogs(long startOffset, long baseOffset, ByteBuf body) { facade.appendDispatchLogData(startOffset, baseOffset, body.nioBuffer()); }
From source file:qunar.tc.qmq.delay.sync.slave.MessageLogSyncProcessor.java
License:Apache License
private void appendLogs(long startOffset, ByteBuf body) { facade.appendMessageLogData(startOffset, body.nioBuffer()); }
From source file:qunar.tc.qmq.store.DataTransfer.java
License:Apache License
public DataTransfer(ByteBuf headerBuffer, SegmentBuffer segmentBuffer, int bufferTotalSize) { this.headerBuffer = headerBuffer; this.segmentBuffer = segmentBuffer; this.bufferTotalSize = bufferTotalSize; this.buffers = new ByteBuffer[2]; this.buffers[0] = headerBuffer.nioBuffer(); this.buffers[1] = segmentBuffer.getBuffer(); }
From source file:qunar.tc.qmq.store.IndexLog.java
License:Apache License
public void appendData(final long startOffset, final ByteBuf input) { if (!input.isReadable()) { checkpointManager.updateMessageIndexCheckpoint(startOffset); return;/*from w w w . j av a 2s .c o m*/ } appendData(startOffset, input.nioBuffer()); }
From source file:qunar.tc.qmq.store.IndexLog.java
License:Apache License
private AppendMessageResult doAppendData(final LogSegment segment, final ByteBuffer data) { int currentPos = segment.getWrotePosition(); final int freeSize = segment.getFileSize() - currentPos; if (data.remaining() <= freeSize) { if (!segment.appendData(data)) throw new RuntimeException("append index data failed."); return new AppendMessageResult<>(SUCCESS, segment.getBaseOffset() + segment.getWrotePosition()); }// w ww .java2 s . c om ByteBuf to = ByteBufAllocator.DEFAULT.ioBuffer(freeSize); try { partialCopy(data, to); if (to.isWritable(Long.BYTES)) { to.writeLong(-1); } fillZero(to); if (!segment.appendData(to.nioBuffer())) throw new RuntimeException("append index data failed."); } finally { ReferenceCountUtil.release(to); } return new AppendMessageResult(END_OF_FILE, segment.getBaseOffset() + segment.getFileSize()); }
From source file:qunar.tc.qmq.sync.SyncActionLogProcessor.java
License:Apache License
@Override public void appendLogs(long startOffset, ByteBuf body) { storage.appendActionLogData(startOffset, body.nioBuffer()); }
From source file:qunar.tc.qmq.sync.SyncMessageLogProcessor.java
License:Apache License
@Override public void appendLogs(long startOffset, ByteBuf body) { storage.appendMessageLogData(startOffset, body.nioBuffer()); }
From source file:ratpack.file.FileIo.java
License:Apache License
/** * Writes the given bytes to the given file, starting at the given position. * Use {@link #open(Path, Set, FileAttribute[])} to create a file promise. * <p>/* w w w .j av a 2s . c o m*/ * The file channel is closed on success or failure. * * @param bytes the bytes to write * @param position the position in the file to start writing * @param file the file to write to * @return a write operation */ public static Operation write(ByteBuf bytes, long position, Promise<? extends AsynchronousFileChannel> file) { return file.flatMap(channel -> Promise.async( down -> channel.write(bytes.nioBuffer(), position, null, new CompletionHandler<Integer, Void>() { @Override public void completed(Integer result, Void attachment) { bytes.readerIndex(bytes.readerIndex() + result); down.success(null); } @Override public void failed(Throwable exc, Void attachment) { down.error(exc); } })).close(bytes::release).close(Blocking.op(((AsynchronousFileChannel) channel)::close))) .operation(); }
From source file:ratpack.file.internal.FileWritingSubscriber.java
License:Apache License
@Override public void onNext(ByteBuf byteBuf) { int toWrite = byteBuf.readableBytes(); if (cancelled || toWrite < 1) { byteBuf.release();// ww w .j ava2 s .c om if (!cancelled) { s.request(1); } return; } Promise.<Integer>async( down -> out.write(byteBuf.nioBuffer(), position, null, new CompletionHandler<Integer, Void>() { @Override public void completed(Integer result, Void attachment) { byteBuf.release(); down.success(result); } @Override public void failed(Throwable exc, Void attachment) { byteBuf.release(); down.error(exc); } })).onError(e -> { cancelled = true; s.cancel(); downstream.error(e); }).then(i -> { position += i; s.request(1); }); }