Example #1
0
 @Override
 public void resultChanged(LookupEvent ev) {
   TopComponent tc = ref.get();
   if (tc == null) {
     r.removeLookupListener(this);
     synchronized (lookupListeners) {
       lookupListeners.remove(this);
     }
     return;
   }
   if (LOG.isLoggable(Level.FINER)) {
     LOG.log(Level.FINER, "  looking result changed for {0} ", new Object[] {ref.get()});
   }
   DataObject tcDataObject = tc.getLookup().lookup(DataObject.class);
   if (tcDataObject != null) {
     try {
       if (hasOpenedEditorPanes(tcDataObject)) {
         addOpenedFiles(getFiles(tcDataObject));
       }
     } catch (InterruptedException ex) {
       LOG.log(Level.WARNING, null, ex);
     } catch (InvocationTargetException ex) {
       LOG.log(Level.WARNING, null, ex);
     }
     r.removeLookupListener(this);
     synchronized (lookupListeners) {
       lookupListeners.remove(this);
     }
   }
 }
Example #2
0
  /** Обработчик всех событий помещенных в очередь */
  void processEvents() {
    for (; ; ) {

      WatchKey key;
      try {
        key = watcher.take();
      } catch (InterruptedException x) {
        LOG.log(Level.SEVERE, x.getMessage());
        return;
      }

      Path dir = keys.get(key);
      if (dir == null) {
        LOG.log(Level.SEVERE, "Входной каталог не найден!");
        continue;
      }

      for (WatchEvent<?> event : key.pollEvents()) {
        WatchEvent.Kind kind = event.kind();

        // TODO - подумать над обработчиком события OVERFLOW
        if (kind == OVERFLOW) {
          continue;
        }

        WatchEvent<Path> ev = cast(event);
        Path name = ev.context();
        Path child = dir.resolve(name);

        // логируем событие
        if (kind == ENTRY_CREATE) {
          LOG.log(Level.FINEST, "{0}: {1}", new Object[] {event.kind().name(), child});
          Runnable worker = new WorkerThread(child);
          executor.execute(worker);
        }
      }

      boolean valid = key.reset();
      if (!valid) {
        keys.remove(key);
        if (keys.isEmpty()) {
          break;
        }
      }
    }
  }
    @Override
    public void onClose(final int code, final String reason) {
      LOG.log(Level.FINE, "WebSocket onClose {0}/{1}", new Object[] {code, reason});
      Socket.this.webSocket = null;
      scheduleReconnectTimer();

      for (final ISocketCloseCallback callback : socketCloseCallbacks) {
        callback.onClose();
      }
    }
Example #4
0
 private void removeOpenedFiles(List<File> files) {
   if (files == null) {
     return;
   }
   synchronized (openedFiles) {
     for (File file : files) {
       LOG.log(Level.FINE, " removing from opened files {0} ", new Object[] {file});
       openedFiles.remove(file.getAbsolutePath());
     }
   }
 }
Example #5
0
 private List<File> getFiles(DataObject tcDataObject) {
   List<File> ret = new ArrayList<File>();
   LOG.log(Level.FINER, "  looking up files in dataobject {0} ", new Object[] {tcDataObject});
   Set<FileObject> fos = tcDataObject.files();
   if (fos != null) {
     for (FileObject fo : fos) {
       LOG.log(Level.FINER, "   found file {0}", new Object[] {fo});
       File f = FileUtil.toFile(fo);
       if (f != null
           && !openedFiles.contains(f.getAbsolutePath())
           && !touchedFiles.contains(f.getAbsolutePath())) {
         ret.add(f);
       }
     }
   }
   if (LOG.isLoggable(Level.FINER)) {
     for (File f : ret) {
       LOG.log(Level.FINER, "   returning file {0} ", new Object[] {f});
     }
   }
   return ret;
 }
 @Override
 public void onFailure(final IOException e, final Response response) {
   LOG.log(Level.WARNING, "WebSocket connection error", e);
   try {
     for (final IErrorCallback callback : errorCallbacks) {
       triggerChannelError();
       callback.onError(e.toString());
     }
   } finally {
     // Assume closed on failure
     if (Socket.this.webSocket != null) {
       try {
         Socket.this.webSocket.close(1001 /*CLOSE_GOING_AWAY*/, "EOF received");
       } catch (IOException ioe) {
         LOG.log(Level.WARNING, "Failed to explicitly close following failure");
       } finally {
         Socket.this.webSocket = null;
       }
     }
     scheduleReconnectTimer();
   }
 }
    @Override
    public void onOpen(final WebSocket webSocket, final Response response) {
      LOG.log(Level.FINE, "WebSocket onOpen: {0}", webSocket);
      Socket.this.webSocket = webSocket;
      cancelReconnectTimer();

      // TODO - Heartbeat
      for (final ISocketOpenCallback callback : socketOpenCallbacks) {
        callback.onOpen();
      }

      Socket.this.flushSendBuffer();
    }
    @Override
    public void onMessage(final ResponseBody payload) throws IOException {
      LOG.log(Level.FINE, "Envelope received: {0}", payload);

      try {
        if (payload.contentType() == WebSocket.TEXT) {
          final Envelope envelope = objectMapper.readValue(payload.byteStream(), Envelope.class);
          for (final Channel channel : channels) {
            if (channel.isMember(envelope.getTopic())) {
              channel.trigger(envelope.getEvent(), envelope);
            }
          }

          for (final IMessageCallback callback : messageCallbacks) {
            callback.onMessage(envelope);
          }
        }
      } catch (IOException e) {
        LOG.log(Level.SEVERE, "Failed to read message payload", e);
      } finally {
        payload.close();
      }
    }
Example #9
0
 private List<File> getFiles(TopComponent tc) {
   LOG.log(Level.FINER, " looking up files in tc {0} ", new Object[] {tc});
   DataObject tcDataObject = tc.getLookup().lookup(DataObject.class);
   if (tcDataObject == null) {
     boolean alreadyListening = false;
     Iterator<L> it = lookupListeners.iterator();
     synchronized (lookupListeners) {
       while (it.hasNext()) {
         L l = it.next();
         if (l.ref.get() == null) {
           l.r.removeLookupListener(l);
           it.remove();
         }
         if (l.ref.get() == tc) {
           alreadyListening = true;
           break;
         }
       }
     }
     if (!alreadyListening) {
       addLookupListener(tc);
     }
     return Collections.EMPTY_LIST;
   } else {
     try {
       return hasOpenedEditorPanes(tcDataObject)
           ? getFiles(tcDataObject)
           : Collections.EMPTY_LIST;
     } catch (InterruptedException ex) {
       LOG.log(Level.WARNING, null, ex);
     } catch (InvocationTargetException ex) {
       LOG.log(Level.WARNING, null, ex);
     }
   }
   return Collections.EMPTY_LIST;
 }
Example #10
0
 private void addOpenedFiles(List<File> files) {
   if (files == null) {
     return;
   }
   synchronized (openedFiles) {
     for (File file : files) {
       LOG.log(Level.FINE, " adding to opened files : ", new Object[] {file});
       openedFiles.add(file.getAbsolutePath());
     }
     for (File file : files) {
       if (handleManaged(file)) {
         break;
       }
     }
   }
 }
Example #11
0
 public void run() {
   while (shouldRun) {
     JobInProgress job = null;
     synchronized (jobInitQueue) {
       if (jobInitQueue.size() > 0) {
         job = (JobInProgress) jobInitQueue.elementAt(0);
         jobInitQueue.remove(job);
       } else {
         try {
           jobInitQueue.wait(JOBINIT_SLEEP_INTERVAL);
         } catch (InterruptedException iex) {
         }
       }
     }
     try {
       if (job != null) {
         job.initTasks();
       }
     } catch (Exception e) {
       LOG.log(Level.WARNING, "job init failed", e);
       job.kill();
     }
   }
 }
 @Override
 public void onPong(final Buffer payload) {
   LOG.log(Level.INFO, "PONG received: {0}", payload);
 }