Search in sources :

Example 91 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class ClientNotificationDispatcher method dispatchForNode.

/**
 * the notification will be applied sync if the method invocation is done in with a {@link IClientSession} in the
 * {@link RunContext}. The sync execution is due to piggyback notifications expected to be applied after a successful
 * backendcall. In case no {@link IClientSession} is in the current {@link RunContext} the notification is applied
 * async.
 *
 * @param notification
 */
public void dispatchForNode(final Serializable notification, final IClientNotificationAddress address) {
    if (IClientSession.CURRENT.get() != null) {
        // dispatch sync for piggyback notifications
        dispatchSync(notification, address);
    } else {
        // dispatch async
        IFuture<Void> future = Jobs.schedule(new IRunnable() {

            @Override
            public void run() throws Exception {
                dispatchSync(notification, address);
            }
        }, Jobs.newInput().withRunContext(ClientRunContexts.copyCurrent()).withName("Dispatching client notification"));
        addPendingNotification(future);
        future.whenDone(new P_NotificationFutureCallback(future), null);
    }
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable)

Example 92 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class AbstractForm method callInitializer.

protected void callInitializer() {
    if (isInitialized()) {
        return;
    }
    // Remember the initial ClientRunContext to not loose the Form from current calling context.
    m_initialClientRunContext = ClientRunContexts.copyCurrent();
    // Run the initialization on behalf of this Form.
    ClientRunContexts.copyCurrent().withForm(this).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            interceptInitConfig();
            postInitConfig();
            setInitialized();
        }
    });
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException)

Example 93 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class AbstractForm method installFormCloseTimer.

/**
 * Installs the timer to close the Form once the given seconds elapse
 */
private IFuture<?> installFormCloseTimer(final long seconds) {
    final long startMillis = System.currentTimeMillis();
    final long delayMillis = TimeUnit.SECONDS.toMillis(seconds);
    return ModelJobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            final long elapsedMillis = System.currentTimeMillis() - startMillis;
            final long remainingSeconds = TimeUnit.MILLISECONDS.toSeconds(delayMillis - elapsedMillis);
            if (!isCloseTimerArmed()) {
                setSubTitle(null);
            } else if (remainingSeconds > 0) {
                setSubTitle("" + remainingSeconds);
            } else {
                // cancel the periodic action
                setCloseTimerArmed(false);
                try {
                    interceptCloseTimer();
                } catch (RuntimeException | PlatformError e) {
                    throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
                }
            }
        }
    }, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withName("Close timer").withExceptionHandling(null, false).withExecutionTrigger(Jobs.newExecutionTrigger().withSchedule(SimpleScheduleBuilder.repeatSecondlyForever())));
}
Also used : PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) PlatformExceptionTranslator(org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException)

Example 94 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class AbstractPage method getTable.

@Override
public T getTable(boolean create) {
    if (create && m_table == null) {
        if (isInitializing()) {
            LOG.warn("Table in page {} is created during page init. This is not recommended. The table should be created lazily when the page is activated. " + "Use e.g. the execInitTable() callback to access the table after it has been created.", getClass(), new Exception("origin"));
        }
        createDisplayParentRunContext().run(new IRunnable() {

            @Override
            public void run() throws Exception {
                runInExtensionContext(new Runnable() {

                    @Override
                    public void run() {
                        m_table = createTable();
                        if (m_table != null) {
                            // calls execInitTable of AbstractTable
                            m_table.initTable();
                            firePageChanged();
                            addDefaultTableControls();
                            // calls execInitTable of AbstractPage
                            interceptInitTable();
                            fireAfterTableInit();
                        }
                    }
                });
            }
        });
    }
    return m_table;
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) VetoException(org.eclipse.scout.rt.platform.exception.VetoException)

Example 95 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class AbstractPage method lazyCreateAndInitializeMenus.

@Override
protected List<IMenu> lazyCreateAndInitializeMenus() {
    /* NOSONAR
    if (isInitializing()) {
      //do not warn in 15.4, this code was introduced in 16.0
      LOG.warn(
          "Menus in page {} are now created during page init. This is not recommended. The menus should be created lazily when the page is activated. "
              + "Use e.g. the execInitTable() callback to access the table after it has been created.",
          getClass(), new Exception("origin"));
    }
     */
    final AtomicReference<List<IMenu>> ref = new AtomicReference<>();
    createDisplayParentRunContext().run(new IRunnable() {

        @Override
        public void run() throws Exception {
            runInExtensionContext(new Runnable() {

                @Override
                public void run() {
                    ref.set(AbstractPage.super.lazyCreateAndInitializeMenus());
                }
            });
        }
    });
    return ref.get();
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) List(java.util.List) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) VetoException(org.eclipse.scout.rt.platform.exception.VetoException)

Aggregations

IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)260 Test (org.junit.Test)210 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)82 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)68 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)40 ArrayList (java.util.ArrayList)36 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)26 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)21 IBlockingCondition (org.eclipse.scout.rt.platform.job.IBlockingCondition)20 IExecutionSemaphore (org.eclipse.scout.rt.platform.job.IExecutionSemaphore)20 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)19 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)17 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)13 Times (org.eclipse.scout.rt.testing.platform.runner.Times)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 IFuture (org.eclipse.scout.rt.platform.job.IFuture)10 IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)10 JMSException (javax.jms.JMSException)9