示例#1
0
  void close() {
    try {
      if (mySelector != null) mySelector.close();
    } catch (IOException e) {
    }
    mySelector = null;

    // run down open connections and sockets.
    Iterator<ServerSocketChannel> i = Acceptors.values().iterator();
    while (i.hasNext()) {
      try {
        i.next().close();
      } catch (IOException e) {
      }
    }

    // 29Sep09: We create an ArrayList of the existing connections, then iterate over
    // that to call unbind on them. This is because an unbind can trigger a reconnect,
    // which will add to the Connections HashMap, causing a ConcurrentModificationException.
    // XXX: The correct behavior here would be to latch the various reactor methods to return
    // immediately if the reactor is shutting down.
    ArrayList<EventableChannel> conns = new ArrayList<EventableChannel>();
    Iterator<EventableChannel> i2 = Connections.values().iterator();
    while (i2.hasNext()) {
      EventableChannel ec = i2.next();
      if (ec != null) {
        conns.add(ec);
      }
    }
    Connections.clear();

    ListIterator<EventableChannel> i3 = conns.listIterator(0);
    while (i3.hasNext()) {
      EventableChannel ec = i3.next();
      eventCallback(ec.getBinding(), EM_CONNECTION_UNBOUND, null);
      ec.close();

      EventableSocketChannel sc = (EventableSocketChannel) ec;
      if (sc != null && sc.isAttached()) DetachedConnections.add(sc);
    }

    ListIterator<EventableSocketChannel> i4 = DetachedConnections.listIterator(0);
    while (i4.hasNext()) {
      EventableSocketChannel ec = i4.next();
      ec.cleanup();
    }
    DetachedConnections.clear();
  }
示例#2
0
  void addNewConnections() {
    ListIterator<EventableSocketChannel> iter = DetachedConnections.listIterator(0);
    while (iter.hasNext()) {
      EventableSocketChannel ec = iter.next();
      ec.cleanup();
    }
    DetachedConnections.clear();

    ListIterator<Long> iter2 = NewConnections.listIterator(0);
    while (iter2.hasNext()) {
      long b = iter2.next();

      EventableChannel ec = Connections.get(b);
      if (ec != null) {
        try {
          ec.register();
        } catch (ClosedChannelException e) {
          UnboundConnections.add(ec.getBinding());
        }
      }
    }
    NewConnections.clear();
  }
示例#3
0
  void runTimers() {
    long now = new Date().getTime();
    while (!Timers.isEmpty()) {
      long k = Timers.firstKey();
      if (k > now) break;

      ArrayList<Long> callbacks = Timers.get(k);
      Timers.remove(k);

      // Fire all timers at this timestamp
      ListIterator<Long> iter = callbacks.listIterator(0);
      while (iter.hasNext()) {
        eventCallback(0, EM_TIMER_FIRED, null, iter.next().longValue());
      }
    }
  }
示例#4
0
  void removeUnboundConnections() {
    ListIterator<Long> iter = UnboundConnections.listIterator(0);
    while (iter.hasNext()) {
      long b = iter.next();

      EventableChannel ec = Connections.remove(b);
      if (ec != null) {
        eventCallback(b, EM_CONNECTION_UNBOUND, null);
        ec.close();

        EventableSocketChannel sc = (EventableSocketChannel) ec;
        if (sc != null && sc.isAttached()) DetachedConnections.add(sc);
      }
    }
    UnboundConnections.clear();
  }
示例#5
0
 public void configureCar(Automotive car) {
   System.out.println("Configure the Car-\nPlease enter option choice.");
   Scanner read = new Scanner(System.in);
   ListIterator<String> it = car.getOptionSetNamesIterator();
   while (it.hasNext()) {
     String optionSetName = it.next().toString();
     System.out.println(optionSetName + ":");
     try {
       car.setOptionChoice(optionSetName, read.nextLine());
     } catch (InvalidOptionException e) {
       e.fixException();
     }
   }
   car.calculateFinalPrice();
   System.out.println("\nFinal Configuration-");
   car.printFinalConfig();
 }
示例#6
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) {
      }
    }