org.infinispan.protostream.SerializationContext Java Examples

The following examples show how to use org.infinispan.protostream.SerializationContext. 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: HotRodSearchClient.java    From apicurio-registry with Apache License 2.0 6 votes vote down vote up
private void registerProto(boolean reset, String... protoKeys) {
    RemoteCache<Object, Object> cache = manager.getCache(PROTO_CACHE);
    if (cache == null) {
        throw new IllegalStateException(String.format("Missing %s cache!", PROTO_CACHE));
    }

    SerializationContext ctx = MarshallerUtil.getSerializationContext(manager);
    FileDescriptorSource fds = new FileDescriptorSource();
    for (String protoKey : protoKeys) {
        if (reset || !cache.containsKey(protoKey)) {
            String protoContent = IoUtil.toString(getClass().getResourceAsStream("/" + protoKey));
            log.info(String.format("Using proto schema: %s%n%s", protoKey, protoContent));
            fds.addProtoFile(protoKey, protoContent);
            cache.put(protoKey, protoContent);
        }
    }
    ctx.registerProtoFiles(fds);
    ctx.registerMarshaller(new ArtifactTypeMarshaller());
    ctx.registerMarshaller(new ArtifactMarshaller());
}
 
Example #2
Source File: MarshallerGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
protected String javaTypeForMessage(FileDescriptor d, String messageName, SerializationContext serializationContext) {

        Map<String, FileDescriptor> descriptors = serializationContext.getFileDescriptors();
        for (Entry<String, FileDescriptor> entry : descriptors.entrySet()) {

            List<Descriptor> messages = entry.getValue().getMessageTypes();

            for (Descriptor msg : messages) {
                if (messageName.equals(msg.getName())) {

                    return packageFromOption(d, msg) + "." + messageName;
                } else if (messageName.equals(msg.getFullName())) {
                    return packageFromOption(d, msg) + "." + msg.getName();
                }
            }
        }
        return null;
    }
 
Example #3
Source File: DeviceManagementCacheProvider.java    From enmasse with Apache License 2.0 6 votes vote down vote up
private String generateSchema() throws IOException {
    final SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(this.remoteCacheManager);

    final String generatedSchema = new ProtoSchemaBuilder()

            .addClass(CredentialKey.class)
            .addClass(DeviceKey.class)
            .addClass(DeviceInformation.class)
            .addClass(DeviceCredential.class)

            .packageName(DeviceInformation.class.getPackageName())
            .fileName(GENERATED_PROTOBUF_FILE_NAME)
            .build(serCtx);

    return generatedSchema;
}
 
Example #4
Source File: InfinispanRemoteQuery.java    From infinispan-simple-tutorials with Apache License 2.0 6 votes vote down vote up
private static void addPersonSchema(RemoteCacheManager cacheManager) throws IOException {
   // Get the serialization context of the client
   SerializationContext ctx = MarshallerUtil.getSerializationContext(cacheManager);

   // Use ProtoSchemaBuilder to define a Protobuf schema on the client
   ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
   String fileName = "person.proto";
   String protoFile = protoSchemaBuilder
         .fileName(fileName)
         .addClass(Person.class)
         .packageName("tutorial")
         .build(ctx);

   // Retrieve metadata cache
   RemoteCache<String, String> metadataCache =
         cacheManager.getCache(PROTOBUF_METADATA_CACHE_NAME);

   // Define the new schema on the server too
   metadataCache.put(fileName, protoFile);
}
 
Example #5
Source File: InfinispanRemoteContinuousQuery.java    From infinispan-simple-tutorials with Apache License 2.0 6 votes vote down vote up
private static void addInstapostsSchema(RemoteCacheManager cacheManager) throws IOException {
   // Get the serialization context of the client
   SerializationContext ctx = MarshallerUtil.getSerializationContext(cacheManager);

   // Use ProtoSchemaBuilder to define a Protobuf schema on the client
   ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
   String fileName = "instapost.proto";
   String protoFile = protoSchemaBuilder
         .fileName(fileName)
         .addClass(InstaPost.class)
         .packageName("tutorial")
         .build(ctx);

   // Retrieve metadata cache
   RemoteCache<String, String> metadataCache =
         cacheManager.getCache(PROTOBUF_METADATA_CACHE_NAME);

   // Define the new schema on the server too
   metadataCache.putIfAbsent(fileName, protoFile);
}
 
Example #6
Source File: DeviceConnectionCacheProvider.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private String generateSchema() throws Exception {
    final SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(this.remoteCacheManager);

    return new ProtoSchemaBuilder()

            .addClass(DeviceConnectionKey.class)
            .packageName(DeviceConnectionKey.class.getPackageName())
            .fileName(GENERATED_PROTOBUF_FILE_NAME)
            .build(serCtx);

}
 
Example #7
Source File: Bucket4jProtobufContextInitializer.java    From bucket4j with Apache License 2.0 5 votes vote down vote up
@Override
public void registerSchema(SerializationContext serCtx) {
    StringBuilder protoBuilder = new StringBuilder(FOOTER);

    for (SerializationHandle<?> serializationHandle : Bucket4j.getSerializationHandles()) {
        String typeName = "Bucket4jType_" + serializationHandle.getTypeId();
        String typeDefinition = TYPE_TEMPLATE.replace("[type_name]", typeName);
        protoBuilder.append(typeDefinition);
    }

    String generatedProtoFile = protoBuilder.toString();
    FileDescriptorSource protoSource = FileDescriptorSource.fromString(getProtoFileName(), generatedProtoFile);
    serCtx.registerProtoFiles(protoSource);
}
 
Example #8
Source File: Bucket4jProtobufContextInitializer.java    From bucket4j with Apache License 2.0 5 votes vote down vote up
@Override
public void registerMarshallers(SerializationContext serCtx) {
    for (SerializationHandle<?> serializationHandle : Bucket4j.getSerializationHandles()) {
        String protoTypeId = "bucket4j.Bucket4jType_" + serializationHandle.getTypeId();
        serCtx.registerMarshaller(new ProtobufMessageMarshaller<>(serializationHandle, protoTypeId));
    }
}
 
Example #9
Source File: QuerySubstitutions.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Substitute
public static void init(SerializationContext ctx) throws IOException {
    // Skip loading the proto definition files as this was already done at compile time with
    // HandleProtostreamMarshaller#handleQueryRequirements
    MarshallerRegistration.INSTANCE.registerMarshallers(ctx);
}