use of org.dcache.util.FireAndForgetTask in project dcache by dCache.
the class Job method start.
public void start() {
_lock.lock();
try {
checkState(_state == State.NEW);
_state = State.INITIALIZING;
long refreshPeriod = _definition.refreshPeriod;
ScheduledExecutorService executor = _context.getExecutor();
_refreshTask = executor.scheduleWithFixedDelay(new FireAndForgetTask(() -> {
_definition.sourceList.refresh();
_definition.poolList.refresh();
}), 0, refreshPeriod, TimeUnit.MILLISECONDS);
executor.submit(new FireAndForgetTask(() -> {
try {
_context.getRepository().addListener(Job.this);
populate();
_lock.lock();
try {
if (getState() == State.INITIALIZING) {
setState(State.RUNNING);
}
} finally {
_lock.unlock();
}
} catch (InterruptedException e) {
LOGGER.error("Migration job was interrupted");
} finally {
_lock.lock();
try {
switch(getState()) {
case INITIALIZING:
setState(State.FAILED);
break;
case CANCELLING:
schedule();
break;
}
} finally {
_lock.unlock();
}
}
}));
} finally {
_lock.unlock();
}
}
use of org.dcache.util.FireAndForgetTask in project dcache by dCache.
the class Companion method done.
/**
* Called at the end of the transfer to call callbacks and free resources associated with the
* transfer.
*/
synchronized void done() {
if (_thread != null) {
throw new IllegalStateException("Cannot close a companion while the transfer is in progress");
}
if (_error != null) {
if (_error instanceof Error) {
LOGGER.error("P2P for {} failed due to a serious problem in the JVM.", _pnfsId, _error);
// We should not attempt to recover from this!
throw (Error) _error;
} else if (_error instanceof RuntimeException) {
LOGGER.error("P2P for {} failed due to a bug. Please report" + " this to <support@dCache.org>", _pnfsId, _error);
} else {
LOGGER.error("P2P for {} failed: {}", _pnfsId, _error.toString());
}
} else {
LOGGER.info("P2P for {} completed", _pnfsId);
}
if (_callback != null) {
final Object error = _error;
_executor.execute(new FireAndForgetTask(() -> {
Throwable t;
if (error == null) {
t = null;
} else if (error instanceof Throwable) {
t = (Throwable) error;
} else {
t = new CacheException(error.toString());
}
_callback.cacheFileAvailable(_pnfsId, t);
}));
}
}
use of org.dcache.util.FireAndForgetTask in project dcache by dCache.
the class ResilientFileTask method call.
@Override
public Void call() {
startTime = System.currentTimeMillis();
FileAttributes attributes = FileAttributes.of().accessLatency(ONLINE).pnfsId(pnfsId).build();
if (cancelled) {
return null;
}
startSubTask = System.currentTimeMillis();
type = handler.handleVerification(attributes);
inVerify = System.currentTimeMillis() - startSubTask;
switch(type) {
case VOID:
endTime = System.currentTimeMillis();
break;
case SET_STICKY:
/*
* create a new copy by promoting a non-sticky copy to sticky
*/
startSubTask = System.currentTimeMillis();
handler.getRemoveService().schedule(new FireAndForgetTask(() -> runPromote(attributes)), 0, TimeUnit.MILLISECONDS);
break;
case WAIT_FOR_STAGE:
if (cancelled) {
break;
}
startSubTask = System.currentTimeMillis();
/*
* We do not want the resilience sessionID in the logging
* context; the new cache location needs to be processed.
*
* Task completes immediately after message is sent.
*/
handler.handleStaging(pnfsId, this);
copyTerminated();
break;
case COPY:
if (cancelled) {
break;
}
startSubTask = System.currentTimeMillis();
Task innerTask = handler.handleMakeOneCopy(attributes);
if (cancelled) {
break;
}
if (innerTask != null) {
MessageGuard.setResilienceSession();
migrationTask = innerTask;
innerTask.run();
} else {
copyTerminated();
}
break;
case REMOVE:
if (cancelled) {
break;
}
startSubTask = System.currentTimeMillis();
handler.getRemoveService().schedule(new FireAndForgetTask(() -> runRemove(attributes)), 0, TimeUnit.MILLISECONDS);
break;
}
return null;
}
use of org.dcache.util.FireAndForgetTask in project dcache by dCache.
the class DefaultPostTransferService method execute.
@Override
public void execute(final Mover<?> mover, final CompletionHandler<Void, Void> completionHandler) {
_executor.execute(new FireAndForgetTask(() -> {
ReplicaDescriptor handle = mover.getIoHandle();
try {
try {
if (mover.getIoMode().contains(StandardOpenOption.WRITE)) {
handle.addChecksums(mover.getExpectedChecksums());
_checksumModule.enforcePostTransferPolicy(handle, mover.getActualChecksums());
}
handle.commit();
} finally {
handle.close();
}
completionHandler.completed(null, null);
} catch (InterruptedIOException | InterruptedException e) {
LOGGER.warn("Transfer was forcefully killed during post-processing");
mover.setTransferStatus(CacheException.DEFAULT_ERROR_CODE, "Transfer was forcefully killed");
completionHandler.failed(e, null);
} catch (CacheException e) {
LOGGER.warn("Transfer failed in post-processing: {}", e.getMessage());
mover.setTransferStatus(e.getRc(), "Post-processing failed: " + e.getMessage());
completionHandler.failed(e, null);
} catch (IOException e) {
LOGGER.warn("Transfer failed in post-processing: {}", e.toString());
mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed in post-processing: " + messageOrClassName(e));
completionHandler.failed(e, null);
} catch (RuntimeException e) {
LOGGER.error("Transfer failed in post-processing. Please report this bug to support@dcache.org.", e);
mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed due to unexpected exception: " + e.getMessage());
completionHandler.failed(e, null);
} catch (Throwable e) {
Thread t = Thread.currentThread();
t.getUncaughtExceptionHandler().uncaughtException(t, e);
mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed due to unexpected exception: " + e.getMessage());
completionHandler.failed(e, null);
}
MoverInfoMessage moverInfoMessage = generateBillingMessage(mover, handle.getReplicaSize());
// as current thread is used to serialize the message, send finish to the door before notifying the billing.
sendFinished(mover, moverInfoMessage);
sendBillingInfo(moverInfoMessage);
}));
}
use of org.dcache.util.FireAndForgetTask in project dcache by dCache.
the class StateMaintainer method enqueueUpdate.
@Override
public void enqueueUpdate(final StateUpdate pendingUpdate) {
LOGGER.trace("enqueing job to process update {}", pendingUpdate);
final NDC ndc = NDC.cloneNdc();
_pendingRequestCount.incrementAndGet();
_scheduler.execute(new FireAndForgetTask(() -> {
CDC.reset(_myAddress);
NDC.set(ndc);
try {
LOGGER.trace("starting job to process update {}", pendingUpdate);
_caretaker.processUpdate(pendingUpdate);
checkScheduledExpungeActivity();
LOGGER.trace("finished job to process update {}", pendingUpdate);
} finally {
_pendingRequestCount.decrementAndGet();
pendingUpdate.updateComplete();
CDC.clear();
}
}));
}
Aggregations