/** Shutdown the processor. */
 public void shutdown() {
   LOG.info("Shutting down");
   finished = true;
   queuedRequests.clear();
   queuedRequests.add(Request.requestOfDeath);
   nextProcessor.shutdown();
 }
  public void send(Message message) {
    try {
      // force keyframe? ditch all the other messages on the queue
      // since this message will overwrite everything
      if (message.isBlockMessage() && ((BlockMessage) message).getForceKeyFrame()) {
        blockDataQ.clear();
        notifyQueueListener(0);
      }
      // stick message on queue
      blockDataQ.put(message);

      // if the queue is backed up, purge it of duplicate blocks
      int qSizeInBlocks = getQueueSizeInBlocks();
      if (qSizeInBlocks > ScreenShareInfo.MAX_QUEUE_SIZE_FOR_PAUSE) {
        if (ScreenShareInfo.getPurgeBackedUpQueue()) {
          purgeBlockDataQ();
        }
        notifyQueueListener(qSizeInBlocks);
      }

      // if we're being slow, notify also
      if (ScreenShareInfo.adjustPauseFromQueueSize && perfStats.isSlow()) {
        notifyPerformanceListener(true);
      }

    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
  @Override
  public void run() {
    Thread videoDecoder = new Thread(new VideoDecoder(this));
    videoDecoder.start();
    long lastFrameWrite = System.nanoTime() - NANOSECONDS_PER_FRAME;
    long timeNow = 0;

    try {
      while ((!videoDecoded || !imgBuffer.isEmpty()) && frame.isVisible()) {
        timeNow = System.nanoTime();
        if (timeNow - lastFrameWrite >= NANOSECONDS_PER_FRAME) {
          lastFrameWrite = timeNow;
          BufferedImage img = imgBuffer.take();
          g.drawImage(img, 0, 0, frame.getWidth(), frame.getHeight(), null);

          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          ImageIO.write(img, "jpg", bos);
          proxy.receiveImage(ByteBuffer.wrap(bos.toByteArray()));
        }
      }
    } catch (IOException | InterruptedException e) {
      // other user has disconnected, stop sending video
    }

    imgBuffer.clear();
    frame.setVisible(false);
    try {
      proxy.setFrameVisible(true, false);
    } catch (IOException e) {
      System.err.println("The other user has disconnected, stopping video.");
    }
  }
Beispiel #4
0
 @Override
 public void clear() {
   Clear clear = new Clear();
   checkNotStopped(); // check we can change the changesDeque
   changesDeque.clear();
   enqueue(clear);
 }
 public void close() throws IOException {
   if (fileTask != null) {
     fileTask.cancel(true);
   }
   fileLinkedBlockingQueue.clear();
   fileLinkedBlockingQueue = null;
   fileTask = null;
   closed = true;
 }
 private void leaveInstance(Vote v) {
   if (LOG.isDebugEnabled()) {
     LOG.debug(
         "About to leave FLE instance: leader="
             + v.getId()
             + ", zxid=0x"
             + Long.toHexString(v.getZxid())
             + ", my id="
             + self.getId()
             + ", my state="
             + self.getPeerState());
   }
   recvqueue.clear();
 }
Beispiel #7
0
    protected void disconnect(final long timeout, final long bannedFor, final String reason) {
      try {
        if (hasConnectionSlot.tryAcquire()) {
          if (unsolicited) {
            unsolicitedConnectSlot.release();
          } else {
            connectSlot.release();
          }
        }
        if (connected.tryAcquire()) {
          openConnections.decrementAndGet();
          log.trace("Number of connections is now " + openConnections.get());
        }
        if (channel.isRegistered()) {
          selectorChanges.add(
              new ChangeRequest(channel, ChangeRequest.CANCEL, SelectionKey.OP_ACCEPT, null));
          selector.wakeup();
        }
        if (channel.isOpen()) {
          channel.close();
          log.trace("Disconnect " + channel);

          writes.clear();
          reads.clear();
          reads.add(closedMark);
          peerThreads.execute(
              new Runnable() {
                @Override
                public void run() {
                  onDisconnect(timeout, bannedFor, reason);
                }
              });
        }
      } catch (IOException e) {
        log.trace("Exception in disconnect ", e);
      }
    }
 @Override
 public void finish() {
   buffer.clear();
 }
 public synchronized void dispose() {
   GnuBackgammon.out.println("===> QUEUE DISPOSED");
   dispatchExecutor.shutdownNow();
   queue.clear();
 }
 private void clearAllBuffers() {
   bluetoothBuffer.clear();
   serialBuffer.clear();
 }
 public static void clearQueue() {
   sWorkQueue.clear();
 }
 public void shutdown() {
   submittedRequests.clear();
   submittedRequests.add(Request.requestOfDeath);
   nextProcessor.shutdown();
 }
 public void dropAll() {
   eventsQueue.clear();
 }
Beispiel #14
0
 /*
  * (non-Javadoc)
  *
  * @see org.mixare.mgr.downloader.DownloadManager#purgeLists()
  */
 public synchronized void resetActivity() {
   todoList.clear();
   doneList.clear();
 }
Beispiel #15
0
 public void stop() {
   if (encodeThread != null) {
     encodeThread.exit();
   }
   captureQueue.clear();
 }
 public void clearData() {
   data.clear();
 }
 @Override
 public void clear() {
   queue.clear();
 }
  /**
   * We used to be much more proactive here -- maintaining file tree info and periodically
   * refreshing it. This used a lot of memory for large directory trees, so now we simply refresh
   * all watch directories periodically.
   */
  private void sync() {
    logger.fine("sync()");
    synchronized (watch_dirs) {
      long startSyncTime = System.currentTimeMillis();

      /** Since we are updating now, just remove all existing ones and create new ones. */
      for (DirectoryWatcher existing : watchers.values()) {
        existing.setDone();
      }
      watchers.clear();

      /**
       * We may have built up a backlog of things to hash -- these will regenerate once we do the
       * initial scan of the newly created watch directories
       */
      additionsToProcess.clear();

      /** first pass: anything to add */
      logger.fine(watch_dirs.size() + " watchdirs");
      for (int i = 0; i < watch_dirs.size(); i++) {
        MagicPath magic = null;

        try {
          if (watch_dirs.get(i) == null) {
            continue;
          }
          if (watch_dirs.get(i).length() == 0) {
            continue;
          }
          magic = new MagicPath(watch_dirs.get(i));

        } catch (MagicPathParseException e) {
          logger.warning(e.toString() + " on " + watch_dirs.get(i));
          watch_dirs = new StringListImpl();
          break;
        }

        String path = magic.getPath();
        if (watchers.containsKey(path) == false && !alreadyWatched(path)) {
          try {
            logger.fine("new directoryWatcher: " + path);
            DirectoryWatcher dw = new DirectoryWatcher(magic, 60);
            // dw.start();
            additionsToProcess.put(
                new FileChange(dw.mTree, magic.getType(), new File(magic.getPath())));
            // dw.addListener(this);
            // watchers.put(path, dw);

          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }

      int preferredIntervalMinutes = 0;
      try {
        preferredIntervalMinutes =
            COConfigurationManager.getIntParameter("oneswarm.watchdir.refresh.interval");
      } catch (Exception e) {
        e.printStackTrace();
      }
      long duration = System.currentTimeMillis() - startSyncTime;
      long interval = 120 * 1000;
      // if( duration < 1000 ) {
      // interval = 30*1000;
      // } else { // huge scan time!
      // at least once/hour, 10X the scan time, but no less than 60
      // seconds
      interval = (long) Math.min(Math.max(120 * 1000, 20 * duration), 60 * 60 * 1000);
      interval = Math.max(120 * 1000, interval);
      // }

      if (preferredIntervalMinutes > 0) {
        logger.finest("Using provided setting for watch directory refresh interval: " + interval);
        interval = preferredIntervalMinutes * 60 * 1000;
      }

      nextSyncTime = System.currentTimeMillis() + interval;
      logger.fine(
          "Watch directories sync took: "
              + duration
              + " (wall) next in: "
              + interval
              + " ("
              + new Date(nextSyncTime)
              + ")");
    }
  }
 public void clearControl() {
   control.clear();
 }
 /**
  * Clear the cache.
  *
  * @since 0.9.21
  */
 public static void clearCache() {
   if (_available != null) _available.clear();
 }
  /**
   * this examines the block data queue for messages that may include the same blocks and discards
   * any dupe blocks todo: refactor this nastiness
   */
  private synchronized void purgeBlockDataQ() {
    Message message, nextMessage;
    BlockMessage blockMessage, nextBlockMessage;
    Integer[] blocks, nextBlocks;
    boolean skipMessage = false;
    int currentMessage = 0;
    LinkedBlockingQueue<Message> cloneQ =
        new LinkedBlockingQueue<Message>(ScreenShareInfo.MAX_QUEUED_MESSAGES);
    AtomicLong startTime = new AtomicLong(System.currentTimeMillis());

    Iterator it = blockDataQ.iterator();
    while (it.hasNext()) {
      message = (Message) it.next();
      skipMessage = false;
      ++currentMessage;

      // we only care about block messages that are keyframes
      // and have another block message after them
      // to dedupe against
      if (!(message.isBlockMessage() && ((BlockMessage) message).getForceKeyFrame())
          && it.hasNext()) {
        continue;
      }

      blockMessage = (BlockMessage) message;
      blocks = blockMessage.getBlocks();

      // look at the next block message to see if it overlaps with this one
      nextMessage = null;
      while (it.hasNext()) {
        nextMessage = (Message) it.next();
        if (!nextMessage.isBlockMessage()) {
          nextMessage = null;
          continue;
        }
      }

      // now compare the blocks between this msg and the next block message
      if (nextMessage != null) {
        nextBlockMessage = (BlockMessage) nextMessage;
        nextBlocks = nextBlockMessage.getBlocks();

        // exactly the same? ditch the whole message
        if (nextBlockMessage.hasSameBlocksAs(blockMessage)) {
          skipMessage = true;
        } else {
          // not exactly the same? See if we can prune dupe blocks
          blockMessage.discardBlocksSharedWith(nextBlockMessage);
          skipMessage = (nextBlockMessage.isEmpty());
        }
      }

      // if the current message must be retained, put it on the clone queue
      if (skipMessage) {
        continue;
      }
      try {
        cloneQ.put(message);
      } catch (InterruptedException e) {
        // System.out.println("Can't put message on clone queue");
      }
    }

    // we've looked at the whole queue, so time to swap in clone for real queue
    try {
      blockDataQ.clear();
      for (Message cloneMessage : cloneQ) {
        blockDataQ.put(cloneMessage);
      }
    } catch (InterruptedException e) {
      // System.out.println("Can't dump clone queue into queue");
    }
  }