Package org.jboss.errai.bus.client.api

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


        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

            }

            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

      }

      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

      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

    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

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

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

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

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

        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

            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

TOP

Related Classes of org.jboss.errai.bus.client.api.AsyncTask

Copyright © 2018 www.massapicom. 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.