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);
}
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));
});
}
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);
}
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);
}
}
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;
}
}
Aggregations