Uploaded image for project: 'Modular Service Container'
  1. Modular Service Container
  2. MSC-137

Helper APIs for LifecycleContext asynchronous handling

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Unresolved
    • Icon: Major Major
    • 1.6.0.Final
    • None
    • runtime
    • None

      Here's a typical usage of the MSC async start/stop API, here with a StartContext:

          final Runnable task = new Runnable() {
                  @Override
                  public void run() {
                      try {
                          jmsManager.createQueue(false, queueName, selectorString, durable, jndi);
                          queue = new HornetQQueue(queueName);
                          context.complete();
                      } catch (Throwable e) {
                          context.failed(MESSAGES.failedToCreate(e, "queue"));
                      }
                  }
              };
              try {
                  executorInjector.getValue().execute(task);
              } catch (RejectedExecutionException e) {
                  task.run();
              } finally {
                  context.asynchronous();
              }
      

      A bit nicer would be:

          final Callable<Void> task = new Callable<Void>() {
                  @Override
                  public Void call() {
                      try {
                          jmsManager.createQueue(false, queueName, selectorString, durable, jndi);
                          queue = new HornetQQueue(queueName);
                          return null;
                      } catch (Throwable e) {
                          throw MESSAGES.failedToCreate(e, "queue");
                      }
                  }
              };
              context.asynchronous(executorInjector.getValue(), task);
      
      

      A similar thing for StopContext would be cleaner since a Runnable could be used for 'task', as there is no need for the task to be able to throw StartException for the failure case.

              ropalka Richard Opalka
              bstansbe@redhat.com Brian Stansberry
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: