Skip to content

Commit

Permalink
pool: Use FireAndForgetTask instead of custom class
Browse files Browse the repository at this point in the history
Target: trunk
Require-notes: no
Require-book: no
Acked-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
Patch: http://rb.dcache.org/r/6676/
  • Loading branch information
gbehrmann committed Mar 6, 2014
1 parent b8108fe commit f437cac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 56 deletions.
29 changes: 5 additions & 24 deletions modules/dcache/src/main/java/org/dcache/pool/migration/Job.java
Expand Up @@ -33,6 +33,7 @@
import org.dcache.pool.repository.Repository;
import org.dcache.pool.repository.StateChangeEvent;
import org.dcache.pool.repository.StickyRecord;
import org.dcache.util.FireAndForgetTask;
import org.dcache.util.expression.Expression;

/**
Expand Down Expand Up @@ -107,7 +108,7 @@ public Job(MigrationContext context, JobDefinition definition)
_state = State.INITIALIZING;

_refreshTask =
executor.scheduleWithFixedDelay(new LoggingTask(new Runnable() {
executor.scheduleWithFixedDelay(new FireAndForgetTask(new Runnable() {
@Override
public void run()
{
Expand All @@ -116,7 +117,7 @@ public void run()
}
}), 0, refreshPeriod, TimeUnit.MILLISECONDS);

executor.submit(new LoggingTask(new Runnable() {
executor.submit(new FireAndForgetTask(new Runnable() {
@Override
public void run()
{
Expand Down Expand Up @@ -365,7 +366,7 @@ private synchronized void setState(State state)
break;

case SLEEPING:
_context.getExecutor().schedule(new LoggingTask(new Runnable() {
_context.getExecutor().schedule(new FireAndForgetTask(new Runnable() {
@Override
public void run()
{
Expand All @@ -379,7 +380,7 @@ public void run()
break;

case PAUSED:
_context.getExecutor().schedule(new LoggingTask(new Runnable() {
_context.getExecutor().schedule(new FireAndForgetTask(new Runnable() {
@Override
public void run()
{
Expand Down Expand Up @@ -758,26 +759,6 @@ public boolean evaluateLifetimePredicate(Expression expression)
return expression.evaluateBoolean(symbols);
}

protected class LoggingTask implements Runnable
{
private final Runnable _inner;

public LoggingTask(Runnable r)
{
_inner = r;
}

@Override
public void run()
{
try {
_inner.run();
} catch (Exception e) {
_log.error(e.toString(), e);
}
}
}

protected class Error
{
private final long _id;
Expand Down
40 changes: 8 additions & 32 deletions modules/dcache/src/main/java/org/dcache/pool/migration/Task.java
@@ -1,7 +1,5 @@
package org.dcache.pool.migration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import statemap.TransitionUndefinedException;

import java.io.PrintWriter;
Expand Down Expand Up @@ -32,12 +30,12 @@
import org.dcache.pool.repository.EntryState;
import org.dcache.pool.repository.StickyRecord;
import org.dcache.services.pinmanager1.PinManagerMovePinMessage;
import org.dcache.util.FireAndForgetTask;
import org.dcache.util.ReflectionUtils;
import org.dcache.vehicles.FileAttributes;

public class Task
{
private final static Logger _log = LoggerFactory.getLogger(Job.class);
private final static AtomicInteger _counter = new AtomicInteger();

private final TaskContext _fsm;
Expand Down Expand Up @@ -296,7 +294,7 @@ synchronized void initiateCopy()
initiateCopy(selectPool());
} catch (NoSuchElementException e) {
_target = null;
_executor.execute(new LoggingTask(new Runnable() {
_executor.execute(new FireAndForgetTask(new Runnable() {
@Override
public void run() {
synchronized (Task.this) {
Expand Down Expand Up @@ -364,7 +362,7 @@ synchronized void movePin()
/** FSM Action */
void notifyCancelled()
{
_executor.execute(new LoggingTask(new Runnable() {
_executor.execute(new FireAndForgetTask(new Runnable() {
@Override
public void run()
{
Expand All @@ -376,7 +374,7 @@ public void run()
/** FSM Action */
void fail(final String message)
{
_executor.execute(new LoggingTask(new Runnable() {
_executor.execute(new FireAndForgetTask(new Runnable() {
@Override
public void run()
{
Expand All @@ -388,7 +386,7 @@ public void run()
/** FSM Action */
void failPermanently(final String message)
{
_executor.execute(new LoggingTask(new Runnable() {
_executor.execute(new FireAndForgetTask(new Runnable() {
@Override
public void run()
{
Expand All @@ -400,7 +398,7 @@ public void run()
/** FSM Action */
void notifyCompleted()
{
_executor.execute(new LoggingTask(new Runnable() {
_executor.execute(new FireAndForgetTask(new Runnable() {
@Override
public void run()
{
Expand All @@ -427,7 +425,7 @@ public void run()
}
};
_timerTask =
_executor.schedule(new LoggingTask(task),
_executor.schedule(new FireAndForgetTask(task),
delay, TimeUnit.MILLISECONDS);
}

Expand Down Expand Up @@ -498,7 +496,7 @@ protected void transition(String name, final Object... arguments)
ReflectionUtils.resolve(_fsm.getClass(), _prefix + name,
parameterTypes);
if (m != null) {
_executor.execute(new LoggingTask(new Runnable() {
_executor.execute(new FireAndForgetTask(new Runnable() {
@Override
public void run() {
try {
Expand Down Expand Up @@ -542,26 +540,4 @@ public void noroute(CellPath path)
transition("noroute");
}
}

protected class LoggingTask implements Runnable
{
private final Runnable _inner;

public LoggingTask(Runnable r)
{
_inner = r;
}

@Override
public void run()
{
try {
_inner.run();
} catch (RuntimeException | Error e) {
Thread me = Thread.currentThread();
me.getUncaughtExceptionHandler().uncaughtException(me, e);
fail(e.getMessage());
}
}
}
}

0 comments on commit f437cac

Please sign in to comment.