Search in sources :

Example 1 with IPingService

use of org.eclipse.scout.rt.shared.services.common.ping.IPingService in project scout.rt by eclipse.

the class ClientJobCancelTest method doPingRequestAsync.

/**
 * Runs a 'ping-request' which gets blocked in the service implementation.
 */
protected RequestData doPingRequestAsync(final String pingRequest) throws Exception {
    final BlockingCountDownLatch serviceCallSetupLatch = new BlockingCountDownLatch(1);
    final BlockingCountDownLatch serviceCallCompletedLatch = new BlockingCountDownLatch(1);
    final AtomicBoolean serviceCallInterrupted = new AtomicBoolean(false);
    // Mock the PingService.
    class PingService implements IPingService {

        @Override
        public String ping(String s) {
            try {
                assertTrue(serviceCallSetupLatch.countDownAndBlock());
            } catch (java.lang.InterruptedException e) {
                serviceCallInterrupted.set(true);
            } finally {
                serviceCallCompletedLatch.countDown();
            }
            return s.toUpperCase();
        }
    }
    // Create a separate RunContext with a separate RunMonitor, so we can wait for the service result in case of cancellation.
    final ClientRunContext runContext = ClientRunContexts.copyCurrent();
    final RunMonitor runMonitor = BEANS.get(RunMonitor.class);
    runContext.withRunMonitor(runMonitor);
    IFuture<String> pingFuture = Jobs.schedule(new Callable<String>() {

        @Override
        public String call() throws Exception {
            return runContext.call(new Callable<String>() {

                @Override
                public String call() throws Exception {
                    IBean<?> bean = TestingUtility.registerBean(new BeanMetaData(PingService.class).withInitialInstance(new PingService()).withApplicationScoped(true));
                    try {
                        return ServiceTunnelUtility.createProxy(IPingService.class).ping(pingRequest);
                    } finally {
                        TestingUtility.unregisterBeans(Arrays.asList(bean));
                    }
                }
            });
        }
    }, Jobs.newInput().withExceptionHandling(null, false));
    // Wait for the ping request to enter service implementation.
    assertTrue(serviceCallSetupLatch.await());
    return new RequestData(pingFuture, runMonitor, serviceCallSetupLatch, serviceCallCompletedLatch, serviceCallInterrupted);
}
Also used : BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IPingService(org.eclipse.scout.rt.shared.services.common.ping.IPingService) Callable(java.util.concurrent.Callable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientRunContext(org.eclipse.scout.rt.client.context.ClientRunContext) IPingService(org.eclipse.scout.rt.shared.services.common.ping.IPingService) RunMonitor(org.eclipse.scout.rt.platform.context.RunMonitor)

Example 2 with IPingService

use of org.eclipse.scout.rt.shared.services.common.ping.IPingService in project scout.rt by eclipse.

the class GeneralView method createMonitoringQuickLink.

private String createMonitoringQuickLink(HtmlComponent p) {
    if (!ACCESS.check(new UpdateServiceConfigurationPermission())) {
        return null;
    }
    final ProcessInspector inst = ProcessInspector.instance();
    if (inst.isEnabled()) {
        p.print("Monitor is active with maximum caching of " + (inst.getTimeout() / 1000 / 60) + " minutes [ ");
        p.linkAction("cache 2 min", new P_SetTimeoutAction(2));
        p.print(" | ");
        p.linkAction("cache 15 min", new P_SetTimeoutAction(15));
        p.print(" | ");
        p.linkAction("cache 60 min", new P_SetTimeoutAction(60));
        p.print(" | ");
        p.linkAction("deactivate", new P_EnableAction(false));
        p.print(" ]");
        p.br();
        if (inst.acceptCall(IPingService.class.getName(), "ping")) {
            p.linkAction("IPingService.ping (click to toggle)", new AbstractHtmlAction("IPingService.ignore") {

                @Override
                public void run() {
                    inst.getIgnoredCallSet().clear();
                    inst.getIgnoredCallSet().add(".*\\.IPingService\\.ping");
                }
            });
        } else {
            p.startLinkAction(new AbstractHtmlAction("IPingService.accept") {

                @Override
                public void run() {
                    inst.getIgnoredCallSet().clear();
                }
            });
            p.raw("<s>");
            p.printNoBreak("IPingService.ping");
            p.raw("</s>");
            p.printNoBreak(" (click to toggle)");
            p.endLinkAction();
        }
    } else {
        p.print("Monitor is inactive [ ");
        p.linkAction("activate", new P_EnableAction(true));
        p.print(" ]");
    }
    p.p();
    if (inst.isEnabled()) {
        return "<p><b>Note: Session Activity Monitor is enabled; this might affect performance and memory due to higher resource consumption during analysis.</b><p>";
    }
    return null;
}
Also used : UpdateServiceConfigurationPermission(org.eclipse.scout.rt.shared.security.UpdateServiceConfigurationPermission) AbstractHtmlAction(org.eclipse.scout.rt.server.admin.html.AbstractHtmlAction) IPingService(org.eclipse.scout.rt.shared.services.common.ping.IPingService) ProcessInspector(org.eclipse.scout.rt.server.admin.inspector.ProcessInspector)

Aggregations

IPingService (org.eclipse.scout.rt.shared.services.common.ping.IPingService)2 Callable (java.util.concurrent.Callable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ClientRunContext (org.eclipse.scout.rt.client.context.ClientRunContext)1 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)1 RunMonitor (org.eclipse.scout.rt.platform.context.RunMonitor)1 AbstractHtmlAction (org.eclipse.scout.rt.server.admin.html.AbstractHtmlAction)1 ProcessInspector (org.eclipse.scout.rt.server.admin.inspector.ProcessInspector)1 UpdateServiceConfigurationPermission (org.eclipse.scout.rt.shared.security.UpdateServiceConfigurationPermission)1 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)1