本文整理汇总了Java中org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput类的典型用法代码示例。如果您正苦于以下问题:Java NamedWriteableAwareStreamInput类的具体用法?Java NamedWriteableAwareStreamInput怎么用?Java NamedWriteableAwareStreamInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamedWriteableAwareStreamInput类属于org.elasticsearch.common.io.stream包,在下文中一共展示了NamedWriteableAwareStreamInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSerialization
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
public void testSerialization() throws Exception {
ShardSearchTransportRequest shardSearchTransportRequest = createShardSearchTransportRequest();
try (BytesStreamOutput output = new BytesStreamOutput()) {
shardSearchTransportRequest.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
ShardSearchTransportRequest deserializedRequest = new ShardSearchTransportRequest();
deserializedRequest.readFrom(in);
assertEquals(deserializedRequest.scroll(), shardSearchTransportRequest.scroll());
assertEquals(deserializedRequest.filteringAliases(), shardSearchTransportRequest.filteringAliases());
assertArrayEquals(deserializedRequest.indices(), shardSearchTransportRequest.indices());
assertArrayEquals(deserializedRequest.types(), shardSearchTransportRequest.types());
assertEquals(deserializedRequest.indicesOptions(), shardSearchTransportRequest.indicesOptions());
assertEquals(deserializedRequest.isProfile(), shardSearchTransportRequest.isProfile());
assertEquals(deserializedRequest.nowInMillis(), shardSearchTransportRequest.nowInMillis());
assertEquals(deserializedRequest.source(), shardSearchTransportRequest.source());
assertEquals(deserializedRequest.searchType(), shardSearchTransportRequest.searchType());
assertEquals(deserializedRequest.shardId(), shardSearchTransportRequest.shardId());
assertEquals(deserializedRequest.numberOfShards(), shardSearchTransportRequest.numberOfShards());
assertEquals(deserializedRequest.cacheKey(), shardSearchTransportRequest.cacheKey());
assertNotSame(deserializedRequest, shardSearchTransportRequest);
assertEquals(deserializedRequest.filteringAliases(), shardSearchTransportRequest.filteringAliases());
assertEquals(deserializedRequest.indexBoost(), shardSearchTransportRequest.indexBoost(), 0.0f);
}
}
}
示例2: testSerialize50RequestForIndexBoost
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
public void testSerialize50RequestForIndexBoost() throws IOException {
BytesArray requestBytes = new BytesArray(Base64.getDecoder()
// this is a base64 encoded request generated with the same input
.decode("AAZpbmRleDEWTjEyM2trbHFUT21XZDY1Z2VDYlo5ZwABBAABAAIA/wD/////DwABBmluZGV4MUAAAAAAAAAAAP////8PAAAAAAAAAgAAAA" +
"AAAPa/q8mOKwIAJg=="));
try (StreamInput in = new NamedWriteableAwareStreamInput(requestBytes.streamInput(), namedWriteableRegistry)) {
in.setVersion(Version.V_5_0_0);
ShardSearchTransportRequest readRequest = new ShardSearchTransportRequest();
readRequest.readFrom(in);
assertEquals(0, in.available());
assertEquals(2.0f, readRequest.indexBoost(), 0);
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(Version.V_5_0_0);
readRequest.writeTo(output);
assertEquals(output.bytes().toBytesRef(), requestBytes.toBytesRef());
}
}
示例3: testSerialize
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
public void testSerialize() throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
ExplainRequest request = new ExplainRequest("index", "type", "id");
request.fetchSourceContext(new FetchSourceContext(true, new String[]{"field1.*"}, new String[] {"field2.*"}));
request.filteringAlias(new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}));
request.preference("the_preference");
request.query(QueryBuilders.termQuery("field", "value"));
request.storedFields(new String[] {"field1", "field2"});
request.routing("some_routing");
request.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
ExplainRequest readRequest = new ExplainRequest();
readRequest.readFrom(in);
assertEquals(request.filteringAlias(), readRequest.filteringAlias());
assertArrayEquals(request.storedFields(), readRequest.storedFields());
assertEquals(request.preference(), readRequest.preference());
assertEquals(request.query(), readRequest.query());
assertEquals(request.routing(), readRequest.routing());
assertEquals(request.fetchSourceContext(), readRequest.fetchSourceContext());
}
}
}
示例4: testSerializeRequest
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
public void testSerializeRequest() throws IOException {
ClusterRerouteRequest req = new ClusterRerouteRequest();
req.setRetryFailed(randomBoolean());
req.dryRun(randomBoolean());
req.explain(randomBoolean());
req.add(new AllocateEmptyPrimaryAllocationCommand("foo", 1, "bar", randomBoolean()));
req.timeout(TimeValue.timeValueMillis(randomIntBetween(0, 100)));
BytesStreamOutput out = new BytesStreamOutput();
req.writeTo(out);
BytesReference bytes = out.bytes();
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(NetworkModule.getNamedWriteables());
StreamInput wrap = new NamedWriteableAwareStreamInput(bytes.streamInput(),
namedWriteableRegistry);
ClusterRerouteRequest deserializedReq = new ClusterRerouteRequest();
deserializedReq.readFrom(wrap);
assertEquals(req.isRetryFailed(), deserializedReq.isRetryFailed());
assertEquals(req.dryRun(), deserializedReq.dryRun());
assertEquals(req.explain(), deserializedReq.explain());
assertEquals(req.timeout(), deserializedReq.timeout());
assertEquals(1, deserializedReq.getCommands().commands().size()); // allocation commands have their own tests
assertEquals(req.getCommands().commands().size(), deserializedReq.getCommands().commands().size());
}
示例5: testSerialize
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
public void testSerialize() throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");
validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
validateQueryRequest.rewrite(true);
validateQueryRequest.explain(false);
validateQueryRequest.types("type1", "type2");
ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1),
new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] {"alias0", "alias1"}), validateQueryRequest);
request.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest();
readRequest.readFrom(in);
assertEquals(request.filteringAliases(), readRequest.filteringAliases());
assertArrayEquals(request.types(), readRequest.types());
assertEquals(request.explain(), readRequest.explain());
assertEquals(request.query(), readRequest.query());
assertEquals(request.rewrite(), readRequest.rewrite());
assertEquals(request.shardId(), readRequest.shardId());
}
}
}
示例6: assertSerialization
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
/**
* Serialize the given query builder and asserts that both are equal
*/
protected static QueryBuilder assertSerialization(QueryBuilder testQuery) throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.writeNamedWriteable(testQuery);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), serviceHolder.namedWriteableRegistry)) {
QueryBuilder deserializedQuery = in.readNamedWriteable(QueryBuilder.class);
assertEquals(testQuery, deserializedQuery);
assertEquals(testQuery.hashCode(), deserializedQuery.hashCode());
assertNotSame(testQuery, deserializedQuery);
return deserializedQuery;
}
}
}
示例7: copyWriteable
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
/**
* Create a copy of an original {@link Writeable} object by running it through a {@link BytesStreamOutput} and
* reading it in again using a provided {@link Writeable.Reader}. The stream that is wrapped around the {@link StreamInput}
* potentially need to use a {@link NamedWriteableRegistry}, so this needs to be provided too (although it can be
* empty if the object that is streamed doesn't contain any {@link NamedWriteable} objects itself.
*/
public static <T extends Writeable> T copyWriteable(T original, NamedWriteableRegistry namedWritabelRegistry,
Writeable.Reader<T> reader) throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
original.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWritabelRegistry)) {
return reader.read(in);
}
}
}
示例8: copyInstance
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
/**
* Round trip {@code instance} through binary serialization, setting the wire compatibility version to {@code version}.
*/
protected T copyInstance(T instance, Version version) throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.setVersion(version);
instance.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(),
getNamedWriteableRegistry())) {
in.setVersion(version);
T newInstance = createBlankInstance();
newInstance.readFrom(in);
return newInstance;
}
}
}
示例9: copyInstance
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
private T copyInstance(T instance) throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
instance.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(),
getNamedWriteableRegistry())) {
return instanceReader().read(in);
}
}
}
示例10: copyInstance
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
/**
* Simulates sending diffs over the wire
*/
public static <T extends Writeable> T copyInstance(T diffs, NamedWriteableRegistry namedWriteableRegistry,
Reader<T> reader) throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
diffs.writeTo(output);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
return reader.read(in);
}
}
}
示例11: marshal
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
/**
* Since custom metadata can be loaded by a plugin class loader that resides in a sub-node, we need to
* marshal this object into something the tribe node can work with
*/
private MetaData.Custom marshal(MetaData.Custom custom) {
try (BytesStreamOutput bytesStreamOutput = new BytesStreamOutput()){
bytesStreamOutput.writeNamedWriteable(custom);
try(StreamInput input = bytesStreamOutput.bytes().streamInput()) {
StreamInput namedInput = new NamedWriteableAwareStreamInput(input, namedWriteableRegistry);
MetaData.Custom marshaled = namedInput.readNamedWriteable(MetaData.Custom.class);
return marshaled;
}
} catch (IOException ex) {
throw new IllegalStateException("cannot marshal object with type " + custom.getWriteableName() + " to tribe node");
}
}
示例12: testBinaryRoundTrip
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
public void testBinaryRoundTrip() throws IOException {
NamedWriteableRegistry registry = new NamedWriteableRegistry(Collections.singletonList(
new NamedWriteableRegistry.Entry(Task.Status.class, RawTaskStatus.NAME, RawTaskStatus::new)));
TaskResult result = randomTaskResult();
TaskResult read;
try (BytesStreamOutput out = new BytesStreamOutput()) {
result.writeTo(out);
try (StreamInput in = new NamedWriteableAwareStreamInput(out.bytes().streamInput(), registry)) {
read = new TaskResult(in);
}
} catch (IOException e) {
throw new IOException("Error processing [" + result + "]", e);
}
assertEquals(result, read);
}
示例13: testSerialization
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
/**
* Test serialization and deserialization of the test AggregatorFactory.
*/
public void testSerialization() throws IOException {
AF testAgg = createTestAggregatorFactory();
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.writeNamedWriteable(testAgg);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
PipelineAggregationBuilder deserializedQuery = in.readNamedWriteable(PipelineAggregationBuilder.class);
assertEquals(deserializedQuery, testAgg);
assertEquals(deserializedQuery.hashCode(), testAgg.hashCode());
assertNotSame(deserializedQuery, testAgg);
}
}
}
示例14: copyAggregation
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
private AF copyAggregation(AF agg) throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.writeNamedWriteable(agg);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
@SuppressWarnings("unchecked")
AF secondAgg = (AF) in.readNamedWriteable(PipelineAggregationBuilder.class);
return secondAgg;
}
}
}
示例15: testSerialization
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; //导入依赖的package包/类
/**
* Test serialization and deserialization of the test AggregatorFactory.
*/
public void testSerialization() throws IOException {
AB testAgg = createTestAggregatorBuilder();
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.writeNamedWriteable(testAgg);
try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
AggregationBuilder deserialized = in.readNamedWriteable(AggregationBuilder.class);
assertEquals(testAgg, deserialized);
assertEquals(testAgg.hashCode(), deserialized.hashCode());
assertNotSame(testAgg, deserialized);
}
}
}