public void run() {
   while (true) {
     LinkedList<PacketCallbackStruct> list = null;
     try {
       queuedPacketCallbacksLock.lock();
       try {
         queuedPacketCallbacksNotEmpty.await();
       } catch (Exception e) {
         Log.error(
             "RDPServer.PacketCallbackThread: queuedPacketCallbacksNotEmpty.await() caught exception "
                 + e.getMessage());
       }
       list = queuedPacketCallbacks;
       queuedPacketCallbacks = new LinkedList<PacketCallbackStruct>();
     } finally {
       queuedPacketCallbacksLock.unlock();
     }
     if (Log.loggingNet)
       Log.net("RDPServer.PacketCallbackThread: Got " + list.size() + " queued packets");
     for (PacketCallbackStruct pcs : list) {
       try {
         callbackProcessPacket(pcs.cb, pcs.con, pcs.packet);
       } catch (Exception e) {
         Log.exception("RDPServer.PacketCallbackThread: ", e);
       }
     }
   }
 }
Example #2
0
 public void run() {
   try {
     for (; ; ) {
       Target t = null;
       synchronized (pending) {
         while (pending.size() == 0) pending.wait();
         t = (Target) pending.removeFirst();
       }
       t.show();
     }
   } catch (InterruptedException x) {
     return;
   }
 }
 public void printFinishedTargets() {
   // 打印finisedTargets队列中的任务
   try {
     for (; ; ) {
       Target target = null;
       synchronized (finishedTargets) {
         while (finishedTargets.size() == 0) finishedTargets.wait();
         target = (Target) finishedTargets.removeFirst();
       }
       target.show();
     }
   } catch (InterruptedException x) {
     return;
   }
 }
Example #4
0
    void processPendingTargets() throws IOException {
      synchronized (pending) {
        while (pending.size() > 0) {
          Target t = (Target) pending.removeFirst();
          try {

            t.channel.register(sel, SelectionKey.OP_CONNECT, t);

          } catch (IOException x) {

            t.channel.close();
            t.failure = x;
            printer.add(t);
          }
        }
      }
    }
  public void registerTargets() {
    // 取出targets队列中的任务,向Selector注册连接就绪事件
    synchronized (targets) {
      while (targets.size() > 0) {
        Target target = (Target) targets.removeFirst();

        try {
          target.channel.register(selector, SelectionKey.OP_CONNECT, target);
        } catch (IOException x) {
          try {
            target.channel.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
          target.failure = x;
          addFinishedTarget(target);
        }
      }
    }
  }
    private void processPending() {
      synchronized (pending) {
        while (pending.size() > 0) {
          SocketEntry entry = (SocketEntry) pending.removeFirst();
          try {
            // Register the channel with the selector, indicating
            // interest in connection completion and attaching the
            // target object so that we can get the target back
            // after the key is added to the selector's
            // selected-key set
            if (entry.getSocket().isConnected()) {
              entry.getSocket().getChannel().register(selector, SelectionKey.OP_WRITE, entry);
            } else {
              entry.getSocket().getChannel().register(selector, SelectionKey.OP_CONNECT, entry);
            }

          } catch (IOException iox) {
            logger.error(iox);
            // Something went wrong, so close the channel and
            // record the failure
            try {
              entry.getSocket().getChannel().close();
              TransportStateEvent e =
                  new TransportStateEvent(
                      DefaultTcpTransportMapping.this,
                      entry.getPeerAddress(),
                      TransportStateEvent.STATE_CLOSED,
                      iox);
              fireConnectionStateChanged(e);
            } catch (IOException ex) {
              logger.error(ex);
            }
            lastError = iox;
          }
        }
      }
    }
Example #7
0
    public void run() {
      System.err.println();
      Date now = new Date();
      if (!done) flout("INTERRUPTED\n");
      flout("START:  " + start + "\n");
      flout("FINISH: " + now + "\n");

      flout("N: " + n_files + "\n");
      flout("Subject id: " + subject_id + "\n");
      flout("Sample id:  " + sample_id + "\n");
      flout("total files: " + total_files + "\n");
      flout("total bytes: " + total_bytes + "\n");
      flout("retrieve failures: " + retrieve_failures + "\n");
      flout("metadata retrieve failures: " + md_retrieve_failures + "\n");
      flout("bad files retrieved: " + bad_file_errors + "\n");
      flout("bad metadata retrieved: " + bad_md_errors + "\n");

      reportExceptions();

      flout("store retries:    " + store_retries + "\n");
      flout("retrieve retries: " + retrieve_retries + "\n");
      flout("md retrieve retries: " + md_retrieve_retries + "\n");
      if (md_retrieve_time > 0)
        flout("md retrieve rate (ms/record): " + (md_retrieve_time / md_retrieves) + "\n");
      if (total_store_time > 0)
        flout("total store rate (bytes/sec): " + ((total_bytes * 1000) / total_store_time) + "\n");
      if (total_retrieve_time > 0)
        flout(
            "total retrieve rate (bytes/sec): "
                + ((total_bytes * 1000) / total_retrieve_time)
                + "\n");
      if (time_store_30M > 0)
        flout("30 MB store (bytes/sec): " + (1000 * bytes_30M / time_store_30M) + "\n");
      if (time_retrv_30M > 0)
        flout("30 MB retrieve (bytes/sec): " + (1000 * bytes_30M / time_retrv_30M) + "\n");
      if (time_store_3M > 0)
        flout("3 MB store (bytes/sec): " + (1000 * bytes_30M / time_store_3M) + "\n");
      if (time_retrv_3M > 0)
        flout("3 MB retrieve (bytes/sec): " + (1000 * bytes_3M / time_retrv_3M) + "\n");
      if (time_store_300K > 0)
        flout("300 KB store (bytes/sec): " + (1000 * bytes_300K / time_store_300K) + "\n");
      if (time_retrv_300K > 0)
        flout("300 KB retrieve (bytes/sec): " + (1000 * bytes_300K / time_retrv_300K) + "\n");
      if (update) {

        flout("update oid query retries: " + query_retries + "\n");
        flout("update retries: " + update_retries + "\n");
        if (oid_query_time > 0) flout("query-oid's time (ms): " + oid_query_time + "\n");
        if (update_time > 0) flout("update time (ms/record): " + (update_time / updates) + "\n");
        if (updating && updates != n_files * 3)
          flout("files saved: " + (n_files * 3) + " updates: " + updates + "\n");
      }

      if (failed_rtrv.size() > 0) {
        ListIterator li = failed_rtrv.listIterator(0);
        while (li.hasNext()) flout("lost data: " + (String) li.next() + "\n");
      }
      if (failed_md_rtrv.size() > 0) {
        ListIterator li = failed_md_rtrv.listIterator(0);
        while (li.hasNext()) flout("lost mdata: " + (String) li.next() + "\n");
      }

      // long deltat = now.getTime() - start.getTime();
      // if (deltat > 0)
      // flout("total thruput (bytes/sec rdwr): " +
      // (2000 * total_bytes / deltat) + "\n");
      try {
        new File(lastfile).delete();
      } catch (Exception e) {
      }
    }