本文整理了Java中org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf.readerIndex()
方法的一些代码示例,展示了ByteBuf.readerIndex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.readerIndex()
方法的具体详情如下:
包路径:org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:readerIndex
暂无
代码示例来源:origin: apache/flink
@Override
public long progress() {
return buf.readerIndex();
}
代码示例来源:origin: apache/flink
/**
* Tests server failure serialization.
*/
@Test
public void testServerFailureSerialization() throws Exception {
IllegalStateException cause = new IllegalStateException("Expected test");
ByteBuf buf = MessageSerializer.serializeServerFailure(alloc, cause);
int frameLength = buf.readInt();
assertEquals(MessageType.SERVER_FAILURE, MessageSerializer.deserializeHeader(buf));
Throwable request = MessageSerializer.deserializeServerFailure(buf);
assertEquals(buf.readerIndex(), frameLength + 4);
assertEquals(cause.getClass(), request.getClass());
assertEquals(cause.getMessage(), request.getMessage());
}
代码示例来源:origin: apache/flink
/**
* Tests request failure serialization.
*/
@Test
public void testKvStateRequestFailureSerialization() throws Exception {
long requestId = Integer.MAX_VALUE + 1111222L;
IllegalStateException cause = new IllegalStateException("Expected test");
ByteBuf buf = MessageSerializer.serializeRequestFailure(alloc, requestId, cause);
int frameLength = buf.readInt();
assertEquals(MessageType.REQUEST_FAILURE, MessageSerializer.deserializeHeader(buf));
RequestFailure requestFailure = MessageSerializer.deserializeRequestFailure(buf);
assertEquals(buf.readerIndex(), frameLength + 4);
assertEquals(requestId, requestFailure.getRequestId());
assertEquals(cause.getClass(), requestFailure.getCause().getClass());
assertEquals(cause.getMessage(), requestFailure.getCause().getMessage());
}
代码示例来源:origin: apache/flink
/**
* Tests response serialization with zero-length serialized result.
*/
@Test
public void testResponseSerializationWithZeroLengthSerializedResult() throws Exception {
byte[] serializedResult = new byte[0];
final KvStateResponse response = new KvStateResponse(serializedResult);
final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
ByteBuf buf = MessageSerializer.serializeResponse(alloc, 72727278L, response);
int frameLength = buf.readInt();
assertEquals(MessageType.REQUEST_RESULT, MessageSerializer.deserializeHeader(buf));
assertEquals(72727278L, MessageSerializer.getRequestId(buf));
KvStateResponse responseDeser = serializer.deserializeResponse(buf);
assertEquals(buf.readerIndex(), frameLength + 4);
assertArrayEquals(serializedResult, responseDeser.getContent());
}
代码示例来源:origin: apache/flink
/**
* Tests response serialization.
*/
@Test
public void testResponseSerialization() throws Exception {
long requestId = Integer.MAX_VALUE + 72727278L;
byte[] serializedResult = randomByteArray(1024);
final KvStateResponse response = new KvStateResponse(serializedResult);
final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
ByteBuf buf = MessageSerializer.serializeResponse(alloc, requestId, response);
int frameLength = buf.readInt();
assertEquals(MessageType.REQUEST_RESULT, MessageSerializer.deserializeHeader(buf));
assertEquals(requestId, MessageSerializer.getRequestId(buf));
KvStateResponse responseDeser = serializer.deserializeResponse(buf);
assertEquals(buf.readerIndex(), frameLength + 4);
assertArrayEquals(serializedResult, responseDeser.getContent());
}
代码示例来源:origin: apache/flink
/**
* Tests request serialization with zero-length serialized key and namespace.
*/
@Test
public void testRequestSerializationWithZeroLengthKeyAndNamespace() throws Exception {
long requestId = Integer.MAX_VALUE + 1337L;
KvStateID kvStateId = new KvStateID();
byte[] serializedKeyAndNamespace = new byte[0];
final KvStateInternalRequest request = new KvStateInternalRequest(kvStateId, serializedKeyAndNamespace);
final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
ByteBuf buf = MessageSerializer.serializeRequest(alloc, requestId, request);
int frameLength = buf.readInt();
assertEquals(MessageType.REQUEST, MessageSerializer.deserializeHeader(buf));
assertEquals(requestId, MessageSerializer.getRequestId(buf));
KvStateInternalRequest requestDeser = serializer.deserializeRequest(buf);
assertEquals(buf.readerIndex(), frameLength + 4);
assertEquals(kvStateId, requestDeser.getKvStateId());
assertArrayEquals(serializedKeyAndNamespace, requestDeser.getSerializedKeyAndNamespace());
}
代码示例来源:origin: apache/flink
/**
* Tests request serialization.
*/
@Test
public void testRequestSerialization() throws Exception {
long requestId = Integer.MAX_VALUE + 1337L;
KvStateID kvStateId = new KvStateID();
byte[] serializedKeyAndNamespace = randomByteArray(1024);
final KvStateInternalRequest request = new KvStateInternalRequest(kvStateId, serializedKeyAndNamespace);
final MessageSerializer<KvStateInternalRequest, KvStateResponse> serializer =
new MessageSerializer<>(new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer());
ByteBuf buf = MessageSerializer.serializeRequest(alloc, requestId, request);
int frameLength = buf.readInt();
assertEquals(MessageType.REQUEST, MessageSerializer.deserializeHeader(buf));
assertEquals(requestId, MessageSerializer.getRequestId(buf));
KvStateInternalRequest requestDeser = serializer.deserializeRequest(buf);
assertEquals(buf.readerIndex(), frameLength + 4);
assertEquals(kvStateId, requestDeser.getKvStateId());
assertArrayEquals(serializedKeyAndNamespace, requestDeser.getSerializedKeyAndNamespace());
}
代码示例来源:origin: org.apache.flink/flink-queryable-state-client-java_2.11
@Override
public long progress() {
return buf.readerIndex();
}
代码示例来源:origin: com.alibaba.blink/flink-runtime
private boolean readOrDiscardBufferResponse(ByteBuf data) {
checkState(currentNettyMessage != null && currentNettyMessage instanceof NettyMessage.BufferResponse);
NettyMessage.BufferResponse bufferResponse = (NettyMessage.BufferResponse) currentNettyMessage;
// If current buffer is empty, then no more data to receive
if (bufferResponse.dataBufferSize == 0) {
return true;
}
ByteBuf dataBuffer = bufferResponse.getBuffer();
if (remainingBufferSize < 0) {
remainingBufferSize = bufferResponse.dataBufferSize;
}
if (dataBuffer != null) {
remainingBufferSize -= copyToTargetBuffer(data, dataBuffer, remainingBufferSize);
} else {
int actualBytesToDiscard = Math.min(data.readableBytes(), remainingBufferSize);
data.readerIndex(data.readerIndex() + actualBytesToDiscard);
remainingBufferSize -= actualBytesToDiscard;
}
return remainingBufferSize == 0;
}
代码示例来源:origin: com.alibaba.blink/flink-runtime
static TaskEventRequest readFrom(ByteBuf buffer, ClassLoader classLoader) throws IOException {
// directly deserialize fromNetty's buffer
int length = buffer.readInt();
ByteBuffer serializedEvent = buffer.nioBuffer(buffer.readerIndex(), length);
// assume this event's content is read from the ByteBuf (positions are not shared!)
buffer.readerIndex(buffer.readerIndex() + length);
TaskEvent event =
(TaskEvent) EventSerializer.fromSerializedEvent(serializedEvent, classLoader);
ResultPartitionID partitionId =
new ResultPartitionID(
IntermediateResultPartitionID.fromByteBuf(buffer),
ExecutionAttemptID.fromByteBuf(buffer));
InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
return new TaskEventRequest(event, partitionId, receiverId);
}
}
代码示例来源:origin: org.apache.flink/flink-runtime_2.11
static TaskEventRequest readFrom(ByteBuf buffer, ClassLoader classLoader) throws IOException {
// directly deserialize fromNetty's buffer
int length = buffer.readInt();
ByteBuffer serializedEvent = buffer.nioBuffer(buffer.readerIndex(), length);
// assume this event's content is read from the ByteBuf (positions are not shared!)
buffer.readerIndex(buffer.readerIndex() + length);
TaskEvent event =
(TaskEvent) EventSerializer.fromSerializedEvent(serializedEvent, classLoader);
ResultPartitionID partitionId =
new ResultPartitionID(
IntermediateResultPartitionID.fromByteBuf(buffer),
ExecutionAttemptID.fromByteBuf(buffer));
InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
return new TaskEventRequest(event, partitionId, receiverId);
}
}
代码示例来源:origin: org.apache.flink/flink-runtime
static TaskEventRequest readFrom(ByteBuf buffer, ClassLoader classLoader) throws IOException {
// directly deserialize fromNetty's buffer
int length = buffer.readInt();
ByteBuffer serializedEvent = buffer.nioBuffer(buffer.readerIndex(), length);
// assume this event's content is read from the ByteBuf (positions are not shared!)
buffer.readerIndex(buffer.readerIndex() + length);
TaskEvent event =
(TaskEvent) EventSerializer.fromSerializedEvent(serializedEvent, classLoader);
ResultPartitionID partitionId =
new ResultPartitionID(
IntermediateResultPartitionID.fromByteBuf(buffer),
ExecutionAttemptID.fromByteBuf(buffer));
InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
return new TaskEventRequest(event, partitionId, receiverId);
}
}
代码示例来源:origin: com.alibaba.blink/flink-runtime
private void readRawResponse(FullHttpResponse msg) {
ByteBuf content = msg.content();
JsonNode rawResponse;
try (InputStream in = new ByteBufInputStream(content)) {
rawResponse = objectMapper.readTree(in);
LOG.debug("Received response {}.", rawResponse);
} catch (JsonParseException je) {
LOG.error("Response was not valid JSON.", je);
// let's see if it was a plain-text message instead
content.readerIndex(0);
try (ByteBufInputStream in = new ByteBufInputStream(content)) {
byte[] data = new byte[in.available()];
in.readFully(data);
String message = new String(data);
LOG.error("Unexpected plain-text response: {}", message);
jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, but plain-text: " + message, je, msg.getStatus()));
} catch (IOException e) {
jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, nor plain-text.", je, msg.getStatus()));
}
return;
} catch (IOException ioe) {
LOG.error("Response could not be read.", ioe);
jsonFuture.completeExceptionally(new RestClientException("Response could not be read.", ioe, msg.getStatus()));
return;
}
jsonFuture.complete(new JsonResponse(rawResponse, msg.getStatus()));
}
}
代码示例来源:origin: org.apache.flink/flink-runtime_2.11
private void readRawResponse(FullHttpResponse msg) {
ByteBuf content = msg.content();
JsonNode rawResponse;
try (InputStream in = new ByteBufInputStream(content)) {
rawResponse = objectMapper.readTree(in);
LOG.debug("Received response {}.", rawResponse);
} catch (JsonProcessingException je) {
LOG.error("Response was not valid JSON.", je);
// let's see if it was a plain-text message instead
content.readerIndex(0);
try (ByteBufInputStream in = new ByteBufInputStream(content)) {
byte[] data = new byte[in.available()];
in.readFully(data);
String message = new String(data);
LOG.error("Unexpected plain-text response: {}", message);
jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, but plain-text: " + message, je, msg.getStatus()));
} catch (IOException e) {
jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, nor plain-text.", je, msg.getStatus()));
}
return;
} catch (IOException ioe) {
LOG.error("Response could not be read.", ioe);
jsonFuture.completeExceptionally(new RestClientException("Response could not be read.", ioe, msg.getStatus()));
return;
}
jsonFuture.complete(new JsonResponse(rawResponse, msg.getStatus()));
}
}
代码示例来源:origin: org.apache.flink/flink-runtime
private void readRawResponse(FullHttpResponse msg) {
ByteBuf content = msg.content();
JsonNode rawResponse;
try (InputStream in = new ByteBufInputStream(content)) {
rawResponse = objectMapper.readTree(in);
LOG.debug("Received response {}.", rawResponse);
} catch (JsonProcessingException je) {
LOG.error("Response was not valid JSON.", je);
// let's see if it was a plain-text message instead
content.readerIndex(0);
try (ByteBufInputStream in = new ByteBufInputStream(content)) {
byte[] data = new byte[in.available()];
in.readFully(data);
String message = new String(data);
LOG.error("Unexpected plain-text response: {}", message);
jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, but plain-text: " + message, je, msg.getStatus()));
} catch (IOException e) {
jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, nor plain-text.", je, msg.getStatus()));
}
return;
} catch (IOException ioe) {
LOG.error("Response could not be read.", ioe);
jsonFuture.completeExceptionally(new RestClientException("Response could not be read.", ioe, msg.getStatus()));
return;
}
jsonFuture.complete(new JsonResponse(rawResponse, msg.getStatus()));
}
}
内容来源于网络,如有侵权,请联系作者删除!