Search in sources :

Example 21 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class SerializerHookLoader method load.

private void load() {
    try {
        final Iterator<SerializerHook> hooks = ServiceLoader.iterator(SerializerHook.class, FACTORY_ID, classLoader);
        while (hooks.hasNext()) {
            final SerializerHook hook = hooks.next();
            final Class serializationType = hook.getSerializationType();
            if (serializationType != null) {
                serializers.put(serializationType, hook);
            }
        }
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
    if (serializerConfigs != null) {
        for (SerializerConfig serializerConfig : serializerConfigs) {
            Serializer serializer = serializerConfig.getImplementation();
            Class serializationType = serializerConfig.getTypeClass();
            if (serializationType == null) {
                try {
                    serializationType = ClassLoaderUtil.loadClass(classLoader, serializerConfig.getTypeClassName());
                } catch (ClassNotFoundException e) {
                    throw new HazelcastSerializationException(e);
                }
            }
            if (serializer == null) {
                serializer = createSerializerInstance(serializerConfig, serializationType);
            }
            register(serializationType, serializer);
        }
    }
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializerHook(com.hazelcast.nio.serialization.SerializerHook) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) Serializer(com.hazelcast.nio.serialization.Serializer)

Example 22 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class AbstractSerializationService method writeObject.

@Override
public final void writeObject(final ObjectDataOutput out, final Object obj) {
    if (obj instanceof Data) {
        throw new HazelcastSerializationException("Cannot write a Data instance, use writeData() instead");
    }
    SerializerAdapter serializer = serializerFor(obj, false);
    try {
        out.writeInt(serializer.getTypeId());
        serializer.write(out, obj);
    } catch (Throwable e) {
        throw handleSerializeException(obj, e);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializationUtil.createSerializerAdapter(com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter) CompactWithSchemaStreamSerializerAdapter(com.hazelcast.internal.serialization.impl.compact.CompactWithSchemaStreamSerializerAdapter) CompactStreamSerializerAdapter(com.hazelcast.internal.serialization.impl.compact.CompactStreamSerializerAdapter) SerializationUtil.isNullData(com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData) Data(com.hazelcast.internal.serialization.Data)

Example 23 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class Edge method readData.

@Override
public void readData(@Nonnull ObjectDataInput in) throws IOException {
    sourceName = in.readUTF();
    sourceOrdinal = in.readInt();
    destName = in.readUTF();
    destOrdinal = in.readInt();
    priority = in.readInt();
    distributedTo = in.readObject();
    routingPolicy = RoutingPolicy.valueOf(in.readString());
    config = in.readObject();
    try {
        partitioner = CustomClassLoadedObject.read(in);
        comparator = CustomClassLoadedObject.read(in);
    } catch (HazelcastSerializationException e) {
        throw new HazelcastSerializationException("Error deserializing edge '" + sourceName + "' -> '" + destName + "': " + e, e);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException)

Example 24 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class StreamEventJournalP method init.

@Override
protected void init(@Nonnull Context context) throws Exception {
    @SuppressWarnings("unchecked") CompletableFuture<EventJournalInitialSubscriberState>[] futures = new CompletableFuture[partitionIds.length];
    Arrays.setAll(futures, i -> eventJournalReader.subscribeToEventJournal(partitionIds[i]));
    for (int i = 0; i < futures.length; i++) {
        emitOffsets[i] = readOffsets[i] = getSequence(futures[i].get());
    }
    if (!isRemoteReader) {
        // try to serde projection/predicate to fail fast if they aren't known to IMDG
        HazelcastInstanceImpl hzInstance = Util.getHazelcastInstanceImpl(context.hazelcastInstance());
        InternalSerializationService ss = hzInstance.getSerializationService();
        try {
            deserializeWithCustomClassLoader(ss, hzInstance.getClass().getClassLoader(), ss.toData(predicate));
            deserializeWithCustomClassLoader(ss, hzInstance.getClass().getClassLoader(), ss.toData(projection));
        } catch (HazelcastSerializationException e) {
            throw new JetException("The projection or predicate classes are not known to IMDG. It's not enough to " + "add them to the job class path, they must be deployed using User code deployment: " + e, e);
        }
    }
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) CompletableFuture(java.util.concurrent.CompletableFuture) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) JetException(com.hazelcast.jet.JetException)

Example 25 with HazelcastSerializationException

use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.

the class AsyncOperation method doSendResponse.

private void doSendResponse(Object value) {
    try {
        final JetServiceBackend service = getJetServiceBackend();
        service.getLiveOperationRegistry().deregister(this);
    } finally {
        try {
            sendResponse(value);
        } catch (Exception e) {
            Throwable ex = peel(e);
            if (value instanceof Throwable && ex instanceof HazelcastSerializationException) {
                // Sometimes exceptions are not serializable, for example on
                // https://github.com/hazelcast/hazelcast-jet/issues/1995.
                // When sending exception as a response and the serialization fails,
                // the response will not be sent and the operation will hang.
                // To prevent this from happening, replace the exception with
                // another exception that can be serialized.
                sendResponse(new JetException(stackTraceToString(ex)));
            } else {
                throw e;
            }
        }
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) JetException(com.hazelcast.jet.JetException) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ExceptionUtil.isTopologyException(com.hazelcast.jet.impl.util.ExceptionUtil.isTopologyException) JetException(com.hazelcast.jet.JetException)

Aggregations

HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)50 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)10 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)10 IOException (java.io.IOException)9 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 Config (com.hazelcast.config.Config)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)5 ClientConfig (com.hazelcast.client.config.ClientConfig)4 JavaSerializationFilterConfig (com.hazelcast.config.JavaSerializationFilterConfig)4 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)4 Portable (com.hazelcast.nio.serialization.Portable)4 TestDeserialized (example.serialization.TestDeserialized)4 Map (java.util.Map)4 HazelcastException (com.hazelcast.core.HazelcastException)3 FieldKind (com.hazelcast.nio.serialization.FieldKind)3 HashMap (java.util.HashMap)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)2