Search in sources :

Example 1 with MarshallingException

use of org.infinispan.commons.marshall.MarshallingException in project infinispan by infinispan.

the class LambdaMarshaller method read.

public static Object read(ObjectInput in, ClassLoader classLoader) throws ClassNotFoundException, IOException {
    SerializedLambda sl = createSerializedLambda(in, classLoader);
    try {
        Class clazz = Class.forName(sl.getCapturingClass().replace("/", "."), true, classLoader);
        Method method = SecurityActions.getMethodAndSetAccessible(clazz, "$deserializeLambda$", SerializedLambda.class);
        return method.invoke(null, sl);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        throw new MarshallingException(e);
    }
}
Also used : MarshallingException(org.infinispan.commons.marshall.MarshallingException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) SerializedLambda(java.lang.invoke.SerializedLambda)

Example 2 with MarshallingException

use of org.infinispan.commons.marshall.MarshallingException in project infinispan by infinispan.

the class LambdaMarshaller method write.

static void write(ObjectOutput out, Object o) throws IOException {
    try {
        Method writeReplace = SecurityActions.getMethodAndSetAccessible(o, "writeReplace");
        SerializedLambda sl = (SerializedLambda) writeReplace.invoke(o);
        writeSerializedLambda(out, sl);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        throw new MarshallingException(e);
    }
}
Also used : MarshallingException(org.infinispan.commons.marshall.MarshallingException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) SerializedLambda(java.lang.invoke.SerializedLambda)

Example 3 with MarshallingException

use of org.infinispan.commons.marshall.MarshallingException in project infinispan by infinispan.

the class ThrowableExternalizer method readGenericThrowable.

private Throwable readGenericThrowable(ObjectInput in) throws IOException, ClassNotFoundException {
    String impl = in.readUTF();
    String msg = MarshallUtil.unmarshallString(in);
    Throwable t = (Throwable) in.readObject();
    try {
        Class<?> clazz = Class.forName(impl);
        if (t == null && msg == null) {
            return (Throwable) clazz.getConstructor().newInstance(new Object[] {});
        } else if (t == null) {
            return (Throwable) clazz.getConstructor(String.class).newInstance(msg);
        } else if (msg == null) {
            return (Throwable) clazz.getConstructor(Throwable.class).newInstance(t);
        }
        return (Throwable) clazz.getConstructor(String.class, Throwable.class).newInstance(msg, t);
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
        throw new MarshallingException(e);
    }
}
Also used : MarshallingException(org.infinispan.commons.marshall.MarshallingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with MarshallingException

use of org.infinispan.commons.marshall.MarshallingException in project infinispan by infinispan.

the class SingleOwnerTest method testRetrieveNonSerializableValueFromNonOwner.

public void testRetrieveNonSerializableValueFromNonOwner() {
    Cache[] owners = getOwners("yourkey", 1);
    Cache[] nonOwners = getNonOwners("yourkey", 1);
    assert owners.length == 1;
    assert nonOwners.length == 1;
    Cache ownerCache = owners[0];
    Cache nonOwnerCache = nonOwners[0];
    ownerCache.put("yourkey", new Object());
    try {
        nonOwnerCache.get("yourkey");
        fail("Should have failed with a org.infinispan.commons.marshall.MarshallingException");
    } catch (RemoteException e) {
        assertTrue(e.getCause() instanceof MarshallingException);
    }
}
Also used : MarshallingException(org.infinispan.commons.marshall.MarshallingException) RemoteException(org.infinispan.remoting.RemoteException) Cache(org.infinispan.Cache)

Example 5 with MarshallingException

use of org.infinispan.commons.marshall.MarshallingException in project infinispan by infinispan.

the class NonBlockingSoftIndexFileStore method migrateFromOldFormat.

private void migrateFromOldFormat(FileProvider oldFileProvider) {
    String cacheName = ctx.getCache().getName();
    PERSISTENCE.startMigratingPersistenceData(cacheName);
    try {
        CompletionStages.join(index.clear());
    } catch (CompletionException e) {
        throw PERSISTENCE.persistedDataMigrationFailed(cacheName, e.getCause());
    }
    // Only update the key/value/meta bytes if the default marshaller is configured
    boolean transformationRequired = ctx.getGlobalConfiguration().serialization().marshaller() == null;
    try (CloseableIterator<Integer> it = oldFileProvider.getFileIterator()) {
        while (it.hasNext()) {
            int fileId = it.next();
            try (FileProvider.Handle handle = oldFileProvider.getFile(fileId)) {
                int offset = 0;
                while (true) {
                    EntryHeader header = EntryRecord.readEntryHeader(handle, offset);
                    if (header == null) {
                        // end of file. go to next one
                        break;
                    }
                    MarshallableEntry<K, V> entry = readEntry(handle, header, offset, null, true, (key, value, meta, internalMeta, created, lastUsed) -> {
                        if (!transformationRequired) {
                            return marshallableEntryFactory.create(key, value, meta, internalMeta, created, lastUsed);
                        }
                        try {
                            Object k = unmarshallLegacy(key, false);
                            Object v = unmarshallLegacy(value, false);
                            Metadata m = unmarshallLegacy(meta, true);
                            PrivateMetadata im = internalMeta == null ? null : (PrivateMetadata) ctx.getPersistenceMarshaller().objectFromByteBuffer(internalMeta.getBuf());
                            return marshallableEntryFactory.create(k, v, m, im, created, lastUsed);
                        } catch (ClassNotFoundException | IOException e) {
                            throw new MarshallingException(e);
                        }
                    }, false);
                    int segment = keyPartitioner.getSegment(entry.getKey());
                    // noinspection ConstantConditions (entry is not null!)
                    if (entry.getValueBytes() != null) {
                        // using the storeQueue (instead of binary copy) to avoid building the index later
                        CompletionStages.join(logAppender.storeRequest(segment, entry));
                    } else {
                        // delete the entry. The file is append only so we can have a put() and later a remove() for the same key
                        CompletionStages.join(logAppender.deleteRequest(segment, entry.getKey(), entry.getKeyBytes()));
                    }
                    offset += header.totalLength();
                }
            }
            // file is read. can be removed.
            oldFileProvider.deleteFile(fileId);
        }
        PERSISTENCE.persistedDataSuccessfulMigrated(cacheName);
    } catch (IOException e) {
        throw PERSISTENCE.persistedDataMigrationFailed(cacheName, e);
    }
}
Also used : Metadata(org.infinispan.metadata.Metadata) PrivateMetadata(org.infinispan.metadata.impl.PrivateMetadata) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MarshallingException(org.infinispan.commons.marshall.MarshallingException) CompletionException(java.util.concurrent.CompletionException) PrivateMetadata(org.infinispan.metadata.impl.PrivateMetadata)

Aggregations

MarshallingException (org.infinispan.commons.marshall.MarshallingException)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 SerializedLambda (java.lang.invoke.SerializedLambda)2 Method (java.lang.reflect.Method)2 IOException (java.io.IOException)1 CompletionException (java.util.concurrent.CompletionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Cache (org.infinispan.Cache)1 LazyByteArrayOutputStream (org.infinispan.commons.io.LazyByteArrayOutputStream)1 Metadata (org.infinispan.metadata.Metadata)1 PrivateMetadata (org.infinispan.metadata.impl.PrivateMetadata)1 RemoteException (org.infinispan.remoting.RemoteException)1 Person (org.infinispan.test.data.Person)1 AbstractTranscoderTest (org.infinispan.test.dataconversion.AbstractTranscoderTest)1 Test (org.testng.annotations.Test)1