Package commonj.work

Examples of commonj.work.WorkListener


    /*
     * Method to indicate a work start.
     */
    private void workStarted(final WorkItemImpl workItem, final Work work) {
        WorkListener listener = workItems.get(workItem);
        if (listener != null) {
            workItem.setStatus(WorkEvent.WORK_STARTED);
            WorkEvent event = new WorkEventImpl(workItem);
            listener.workStarted(event);
        }
    }
View Full Code Here


    /*
     * Method to indicate a work completion.
     */
    private void workCompleted(final WorkItemImpl workItem, final Work work, final WorkException exception) {
        WorkListener listener = workItems.get(workItem);
        if (listener != null) {
            workItem.setStatus(WorkEvent.WORK_COMPLETED);
            workItem.setResult(work);
            workItem.setException(exception);
            WorkEvent event = new WorkEventImpl(workItem);
            listener.workCompleted(event);
            workItems.remove(workItem);
        }
    }
View Full Code Here

     *
     * @param workItem Work item representing the work that was accepted.
     * @param work     Work that was accepted.
     */
    private void workAccepted(final DefaultWorkItem workItem, final Work work) {
        WorkListener listener = workItems.get(workItem);
        if (listener != null) {
            workItem.setStatus(WorkEvent.WORK_ACCEPTED);
            WorkEvent event = new DefaultWorkEvent(workItem);
            listener.workAccepted(event);
        }
    }
View Full Code Here

    /*
     * Method to indicate a work start.
     */
    private void workStarted(final DefaultWorkItem workItem, final Work work) {
        WorkListener listener = workItems.get(workItem);
        if (listener != null) {
            workItem.setStatus(WorkEvent.WORK_STARTED);
            WorkEvent event = new DefaultWorkEvent(workItem);
            listener.workStarted(event);
        }
    }
View Full Code Here

    /*
     * Method to indicate a work completion.
     */
    private void workCompleted(final DefaultWorkItem workItem, final Work work, final WorkException exception) {
        WorkListener listener = workItems.get(workItem);
        if (listener != null) {
            workItem.setStatus(WorkEvent.WORK_COMPLETED);
            workItem.setResult(work);
            workItem.setException(exception);
            WorkEvent event = new DefaultWorkEvent(workItem);
            listener.workCompleted(event);
            workItems.remove(workItem);
        }
    }
View Full Code Here

        verify(work);
    }

    public void testListener() throws Exception {
        final CountDownLatch latch = new CountDownLatch(1);
        WorkListener listener = createStrictMock(WorkListener.class);
        listener.workAccepted(isA(WorkEvent.class));
        listener.workStarted(isA(WorkEvent.class));
        listener.workCompleted(isA(WorkEvent.class));
        expectLastCall();
        replay(listener);
        Work work = createMock(Work.class);
        work.run();
        expectLastCall().andStubAnswer(new IAnswer<Object>() {
View Full Code Here

    }

    public void testDelayListener() throws Exception {
        final CountDownLatch latch = new CountDownLatch(1);
        final CountDownLatch latch2 = new CountDownLatch(1);
        WorkListener listener = createStrictMock(WorkListener.class);
        listener.workAccepted(isA(WorkEvent.class));
        listener.workStarted(isA(WorkEvent.class));
        listener.workCompleted(isA(WorkEvent.class));
        expectLastCall().andStubAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                latch2.countDown();
                return null;
            }
View Full Code Here

        verify(work);
    }

    public void testErrorListener() throws Exception {
        final CountDownLatch latch = new CountDownLatch(1);
        WorkListener listener = createStrictMock(WorkListener.class);
        listener.workAccepted(isA(WorkEvent.class));
        listener.workStarted(isA(WorkEvent.class));
        listener.workCompleted(isA(WorkEvent.class));
        replay(listener);
        Work work = createMock(Work.class);
        work.run();
        expectLastCall().andStubAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
View Full Code Here

TOP

Related Classes of commonj.work.WorkListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.