本文整理汇总了Java中org.elasticsearch.common.io.stream.StreamInput.available方法的典型用法代码示例。如果您正苦于以下问题:Java StreamInput.available方法的具体用法?Java StreamInput.available怎么用?Java StreamInput.available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.io.stream.StreamInput
的用法示例。
在下文中一共展示了StreamInput.available方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStreamInputMarkAndReset
import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testStreamInputMarkAndReset() throws IOException {
int length = randomIntBetween(10, scaledRandomIntBetween(PAGE_SIZE * 2, PAGE_SIZE * 20));
BytesReference pbr = newBytesReference(length);
StreamInput si = pbr.streamInput();
assertNotNull(si);
StreamInput wrap = StreamInput.wrap(BytesReference.toBytes(pbr));
while(wrap.available() > 0) {
if (rarely()) {
wrap.mark(Integer.MAX_VALUE);
si.mark(Integer.MAX_VALUE);
} else if (rarely()) {
wrap.reset();
si.reset();
}
assertEquals(si.readByte(), wrap.readByte());
assertEquals(si.available(), wrap.available());
}
}
示例2: validateRequest
import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
protected void validateRequest(StreamInput stream, long requestId, String action) throws IOException {
final int nextByte = stream.read();
// calling read() is useful to make sure the message is fully read, even if there some kind of EOS marker
if (nextByte != -1) {
throw new IllegalStateException("Message not fully read (request) for requestId [" + requestId + "], action [" + action
+ "], available [" + stream.available() + "]; resetting");
}
}
示例3: processRequests
import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
private void processRequests(final StreamInput streamInput) {
heartbeat = System.currentTimeMillis();
if (terminated) {
IOUtils.closeQuietly(streamInput);
logger.warn("[Sender][" + index + "] Terminate DocIndexer.");
return;
}
requestPosition++;
try {
if (logger.isDebugEnabled()) {
logger.debug("RequestSender(" + index + ") is processing requests.");
}
if (streamInput.available() > 0) {
final short classType = streamInput.readShort();
switch (classType) {
case RequestUtils.TYPE_DELETE:
processDeleteRequest(streamInput);
break;
case RequestUtils.TYPE_DELETE_BY_QUERY:
processDeleteByQueryRequest(streamInput);
break;
case RequestUtils.TYPE_INDEX:
processIndexRequest(streamInput);
break;
case RequestUtils.TYPE_UPDATE:
processUpdateRequest(streamInput);
break;
case RequestUtils.TYPE_UPDATE_BY_QUERY:
processUpdateByQueryRequest(streamInput);
break;
case RequestUtils.TYPE_BULK:
processBulkRequest(streamInput);
break;
default:
throw new ElasticsearchException("Unknown request type: " + classType);
}
} else {
IOUtils.closeQuietly(streamInput);
logger.info("[Sender][{}] Indexed: {}", index, path.toAbsolutePath());
processNext(getNextValue(filePosition));
}
} catch (final Exception e) {
IOUtils.closeQuietly(streamInput);
retryWithError("Failed to access streamInput.", e);
// retry
}
}