From 9f47598b91f745f1581db5c5d104f496fc9a340f Mon Sep 17 00:00:00 2001 From: Roberto E. Escobar Date: Tue, 2 Dec 2014 14:18:50 -0700 Subject: refactor: Remove unused client task scheduler Change-Id: If9a7e7c1d534fd7e939031797cd6ed6dd17f6080 --- .../META-INF/MANIFEST.MF | 3 +- .../core/client/task/ProgressMonitorTask.java | 59 -------------- .../framework/core/client/task/ScheduledTask.java | 51 ------------ .../osee/framework/core/client/task/Scheduler.java | 91 ---------------------- 4 files changed, 1 insertion(+), 203 deletions(-) delete mode 100644 plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ProgressMonitorTask.java delete mode 100644 plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ScheduledTask.java delete mode 100644 plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/Scheduler.java (limited to 'plugins/org.eclipse.osee.framework.core.client') diff --git a/plugins/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF index b9e4d3803ec..98264ef5bc8 100644 --- a/plugins/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF @@ -23,6 +23,5 @@ Import-Package: org.eclipse.core.runtime, org.eclipse.osee.framework.plugin.core.util, org.osgi.framework Export-Package: org.eclipse.osee.framework.core.client, - org.eclipse.osee.framework.core.client.server, - org.eclipse.osee.framework.core.client.task + org.eclipse.osee.framework.core.client.server Service-Component: OSGI-INF/*.xml diff --git a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ProgressMonitorTask.java b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ProgressMonitorTask.java deleted file mode 100644 index 43e7f9ce2ad..00000000000 --- a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ProgressMonitorTask.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.client.task; - -import java.sql.Statement; -import java.util.concurrent.TimeUnit; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * @author Roberto E. Escobar - */ -public class ProgressMonitorTask extends ScheduledTask { - private final IProgressMonitor monitor; - private final Statement statement; - - private ProgressMonitorTask(IProgressMonitor monitor, Statement statement, String name) { - super(name); - this.monitor = monitor; - this.statement = statement; - } - - @Override - protected void innerRun() throws Exception { - if (monitor != null) { - if (monitor.isCanceled()) { - if (statement != null) { - statement.cancel(); - } - unscheduleTask(); - } - } else { - unscheduleTask(); - } - } - - private void unscheduleTask() { - Thread stopThread = new Thread() { - @Override - public void run() { - Scheduler.cancelTask(ProgressMonitorTask.this); - } - }; - stopThread.start(); - } - - public static ScheduledTask monitor(String name, IProgressMonitor monitor, Statement statement, long millis) { - ProgressMonitorTask task = new ProgressMonitorTask(monitor, statement, name); - Scheduler.scheduleAtFixedRate(task, 0, millis, TimeUnit.MILLISECONDS); - return task; - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ScheduledTask.java b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ScheduledTask.java deleted file mode 100644 index e7a5bd78c6f..00000000000 --- a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ScheduledTask.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.client.task; - -import java.util.concurrent.ScheduledFuture; - -/** - * @author Roberto E. Escobar - */ -public abstract class ScheduledTask implements Runnable { - private final String name; - private ScheduledFuture futureTask; - - protected ScheduledTask(String name) { - this.name = name; - this.futureTask = null; - } - - public String getName() { - return name; - } - - @Override - public final void run() { - try { - innerRun(); - } catch (Throwable th) { - th.printStackTrace(); - } - } - - @SuppressWarnings("unchecked") - void setScheduledFuture(ScheduledFuture futureTask) { - this.futureTask = (ScheduledFuture) futureTask; - } - - protected ScheduledFuture getFutureTask() { - return futureTask; - } - - protected abstract void innerRun() throws Exception; - -} diff --git a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/Scheduler.java b/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/Scheduler.java deleted file mode 100644 index 89e2065e7e0..00000000000 --- a/plugins/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/Scheduler.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.client.task; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - -/** - * @author Roberto E. Escobar - */ -public class Scheduler { - - private static final InternalScheduler scheduler = new InternalScheduler(); - - private Scheduler() { - } - - public static void scheduleAtFixedRate(ScheduledTask command, long initialDelay, long period, TimeUnit unit) { - scheduler.scheduleAtFixedRate(command, initialDelay, period, unit); - } - - public static void scheduleWithFixedDelay(ScheduledTask command, long initialDelay, long delay, TimeUnit unit) { - scheduler.scheduleWithFixedDelay(command, initialDelay, delay, unit); - } - - public static void cancelTask(ScheduledTask command) { - scheduler.cancelTask(command); - } - - public static void shutdown() { - scheduler.shutdown(); - } - - private static final class InternalScheduler { - private final Map> futures; - private final ScheduledExecutorService executor; - - public InternalScheduler() { - futures = Collections.synchronizedMap(new HashMap>()); - executor = Executors.newSingleThreadScheduledExecutor(new SchedulerThreadFactory()); - } - - public void scheduleAtFixedRate(ScheduledTask command, long initialDelay, long period, TimeUnit unit) { - ScheduledFuture futureTask = executor.scheduleAtFixedRate(command, initialDelay, period, unit); - futures.put(command, futureTask); - command.setScheduledFuture(futureTask); - } - - public void scheduleWithFixedDelay(ScheduledTask command, long initialDelay, long delay, TimeUnit unit) { - ScheduledFuture futureTask = executor.scheduleWithFixedDelay(command, initialDelay, delay, unit); - futures.put(command, futureTask); - command.setScheduledFuture(futureTask); - } - - public void cancelTask(ScheduledTask command) { - ScheduledFuture future = futures.get(command); - if (future != null) { - if (future.cancel(true)) { - futures.remove(command); - } - } - } - - public void shutdown() { - executor.shutdownNow(); - } - } - - private static final class SchedulerThreadFactory implements ThreadFactory { - - @Override - public Thread newThread(Runnable runnable) { - return new Thread(((ScheduledTask) runnable).getName()); - } - - } -} -- cgit v1.2.3