当前位置: 首页>>代码示例>>Java>>正文


Java Task.waitFinished方法代码示例

本文整理汇总了Java中org.openide.util.Task.waitFinished方法的典型用法代码示例。如果您正苦于以下问题:Java Task.waitFinished方法的具体用法?Java Task.waitFinished怎么用?Java Task.waitFinished使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.util.Task的用法示例。


在下文中一共展示了Task.waitFinished方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:Deadlock169717Test.java

示例2: 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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ProxyTaskTest.java

示例3: 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]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:NbStartStopTest.java

示例4: testPlainTaskWaitsForBeingExecuted

import org.openide.util.Task; //导入方法依赖的package包/类
public void testPlainTaskWaitsForBeingExecuted () throws Exception {
    R run = new R ();
    Task t = new Task (run);
    
    Thread thread = new Thread (t);
    synchronized (run) {
        thread.start ();
        run.wait ();
    }
    
    assertFalse ("Not finished", t.isFinished ());
    synchronized (run) {
        run.notify ();
    }
    
    t.waitFinished ();
    assertTrue ("Finished", t.isFinished ());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:TaskTest.java

示例5: testWaitWithTimeOutReturnsAfterTimeOutWhenTheTaskIsNotComputedAtAll

import org.openide.util.Task; //导入方法依赖的package包/类
public void testWaitWithTimeOutReturnsAfterTimeOutWhenTheTaskIsNotComputedAtAll () throws Exception {
    if (!canWait1s()) {
        LOG.warning("Skipping testWaitWithTimeOutReturnsAfterTimeOutWhenTheTaskIsNotComputedAtAll, as the computer is not able to wait 1s!");
        return;
    }
    
    long time = -1;
    
    CharSequence log = Log.enable("org.openide.util.Task", Level.FINER);
    for (int i = 1; i < 10; i++) {
        Task t = new Task (new R ());
        time = System.currentTimeMillis ();
        t.waitFinished (1000);
        time = System.currentTimeMillis () - time;

        assertFalse ("Still not finished", t.isFinished ());
        if (time >= 900 && time < 1100) {
            return;
        }
        LOG.log(Level.INFO, "Round {0} took {1}", new Object[]{i, time});
    }
    
    fail ("Something wrong happened the task should wait for 1000ms but it took: " + time + "\n" + log);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:TaskTest.java

示例6: 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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TaskTest.java

示例7: waitForCloseFinish

import org.openide.util.Task; //导入方法依赖的package包/类
private void waitForCloseFinish() {
    Task closeTask;
    synchronized (lock) {
        closeTask = activeCloseTask;
    }
    // Must wait for finishing outside of "lock" otherwise deadlock with close task processing
    if (closeTask != null) {
        closeTask.waitFinished();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:DocumentOpenClose.java

示例8: testBlockGetDocument

import org.openide.util.Task; //导入方法依赖的package包/类
public void testBlockGetDocument () throws Exception {
    //Start asynchronous loading, it contains wait so document
    //loading is blocked till notifyAll below.
    synchronized (LOCK) {
        isWaiting = false;
    }
    Task prepare = support.prepareDocument();
    while (true) {
        Thread.sleep(200);
        synchronized (LOCK) {
            if (isWaiting) {
                break;
            }
        }
    }

    UndoRedo u = support.getUndoRedo();
    //Check that following methods will return even if document is being loaded
    u.getUndoPresentationName();
    u.getRedoPresentationName();
    
    //Finish document loading cleanly
    synchronized (LOCK) {
        LOCK.notifyAll();
    }
    prepare.waitFinished();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:CloneableEditor143143Test.java

示例9: testPrepareDocument

import org.openide.util.Task; //导入方法依赖的package包/类
public void testPrepareDocument() throws Exception {
    content = "Ahoj\nMyDoc";
    Task task = support.prepareDocument();
    task.waitFinished();

    try {
        Object o = new Object();
        assertGC("", new WeakReference<Object>(o));
    } catch (AssertionFailedError e) {
        // ignore, intentional
    }

    Document doc = support.getDoc();
    assertNotNull("Document should not be GCed while its loading task exists", doc);

    Task task2 = support.prepareDocument();
    assertTrue("Loading task should be finished", task2.isFinished());
    assertNotSame("Expecting different task instance", task, task2);
    task2 = null;
    
    Reference<Task> taskRef = new WeakReference<Task>(task);
    Reference<Document> docRef = new WeakReference<Document>(doc);
    task = null;
    doc = null;
    assertGC("Can't GC document loading task", taskRef);
    assertGC("Can't GC document", docRef);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:CloneableEditorSupportTest.java

示例10: testRefreshProblem46885

import org.openide.util.Task; //导入方法依赖的package包/类
public void testRefreshProblem46885 () throws Exception {
    StyledDocument doc = support.openDocument ();
    
    doc.insertString (0, "A text", null);
    support.saveDocument ();
    
    content = "New";
    propL.firePropertyChange (CloneableEditorSupport.Env.PROP_TIME, null, null);
    
    waitAWT ();
    Task reloadTask = support.reloadDocument();
    reloadTask.waitFinished();
    
    String s = doc.getText (0, doc.getLength ());
    assertEquals ("Text has been updated", content, s);
    

    long oldtime = System.currentTimeMillis ();
    Thread.sleep(300);
    err.info("Document modified");
    doc.insertString (0, "A text", null);
    err.info("Document about to save");
    support.saveDocument ();
    err.info("Document saved");
    s = doc.getText (0, doc.getLength ());

    err.info("Current content: " + s);
    content = "NOT TO be loaded";
    propL.firePropertyChange (CloneableEditorSupport.Env.PROP_TIME, null, new Date (oldtime));
    
    waitAWT ();
    
    String s1 = doc.getText (0, doc.getLength ());
    err.info("New content: " + s1);
    assertEquals ("Text has not been updated", s, s1);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:ReloadTest.java

示例11: testEDTAssert

import org.openide.util.Task; //导入方法依赖的package包/类
public void testEDTAssert () {
    // run off EQ thread and check
    Task task = RequestProcessor.getDefault().post(new Runnable() {
        public void run() {
            // test both versions, assertions on and off
            checkEDTAssert(WindowManagerImpl.assertsEnabled);
            WindowManagerImpl.assertsEnabled = !WindowManagerImpl.assertsEnabled;
            checkEDTAssert(WindowManagerImpl.assertsEnabled);
        }
    });

    task.waitFinished();

    assertTrue(failMsg, checkOK);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:WindowManagerImplTest.java

示例12: testParralelMods

import org.openide.util.Task; //导入方法依赖的package包/类
public void testParralelMods() throws Exception {
        loggingOn();
        RandomTestContainer container = createContainer();
        JEditorPane pane = container.getInstance(JEditorPane.class);
        final Document doc = pane.getDocument();
        doc.putProperty("mimeType", "text/x-java");
        final RandomTestContainer.Context context = container.context();
        DocumentTesting.setSameThreadInvoke(context, true); // Do not post to EDT
        // (Done automatically) Logger.getLogger("org.netbeans.editor.BaseDocument.EDT").setLevel(Level.OFF);
//        ViewHierarchyRandomTesting.disableHighlighting(container);
        int opCount = 100;
        final int throughput = 5; // How many truly parallel invocations
        RequestProcessor rp = new RequestProcessor("Doc-Mod", throughput, false, false);
        Task task = null;
        for (int i = opCount - 1; i >= 0; i--) {
            task = rp.post(new Runnable() {
                @Override
                public void run() {
                    // make sure insert won't fail for multiple threads
                    int offset = Math.max(doc.getLength() - throughput, 0);
                    try {
                        DocumentTesting.insert(context, offset, "ab");
                        DocumentTesting.remove(context, offset, 1);
                    } catch (Exception ex) {
                        throw new IllegalStateException(ex);
                    }
                }
            });
        }
        task.waitFinished();
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:JavaViewHierarchyRandomTest.java

示例13: doWithProgress

import org.openide.util.Task; //导入方法依赖的package包/类
public static <T> T doWithProgress(String message, final Callable<? extends T> run) throws InvocationTargetException {
    final ProgressPanel panel = new ProgressPanel();
    panel.setCancelVisible(false);
    panel.setText(message);
    ProgressHandle handle = ProgressHandleFactory.createHandle(null);
    JComponent progress = ProgressHandleFactory.createProgressComponent(handle);
    handle.start();
    final List<T> result = new ArrayList<T>(1);
    final List<Exception> exception = new ArrayList<Exception>(1);
    try {
        Task task = RequestProcessor.getDefault().post(new Runnable() {
            public void run() {
                if (!SwingUtilities.isEventDispatchThread()) {
                    try {
                        result.add(run.call());
                        exception.add(null);
                    } catch (Exception e) {
                        result.add(null);
                        exception.add(e);
                    } finally {
                        SwingUtilities.invokeLater(this);
                    }
                } else {
                    panel.close();
                }
            }
        });
        panel.open(progress);
        task.waitFinished();
    } finally {
        handle.finish();
    }
    Exception inner = exception.get(0);
    if (inner != null) {
        throw new InvocationTargetException(inner, inner.getMessage());
    }
    return result.get(0);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:DbUtilities.java

示例14: deadlockSimulation

import org.openide.util.Task; //导入方法依赖的package包/类
private void deadlockSimulation() {
    Task task = org.openide.util.RequestProcessor.getDefault().post(new Runnable () {
        public void run() {
            StreamPool.find(tfs);
        }                
    });
    task.waitFinished();                        
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:StreamPool50137Test.java

示例15: open

import org.openide.util.Task; //导入方法依赖的package包/类
StyledDocument open() throws IOException {
    DocumentLoad load;
    Task task;
    if (LOG.isLoggable(Level.FINEST)) {
        LOG.log(Level.FINEST, "open() requested by", new Exception());
    }
    synchronized (lock) {
        StyledDocument openDoc = retainExistingDocLA();
        if (openDoc != null) {
            if (LOG.isLoggable(Level.FINER)) {
                LOG.finer("open(): Existing openDoc retained.\n"); // NOI18N
            }
            return openDoc;
        }
        switch (documentStatus) {
            case OPENED:
                // Doc was null (retainDocLA() failed) but automatic close()
                // due to docRef GC might already be scheduled or not yet.
                // Anyway ensure closing task gets scheduled before opening task (by passing false).
                if (LOG.isLoggable(Level.FINER)) {
                    LOG.finer("open(): status OPENED but doc GCed. Schedule close task followed by possible open task\n"); // NOI18N
                }
                closeImplLA(null, false);
                if (activeOpen == null) {
                    initLoadTaskLA();
                }
                load = activeOpen;
                task = activeOpenTask;
                break;
            case CLOSED:
                if (LOG.isLoggable(Level.FINER)) {
                    LOG.finer("open(): status CLOSED. Schedule a synchronous open task\n"); // NOI18N
                }
                if (activeOpen == null) {
                    initLoadTaskLA();
                }
                load = activeOpen;
                task = activeOpenTask;
                break;
            case RELOADING:
                load = activeReload;
                task = activeReloadTask;
                break;
            case LOADING:
                load = activeOpen;
                task = activeOpenTask;
                break;
            default:
                throw invalidStatus();
        }
    }
    if (load == null || task == null) {
        LOG.info("load=" + load + ", task=" + task + ", this: " + this); // Will throw NPE so dump state
    }
    // Thread may be RP thread in case CES.openDocument() is called synchronously
    // from fireDocumentChange() upon document close in which case
    // task.waitFinished() will run the task synchronously.
    task.waitFinished();
    if (load.loadIOException != null) {
        throw load.loadIOException;
    }
    if (load.loadRuntimeException != null) {
        throw load.loadRuntimeException;
    }
    return load.loadDoc;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:67,代码来源:DocumentOpenClose.java


注:本文中的org.openide.util.Task.waitFinished方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。