當前位置: 首頁>>代碼示例>>Java>>正文


Java StreamInput.available方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:AbstractBytesReferenceTestCase.java

示例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");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:TcpTransport.java

示例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
    }
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:49,代碼來源:RequestSender.java


注:本文中的org.elasticsearch.common.io.stream.StreamInput.available方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。