本文整理汇总了Java中org.infinispan.protostream.SerializationContext类的典型用法代码示例。如果您正苦于以下问题:Java SerializationContext类的具体用法?Java SerializationContext怎么用?Java SerializationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializationContext类属于org.infinispan.protostream包,在下文中一共展示了SerializationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerProtoBufSchema
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
private void registerProtoBufSchema() {
SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(cacheManager);
String generatedSchema = null;
try {
ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
generatedSchema = protoSchemaBuilder.fileName("heschema.proto").packageName("model")
.addClass(HEElementModel.class).addClass(HEElementCategoryModel.class).build(serCtx);
// register the schemas with the server too
RemoteCache<String, String> metadataCache = cacheManager
.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put("heschema.proto", generatedSchema);
} catch (Exception e1) {
StringBuilder sb = new StringBuilder();
sb.append("No schema generated because of Exception");
log.error(sb.toString(), e1);
}
log.debug(generatedSchema);
}
示例2: setUp
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@Before
public void setUp() {
ConfigurationBuilder builder = new ConfigurationBuilder().addServer().host("localhost").port(11222)
.marshaller(new ProtoStreamMarshaller());
cacheManager = new RemoteCacheManager(builder.build());
SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(cacheManager);
ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
String memoSchemaFile = null;
try {
memoSchemaFile = protoSchemaBuilder.fileName("file.proto").packageName("test").addClass(Author.class)
.build(serCtx);
} catch (ProtoSchemaBuilderException | IOException e) {
e.printStackTrace();
}
// register the schemas with the server too
RemoteCache<String, String> metadataCache = cacheManager
.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put("file.proto", memoSchemaFile);
}
示例3: doPreSetup
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@Override
protected void doPreSetup() throws IOException {
ConfigurationBuilder builder = new ConfigurationBuilder()
.addServer()
.host("localhost")
.port(11222)
.marshaller(new ProtoStreamMarshaller());
manager = new RemoteCacheManager(builder.build());
RemoteCache<String, String> metadataCache = manager
.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache
.put("sample_bank_account/bank.proto",
Util.read(InfinispanRemoteQueryProducerIT.class
.getResourceAsStream("/sample_bank_account/bank.proto")));
MarshallerRegistration.registerMarshallers(ProtoStreamMarshaller
.getSerializationContext(manager));
SerializationContext serCtx = ProtoStreamMarshaller
.getSerializationContext(manager);
serCtx.registerProtoFiles(FileDescriptorSource
.fromResources("/sample_bank_account/bank.proto"));
serCtx.registerMarshaller(new UserMarshaller());
serCtx.registerMarshaller(new GenderMarshaller());
}
示例4: registerMarshallers
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void registerMarshallers(SerializationContext ctx, ClassLoader cl) throws ResourceException {
try {
FileDescriptorSource fds = new FileDescriptorSource();
fds.addProtoFile("protofile", cl.getResourceAsStream(getProtobufDefinitionFile() ) );
ctx.registerProtoFiles( fds );
List<Class<?>> registeredClasses = methodUtil.getRegisteredClasses();
for (Class clz:registeredClasses) {
BaseMarshaller m = messageMarshallerMap.get(clz.getName());
ctx.registerMarshaller(m);
}
} catch (IOException e) {
throw new ResourceException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25032), e);
}
}
示例5: build
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
/**
* Builds the Protocol Buffers schema file defining the types and generates marshaller implementations for these
* types and registers everything with the given {@link SerializationContext}.
*
* @param serializationContext
* @return the generated Protocol Buffers schema file
* @throws ProtoSchemaBuilderException
* @throws IOException
*/
public String build(SerializationContext serializationContext) throws ProtoSchemaBuilderException, IOException {
if (fileName == null) {
throw new ProtoSchemaBuilderException("fileName cannot be null");
}
if (classes.isEmpty()) {
throw new ProtoSchemaBuilderException("At least one class must be specified");
}
String schemaFile = new ProtoSchemaGenerator(serializationContext, fileName, packageName, classes)
.generateAndRegister();
fileName = null;
packageName = null;
classes.clear();
return schemaFile;
}
示例6: createCtxWithHandWrittenMarshaller
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
private SerializationContext createCtxWithHandWrittenMarshaller() throws IOException {
Configuration.Builder cfgBuilder = Configuration.builder()
.setLogOutOfSequenceWrites(false)
.setLogOutOfSequenceReads(false);
SerializationContext ctx = createContext(cfgBuilder);
String file = " package sample_bank_account;\n" +
"import \"sample_bank_account/bank.proto\";\n" +
"message Note {\n" +
" optional string text = 1;\n" +
" optional User author = 2;\n" +
" optional Note note = 3;\n" +
" repeated Note notes = 4;\n" +
" optional uint64 creationDate = 5 [default = 0];\n" +
" optional bytes digest = 6;\n" +
"}\n";
ctx.registerProtoFiles(FileDescriptorSource.fromString("note.proto", file));
ctx.registerMarshaller(new UserMarshaller());
ctx.registerMarshaller(new NoteMarshaller());
return ctx;
}
示例7: createCtxWithGeneratedMarshaller
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
private SerializationContext createCtxWithGeneratedMarshaller() throws IOException {
Configuration.Builder cfgBuilder = Configuration.builder()
.setLogOutOfSequenceWrites(false)
.setLogOutOfSequenceReads(false);
SerializationContext ctx = createContext(cfgBuilder);
ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
protoSchemaBuilder
.fileName("note.proto")
.packageName("sample_bank_account2")
.addClass(User.class)
.addClass(Note.class)
.build(ctx);
return ctx;
}
示例8: writeWithProtoStream
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
private byte[] writeWithProtoStream(User user, long[] result) throws IOException, DescriptorParserException {
Configuration.Builder cfgBuilder = Configuration.builder().setLogOutOfSequenceWrites(false);
SerializationContext ctx = createContext(cfgBuilder);
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
long tStart = System.nanoTime();
for (int i = 0; i < NUM_INNER_LOOPS; i++) {
ProtobufUtil.writeTo(ctx, out, user);
if (i != NUM_INNER_LOOPS - 1) {
out.reset();
}
}
result[0] = System.nanoTime() - tStart;
log.infof("ProtoStream write duration = %d ns", result[0]);
return out.toByteArray();
}
示例9: testGeneration2
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@Test
public void testGeneration2() throws Exception {
SerializationContext ctx = createContext();
ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
protoSchemaBuilder
.fileName("test.proto")
.packageName("test_package")
.addClass(TestArraysAndCollectionsClass.class)
.build(ctx);
assertTrue(ctx.canMarshall(TestArraysAndCollectionsClass.class));
assertTrue(ctx.canMarshall("test_package.TestArraysAndCollectionsClass"));
TestArraysAndCollectionsClass testObject = new TestArraysAndCollectionsClass();
byte[] bytes = ProtobufUtil.toWrappedByteArray(ctx, testObject);
Object unmarshalled = ProtobufUtil.fromWrappedByteArray(ctx, bytes);
assertTrue(unmarshalled instanceof TestArraysAndCollectionsClass);
}
示例10: testGeneration3
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@Test
public void testGeneration3() throws Exception {
SerializationContext ctx = createContext();
ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
protoSchemaBuilder
.fileName("test.proto")
.packageName("test_package")
.addClass(TestArraysAndCollectionsClass2.class)
.build(ctx);
assertTrue(ctx.canMarshall(TestArraysAndCollectionsClass2.class));
assertTrue(ctx.canMarshall("test_package.TestArraysAndCollectionsClass2"));
TestArraysAndCollectionsClass2 testObject = new TestArraysAndCollectionsClass2();
byte[] bytes = ProtobufUtil.toWrappedByteArray(ctx, testObject);
Object unmarshalled = ProtobufUtil.fromWrappedByteArray(ctx, bytes);
assertTrue(unmarshalled instanceof TestArraysAndCollectionsClass2);
}
示例11: testTwoFilesGeneration
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@Test
public void testTwoFilesGeneration() throws Exception {
SerializationContext ctx = createContext();
ProtoSchemaBuilder protoSchemaBuilder1 = new ProtoSchemaBuilder();
protoSchemaBuilder1
.fileName("test1.proto")
.packageName("test_package1")
.addClass(TestEnum.class)
.build(ctx);
assertTrue(ctx.canMarshall(TestEnum.class));
assertTrue(ctx.canMarshall("test_package1.TestEnumABC"));
ProtoSchemaBuilder protoSchemaBuilder2 = new ProtoSchemaBuilder();
protoSchemaBuilder2
.fileName("test2.proto")
.packageName("test_package2")
.addClass(TestClass.class)
.build(ctx);
assertTrue(ctx.canMarshall(TestClass.class));
assertTrue(ctx.canMarshall("test_package2.TestClass"));
assertFalse(ctx.canMarshall("test_package2.TestEnumABC"));
}
示例12: startInternal
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
protected void startInternal() throws Exception {
SerializationContext serializationContext = ProtoStreamMarshaller.getSerializationContext(remoteCacheManager);
String protoFile = builder.build(serializationContext);
//initialize server-side serialization context
RemoteCache<String, String> metadataCache = remoteCacheManager.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put(fileName, protoFile);
Object error = metadataCache.get(fileName + ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX);
if (error != null) {
throw new IllegalStateException("Protobuf metadata failed: " + error);
}
}
示例13: doPreSetup
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@Override
protected void doPreSetup() throws IOException {
ConfigurationBuilder builder = new ConfigurationBuilder()
.addServer()
.host("localhost")
.port(11222)
.marshaller(new ProtoStreamMarshaller());
manager = new RemoteCacheManager(builder.build());
RemoteCache<String, String> metadataCache = manager.getCache(
ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put(
"sample_bank_account/bank.proto",
Util.read(InfinispanContinuousQueryIT.class.getResourceAsStream("/sample_bank_account/bank.proto")));
MarshallerRegistration.registerMarshallers(ProtoStreamMarshaller.getSerializationContext(manager));
SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(manager);
serCtx.registerProtoFiles(FileDescriptorSource.fromResources("/sample_bank_account/bank.proto"));
serCtx.registerMarshaller(new UserMarshaller());
serCtx.registerMarshaller(new GenderMarshaller());
// pre-load data
cache = manager.getCache("remote_query");
cache.clear();
}
示例14: registerMarshallers
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
public static void registerMarshallers(SerializationContext ctx) throws IOException, DescriptorParserException {
ctx.registerProtoFiles(FileDescriptorSource.fromResources(PROTOBUF_RES));
ctx.registerMarshaller(new UserMarshaller());
ctx.registerMarshaller(new GenderMarshaller());
ctx.registerMarshaller(new AddressMarshaller());
ctx.registerMarshaller(new AccountMarshaller());
ctx.registerMarshaller(new LimitsMarshaller());
ctx.registerMarshaller(new TransactionMarshaller());
}
示例15: readWithProtoStream
import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
private long readWithProtoStream(SerializationContext ctx, byte[] bytes) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
long tStart = System.nanoTime();
for (int i = 0; i < NUM_LOOPS; i++) {
ProtobufUtil.readFrom(ctx, bais, Note.class);
bais.close();
bais.reset();
}
long duration = System.nanoTime() - tStart;
return duration / NUM_LOOPS;
}