コード例 #1
0
 @SuppressWarnings("incomplete-switch")
 private void restart() {
   switch (state.get()) {
     case STARTING:
       Trace.debug(
           "Returning early from restart.  Already starting for project {0} and kind {1}",
           project.getName(), kind);
     case DISCONNECTED:
       Trace.debug(
           "Endpoint disconnected and skipping restart for project {0} and kind {1}",
           project.getName(), kind);
       return;
   }
   try {
     // TODO enhance fix to only check project once
     conn.refresh(project);
     Trace.debug(
         "WatchManager Rescheduling watch job for project {0} and kind {1}",
         project.getName(), kind);
     startWatch(project, backoff, lastConnect, this);
   } catch (Exception e) {
     Trace.debug(
         "WatchManager Unable to rescheduling watch job for project {0} and kind {1}",
         e, project.getName(), kind);
     stopWatch(project, conn);
   }
 }
コード例 #2
0
 @Override
 public void connected(List<IResource> resources) {
   Trace.debug(
       "WatchManager Endpoint connected to {0} with {1} resources",
       conn.toString(), resources.size());
   this.resources.addAll(resources);
 }
コード例 #3
0
    public WatchListener(
        IProject project, IOpenShiftConnection conn, String kind, int backoff, long lastConnect) {
      Trace.debug(
          "WatchManager Adding WatchListener for {0} and kind {1}", project.getName(), kind);
      this.project = project;
      this.conn = conn;
      this.backoff = backoff;
      this.lastConnect = lastConnect;
      this.kind = kind;

      if (System.currentTimeMillis() - lastConnect > BACKOFF_RESET) {
        backoff = 0;
      }
      Trace.debug(
          "WatchManager Initial watch backoff of {0} ms", FIBONACCI[backoff] * BACKOFF_MILLIS);
    }
コード例 #4
0
 public void start(int backoff, long lastConnect) {
   if (state.getAndSet(State.STARTING) == State.STARTING) {
     Trace.debug("In the process of starting watch already.  Returning early");
     return;
   }
   this.backoff = backoff;
   this.lastConnect = lastConnect;
   Trace.info("Starting watch on project {0} for kind {1}", project.getName(), kind);
   IClient client = getClientFor(project);
   if (client != null) {
     new RestartWatchJob(client).schedule();
   }
 }
コード例 #5
0
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   try {
     connect(client);
   } catch (Exception e) {
     Trace.debug(
         "Exception starting watch on project {0} and {1} kind", e, project.getName(), kind);
     backoff++;
     if (backoff >= FIBONACCI.length) {
       Trace.info(
           "Exceeded backoff attempts trying to reconnect watch for {0} and kind {1}",
           project.getName(), kind);
       watches.remove(project);
       state.set(State.DISCONNECTED);
       return Status.OK_STATUS;
     }
     final long delay = FIBONACCI[backoff] * BACKOFF_MILLIS;
     Trace.debug(
         "Delaying watch restart by {0}ms for project {1} and kinds {2} ",
         delay, project.getName(), kind);
     new RestartWatchJob(client).schedule(delay);
   }
   return Status.OK_STATUS;
 }
コード例 #6
0
 @Override
 public void received(IResource resource, ChangeType change) {
   Trace.debug("Watch received change in {0} state\n{1}", state, resource.toJson(false));
   if (State.CONNECTED == state.get()) {
     IResource newItem = null;
     IResource oldItem = null;
     int index = resources.indexOf(resource);
     if (ChangeType.ADDED.equals(change)) {
       resources.add(resource);
       newItem = resource;
     } else if (ChangeType.DELETED.equals(change)) {
       oldItem = index > NOT_FOUND ? resources.remove(index) : resource;
     } else if (ChangeType.MODIFIED.equals(change)) {
       if (index > NOT_FOUND) {
         oldItem = resources.remove(index);
       }
       resources.add(resource);
       newItem = resource;
     }
     ConnectionsRegistrySingleton.getInstance()
         .fireConnectionChanged(conn, ConnectionProperties.PROPERTY_RESOURCE, oldItem, newItem);
   }
 }
コード例 #7
0
 @Override
 public void disconnected() {
   Trace.debug("WatchManager Endpoint disconnected to {0}.", conn.toString());
   state.set(State.DISCONNECTED);
 }