Search in sources :

Example 1 with CommandDataDemand

use of es.bsc.compss.nio.commands.CommandDataDemand in project compss by bsc-wdc.

the class NIOAgent method requestTransfers.

/**
 * Check if receive slots available
 */
public void requestTransfers() {
    DataRequest dr = null;
    synchronized (pendingRequests) {
        if (!pendingRequests.isEmpty() && tryAcquireReceiveSlot()) {
            dr = pendingRequests.remove();
        }
    }
    while (dr != null) {
        Data source = dr.getSource();
        NIOURI uri = source.getFirstURI();
        if (NIOTracer.isActivated()) {
            NIOTracer.emitDataTransferEvent(source.getName());
        }
        NIONode nn = uri.getHost();
        if (nn.getIp() == null) {
            nn = masterNode;
        }
        Connection c = null;
        try {
            c = TM.startConnection(nn);
            LOGGER.debug("Connection " + c.hashCode() + " will be used to acquire data " + dr.getTarget() + " stored in " + nn + " with name " + dr.getSource().getName());
            Data remoteData = new Data(source.getName(), uri);
            CommandDataDemand cdd = new CommandDataDemand(this, remoteData, tracingID);
            ongoingTransfers.put(c, dr.getSource().getName());
            c.sendCommand(cdd);
            if (NIOTracer.isActivated()) {
                c.receive();
            }
            if (dr.getType() == DataType.FILE_T) {
                c.receiveDataFile(dr.getTarget());
            } else {
                c.receiveDataObject();
            }
        } catch (Exception e) {
            e.printStackTrace(System.err);
        } finally {
            if (c != null) {
                c.finishConnection();
            }
        }
        synchronized (pendingRequests) {
            if (!pendingRequests.isEmpty() && tryAcquireReceiveSlot()) {
                dr = pendingRequests.remove();
            } else {
                dr = null;
            }
        }
        if (NIOTracer.isActivated()) {
            NIOTracer.emitDataTransferEvent(NIOTracer.TRANSFER_END);
        }
    }
}
Also used : NIONode(es.bsc.comm.nio.NIONode) CommandDataDemand(es.bsc.compss.nio.commands.CommandDataDemand) Connection(es.bsc.comm.Connection) DataRequest(es.bsc.compss.nio.dataRequest.DataRequest) Data(es.bsc.compss.nio.commands.Data) SerializedObjectException(es.bsc.compss.nio.exceptions.SerializedObjectException) IOException(java.io.IOException)

Aggregations

Connection (es.bsc.comm.Connection)1 NIONode (es.bsc.comm.nio.NIONode)1 CommandDataDemand (es.bsc.compss.nio.commands.CommandDataDemand)1 Data (es.bsc.compss.nio.commands.Data)1 DataRequest (es.bsc.compss.nio.dataRequest.DataRequest)1 SerializedObjectException (es.bsc.compss.nio.exceptions.SerializedObjectException)1 IOException (java.io.IOException)1