本文整理汇总了Java中org.openide.util.Task类的典型用法代码示例。如果您正苦于以下问题:Java Task类的具体用法?Java Task怎么用?Java Task使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Task类属于org.openide.util包,在下文中一共展示了Task类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStartCreatedJob
import org.openide.util.Task; //导入依赖的package包/类
public void testStartCreatedJob() throws Exception {
final RequestProcessor rp = new RequestProcessor("testStartCreatedJob");
final boolean[] executed = new boolean[1];
rp.post (new Runnable() {
@Override
public void run() {
RequestProcessor.Task t = rp.create(new Runnable() {
@Override
public void run() {
executed[0] = true;
}
});
t.waitFinished();
}
}).waitFinished();
assertTrue("Inner created task finished", executed[0]);
}
示例2: testDeadlock
import org.openide.util.Task; //导入依赖的package包/类
/**
* Test that ChangeEvent is not fired under document lock during loading document.
*
* NbLikeEditorKit is used so document can be write locked using NbDocument.runAtomic in CES.prepareDocument.
*
* @throws java.lang.Exception
*/
public void testDeadlock () throws Exception {
support.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
Document doc = ((EnhancedChangeEvent) evt).getDocument();
if (doc != null) {
isDocumentLocked = Deadlock169717Test.isReadLocked(doc);
}
}
});
//Use prepare document to make sure stateChanged above is called BEFORE test ends
//so isDocumentLocked is set.
Task t = support.prepareDocument();
t.waitFinished();
assertFalse("Document cannot be locked", isDocumentLocked);
}
示例3: postUpdate
import org.openide.util.Task; //导入依赖的package包/类
public Task postUpdate() {
Task t = initTask;
if (t != null && t.isFinished()) {
scheduleUpdate();
return t;
}
if (t == null) {
return initTask = KeymapModel.RP.post(new Runnable() {
public void run() {
// just initialize
mutableModel.getCategories();
mutableModel.getItems("");
scheduleUpdate();
}
});
} else if (t.isFinished()) {
scheduleUpdate();
}
return t;
}
示例4: testWaitOnStrangeTaskThatStartsItsExecutionInOverridenWaitFinishedMethodLikeFolderInstancesDo
import org.openide.util.Task; //导入依赖的package包/类
public void testWaitOnStrangeTaskThatStartsItsExecutionInOverridenWaitFinishedMethodLikeFolderInstancesDo () throws Exception {
class MyTask extends Task {
private int values;
public MyTask () {
notifyFinished ();
}
public void waitFinished () {
notifyRunning ();
values++;
notifyFinished ();
}
}
MyTask my = new MyTask ();
assertTrue ("The task thinks that he is finished", my.isFinished ());
assertTrue ("Ok, even with timeout we got the result", my.waitFinished (1000));
assertEquals ("But the old waitFinished is called", 1, my.values);
}
示例5: testSomeMethod
import org.openide.util.Task; //导入依赖的package包/类
@Test
public void testSomeMethod() throws Exception {
T t1 = new T();
T t2 = new T();
List<Task> l = new ArrayList<Task>();
l.add(t1);
l.add(Task.EMPTY);
l.add(t2);
Task p = new ProxyTask(l);
assertFalse("Not finished yet", p.waitFinished(100));
t2.done();
assertFalse("Still not finished yet", p.waitFinished(100));
t1.done();
p.waitFinished();
}
示例6: testStop
import org.openide.util.Task; //导入依赖的package包/类
public void testStop() {
final boolean[] ok = { false };
onStartStop.initialize();
onStartStop.waitOnStart();
final Runnable run = new Runnable() {
@Override public void run() {
ok[0] = true;
}
};
stop.add(run);
List<ModuleInfo> modules = Collections.singletonList(Modules.getDefault().ownerOf(run.getClass()));
for (Task t : onStartStop.startClose(modules)) {
t.waitFinished();
}
assertTrue("Initialized", ok[0]);
}
示例7: testWaitFinished0WaitsUntilFinished
import org.openide.util.Task; //导入依赖的package包/类
public void testWaitFinished0WaitsUntilFinished() throws Exception {
Task task = new Task(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
}
});
Thread thread = new Thread(task);
thread.start();
task.waitFinished(0);
assertTrue ("Should be finished", task.isFinished());
}
示例8: waitFor
import org.openide.util.Task; //导入依赖的package包/类
public static boolean waitFor(Task t) {
assert EventQueue.isDispatchThread();
if (!PENDING.isEmpty()) {
PROCESSOR.run();
return false;
}
Thread previous = null;
try {
previous = WAKE_UP.enter();
if (!t.waitFinished(10000)) {
flush();
return false;
}
} catch (InterruptedException ex) {
flush();
return false;
} finally {
WAKE_UP.exit(previous);
}
return true;
}
示例9: testWaitForItself
import org.openide.util.Task; //导入依赖的package包/类
public void testWaitForItself() {
final Semaphore s = new Semaphore(0);
class R implements Runnable {
int cnt;
volatile Task waitFor;
@Override
public void run() {
cnt++;
try {
s.acquire(); // Ensure waitFor != null.
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
waitFor.waitFinished();
}
}
R r = new R();
r.waitFor = new AWTTask(r, null);
s.release();
r.waitFor.waitFinished();
assertEquals("Executed once", 1, r.cnt);
}
示例10: detach
import org.openide.util.Task; //导入依赖的package包/类
private Task detach() {
Task t;
synchronized (allSessions) {
Reference<ShellSession> refS = allSessions.get(consoleDocument);
if (refS != null && refS.get() == this) {
allSessions.remove(consoleDocument);
detached = true;
} else {
return Task.EMPTY;
}
}
// closed = true;
model.detach();
closed();
if (exec != null) {
FORCE_CLOSE_RP.post(this::forceCloseStreams, 300);
}
// leave the model
gsm.getGuardedSections().forEach((GuardedSection gs) -> gs.removeSection());
return sendJShellClose();
}
示例11: sendJShellClose
import org.openide.util.Task; //导入依赖的package包/类
private synchronized Task sendJShellClose() {
RemoteJShellService e;
synchronized (this) {
if (launcher == null) {
return Task.EMPTY;
}
e = this.exec;
}
if (e != null) {
e.requestShutdown();
}
// possibly delayed, if the evaluator is just processing some remote call.
return evaluator.post(() -> {
try {
launcher.closeState();
} catch (InternalError ex) {
// ignore
}
forceCloseStreams();
});
}
示例12: testCheckFinishedWithTrue
import org.openide.util.Task; //导入依赖的package包/类
public void testCheckFinishedWithTrue () {
RequestProcessor rp = new RequestProcessor ("Finish");
class R extends Object implements Runnable {
RequestProcessor.Task t;
public void run () {
if (t.isFinished ()) {
fail ("Finished when running");
}
}
}
R r = new R ();
RequestProcessor.Task task = rp.create(r, true);
r.t = task;
assertTrue("It has to be finished after creation", task.isFinished());
task.waitFinished();
// rest is the same
doCommonTestWithScheduling(task);
}
示例13: getReqularlyTimerTask
import org.openide.util.Task; //导入依赖的package包/类
private static RequestProcessor.Task getReqularlyTimerTask () {
if (regularlyCheck == null) {
// only for ordinary periods
if (getWaitPeriod () > 0) {
int waitPeriod = getWaitPeriod ();
int restTime = waitPeriod;
// calculate rest time to check
if (AutoupdateSettings.getLastCheck () != null) {
restTime = waitPeriod - (int)(System.currentTimeMillis () - AutoupdateSettings.getLastCheck ().getTime ());
}
// if restTime < 0 then schedule next round by given period
if (restTime <= 0) {
restTime = waitPeriod;
}
regularlyCheck = REGULARLY_CHECK_TIMER.post (doCheck, restTime, Thread.MIN_PRIORITY);
}
}
return regularlyCheck;
}
示例14: testWaitOnStrangeTaskThatTakesReallyLongTime
import org.openide.util.Task; //导入依赖的package包/类
public void testWaitOnStrangeTaskThatTakesReallyLongTime () throws Exception {
class MyTask extends Task {
public MyTask () {
notifyFinished ();
}
public void waitFinished () {
try {
Thread.sleep (5000);
} catch (InterruptedException ex) {
fail ("Should not happen");
}
}
}
MyTask my = new MyTask ();
assertTrue ("The task thinks that he is finished", my.isFinished ());
assertFalse ("but still it get's called, but timeouts", my.waitFinished (1000));
}
示例15: taskFinished
import org.openide.util.Task; //导入依赖的package包/类
/**
*/
@Override
public void taskFinished(Task task) {
Runnable rTask;
synchronized (Manager.this) {
rTask = Manager.this.tasksMap.remove(task);
}
if (rTask != null) {
Manager.this.taskFinished(rTask);
}
}