Examples of AsyncTask


Examples of org.jboss.errai.bus.client.api.AsyncTask

    timer.schedule((int) unit.convert(interval, TimeUnit.MILLISECONDS));
    return asyncTask;
  }

  private static AsyncTask createAsyncTask(final Runnable task, final Timer timer) {
    AsyncTask asyncTask = new AsyncTask() {
      boolean cancelled = false;

      public boolean cancel(boolean interrupt) {
        timer.cancel();
        return cancelled = true;
View Full Code Here

Examples of org.jboss.errai.bus.client.api.AsyncTask

      }

      if (autoStartStop) startIfTasks();
    }

    return new AsyncTask() {
      private boolean finished = false;

      public boolean cancel(boolean mayInterruptIfRunning) {
        task.cancel(mayInterruptIfRunning);
        return finished = true;
View Full Code Here

Examples of org.jboss.errai.bus.client.api.AsyncTask

    String commandType = message.getCommandType();
    String taskName = getTaskName(commandType);

    if (StartMatcher.matcher(commandType).matches()) {
      AsyncTask task = ctx.getAttribute(AsyncTask.class, taskName);

      // there's no task running in this context.
      if (task == null) {
        ResourceProvider<Double> randomNumberProvider = new ResourceProvider<Double>() {
          public Double get() {
            return Math.random();
          }
        };

        task = MessageBuilder.createConversation(message)
            .subjectProvided()
            .withProvided("Data", randomNumberProvider)
            .noErrorHandling()
            .replyRepeating(TimeUnit.MILLISECONDS, 50);

        System.out.println("New task started: " + taskName);
        ctx.setAttribute(taskName, task);
      }
      else {
        System.out.println("Task already started: " + taskName);
      }
    }
    else if (StopMatcher.matcher(commandType).matches()) {
      AsyncTask task = ctx.getAttribute(AsyncTask.class, taskName);

      if (task == null) {
        System.out.println("Nothing to stop: " + taskName);
      }
      else {
        System.out.println("Stopping: " + taskName);
        task.cancel(true);
        ctx.removeAttribute(taskName);
      }
    }
  }
View Full Code Here

Examples of org.jboss.errai.bus.client.api.AsyncTask

            public void run() {
                task.run();
            }
        };

        AsyncTask asyncTask = createAsyncTask(task, timer);
        timer.scheduleRepeating((int) unit.convert(interval, TimeUnit.MILLISECONDS));
        return asyncTask;
    }
View Full Code Here

Examples of org.jboss.errai.bus.client.api.AsyncTask

            public void run() {
                task.run();
            }
        };

        AsyncTask asyncTask = createAsyncTask(task, timer);
        timer.schedule((int) unit.convert(interval, TimeUnit.MILLISECONDS));
        return asyncTask;
    }
View Full Code Here

Examples of org.jboss.errai.bus.client.api.AsyncTask

        timer.schedule((int) unit.convert(interval, TimeUnit.MILLISECONDS));
        return asyncTask;
    }

    private static AsyncTask createAsyncTask(final Runnable task, final Timer timer) {
        AsyncTask asyncTask = new AsyncTask() {
            boolean cancelled = false;
            public boolean cancel(boolean interrupt) {
                timer.cancel();
                return cancelled = true;
            }
View Full Code Here

Examples of org.jboss.errai.bus.client.api.AsyncTask

            throw new RuntimeException(e);
        }
    }

    public AsyncTask scheduleRepeating(TimeUnit unit, int interval, Runnable task) {
        AsyncTask t = service.scheduleRepeating(task, unit, 0, interval);

        if (task instanceof HasAsyncTaskRef) {
            ((HasAsyncTaskRef) task).setAsyncTask(t);
        }
View Full Code Here

Examples of org.jboss.errai.bus.client.api.AsyncTask

        return t;
    }

    public AsyncTask schedule(TimeUnit unit, int interval, Runnable task) {
        AsyncTask t = service.schedule(task, unit, interval);

        if (task instanceof HasAsyncTaskRef) {
            ((HasAsyncTaskRef) task).setAsyncTask(t);
        }
View Full Code Here

Examples of org.jboss.errai.bus.client.api.AsyncTask

            }

            if (autoStartStop) startIfTasks();
        }

        return new AsyncTask() {
            private boolean finished = false;
            public boolean cancel(boolean mayInterruptIfRunning) {
                task.cancel(mayInterruptIfRunning);
                return finished = true;
            }
View Full Code Here

Examples of org.jboss.errai.bus.client.api.AsyncTask

      }

      private AsyncTask _sendRepeatingWith(final Message message, final RequestDispatcher viaThis, TimeUnit unit, int interval) {
        final boolean isConversational = message instanceof ConversationMessageWrapper;

        final AsyncTask task = TaskManagerFactory.get().scheduleRepeating(unit, interval, new HasAsyncTaskRef() {
          AsyncTask task;
          AsyncDelegateErrorCallback errorCallback;

          final Runnable sender;

          {
            errorCallback = new AsyncDelegateErrorCallback(this, message.getErrorCallback());

            if (isConversational) {
              final Message incomingMsg = ((ConversationMessageWrapper) message).getIncomingMessage();

              if (incomingMsg.hasPart(MessageParts.ReplyTo)) {
                sender = new Runnable() {
                  final String replyTo = incomingMsg
                          .get(String.class, MessageParts.ReplyTo);

                  @Override
                  public void run() {
                    try {
                      MessageBuilder.getMessageProvider().get()
                              .toSubject(replyTo)
                              .copyResource("Session", incomingMsg)
                              .addAllParts(message.getParts())
                              .addAllProvidedParts(message.getProvidedParts())
                              .errorsCall(errorCallback).sendNowWith(viaThis);
                    }
                    catch (Throwable t) {
                      t.printStackTrace();
                      getAsyncTask().cancel(true);
                    }
                  }
                };
              }
              else {
                sender = new Runnable() {

                  @Override
                  public void run() {
                    try {
                      MessageBuilder.getMessageProvider().get()
                              .copyResource("Session", incomingMsg)
                              .addAllParts(message.getParts())
                              .addAllProvidedParts(message.getProvidedParts())
                              .errorsCall(errorCallback).sendNowWith(viaThis);
                    }
                    catch (Throwable t) {
                      t.printStackTrace();
                      getAsyncTask().cancel(true);
                    }

                  }
                };
              }
            }
            else {
              sender = new Runnable() {
                @Override
                public void run() {
                  try {
                    viaThis.dispatchGlobal(MessageBuilder.getMessageProvider().get()
                            .addAllParts(message.getParts())
                            .addAllProvidedParts(message.getProvidedParts())
                            .errorsCall(errorCallback));
                  }
                  catch (Throwable t) {
                    t.printStackTrace();
                    getAsyncTask().cancel(true);
                  }
                }
              };
            }
          }

          @Override
          public void setAsyncTask(AsyncTask task) {
            synchronized (this) {
              this.task = task;
            }
          }


          @Override
          public AsyncTask getAsyncTask() {
            synchronized (this) {
              return task;
            }
          }

          @Override
          public void run() {
            sender.run();
          }
        });

        if (isConversational) {
          Object sessionResource = ((ConversationMessageWrapper) message).getIncomingMessage().getResource(Object.class, "Session");
          final LaundryReclaim reclaim =
                  LaundryListProviderFactory.get().getLaundryList(sessionResource).add(new Laundry() {
                            @Override
                            public void clean() {
                              task.cancel(true);
                            }
                          });

          task.setExitHandler(new Runnable() {
            @Override
            public void run() {
              reclaim.reclaim();
            }
          });
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.