use of es.bsc.compss.types.data.operation.ObjectTransferable in project compss by bsc-wdc.
the class DataInfoProvider method transferObjectValue.
/**
* Transfers the value of an object
*
* @param toRequest
* @return
*/
public LogicalData transferObjectValue(TransferObjectRequest toRequest) {
Semaphore sem = toRequest.getSemaphore();
DataAccessId daId = toRequest.getDaId();
RWAccessId rwaId = (RWAccessId) daId;
String sourceName = rwaId.getReadDataInstance().getRenaming();
// String targetName = rwaId.getWrittenDataInstance().getRenaming();
if (DEBUG) {
LOGGER.debug("Requesting getting object " + sourceName);
}
LogicalData ld = Comm.getData(sourceName);
if (ld == null) {
ErrorManager.error("Unregistered data " + sourceName);
return null;
}
if (ld.isInMemory()) {
// Write to storage (if needed)
try {
ld.writeToStorage();
} catch (IOException e) {
ErrorManager.error("Exception writing object to file.", e);
}
// Clear value
ld.removeValue();
// Set response
toRequest.setResponse(ld.getValue());
toRequest.setTargetData(ld);
toRequest.getSemaphore().release();
} else {
if (DEBUG) {
LOGGER.debug("Object " + sourceName + " not in memory. Requesting tranfers to " + Comm.getAppHost().getName());
}
DataLocation targetLocation = null;
String path = DataLocation.Protocol.FILE_URI.getSchema() + Comm.getAppHost().getTempDirPath() + sourceName;
try {
SimpleURI uri = new SimpleURI(path);
targetLocation = DataLocation.createLocation(Comm.getAppHost(), uri);
} catch (Exception e) {
ErrorManager.error(DataLocation.ERROR_INVALID_LOCATION + " " + path, e);
}
Comm.getAppHost().getData(sourceName, targetLocation, new ObjectTransferable(), new OneOpWithSemListener(sem));
}
return ld;
}
Aggregations