Search in sources :

Example 1 with EjbObjectInputStream

use of org.apache.openejb.core.ivm.EjbObjectInputStream in project tomee by apache.

the class CrossClassLoaderJndiReference method copy.

private static Object copy(final Object source) throws Exception {
    IntraVmCopyMonitor.preCrossClassLoaderOperation();
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
        final ObjectOutputStream out = new ObjectOutputStream(baos);
        out.writeObject(source);
        out.close();
        final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        final ObjectInputStream in = new EjbObjectInputStream(bais);
        return in.readObject();
    } finally {
        IntraVmCopyMonitor.postCrossClassLoaderOperation();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) EjbObjectInputStream(org.apache.openejb.core.ivm.EjbObjectInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) EjbObjectInputStream(org.apache.openejb.core.ivm.EjbObjectInputStream)

Example 2 with EjbObjectInputStream

use of org.apache.openejb.core.ivm.EjbObjectInputStream in project tomee by apache.

the class SimplePassivater method activate.

@Override
public Object activate(final Object primaryKey) throws SystemException {
    try {
        final String filename = primaryKey.toString().replace(':', '=');
        final File sessionFile = new File(sessionDirectory, filename);
        if (sessionFile.exists()) {
            logger.info("Activating from file " + sessionFile);
            try (final InputStream source = IO.read(sessionFile);
                final ObjectInputStream ois = new EjbObjectInputStream(source)) {
                return ois.readObject();
            } finally {
                if (!sessionFile.delete()) {
                    sessionFile.deleteOnExit();
                }
            }
        } else {
            logger.info("Activation failed: file not found " + sessionFile);
            return null;
        }
    } catch (final Exception t) {
        logger.info("Activation failed ", t);
        throw new SystemException(t);
    }
}
Also used : SystemException(org.apache.openejb.SystemException) ObjectInputStream(java.io.ObjectInputStream) EjbObjectInputStream(org.apache.openejb.core.ivm.EjbObjectInputStream) InputStream(java.io.InputStream) EjbObjectInputStream(org.apache.openejb.core.ivm.EjbObjectInputStream) File(java.io.File) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(org.apache.openejb.SystemException) ObjectInputStream(java.io.ObjectInputStream) EjbObjectInputStream(org.apache.openejb.core.ivm.EjbObjectInputStream)

Example 3 with EjbObjectInputStream

use of org.apache.openejb.core.ivm.EjbObjectInputStream in project tomee by apache.

the class EjbFactory method copy.

private static Object copy(final Object source) throws Exception {
    IntraVmCopyMonitor.preCrossClassLoaderOperation();
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
        final ObjectOutputStream out = new ObjectOutputStream(baos);
        out.writeObject(source);
        out.close();
        final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        final ObjectInputStream in = new EjbObjectInputStream(bais);
        final Object copy = in.readObject();
        return copy;
    } finally {
        IntraVmCopyMonitor.postCrossClassLoaderOperation();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) EjbObjectInputStream(org.apache.openejb.core.ivm.EjbObjectInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) EjbObjectInputStream(org.apache.openejb.core.ivm.EjbObjectInputStream)

Example 4 with EjbObjectInputStream

use of org.apache.openejb.core.ivm.EjbObjectInputStream in project tomee by apache.

the class CrossClassLoaderProxyTest method copy.

private static Object copy(final Object source) throws Exception {
    IntraVmCopyMonitor.preCrossClassLoaderOperation();
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
        final ObjectOutputStream out = new ObjectOutputStream(baos);
        out.writeObject(source);
        out.close();
        final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        final ObjectInputStream in = new EjbObjectInputStream(bais);
        final Object copy = in.readObject();
        return copy;
    } finally {
        IntraVmCopyMonitor.postCrossClassLoaderOperation();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) EjbObjectInputStream(org.apache.openejb.core.ivm.EjbObjectInputStream) EJBObject(javax.ejb.EJBObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) EjbObjectInputStream(org.apache.openejb.core.ivm.EjbObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)4 EjbObjectInputStream (org.apache.openejb.core.ivm.EjbObjectInputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 NotSerializableException (java.io.NotSerializableException)1 EJBObject (javax.ejb.EJBObject)1 SystemException (org.apache.openejb.SystemException)1