提交 0ad61139 编写于 作者: M Mathieu Bastian

Minor reformatting

上级 39a99e58
/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.utils.longtask.api;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
......@@ -63,7 +62,7 @@ import org.openide.util.Lookup;
* execution, progress, cancellation and error management.
* <p>
* Note that only one task can be executed by the executor at one time.
*
*
* @author Mathieu Bastian
* @see LongTask
*/
......@@ -82,9 +81,12 @@ public final class LongTaskExecutor {
/**
* Creates a new long task executor.
* @param doInBackground when <code>true</code>, the task will be executed in a separate thread
*
* @param doInBackground when <code>true</code>, the task will be executed
* in a separate thread
* @param name the name of the executor, used to recognize threads by names
* @param interruptDelay number of seconds to wait before calling <code>Thread.interrupt()</code> after a cancel request
* @param interruptDelay number of seconds to wait before *
* calling <code>Thread.interrupt()</code> after a cancel request
*/
public LongTaskExecutor(boolean doInBackground, String name, int interruptDelay) {
this.inBackground = doInBackground;
......@@ -95,7 +97,9 @@ public final class LongTaskExecutor {
/**
* Creates a new long task executor.
* @param doInBackground doInBackground when <code>true</code>, the task will be executed in a separate thread
*
* @param doInBackground doInBackground when <code>true</code>, the task
* will be executed in a separate thread
* @param name the name of the executor, used to recognize threads by names
*/
public LongTaskExecutor(boolean doInBackground, String name) {
......@@ -105,21 +109,28 @@ public final class LongTaskExecutor {
/**
* Creates a new long task executor.
* @param doInBackground doInBackground when <code>true</code>, the task will be executed in a separate thread
*
* @param doInBackground doInBackground when <code>true</code>, the task
* will be executed in a separate thread
*/
public LongTaskExecutor(boolean doInBackground) {
this(doInBackground, "LongTaskExecutor");
}
/**
* Execute a long task with cancel and progress support. Task can be <code>null</code>.
* In this case <code>runnable</code> will be executed normally, but without
* cancel and progress support.
* Execute a long task with cancel and progress support. Task can be
* <code>null</code>. In this case
* <code>runnable</code> will be executed normally, but without cancel and
* progress support.
*
* @param task the task to be executed, can be <code>null</code>.
* @param runnable the runnable to be executed
* @param taskName the name of the task, is displayed in the status bar if available
* @param errorHandler error handler for exception retrieval during execution
* @throws NullPointerException if <code>runnable</code> or <code>taskName</code> is null
* @param taskName the name of the task, is displayed in the status bar if
* available
* @param errorHandler error handler for exception retrieval during
* execution
* @throws NullPointerException if <code>runnable</code> *
* or <code>taskName</code> is null
* @throws IllegalStateException if a task is still executing at this time
*/
public void execute(LongTask task, final Runnable runnable, String taskName, LongTaskErrorHandler errorHandler) {
......@@ -144,9 +155,11 @@ public final class LongTaskExecutor {
}
/**
* Execute a long task with cancel and progress support. Task can be <code>null</code>.
* In this case <code>runnable</code> will be executed normally, but without
* cancel and progress support.
* Execute a long task with cancel and progress support. Task can be
* <code>null</code>. In this case
* <code>runnable</code> will be executed normally, but without cancel and
* progress support.
*
* @param task the task to be executed, can be <code>null</code>.
* @param runnable the runnable to be executed
* @throws NullPointerException if <code>runnable</code> is null
......@@ -157,9 +170,12 @@ public final class LongTaskExecutor {
}
/**
* Cancel the current task. If the task fails to cancel itself and if an <code>interruptDelay</code> has been specified,
* the task will be <b>interrupted</b> after <code>interruptDelay</code>. Using <code>Thread.interrupt()</code> may cause
* hazardous behaviours and should be avoided. Therefore any task should be cancellable.
* Cancel the current task. If the task fails to cancel itself and if an
* <code>interruptDelay</code> has been specified, the task will be
* <b>interrupted</b> after
* <code>interruptDelay</code>. Using
* <code>Thread.interrupt()</code> may cause hazardous behaviours and should
* be avoided. Therefore any task should be cancellable.
*/
public synchronized void cancel() {
if (runningTask != null) {
......@@ -177,16 +193,20 @@ public final class LongTaskExecutor {
}
/**
* Returns <code>true</code> if the executor is executing a task.
* @return <code>true</code> if a task is running, <code>false</code> otherwise
* Returns
* <code>true</code> if the executor is executing a task.
*
* @return <code>true</code> if a task is running, <code>false</code>
* otherwise
*/
public boolean isRunning() {
return runningTask != null;
}
/**
* Set the listener to this executor. Only a unique listener can be set to this executor. The listener
* is called when the task terminates normally.
* Set the listener to this executor. Only a unique listener can be set to
* this executor. The listener is called when the task terminates normally.
*
* @param listener a listener for this executor
*/
public void setLongTaskListener(LongTaskListener listener) {
......@@ -194,8 +214,9 @@ public final class LongTaskExecutor {
}
/**
* Set the default error handler. Use error handlers to get errors and exceptions thrown during
* tasks execution.
* Set the default error handler. Use error handlers to get errors and
* exceptions thrown during tasks execution.
*
* @param errorHandler the default error handler
*/
public void setDefaultErrorHandler(LongTaskErrorHandler errorHandler) {
......@@ -223,7 +244,7 @@ public final class LongTaskExecutor {
private final LongTask task;
private final Runnable runnable;
private Future future;
private Future<?> future;
private ProgressTicket progress;
public RunningLongTask(LongTask task, Runnable runnable, String taskName) {
......@@ -232,7 +253,7 @@ public final class LongTaskExecutor {
ProgressTicketProvider progressProvider = Lookup.getDefault().lookup(ProgressTicketProvider.class);
if (progressProvider != null) {
this.progress = progressProvider.createTicket(taskName, new Cancellable() {
@Override
public boolean cancel() {
LongTaskExecutor.this.cancel();
return true;
......@@ -246,6 +267,7 @@ public final class LongTaskExecutor {
}
}
@Override
public void run() {
try {
runnable.run();
......@@ -272,10 +294,10 @@ public final class LongTaskExecutor {
public boolean cancel() {
/*if (inBackground) {
if (future != null && future.cancel(false)) {
return true;
}
}*/
if (future != null && future.cancel(false)) {
return true;
}
}*/
if (task != null) {
return task.cancel();
}
......@@ -298,6 +320,7 @@ public final class LongTaskExecutor {
*/
private class NamedThreadFactory implements ThreadFactory {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, name);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册