From bd027c7c2337939c0240e6cef9fea4a22cd3d919 Mon Sep 17 00:00:00 2001 From: Albert Cardona Date: Fri, 10 Apr 2009 12:10:55 +0200 Subject: [PATCH] Added a Worker.Task class with an exe() method that wraps the worker run() method for proper exception handling and start/end of task monitoring. --- ini/trakem2/utils/Worker.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ini/trakem2/utils/Worker.java b/ini/trakem2/utils/Worker.java index 5eeaeb6a..6b6ee039 100644 --- a/ini/trakem2/utils/Worker.java +++ b/ini/trakem2/utils/Worker.java @@ -109,4 +109,32 @@ public abstract class Worker implements Runnable { if (null == key || null == properties) return null; return properties.get(key); } + + /** A class that calls run() wrapped properly for task monitoring; + * Create it like this: + * + * Bureaucrat b = Bureaucrat.createAndStart(new Worker.Task("Title") { public void exec() { + * doSomething(); + * doSomethingElse(); + * }}, project); + * + */ + static public abstract class Task extends Worker { + public Task(String title) { + super(title); + } + + abstract public void exec(); + + public void run() { + try { + startedWorking(); + exec(); + } catch (Throwable t) { + IJError.print(t); + } finally { + finishedWorking(); + } + } + } } -- 2.11.4.GIT