serlock.unlock();
}
}
private <Message> ActorRef<Message> getRootFromStoreAndUpdateCache(final String rootName) throws SuspendExecution, RuntimeException {
final Store store = grid.store();
StoreTransaction txn = store.beginTransaction();
try {
boolean error = false;
try {
final long root = store.getRoot(rootName, txn);
byte[] buf = store.get(root);
if (buf == null)
return null;
if (buf.length == 0)
return null; // TODO: Galaxy should return null
final ActorRef<Message> actor;
try {
actor = (ActorRef<Message>) ser.read(buf);
} catch (Exception e) {
LOG.info("Deserializing actor at root " + rootName + " has failed with exception", e);
return null;
}
store.setListener(root, new CacheListener() {
@Override
public void invalidated(long id) {
evicted(id);
}
@Override
public void received(long id, long version, ByteBuffer data) {
evicted(id);
}
@Override
public void evicted(long id) {
rootCache.remove(rootName);
store.setListener(id, null);
}
});
rootCache.put(rootName, actor);
return actor;
} catch (TimeoutException e) {
error = true;
LOG.error("Getting actor {} failed due to timeout", rootName);
store.rollback(txn);
store.abort(txn);
throw new RuntimeException("Actor discovery failed");
} finally {
if(!error)
store.commit(txn);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}