コード例 #1
0
 /**
  * Registers proto files and marshallers.
  *
  * @param ctx the serialization context
  * @throws org.infinispan.protostream.DescriptorParserException if a proto definition file fails
  *     to parse correctly
  * @throws IOException if proto file registration fails
  */
 public static void registerMarshallers(SerializationContext ctx) throws IOException {
   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 TransactionMarshaller());
 }
  @BeforeClass
  protected void registerProtobufSchema() throws Exception {
    // initialize client-side serialization context
    String authorSchemaFile =
        "/* @Indexed */\n"
            + "message Author {\n"
            + "   required int32 id = 1;\n"
            + "   /* @IndexedField */\n"
            + "   required string name = 2;\n"
            + "}";
    SerializationContext serializationContext =
        ProtoStreamMarshaller.getSerializationContext(remoteCacheManager);
    serializationContext.registerProtoFiles(
        FileDescriptorSource.fromString("author.proto", authorSchemaFile));
    serializationContext.registerMarshaller(
        new MessageMarshaller<Author>() {
          @Override
          public Author readFrom(ProtoStreamReader reader) throws IOException {
            int id = reader.readInt("id");
            String name = reader.readString("name");
            Author author = new Author();
            author.setId(id);
            author.setName(name);
            return author;
          }

          @Override
          public void writeTo(ProtoStreamWriter writer, Author author) throws IOException {
            writer.writeInt("id", author.getId());
            writer.writeString("name", author.getName());
          }

          @Override
          public Class<? extends Author> getJavaClass() {
            return Author.class;
          }

          @Override
          public String getTypeName() {
            return "Author";
          }
        });

    ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
    String memoSchemaFile =
        protoSchemaBuilder.fileName("memo.proto").addClass(Memo.class).build(serializationContext);

    // initialize server-side serialization context
    RemoteCache<String, String> metadataCache =
        remoteCacheManager.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
    metadataCache.put("author.proto", authorSchemaFile);
    metadataCache.put("memo.proto", memoSchemaFile);
    assertFalse(metadataCache.containsKey(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX));
  }
コード例 #3
0
 @Override
 public QueryBuilder<Query> from(Class entityType) {
   String typeName = serializationContext.getMarshaller(entityType).getTypeName();
   return new RemoteQueryBuilder(this, cache, serializationContext, typeName);
 }
コード例 #4
0
 @Override
 public String getTypeNameById(Integer typeId) {
   return delegate.getTypeNameById(typeId);
 }
コード例 #5
0
 @Override
 public <T> BaseMarshaller<T> getMarshaller(Class<T> clazz) {
   return delegate.getMarshaller(clazz);
 }
コード例 #6
0
 @Override
 public <T> BaseMarshaller<T> getMarshaller(String descriptorFullName) {
   return delegate.getMarshaller(descriptorFullName);
 }
コード例 #7
0
 @Override
 public boolean canMarshall(String descriptorFullName) {
   return delegate.canMarshall(descriptorFullName);
 }
コード例 #8
0
 @Override
 public boolean canMarshall(Class clazz) {
   return delegate.canMarshall(clazz);
 }
コード例 #9
0
 @Override
 public EnumDescriptor getEnumDescriptor(String fullName) {
   return delegate.getEnumDescriptor(fullName);
 }
コード例 #10
0
 @Override
 public Descriptor getMessageDescriptor(String fullName) {
   return delegate.getMessageDescriptor(fullName);
 }
コード例 #11
0
 @Override
 public <T> void registerMarshaller(BaseMarshaller<T> marshaller) {
   delegate.registerMarshaller(marshaller);
 }
コード例 #12
0
 @Override
 public Map<String, FileDescriptor> getFileDescriptors() {
   return delegate.getFileDescriptors();
 }
コード例 #13
0
 @Override
 public Configuration getConfiguration() {
   return delegate.getConfiguration();
 }
コード例 #14
0
 @Override
 public Integer getTypeIdByName(String descriptorFullName) {
   return delegate.getTypeIdByName(descriptorFullName);
 }