org.elasticsearch.common.io.stream.InputStreamStreamInput Java Examples

The following examples show how to use org.elasticsearch.common.io.stream.InputStreamStreamInput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockTcpTransport.java    From crate with Apache License 2.0 6 votes vote down vote up
void loopRead(Executor executor) {
    executor.execute(new AbstractRunnable() {
        @Override
        public void onFailure(Exception e) {
            if (isOpen.get()) {
                try {
                    onException(MockChannel.this, e);
                } catch (Exception ex) {
                    logger.warn("failed on handling exception", ex);
                    IOUtils.closeWhileHandlingException(MockChannel.this); // pure paranoia
                }
            }
        }

        @Override
        protected void doRun() throws Exception {
            StreamInput input = new InputStreamStreamInput(new BufferedInputStream(activeChannel.getInputStream()));
            // There is a (slim) chance that we get interrupted right after a loop iteration, so check explicitly
            while (isOpen.get() && !Thread.currentThread().isInterrupted()) {
                cancellableThreads.executeIO(() -> readMessage(MockChannel.this, input));
            }
        }
    });
}
 
Example #2
Source File: SslContextProviderService.java    From crate with Apache License 2.0 6 votes vote down vote up
public boolean didChange() throws IOException {
    FileTime lastModifiedTime = Files.getLastModifiedTime(path);
    boolean changed = false;
    if (!lastModifiedTime.equals(this.lastModifiedTime)) {
        this.lastModifiedTime = lastModifiedTime;
        changed = true;
    }
    try (var in = new BufferedChecksumStreamInput(new InputStreamStreamInput(Files.newInputStream(path)), path.toString())) {
        long checksum = in.getChecksum();
        if (checksum != this.checksum) {
            this.checksum = checksum;
            changed = true;
        }
    }
    return changed;
}
 
Example #3
Source File: AnomalyResultResponse.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public static AnomalyResultResponse fromActionResponse(final ActionResponse actionResponse) {
    if (actionResponse instanceof AnomalyResultResponse) {
        return (AnomalyResultResponse) actionResponse;
    }

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) {
        actionResponse.writeTo(osso);
        try (InputStreamStreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray()))) {
            return new AnomalyResultResponse(input);
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("failed to parse ActionResponse into AnomalyResultResponse", e);
    }
}
 
Example #4
Source File: StopDetectorResponse.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public static StopDetectorResponse fromActionResponse(final ActionResponse actionResponse) {
    if (actionResponse instanceof StopDetectorResponse) {
        return (StopDetectorResponse) actionResponse;
    }

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) {
        actionResponse.writeTo(osso);
        try (InputStreamStreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray()))) {
            return new StopDetectorResponse(input);
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("failed to parse ActionResponse into StopDetectorResponse", e);
    }
}
 
Example #5
Source File: AnomalyResultRequest.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public static AnomalyResultRequest fromActionRequest(final ActionRequest actionRequest) {
    if (actionRequest instanceof AnomalyResultRequest) {
        return (AnomalyResultRequest) actionRequest;
    }

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) {
        actionRequest.writeTo(osso);
        try (StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray()))) {
            return new AnomalyResultRequest(input);
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("failed to parse ActionRequest into AnomalyResultRequest", e);
    }
}
 
Example #6
Source File: StopDetectorRequest.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public static StopDetectorRequest fromActionRequest(final ActionRequest actionRequest) {
    if (actionRequest instanceof StopDetectorRequest) {
        return (StopDetectorRequest) actionRequest;
    }

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) {
        actionRequest.writeTo(osso);
        try (StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray()))) {
            return new StopDetectorRequest(input);
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("failed to parse ActionRequest into StopDetectorRequest", e);
    }
}
 
Example #7
Source File: SslContextProviderService.java    From crate with Apache License 2.0 5 votes vote down vote up
public static FingerPrint create(Path path) {
    try (var in = new BufferedChecksumStreamInput(new InputStreamStreamInput(Files.newInputStream(path)), path.toString())) {
        long checksum = in.getChecksum();
        FileTime lastModifiedTime = Files.getLastModifiedTime(path);
        return new FingerPrint(path, lastModifiedTime, checksum);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #8
Source File: NodeStatsContextTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testStreamContext() throws Exception {
    NodeStatsContext ctx1 = new NodeStatsContext(true);
    ctx1.id("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18");
    ctx1.name("crate1");
    ctx1.hostname("crate1.example.com");
    ctx1.timestamp(100L);
    ctx1.version(Version.CURRENT);
    ctx1.build(Build.CURRENT);
    ctx1.httpPort(4200);
    ctx1.transportPort(4300);
    ctx1.restUrl("10.0.0.1:4200");
    ctx1.jvmStats(JvmStats.jvmStats());
    ctx1.osInfo(DummyOsInfo.INSTANCE);
    ProcessProbe processProbe = ProcessProbe.getInstance();
    ctx1.processStats(processProbe.processStats());
    OsProbe osProbe = OsProbe.getInstance();
    ctx1.osStats(osProbe.osStats());
    ctx1.extendedOsStats(extendedNodeInfo.osStats());
    ctx1.threadPools(threadPool.stats());
    ctx1.clusterStateVersion(10L);

    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    StreamOutput out = new OutputStreamStreamOutput(outBuffer);
    ctx1.writeTo(out);

    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    NodeStatsContext ctx2 = new NodeStatsContext(in, true);

    assertThat(ctx1.id(), is(ctx2.id()));
    assertThat(ctx1.name(), is(ctx2.name()));
    assertThat(ctx1.hostname(), is(ctx2.hostname()));
    assertThat(ctx1.timestamp(), is(100L));
    assertThat(ctx1.version(), is(ctx2.version()));
    assertThat(ctx1.build().hash(), is(ctx2.build().hash()));
    assertThat(ctx1.restUrl(), is(ctx2.restUrl()));
    assertThat(ctx1.httpPort(), is(ctx2.httpPort()));
    assertThat(ctx1.transportPort(), is(ctx2.transportPort()));
    assertThat(ctx1.pgPort(), is(ctx2.pgPort()));
    assertThat(ctx1.jvmStats().getTimestamp(), is(ctx2.jvmStats().getTimestamp()));
    assertThat(ctx1.osInfo().getArch(), is(ctx2.osInfo().getArch()));
    assertThat(ctx1.processStats().getTimestamp(), is(ctx2.processStats().getTimestamp()));
    assertThat(ctx1.osStats().getTimestamp(), is(ctx2.osStats().getTimestamp()));
    assertThat(ctx1.extendedOsStats().uptime(), is(ctx2.extendedOsStats().uptime()));
    assertThat(ctx1.threadPools().iterator().next().getActive(), is(ctx2.threadPools().iterator().next().getActive()));
    assertThat(ctx1.clusterStateVersion(), is(ctx2.clusterStateVersion()));
}