Search in sources :

Example 1 with ObjectTransferable

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;
}
Also used : ObjectTransferable(es.bsc.compss.types.data.operation.ObjectTransferable) SimpleURI(es.bsc.compss.types.uri.SimpleURI) DataLocation(es.bsc.compss.types.data.location.DataLocation) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) OneOpWithSemListener(es.bsc.compss.types.data.operation.OneOpWithSemListener) DataAccessId(es.bsc.compss.types.data.DataAccessId) StorageException(storage.StorageException) IOException(java.io.IOException)

Aggregations

DataAccessId (es.bsc.compss.types.data.DataAccessId)1 DataLocation (es.bsc.compss.types.data.location.DataLocation)1 ObjectTransferable (es.bsc.compss.types.data.operation.ObjectTransferable)1 OneOpWithSemListener (es.bsc.compss.types.data.operation.OneOpWithSemListener)1 SimpleURI (es.bsc.compss.types.uri.SimpleURI)1 IOException (java.io.IOException)1 Semaphore (java.util.concurrent.Semaphore)1 StorageException (storage.StorageException)1