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);
}
}
}
Aggregations