use of diskCacheV111.vehicles.Message in project dcache by dCache.
the class QoSMessageHandler method messageArrived.
/**
* Returns whether replica exists, the status of its system sticky flag and whether its state
* allows for reading and removal.
*/
public Reply messageArrived(ReplicaStatusMessage message) {
MessageReply<Message> reply = new MessageReply<>();
executor.execute(() -> {
PnfsId pnfsId = message.getPnfsId();
try {
CacheEntry entry = repository.getEntry(pnfsId);
message.setExists(true);
switch(entry.getState()) {
case FROM_CLIENT:
case FROM_POOL:
case FROM_STORE:
message.setWaiting(true);
break;
case CACHED:
message.setReadable(true);
message.setRemovable(true);
break;
case BROKEN:
message.setBroken(true);
message.setRemovable(true);
break;
case PRECIOUS:
message.setReadable(true);
message.setPrecious(true);
break;
default:
break;
}
Collection<StickyRecord> records = entry.getStickyRecords();
for (StickyRecord record : records) {
if (record.owner().equals(SYSTEM_OWNER) && record.isNonExpiring()) {
message.setSystemSticky(true);
break;
}
}
reply.reply(message);
} catch (FileNotInCacheException e) {
reply.reply(message);
} catch (Exception e) {
reply.fail(message, e);
}
});
return reply;
}
use of diskCacheV111.vehicles.Message in project dcache by dCache.
the class RemoteHttpDataTransferProtocol method receiveFile.
private void receiveFile(final RemoteHttpDataTransferProtocolInfo info) throws ThirdPartyTransferFailedCacheException {
Set<Checksum> checksums;
long deadline = System.currentTimeMillis() + GET_RETRY_DURATION;
HttpClientContext context = storeContext(new HttpClientContext());
try {
try (CloseableHttpResponse response = doGet(info, context, deadline)) {
String rfc3230 = headerValue(response, "Digest");
checksums = Checksums.decodeRfc3230(rfc3230);
checksums.forEach(_integrityChecker);
HttpEntity entity = response.getEntity();
if (entity == null) {
throw new ThirdPartyTransferFailedCacheException("GET response contains no content");
}
long length = entity.getContentLength();
if (length > 0) {
_channel.truncate(length);
}
if (response.getStatusLine() != null && response.getStatusLine().getStatusCode() < 300 && length > -1) {
_expectedTransferSize = length;
}
entity.writeTo(Channels.newOutputStream(_channel));
} catch (SocketTimeoutException e) {
String message = "socket timeout on GET (received " + describeSize(_channel.getBytesTransferred()) + " of data; " + describeSize(e.bytesTransferred) + " pending)";
if (e.getMessage() != null) {
message += ": " + e.getMessage();
}
throw new ThirdPartyTransferFailedCacheException(message, e);
} catch (IOException e) {
throw new ThirdPartyTransferFailedCacheException(messageOrClassName(e), e);
} catch (InterruptedException e) {
throw new ThirdPartyTransferFailedCacheException("pool is shutting down", e);
}
} catch (ThirdPartyTransferFailedCacheException e) {
List<URI> redirections = context.getRedirectLocations();
if (redirections != null && !redirections.isEmpty()) {
StringBuilder message = new StringBuilder(e.getMessage());
message.append("; redirects ").append(redirections);
throw new ThirdPartyTransferFailedCacheException(message.toString(), e.getCause());
} else {
throw e;
}
}
// HEAD requests.
if (checksums.isEmpty() && info.isVerificationRequired()) {
HttpHead head = buildHeadRequest(info, deadline);
head.addHeader("Want-Digest", WANT_DIGEST_VALUE);
try {
try (CloseableHttpResponse response = _client.execute(head)) {
String rfc3230 = headerValue(response, "Digest");
checkThirdPartyTransferSuccessful(rfc3230 != null, "no checksums in HEAD response");
checksums = Checksums.decodeRfc3230(rfc3230);
checkThirdPartyTransferSuccessful(!checksums.isEmpty(), "no useful checksums in HEAD response: %s", rfc3230);
// Ensure integrety. If we're lucky, this won't trigger
// rescanning the uploaded file.
checksums.forEach(_integrityChecker);
}
} catch (IOException e) {
throw new ThirdPartyTransferFailedCacheException("HEAD request failed: " + messageOrClassName(e), e);
}
}
}
use of diskCacheV111.vehicles.Message in project dcache by dCache.
the class P2PClient method messageArrived.
public synchronized void messageArrived(DoorTransferFinishedMessage message) {
HttpProtocolInfo pinfo = (HttpProtocolInfo) message.getProtocolInfo();
int sessionId = pinfo.getSessionId();
Companion companion = _companions.get(sessionId);
if (companion != null) {
companion.messageArrived(message);
}
}
use of diskCacheV111.vehicles.Message in project dcache by dCache.
the class StagingAdjuster method poll.
/**
* Polled by main map thread. If the future is done, this will trigger the completion handler.
*/
public void poll() {
synchronized (this) {
if (future == null) {
completionHandler.taskFailed(pnfsId, Optional.empty(), new CacheException(CacheException.SERVICE_UNAVAILABLE, "no future returned by message send."));
return;
}
}
PinManagerPinMessage migrationReply = null;
Object error = null;
try {
LOGGER.debug("poll, checking pin request future.isDone() for {}.", pnfsId);
if (!future.isDone()) {
return;
}
migrationReply = getUninterruptibly(future);
if (migrationReply.getReturnCode() != 0) {
error = migrationReply.getErrorObject();
}
} catch (CancellationException e) {
/*
* Cancelled state set by caller.
*/
} catch (ExecutionException e) {
error = e.getCause();
}
LOGGER.debug("poll, calling completion handler for {}.", pnfsId);
String target = migrationReply.getPool();
if (error == null) {
completionHandler.taskCompleted(pnfsId, Optional.ofNullable(target));
} else if (error instanceof Throwable) {
completionHandler.taskFailed(pnfsId, Optional.ofNullable(target), new CacheException("Pin failure", (Throwable) error));
} else {
completionHandler.taskFailed(pnfsId, Optional.ofNullable(target), new CacheException(String.valueOf(error)));
}
}
use of diskCacheV111.vehicles.Message in project dcache by dCache.
the class QoSAdjustmentReceiver method messageArrived.
public void messageArrived(QoSAdjustmentCancelledMessage message) {
PnfsId pnfsId = message.getPnfsId();
ACTIVITY_LOGGER.info("Received cancellation for adjustment of {}.", pnfsId);
if (messageGuard.getStatus("QoSAdjustmentCancelledMessage", message) == Status.DISABLED) {
return;
}
taskHandler.handleAdjustmentCancelled(pnfsId);
}
Aggregations