use of es.bsc.compss.exceptions.CannotLoadException in project compss by bsc-wdc.
the class LogicalData method loadFromStorage.
/**
* Loads the value of the LogicalData from a file
*
* @throws CannotLoadException
* @throws IOException
* @throws ClassNotFoundException
* @throws StorageException
* @throws UnstartedNodeException
*
* @throws Exception
*/
public synchronized void loadFromStorage() throws CannotLoadException {
if (value != null) {
// Value is already loaded in memory
return;
}
for (DataLocation loc : this.locations) {
switch(loc.getType()) {
case PRIVATE:
case SHARED:
// Get URI and deserialize object if possible
MultiURI u = loc.getURIInHost(Comm.getAppHost());
if (u == null) {
continue;
}
String path = u.getPath();
if (path.startsWith(File.separator)) {
try {
this.value = Serializer.deserialize(path);
} catch (ClassNotFoundException | IOException e) {
// Check next location since deserialization was invalid
this.value = null;
continue;
}
String targetPath = Protocol.OBJECT_URI.getSchema() + this.name;
SimpleURI uri = new SimpleURI(targetPath);
try {
DataLocation tgtLoc = DataLocation.createLocation(Comm.getAppHost(), uri);
addLocation(tgtLoc);
} catch (IOException e) {
// Check next location since location was invalid
this.value = null;
continue;
}
}
return;
case PERSISTENT:
PersistentLocation pLoc = (PersistentLocation) loc;
if (Tracer.isActivated()) {
Tracer.emitEvent(Tracer.Event.STORAGE_GETBYID.getId(), Tracer.Event.STORAGE_GETBYID.getType());
}
try {
this.value = StorageItf.getByID(pLoc.getId());
this.id = pLoc.getId();
} catch (StorageException se) {
// Check next location since cannot retrieve the object from the storage Back-end
continue;
} finally {
if (Tracer.isActivated()) {
Tracer.emitEvent(Tracer.EVENT_END, Tracer.Event.STORAGE_GETBYID.getType());
}
}
String targetPath = Protocol.OBJECT_URI.getSchema() + this.name;
SimpleURI uri = new SimpleURI(targetPath);
try {
DataLocation tgtLoc = DataLocation.createLocation(Comm.getAppHost(), uri);
addLocation(tgtLoc);
} catch (IOException e) {
// Check next location since location was invalid
this.value = null;
continue;
}
return;
}
}
// Any location has been able to load the value
throw new CannotLoadException("Object has not any valid location available in the master");
}
use of es.bsc.compss.exceptions.CannotLoadException in project compss by bsc-wdc.
the class AccessProcessor method obtainObject.
/**
* Adds a request to obtain an object from a worker to the master
*
* @param oaId
* @return
*/
private Object obtainObject(DataAccessId oaId) {
LOGGER.debug("Obtain object with id " + oaId);
// Ask for the object
Semaphore sem = new Semaphore(0);
TransferObjectRequest tor = new TransferObjectRequest(oaId, sem);
if (!requestQueue.offer(tor)) {
ErrorManager.error(ERROR_QUEUE_OFFER + "obtain object");
}
// Wait for response
sem.acquireUninterruptibly();
// Get response
Object oUpdated = tor.getResponse();
if (oUpdated == null) {
/*
* The Object didn't come from a WS but was transferred from a worker, we load it from its storage (file or
* persistent)
*/
LogicalData ld = tor.getLogicalDataTarget();
try {
ld.loadFromStorage();
oUpdated = ld.getValue();
} catch (CannotLoadException e) {
LOGGER.fatal(ERROR_OBJECT_LOAD_FROM_STORAGE + ": " + ((ld == null) ? "null" : ld.getName()), e);
ErrorManager.fatal(ERROR_OBJECT_LOAD_FROM_STORAGE + ": " + ((ld == null) ? "null" : ld.getName()), e);
}
}
return oUpdated;
}
Aggregations