Search in sources :

Example 6 with Schema

use of com.hazelcast.internal.serialization.impl.compact.Schema in project hazelcast by hazelcast.

the class ClientSchemaService method put.

@Override
public void put(Schema schema) {
    long schemaId = schema.getSchemaId();
    Schema existingSchema = schemas.get(schemaId);
    if (existingSchema != null) {
        return;
    }
    ClientMessage clientMessage = ClientSendSchemaCodec.encodeRequest(schema);
    ClientInvocation invocation = new ClientInvocation(client, clientMessage, SERVICE_NAME);
    invocation.invoke().joinInternal();
    putIfAbsent(schema);
}
Also used : Schema(com.hazelcast.internal.serialization.impl.compact.Schema) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 7 with Schema

use of com.hazelcast.internal.serialization.impl.compact.Schema in project hazelcast by hazelcast.

the class MemberSchemaService method searchClusterAsync.

private CompletableFuture<Schema> searchClusterAsync(long schemaId, Iterator<Member> iterator, OperationService operationService) {
    if (!iterator.hasNext()) {
        return CompletableFuture.completedFuture(null);
    }
    Address address = iterator.next().getAddress();
    FetchSchemaOperation op = new FetchSchemaOperation(schemaId);
    InvocationFuture<Schema> future = operationService.invokeOnTarget(SERVICE_NAME, op, address);
    return future.handle((data, throwable) -> {
        // handle the exception and carry it to next `thenCompose` method
        if (throwable != null) {
            return throwable;
        }
        return data;
    }).thenCompose(o -> {
        if (o instanceof Throwable || o == null) {
            return searchClusterAsync(schemaId, iterator, operationService);
        }
        Schema retrievedSchema = (Schema) o;
        putLocal(retrievedSchema);
        return CompletableFuture.completedFuture(getLocal(schemaId));
    });
}
Also used : InvocationUtil.invokeOnStableClusterSerial(com.hazelcast.internal.util.InvocationUtil.invokeOnStableClusterSerial) Address(com.hazelcast.cluster.Address) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Properties(java.util.Properties) Iterator(java.util.Iterator) Member(com.hazelcast.cluster.Member) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedService(com.hazelcast.internal.services.ManagedService) Schema(com.hazelcast.internal.serialization.impl.compact.Schema) ArrayList(java.util.ArrayList) ClusterService(com.hazelcast.internal.cluster.ClusterService) List(java.util.List) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) SchemaService(com.hazelcast.internal.serialization.impl.compact.SchemaService) Map(java.util.Map) PreJoinAwareService(com.hazelcast.internal.services.PreJoinAwareService) Versions(com.hazelcast.internal.cluster.Versions) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Nonnull(javax.annotation.Nonnull) Address(com.hazelcast.cluster.Address) Schema(com.hazelcast.internal.serialization.impl.compact.Schema)

Example 8 with Schema

use of com.hazelcast.internal.serialization.impl.compact.Schema in project hazelcast by hazelcast.

the class MemberSchemaService method getAsync.

public CompletableFuture<Schema> getAsync(long schemaId) {
    if (!nodeEngine.getClusterService().getClusterVersion().isEqualTo(Versions.V5_2)) {
        throw new UnsupportedOperationException("The BETA compact format can only be used with 5.2 cluster");
    }
    Schema schema = getLocal(schemaId);
    if (schema != null) {
        return CompletableFuture.completedFuture(schema);
    }
    if (logger.isFinestEnabled()) {
        logger.finest("Could not find schema id  " + schemaId + " locally, will search on the cluster" + schemaId);
    }
    ClusterService cluster = nodeEngine.getClusterService();
    OperationService operationService = nodeEngine.getOperationService();
    Set<Member> members = cluster.getMembers();
    Iterator<Member> iterator = members.iterator();
    return searchClusterAsync(schemaId, iterator, operationService);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Schema(com.hazelcast.internal.serialization.impl.compact.Schema) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Member(com.hazelcast.cluster.Member)

Example 9 with Schema

use of com.hazelcast.internal.serialization.impl.compact.Schema in project hazelcast by hazelcast.

the class SendAllSchemasOperation method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    int size = in.readInt();
    schemas = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        Schema schema = in.readObject();
        schemas.add(schema);
    }
}
Also used : Schema(com.hazelcast.internal.serialization.impl.compact.Schema)

Example 10 with Schema

use of com.hazelcast.internal.serialization.impl.compact.Schema in project hazelcast by hazelcast.

the class SampleMetadataResolver method resolve.

@Nullable
@SuppressWarnings("checkstyle:returncount")
static Metadata resolve(InternalSerializationService ss, Object target, boolean key) {
    try {
        if (target instanceof Data) {
            Data data = (Data) target;
            if (data.isPortable()) {
                ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(data);
                return resolvePortable(classDefinition, key);
            } else if (data.isCompact()) {
                return resolveCompact(ss.extractSchemaFromData(data), key);
            } else if (data.isJson()) {
                return null;
            } else {
                return resolveJava(ss.toObject(data).getClass(), key);
            }
        } else if (target instanceof VersionedPortable) {
            VersionedPortable portable = (VersionedPortable) target;
            ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), portable.getClassVersion());
            return resolvePortable(classDefinition, key);
        } else if (target instanceof Portable) {
            Portable portable = (Portable) target;
            ClassDefinition classDefinition = ss.getPortableContext().lookupClassDefinition(portable.getFactoryId(), portable.getClassId(), 0);
            return resolvePortable(classDefinition, key);
        } else if (target instanceof PortableGenericRecord) {
            return resolvePortable(((PortableGenericRecord) target).getClassDefinition(), key);
        } else if (target instanceof CompactGenericRecord) {
            return resolveCompact(((CompactGenericRecord) target).getSchema(), key);
        } else if (ss.isCompactSerializable(target)) {
            Schema schema = ss.extractSchemaFromObject(target);
            return resolveCompact(schema, key);
        } else if (target instanceof HazelcastJsonValue) {
            return null;
        } else {
            return resolveJava(target.getClass(), key);
        }
    } catch (Exception e) {
        return null;
    }
}
Also used : VersionedPortable(com.hazelcast.nio.serialization.VersionedPortable) Portable(com.hazelcast.nio.serialization.Portable) PortableGenericRecord(com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord) Schema(com.hazelcast.internal.serialization.impl.compact.Schema) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) CompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord) Data(com.hazelcast.internal.serialization.Data) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) VersionedPortable(com.hazelcast.nio.serialization.VersionedPortable) Nullable(javax.annotation.Nullable)

Aggregations

Schema (com.hazelcast.internal.serialization.impl.compact.Schema)11 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)2 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)2 Member (com.hazelcast.cluster.Member)2 ClusterService (com.hazelcast.internal.cluster.ClusterService)2 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Nonnull (javax.annotation.Nonnull)2 Address (com.hazelcast.cluster.Address)1 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)1 Versions (com.hazelcast.internal.cluster.Versions)1 Data (com.hazelcast.internal.serialization.Data)1 CompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord)1 DefaultCompactReader (com.hazelcast.internal.serialization.impl.compact.DefaultCompactReader)1 FieldDescriptor (com.hazelcast.internal.serialization.impl.compact.FieldDescriptor)1 SchemaService (com.hazelcast.internal.serialization.impl.compact.SchemaService)1 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)1 ManagedService (com.hazelcast.internal.services.ManagedService)1