Search in sources :

Example 1 with JobEventData

use of org.eclipse.scout.rt.platform.job.listener.JobEventData in project scout.rt by eclipse.

the class JobManager method shutdown.

@Override
public final void shutdown() {
    LOG.debug("JobManager shutting down.");
    m_shutdownLock.writeLock().lock();
    try {
        m_shutdown = true;
    } finally {
        m_shutdownLock.writeLock().unlock();
    }
    // Dispose Futures.
    m_futures.dispose();
    // Shutdown the Executor.
    shutdownExecutor(m_executor);
    // Fire event that job manager was shutdown.
    fireEvent(new JobEvent(this, JobEventType.JOB_MANAGER_SHUTDOWN, new JobEventData()));
}
Also used : JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) JobEventData(org.eclipse.scout.rt.platform.job.listener.JobEventData)

Example 2 with JobEventData

use of org.eclipse.scout.rt.platform.job.listener.JobEventData in project scout.rt by eclipse.

the class JobEventFilterTest method test2.

@Test
public void test2() {
    JobEventFilter filter = new JobEventFilter(JobEventType.JOB_STATE_CHANGED, JobEventType.JOB_MANAGER_SHUTDOWN);
    assertTrue(filter.accept(new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData())));
    assertTrue(filter.accept(new JobEvent(mock(IJobManager.class), JobEventType.JOB_MANAGER_SHUTDOWN, new JobEventData())));
    assertFalse(filter.accept(new JobEvent(mock(IJobManager.class), JobEventType.JOB_EXECUTION_HINT_ADDED, new JobEventData())));
}
Also used : JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) IJobManager(org.eclipse.scout.rt.platform.job.IJobManager) JobEventData(org.eclipse.scout.rt.platform.job.listener.JobEventData) Test(org.junit.Test)

Example 3 with JobEventData

use of org.eclipse.scout.rt.platform.job.listener.JobEventData in project scout.rt by eclipse.

the class JobEventFilterTest method test1.

@Test
public void test1() {
    JobEventFilter filter = new JobEventFilter(JobEventType.JOB_STATE_CHANGED);
    assertTrue(filter.accept(new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData())));
    assertFalse(filter.accept(new JobEvent(mock(IJobManager.class), JobEventType.JOB_MANAGER_SHUTDOWN, new JobEventData())));
    assertFalse(filter.accept(new JobEvent(mock(IJobManager.class), JobEventType.JOB_EXECUTION_HINT_ADDED, new JobEventData())));
}
Also used : JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) IJobManager(org.eclipse.scout.rt.platform.job.IJobManager) JobEventData(org.eclipse.scout.rt.platform.job.listener.JobEventData) Test(org.junit.Test)

Example 4 with JobEventData

use of org.eclipse.scout.rt.platform.job.listener.JobEventData in project scout.rt by eclipse.

the class SessionJobEventFilterTest method test.

@Test
public void test() {
    IServerSession session1 = mock(IServerSession.class);
    IServerSession session2 = mock(IServerSession.class);
    SessionJobEventFilter filter = new SessionJobEventFilter(session1);
    // Tests JobEvent of an event without a job associated
    JobEvent event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(null));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job without RunContext
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput())));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with RunContext
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(RunContexts.empty()))));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext without session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ServerRunContexts.empty()))));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext with correct session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ServerRunContexts.empty().withSession(session1)))));
    assertTrue(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext with wrong session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ServerRunContexts.empty().withSession(session2)))));
    assertFalse(filter.accept(event));
    // Tests adaptable to the session
    assertSame(session1, filter.getAdapter(ISession.class));
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) SessionJobEventFilter(org.eclipse.scout.rt.shared.job.filter.event.SessionJobEventFilter) IServerSession(org.eclipse.scout.rt.server.IServerSession) IJobManager(org.eclipse.scout.rt.platform.job.IJobManager) JobEventData(org.eclipse.scout.rt.platform.job.listener.JobEventData) Test(org.junit.Test)

Example 5 with JobEventData

use of org.eclipse.scout.rt.platform.job.listener.JobEventData in project scout.rt by eclipse.

the class BlockingCondition method blockJobThread.

/**
 * Blocks a thread associated with a job.
 */
protected void blockJobThread(final JobFutureTask<?> futureTask, final long timeout, final TimeUnit unit, final boolean awaitInterruptibly, final String... executionHints) {
    if (!m_blocking) {
        return;
    }
    IRegistrationHandle waitForHints = IRegistrationHandle.NULL_HANDLE;
    RuntimeException exceptionWhileWaiting = null;
    Error errorWhileWaiting = null;
    m_lock.lock();
    try {
        if (!m_blocking) {
            // double-checked locking
            return;
        }
        // Associate the future with execution hints.
        waitForHints = registerWaitForHints(futureTask, executionHints);
        // Change job state.
        futureTask.changeState(new JobEventData().withState(JobState.WAITING_FOR_BLOCKING_CONDITION).withFuture(futureTask).withBlockingCondition(this));
        // Release the permit if being a semaphore aware task, but only if currently being a permit owner.
        futureTask.releasePermit();
        try {
            awaitUntilSignaledOrTimeout(timeout, unit, awaitInterruptibly);
        } catch (final RuntimeException e) {
            exceptionWhileWaiting = e;
        } catch (final Error e) {
            // NOSONAR
            errorWhileWaiting = e;
        }
    } finally {
        m_lock.unlock();
    }
    // re-acquire the permit (must be outside the lock)
    acquirePermitUninterruptibly(futureTask);
    // prepare to continue execution
    // if released via 'setBlocking(false)', the 'wait-for' hints are already disposed, but not if interrupted or timed out.
    waitForHints.dispose();
    futureTask.changeState(JobState.RUNNING);
    if (errorWhileWaiting != null) {
        // NOSONAR
        throw errorWhileWaiting;
    }
    if (exceptionWhileWaiting != null) {
        throw exceptionWhileWaiting;
    }
}
Also used : ThreadInterruptedError(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError) TimedOutError(org.eclipse.scout.rt.platform.util.concurrent.TimedOutError) IRegistrationHandle(org.eclipse.scout.rt.platform.util.IRegistrationHandle) JobEventData(org.eclipse.scout.rt.platform.job.listener.JobEventData)

Aggregations

JobEventData (org.eclipse.scout.rt.platform.job.listener.JobEventData)7 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)6 IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)5 Test (org.junit.Test)5 IClientSession (org.eclipse.scout.rt.client.IClientSession)2 ISession (org.eclipse.scout.rt.shared.ISession)2 SessionJobEventFilter (org.eclipse.scout.rt.shared.job.filter.event.SessionJobEventFilter)2 IRegistrationHandle (org.eclipse.scout.rt.platform.util.IRegistrationHandle)1 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)1 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)1 IServerSession (org.eclipse.scout.rt.server.IServerSession)1