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()));
}
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())));
}
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())));
}
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));
}
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;
}
}
Aggregations