• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SerializationContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.infinispan.protostream.SerializationContext的典型用法代码示例。如果您正苦于以下问题:Java SerializationContext类的具体用法?Java SerializationContext怎么用?Java SerializationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SerializationContext类属于org.infinispan.protostream包,在下文中一共展示了SerializationContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:benemon,项目名称:he-rss-poll,代码行数:26,代码来源:AbstractJDGVerticle.java


示例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);
}
 
开发者ID:infinispan,项目名称:infinispan-kafka,代码行数:23,代码来源:InfinispanTaskTestIT.java


示例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());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:InfinispanRemoteQueryProducerIT.java


示例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);
	} 
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:20,代码来源:AbstractInfinispanManagedConnectionFactory.java


示例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;
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:26,代码来源:ProtoSchemaBuilder.java


示例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;
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:23,代码来源:AnnotationsPerformanceTest.java


示例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;
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:17,代码来源:AnnotationsPerformanceTest.java


示例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();
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:17,代码来源:PerformanceTest.java


示例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);
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:20,代码来源:ProtoSchemaBuilderTest.java


示例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);
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:20,代码来源:ProtoSchemaBuilderTest.java


示例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"));
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:26,代码来源:ProtoSchemaBuilderTest.java


示例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);
    }
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:14,代码来源:ProtobufInitializer.java


示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:InfinispanContinuousQueryIT.java


示例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());
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:10,代码来源:MarshallerRegistration.java


示例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;
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:12,代码来源:AnnotationsPerformanceTest.java


示例16: writeWithProtoStream

import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
private byte[] writeWithProtoStream(SerializationContext ctx, Note note) throws IOException {
   ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
   long tStart = System.nanoTime();
   for (int i = 0; i < NUM_LOOPS; i++) {
      ProtobufUtil.writeTo(ctx, out, note);
      if (i != NUM_LOOPS - 1) {
         out.reset();
      }
   }
   long duration = System.nanoTime() - tStart;
   log.infof("ProtoStream write duration          = %d ns", duration / NUM_LOOPS);
   return out.toByteArray();
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:14,代码来源:AnnotationsPerformanceTest.java


示例17: readWithProtoStream

import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
private void readWithProtoStream(byte[] bytes, long[] result) throws IOException, DescriptorParserException {
   Configuration.Builder cfgBuilder = Configuration.builder().setLogOutOfSequenceReads(false);
   SerializationContext ctx = createContext(cfgBuilder);
   ByteArrayInputStream bais = new ByteArrayInputStream(bytes);

   long tStart = System.nanoTime();
   for (int i = 0; i < NUM_INNER_LOOPS; i++) {
      ProtobufUtil.readFrom(ctx, bais, User.class);
      bais.close();
      bais.reset();
   }

   result[0] = System.nanoTime() - tStart;
   log.infof("ProtoStream read duration           = %d ns", result[0]);
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:16,代码来源:PerformanceTest.java


示例18: testNullFileName

import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@Test
public void testNullFileName() throws Exception {
   exception.expect(ProtoSchemaBuilderException.class);
   exception.expectMessage("fileName cannot be null");

   SerializationContext ctx = createContext();
   ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
   protoSchemaBuilder.addClass(Simple.class).build(ctx);
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:10,代码来源:ProtoSchemaBuilderTest.java


示例19: testNoAnnotations

import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@Test
public void testNoAnnotations() throws Exception {
   exception.expect(ProtoSchemaBuilderException.class);
   exception.expectMessage("Class java.lang.Object does not have any @ProtoField annotated fields. The class should be either annotated or it should have a custom marshaller");

   SerializationContext ctx = createContext();
   ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
   protoSchemaBuilder.fileName("test.proto");
   protoSchemaBuilder.addClass(Object.class).build(ctx);
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:11,代码来源:ProtoSchemaBuilderTest.java


示例20: testDocumentation

import org.infinispan.protostream.SerializationContext; //导入依赖的package包/类
@Test
public void testDocumentation() throws Exception {
   SerializationContext ctx = createContext();

   ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
   String schemaFile = protoSchemaBuilder
         .fileName("test1.proto")
         .packageName("test_package1")
         .addClass(TestEnum.class)
         .addClass(TestClass.class)
         .build(ctx);

   FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test1.proto", schemaFile);
   Map<String, FileDescriptor> fileDescriptors = new SquareProtoParser(ctx.getConfiguration()).parse(fileDescriptorSource);

   FileDescriptor fd = fileDescriptors.get("test1.proto");
   assertNotNull(fd);

   Map<String, EnumDescriptor> enums = new HashMap<>();
   for (EnumDescriptor e : fd.getEnumTypes()) {
      enums.put(e.getFullName(), e);
   }

   Map<String, Descriptor> messages = new HashMap<>();
   for (Descriptor m : fd.getMessageTypes()) {
      messages.put(m.getFullName(), m);
   }

   EnumDescriptor testEnum = enums.get("test_package1.TestEnumABC");
   assertNotNull(testEnum);

   assertEquals("bla bla bla\nand some more bla", testEnum.getDocumentation());
   assertEquals("This should never be read.", testEnum.getValues().get(0).getDocumentation());

   Descriptor testClass = messages.get("test_package1.TestClass");
   assertNotNull(testClass);

   assertEquals("@Indexed()\nbla bla bla\nand some more bla", testClass.getDocumentation());
   assertEquals("The surname, of course", testClass.getFields().get(0).getDocumentation());
}
 
开发者ID:infinispan,项目名称:protostream,代码行数:41,代码来源:ProtoSchemaBuilderTest.java



注:本文中的org.infinispan.protostream.SerializationContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EthernetMatch类代码示例发布时间:2022-05-23
下一篇:
Java GraphDatabaseConfiguration类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap