Search in sources :

Example 1 with ThreadInfo

use of org.eclipse.scout.rt.platform.job.internal.NamedThreadFactory.ThreadInfo in project scout.rt by eclipse.

the class ThreadNameDecorator method decorate.

@Override
public IUndecorator decorate() throws Exception {
    final ThreadInfo threadInfo = ThreadInfo.CURRENT.get();
    threadInfo.updateThreadName(IFuture.CURRENT.get().getJobInput().getThreadName(), null);
    return new IUndecorator() {

        @Override
        public void undecorate() {
            // Restore to the original thread name.
            threadInfo.reset();
        }
    };
}
Also used : ThreadInfo(org.eclipse.scout.rt.platform.job.internal.NamedThreadFactory.ThreadInfo)

Example 2 with ThreadInfo

use of org.eclipse.scout.rt.platform.job.internal.NamedThreadFactory.ThreadInfo in project scout.rt by eclipse.

the class DevelopmentThreadNameDecorator method decorate.

@Override
public IUndecorator decorate() throws Exception {
    final ThreadInfo threadInfo = ThreadInfo.CURRENT.get();
    final IFuture<?> future = IFuture.CURRENT.get();
    // Update the thread name.
    threadInfo.updateThreadName(future.getJobInput().getThreadName(), buildExecutionInfo(future));
    // Decorate the thread name upon job state change.
    final IRegistrationHandle listenerRegistration = future.addListener(Jobs.newEventFilterBuilder().andMatchEventType(JobEventType.JOB_STATE_CHANGED).andMatchState(JobState.RUNNING, JobState.WAITING_FOR_PERMIT, JobState.WAITING_FOR_BLOCKING_CONDITION).toFilter(), new IJobListener() {

        @Override
        public void changed(final JobEvent event) {
            threadInfo.updateThreadName(future.getJobInput().getThreadName(), buildExecutionInfo(future));
        }
    });
    return new IUndecorator() {

        @Override
        public void undecorate() {
            // Restore to the original thread name.
            listenerRegistration.dispose();
            threadInfo.reset();
        }
    };
}
Also used : ThreadInfo(org.eclipse.scout.rt.platform.job.internal.NamedThreadFactory.ThreadInfo) JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) IRegistrationHandle(org.eclipse.scout.rt.platform.util.IRegistrationHandle) IJobListener(org.eclipse.scout.rt.platform.job.listener.IJobListener)

Aggregations

ThreadInfo (org.eclipse.scout.rt.platform.job.internal.NamedThreadFactory.ThreadInfo)2 IJobListener (org.eclipse.scout.rt.platform.job.listener.IJobListener)1 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)1 IRegistrationHandle (org.eclipse.scout.rt.platform.util.IRegistrationHandle)1