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