Search in sources :

Example 1 with SerializationException

use of com.nokia.dempsy.serialization.SerializationException in project Dempsy by Dempsy.

the class KryoSerializer method deserialize.

@SuppressWarnings("unchecked")
@Override
public T deserialize(byte[] data) throws SerializationException {
    KryoHolder k = null;
    try {
        k = getKryoHolder();
        k.input.setBuffer(data);
        return (T) (k.kryo.readClassAndObject(k.input));
    } catch (KryoException ke) {
        throw new SerializationException("Failed to deserialize.", ke);
    } catch (// this happens when requiring registration but deserializing an unregistered class
    IllegalArgumentException e) {
        throw new SerializationException("Failed to deserialize. Did you require registration and attempt to deserialize an unregistered class?", e);
    } finally {
        if (k != null)
            kryopool.offer(k);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) SerializationException(com.nokia.dempsy.serialization.SerializationException)

Example 2 with SerializationException

use of com.nokia.dempsy.serialization.SerializationException in project Dempsy by Dempsy.

the class KryoSerializer method serialize.

@Override
public byte[] serialize(T object) throws SerializationException {
    KryoHolder k = null;
    try {
        k = getKryoHolder();
        k.output.clear();
        k.kryo.writeClassAndObject(k.output, object);
        return k.output.toBytes();
    } catch (KryoException ke) {
        throw new SerializationException("Failed to serialize.", ke);
    } catch (// this happens when requiring registration but serializing an unregistered class
    IllegalArgumentException e) {
        throw new SerializationException("Failed to serialize " + SafeString.objectDescription(object) + " (did you require registration and attempt to serialize an unregistered class?)", e);
    } finally {
        if (k != null)
            kryopool.offer(k);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) SerializationException(com.nokia.dempsy.serialization.SerializationException)

Example 3 with SerializationException

use of com.nokia.dempsy.serialization.SerializationException in project Dempsy by Dempsy.

the class JavaSerializer method deserialize.

@Override
public T deserialize(byte[] data) throws SerializationException {
    ByteArrayInputStream bis = new ByteArrayInputStream(data);
    InputStream in;
    try {
        in = new ObjectInputStream(bis);
        @SuppressWarnings("unchecked") T readObject = (T) ((ObjectInputStream) in).readObject();
        return readObject;
    } catch (IOException e) {
        throw new SerializationException(e);
    } catch (ClassNotFoundException e) {
        throw new SerializationException(e);
    }
}
Also used : SerializationException(com.nokia.dempsy.serialization.SerializationException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with SerializationException

use of com.nokia.dempsy.serialization.SerializationException in project Dempsy by Dempsy.

the class JavaSerializer method serialize.

@Override
public byte[] serialize(T object) throws SerializationException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream out;
    try {
        out = new ObjectOutputStream(bos);
        // no need to reset the stream since we're tossing it.
        out.writeObject(object);
        out.flush();
    } catch (IOException e) {
        throw new SerializationException(e);
    }
    byte[] data = bos.toByteArray();
    return data;
}
Also used : SerializationException(com.nokia.dempsy.serialization.SerializationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 5 with SerializationException

use of com.nokia.dempsy.serialization.SerializationException in project Dempsy by Dempsy.

the class ZookeeperSession method callZookeeper.

private Object callZookeeper(final String name, final String path, final ClusterInfoWatcher watcher, final Object userdata, final ZookeeperCall callee) throws ClusterInfoException {
    if (isRunning) {
        final WatcherProxy wp = watcher != null ? makeWatcherProxy(watcher) : null;
        if (wp != null) {
            synchronized (registeredWatchers) {
                registeredWatchers.add(wp);
            }
        }
        final ZooKeeper cur = zkref.get();
        try {
            return callee.call(cur, path, wp, userdata);
        } catch (final KeeperException.NodeExistsException e) {
            if (logger.isTraceEnabled())
                logger.trace("Failed call to " + name + " at " + path + " because the node already exists.", e);
            else if (logger.isDebugEnabled())
                logger.debug("Failed call to " + name + " at " + path + " because the node already exists.");
            // this is only thrown from mkdir and so if the Node Exists
            return null;
        // we simply want to return a null String
        } catch (final KeeperException.NoNodeException e) {
            throw new ClusterInfoException.NoNodeException("Node doesn't exist at " + path + " while running " + name, e);
        } catch (final KeeperException e) {
            resetZookeeper(cur);
            throw new ClusterInfoException("Zookeeper failed while trying to " + name + " at " + path, e);
        } catch (final InterruptedException e) {
            throw new ClusterInfoException("Interrupted while trying to " + name + " at " + path, e);
        } catch (final SerializationException e) {
            throw new ClusterInfoException("Failed to deserialize the object durring a " + name + " call at " + path, e);
        }
    }
    throw new ClusterInfoException(name + " called on stopped ZookeeperSession.");
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) SerializationException(com.nokia.dempsy.serialization.SerializationException) ClusterInfoException(com.nokia.dempsy.cluster.ClusterInfoException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

SerializationException (com.nokia.dempsy.serialization.SerializationException)5 KryoException (com.esotericsoftware.kryo.KryoException)2 IOException (java.io.IOException)2 ClusterInfoException (com.nokia.dempsy.cluster.ClusterInfoException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 KeeperException (org.apache.zookeeper.KeeperException)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1