public void testIteration() {
    assertTrue(_nbhm.isEmpty());
    assertThat(_nbhm.put("k1", "v1"), nullValue());
    assertThat(_nbhm.put("k2", "v2"), nullValue());

    String str1 = "";
    for (Iterator<Map.Entry<String, String>> i = _nbhm.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry<String, String> e = i.next();
      str1 += e.getKey();
    }
    assertThat("found all entries", str1, anyOf(is("k1k2"), is("k2k1")));

    String str2 = "";
    for (Iterator<String> i = _nbhm.keySet().iterator(); i.hasNext(); ) {
      String key = i.next();
      str2 += key;
    }
    assertThat("found all keys", str2, anyOf(is("k1k2"), is("k2k1")));

    String str3 = "";
    for (Iterator<String> i = _nbhm.values().iterator(); i.hasNext(); ) {
      String val = i.next();
      str3 += val;
    }
    assertThat("found all vals", str3, anyOf(is("v1v2"), is("v2v1")));

    assertThat(
        "toString works", _nbhm.toString(), anyOf(is("{k1=v1, k2=v2}"), is("{k2=v2, k1=v1}")));
  }
 public void testSubMapContents2() {
   ConcurrentNavigableMap map = map5();
   SortedMap sm = map.subMap(two, three);
   assertEquals(1, sm.size());
   assertEquals(two, sm.firstKey());
   assertEquals(two, sm.lastKey());
   assertFalse(sm.containsKey(one));
   assertTrue(sm.containsKey(two));
   assertFalse(sm.containsKey(three));
   assertFalse(sm.containsKey(four));
   assertFalse(sm.containsKey(five));
   Iterator i = sm.keySet().iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(two, k);
   assertFalse(i.hasNext());
   Iterator j = sm.keySet().iterator();
   j.next();
   j.remove();
   assertFalse(map.containsKey(two));
   assertEquals(4, map.size());
   assertEquals(0, sm.size());
   assertTrue(sm.isEmpty());
   assertSame(sm.remove(three), null);
   assertEquals(4, map.size());
 }
 public void run() {
   long nextStart = System.currentTimeMillis();
   try {
     while (!dead) {
       long timeToSleep = nextStart - System.currentTimeMillis();
       if (timeToSleep > 10) Thread.sleep(timeToSleep);
       nextStart += Tickable.TIME_TICK;
       if ((CMProps.Bools.MUDSTARTED.property()) && (!CMLib.threads().isAllSuspended())) {
         globalTickCount++;
         for (Iterator<Exit> iter = exits.iterator(); iter.hasNext(); ) {
           Exit exit = iter.next();
           try {
             if (!exit.tick(globalTickCount)) exits.remove(exit);
           } catch (Exception e) {
             Log.errOut("ServiceEngine", e.toString());
           }
         }
         for (Iterator<TimeClock> iter = clocks.iterator(); iter.hasNext(); ) {
           TimeClock clock = iter.next();
           try {
             if (!clock.tick(globalTickCount)) clocks.remove(clock);
           } catch (Exception e) {
             Log.errOut("ServiceEngine", e.toString());
           }
         }
       }
     }
   } catch (InterruptedException e) {
   }
 }
  /**
   * Determines whether {@code effect} has been paused/stopped by the remote peer. The determination
   * is based on counting frames and is triggered by the receipt of (a piece of) a new (video) frame
   * by {@code cause}.
   *
   * @param cause the {@code SimulcastLayer} which has received (a piece of) a new (video) frame and
   *     has thus triggered a check on {@code effect}
   * @param pkt the {@code RawPacket} which was received by {@code cause} and possibly influenced
   *     the decision to trigger a check on {@code effect}
   * @param effect the {@code SimulcastLayer} which is to be checked whether it looks like it has
   *     been paused/stopped by the remote peer
   * @param endIndexInSimulcastLayerFrameHistory
   */
  private void maybeTimeout(
      SimulcastLayer cause,
      RawPacket pkt,
      SimulcastLayer effect,
      int endIndexInSimulcastLayerFrameHistory) {
    Iterator<SimulcastLayer> it = simulcastLayerFrameHistory.iterator();
    boolean timeout = true;

    for (int ix = 0; it.hasNext() && ix < endIndexInSimulcastLayerFrameHistory; ++ix) {
      if (it.next() == effect) {
        timeout = false;
        break;
      }
    }
    if (timeout) {
      effect.maybeTimeout(pkt);

      if (!effect.isStreaming()) {
        // Since effect has been determined to have been paused/stopped
        // by the remote peer, its possible presence in
        // simulcastLayerFrameHistory is irrelevant now. In other words,
        // remove effect from simulcastLayerFrameHistory.
        while (it.hasNext()) {
          if (it.next() == effect) it.remove();
        }
      }
    }
  }
 public void testDescendingSubMapContents2() {
   ConcurrentNavigableMap map = dmap5();
   SortedMap sm = map.subMap(m2, m3);
   assertEquals(1, sm.size());
   assertEquals(m2, sm.firstKey());
   assertEquals(m2, sm.lastKey());
   assertFalse(sm.containsKey(m1));
   assertTrue(sm.containsKey(m2));
   assertFalse(sm.containsKey(m3));
   assertFalse(sm.containsKey(m4));
   assertFalse(sm.containsKey(m5));
   Iterator i = sm.keySet().iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(m2, k);
   assertFalse(i.hasNext());
   Iterator j = sm.keySet().iterator();
   j.next();
   j.remove();
   assertFalse(map.containsKey(m2));
   assertEquals(4, map.size());
   assertEquals(0, sm.size());
   assertTrue(sm.isEmpty());
   assertSame(sm.remove(m3), null);
   assertEquals(4, map.size());
 }
Beispiel #6
0
  public void removeChannel(Channel channel) {
    lock.lock();
    try {
      if (channel.getDirection() == Direction.OUT) {
        BrokerHost registeredHost = null;
        for (Map.Entry<BrokerHost, List<Channel>> e : brokerHostToProducerChannelMap.entrySet()) {
          List<Channel> channels = e.getValue();
          Iterator<Channel> channelIterator = channels.iterator();
          while (channelIterator.hasNext()) {
            Channel c = channelIterator.next();
            if (c.equals(channel)) {
              registeredHost = e.getKey();
              channelIterator.remove();

              // if there are no more channels remove the producer
              if (channels.size() == 0) {
                Manageable producer = producers.remove(registeredHost);
                producer.stop();
              }
              break;
            }
          }
          if (registeredHost != null) {
            break;
          }
        }
      } else if (channel.getDirection() == Direction.IN) {
        BrokerHost registeredHost = null;
        for (Map.Entry<BrokerHost, List<Channel>> e : brokerHostToConsumerChannelMap.entrySet()) {
          List<Channel> channels = e.getValue();
          Iterator<Channel> channelIterator = channels.iterator();
          while (channelIterator.hasNext()) {
            Channel c = channelIterator.next();
            if (c.equals(channel)) {
              registeredHost = e.getKey();
              channelIterator.remove();

              // if there are no more channels remove the producer
              if (channels.size() == 0) {
                ConsumingWorker worker = consumingWorkers.remove(registeredHost);
                worker.stop();

                Manageable consumer = consumers.remove(registeredHost);
                consumer.stop();
              }
              break;
            }
          }
          if (registeredHost != null) {
            break;
          }
        }
      }
    } finally {
      lock.unlock();
    }
  }
 /** keySet is ordered */
 public void testDescendingKeySetOrder() {
   ConcurrentNavigableMap map = dmap5();
   Set s = map.keySet();
   Iterator i = s.iterator();
   Integer last = (Integer) i.next();
   assertEquals(last, m1);
   while (i.hasNext()) {
     Integer k = (Integer) i.next();
     assertTrue(last.compareTo(k) > 0);
     last = k;
   }
 }
  /**
   * JUnit.
   *
   * @throws Exception If failed.
   */
  public void testIterator() throws Exception {
    // Random queue name.
    String queueName = UUID.randomUUID().toString();

    IgniteQueue<String> queue = grid(0).queue(queueName, 0, config(false));

    for (int i = 0; i < 100; i++) assert queue.add(Integer.toString(i));

    Iterator<String> iter1 = queue.iterator();

    int cnt = 0;
    for (int i = 0; i < 100; i++) {
      assertNotNull(iter1.next());
      cnt++;
    }

    assertEquals(100, queue.size());
    assertEquals(100, cnt);

    assertNotNull(queue.take());
    assertNotNull(queue.take());
    assertTrue(queue.remove("33"));
    assertTrue(queue.remove("77"));

    assertEquals(96, queue.size());

    Iterator<String> iter2 = queue.iterator();

    try {
      iter2.remove();
    } catch (IllegalStateException e) {
      info("Caught expected exception: " + e);
    }

    iter2.next();
    iter2.remove();

    cnt = 0;
    while (iter2.hasNext()) {
      assertNotNull(iter2.next());
      cnt++;
    }

    assertEquals(95, cnt);
    assertEquals(95, queue.size());

    iter2.remove();
  }
 /** iterator() returns an iterator containing the elements of the list */
 public void testIterator() {
   List full = populatedArray(SIZE);
   Iterator i = full.iterator();
   int j;
   for (j = 0; i.hasNext(); j++) assertEquals(j, ((Integer) i.next()).intValue());
   assertEquals(SIZE, j);
 }
  @Test
  public void putFromMultipleThreads() throws InterruptedException {
    final HazelcastInstance h = Hazelcast.newHazelcastInstance(null);
    final AtomicInteger counter = new AtomicInteger(0);
    class Putter implements Runnable {
      volatile Boolean run = true;

      public void run() {
        HazelcastClient hClient = TestUtility.newHazelcastClient(h);
        while (run) {
          Map<String, String> clientMap = hClient.getMap("putFromMultipleThreads");
          clientMap.put(String.valueOf(counter.incrementAndGet()), String.valueOf(counter.get()));
        }
      }
    };
    List<Putter> list = new ArrayList<Putter>();
    for (int i = 0; i < 10; i++) {
      Putter p = new Putter();
      list.add(p);
      new Thread(p).start();
    }
    Thread.sleep(5000);
    for (Iterator<Putter> it = list.iterator(); it.hasNext(); ) {
      Putter p = it.next();
      p.run = false;
    }
    Thread.sleep(100);
    assertEquals(counter.get(), h.getMap("putFromMultipleThreads").size());
  }
  /**
   * Waits for renting partitions.
   *
   * @return {@code True} if mapping was changed.
   * @throws IgniteCheckedException If failed.
   */
  private boolean waitForRent() throws IgniteCheckedException {
    boolean changed = false;

    // Synchronously wait for all renting partitions to complete.
    for (Iterator<GridDhtLocalPartition> it = locParts.values().iterator(); it.hasNext(); ) {
      GridDhtLocalPartition p = it.next();

      GridDhtPartitionState state = p.state();

      if (state == RENTING || state == EVICTED) {
        if (log.isDebugEnabled()) log.debug("Waiting for renting partition: " + p);

        // Wait for partition to empty out.
        p.rent(true).get();

        if (log.isDebugEnabled()) log.debug("Finished waiting for renting partition: " + p);

        // Remove evicted partition.
        it.remove();

        changed = true;
      }
    }

    return changed;
  }
Beispiel #12
0
  /** Selects on sockets and informs their Communicator when there is something to do. */
  public void communicate(int timeout) {

    try {
      selector.select(timeout);
    } catch (IOException e) {
      // Not really sure why/when this happens yet
      return;
    }

    Iterator<SelectionKey> keys = selector.selectedKeys().iterator();

    while (keys.hasNext()) {
      SelectionKey key = keys.next();
      keys.remove();
      if (!key.isValid()) continue; // WHY
      Communicator communicator = (Communicator) key.attachment();

      if (key.isReadable()) communicator.onReadable();
      if (key.isWritable()) communicator.onWritable();
      if (key.isAcceptable()) communicator.onAcceptable();
    }

    // Go through the queue and handle each communicator
    while (!queue.isEmpty()) {
      Communicator c = queue.poll();
      c.onMemo();
    }
  }
Beispiel #13
0
  /**
   * Converts the form field values in the <tt>ffValuesIter</tt> into a caps string.
   *
   * @param ffValuesIter the {@link Iterator} containing the form field values.
   * @param capsBldr a <tt>StringBuilder</tt> to which the caps string representing the form field
   *     values is to be appended
   */
  private static void formFieldValuesToCaps(Iterator<String> ffValuesIter, StringBuilder capsBldr) {
    SortedSet<String> fvs = new TreeSet<String>();

    while (ffValuesIter.hasNext()) fvs.add(ffValuesIter.next());

    for (String fv : fvs) capsBldr.append(fv).append('<');
  }
Beispiel #14
0
  @Test
  public void testCloseable() throws IOException {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));

    JedisCluster jc = null;
    try {
      jc = new JedisCluster(jedisClusterNode);
      jc.set("51", "foo");
    } finally {
      if (jc != null) {
        jc.close();
      }
    }

    Iterator<JedisPool> poolIterator = jc.getClusterNodes().values().iterator();
    while (poolIterator.hasNext()) {
      JedisPool pool = poolIterator.next();
      try {
        pool.getResource();
        fail("JedisCluster's internal pools should be already destroyed");
      } catch (JedisConnectionException e) {
        // ok to go...
      }
    }
  }
  /** Return all of the neighbors with whom we share the provided range. */
  static Set<InetAddress> getNeighbors(String table, Range<Token> toRepair) {
    StorageService ss = StorageService.instance;
    Map<Range<Token>, List<InetAddress>> replicaSets = ss.getRangeToAddressMap(table);
    Range<Token> rangeSuperSet = null;
    for (Range<Token> range : ss.getLocalRanges(table)) {
      if (range.contains(toRepair)) {
        rangeSuperSet = range;
        break;
      } else if (range.intersects(toRepair)) {
        throw new IllegalArgumentException(
            "Requested range intersects a local range but is not fully contained in one; this would lead to imprecise repair");
      }
    }
    if (rangeSuperSet == null || !replicaSets.containsKey(toRepair)) return Collections.emptySet();

    Set<InetAddress> neighbors = new HashSet<InetAddress>(replicaSets.get(rangeSuperSet));
    neighbors.remove(FBUtilities.getBroadcastAddress());
    // Excluding all node with version <= 0.7 since they don't know how to
    // create a correct merkle tree (they build it over the full range)
    Iterator<InetAddress> iter = neighbors.iterator();
    while (iter.hasNext()) {
      InetAddress endpoint = iter.next();
      if (Gossiper.instance.getVersion(endpoint) <= MessagingService.VERSION_07) {
        logger.info(
            "Excluding "
                + endpoint
                + " from repair because it is on version 0.7 or sooner. You should consider updating this node before running repair again.");
        iter.remove();
      }
    }
    return neighbors;
  }
  public List<TravelQuote> getRankedTravelQuotes(
      TravelInfo travelInfo,
      Set<TravelCompany> companies,
      Comparator<TravelQuote> ranking,
      long time,
      TimeUnit unit)
      throws InterruptedException {
    List<QuoteTask> tasks = new ArrayList<QuoteTask>();
    for (TravelCompany company : companies) tasks.add(new QuoteTask(company, travelInfo));

    List<Future<TravelQuote>> futures = exec.invokeAll(tasks, time, unit);

    List<TravelQuote> quotes = new ArrayList<TravelQuote>(tasks.size());
    Iterator<QuoteTask> taskIter = tasks.iterator();
    for (Future<TravelQuote> f : futures) {
      QuoteTask task = taskIter.next();
      try {
        quotes.add(f.get());
      } catch (ExecutionException e) {
        quotes.add(task.getFailureQuote(e.getCause()));
      } catch (CancellationException e) {
        quotes.add(task.getTimeoutQuote(e));
      }
    }

    Collections.sort(quotes, ranking);
    return quotes;
  }
Beispiel #17
0
 protected void handleIterator(String[] args) {
   Iterator it = null;
   String iteratorStr = args[0];
   if (iteratorStr.startsWith("s.")) {
     it = getSet().iterator();
   } else if (iteratorStr.startsWith("m.")) {
     it = getMap().keySet().iterator();
   } else if (iteratorStr.startsWith("q.")) {
     it = getQueue().iterator();
   } else if (iteratorStr.startsWith("l.")) {
     it = getList().iterator();
   }
   if (it != null) {
     boolean remove = false;
     if (args.length > 1) {
       String removeStr = args[1];
       remove = removeStr.equals("remove");
     }
     int count = 1;
     while (it.hasNext()) {
       print(count++ + " " + it.next());
       if (remove) {
         it.remove();
         print(" removed");
       }
       println("");
     }
   }
 }
Beispiel #18
0
  /**
   * Remove records telling what entity caps node a contact has.
   *
   * @param contact the contact
   */
  public void removeContactCapsNode(Contact contact) {
    Caps caps = null;
    String lastRemovedJid = null;

    Iterator<String> iter = userCaps.keySet().iterator();
    while (iter.hasNext()) {
      String jid = iter.next();

      if (StringUtils.parseBareAddress(jid).equals(contact.getAddress())) {
        caps = userCaps.get(jid);
        lastRemovedJid = jid;
        iter.remove();
      }
    }

    // fire only for the last one, at the end the event out
    // of the protocol will be one and for the contact
    if (caps != null) {
      UserCapsNodeListener[] listeners;
      synchronized (userCapsNodeListeners) {
        listeners = userCapsNodeListeners.toArray(NO_USER_CAPS_NODE_LISTENERS);
      }
      if (listeners.length != 0) {
        String nodeVer = caps.getNodeVer();

        for (UserCapsNodeListener listener : listeners)
          listener.userCapsNodeRemoved(lastRemovedJid, nodeVer, false);
      }
    }
  }
Beispiel #19
0
  protected void handleView(View view) {
    this.view = view;
    if (log.isDebugEnabled()) log.debug("view=" + view);
    List<Address> members = view.getMembers();

    _consumerLock.lock();
    try {
      // This removes the consumers that were registered that are now gone
      Iterator<Owner> iterator = _consumersAvailable.iterator();
      while (iterator.hasNext()) {
        Owner owner = iterator.next();
        if (!members.contains(owner.getAddress())) {
          iterator.remove();
          sendRemoveConsumerRequest(owner);
        }
      }

      // This removes the tasks that those requestors are gone
      iterator = _runRequests.iterator();
      while (iterator.hasNext()) {
        Owner owner = iterator.next();
        if (!members.contains(owner.getAddress())) {
          iterator.remove();
          sendRemoveRunRequest(owner);
        }
      }

      synchronized (_awaitingReturn) {
        for (Entry<Owner, Runnable> entry : _awaitingReturn.entrySet()) {
          // The person currently servicing our request has gone down
          // without completing so we have to keep our request alive by
          // sending ours back to the coordinator
          Owner owner = entry.getKey();
          if (!members.contains(owner.getAddress())) {
            Runnable runnable = entry.getValue();
            // We need to register the request id before sending the request back to the coordinator
            // in case if our task gets picked up since another was removed
            _requestId.put(runnable, owner.getRequestId());
            _awaitingConsumer.add(runnable);
            sendToCoordinator(RUN_REQUEST, owner.getRequestId(), local_addr);
          }
        }
      }
    } finally {
      _consumerLock.unlock();
    }
  }
  /**
   * Notifies this {@code SimulcastReceiver} that a specific {@code SimulcastReceiver} has detected
   * the start of a new video frame in the RTP stream that it represents. Determines whether any of
   * {@link #simulcastLayers} other than {@code source} have been paused/stopped by the remote peer.
   * The determination is based on counting (video) frames.
   *
   * @param source the {@code SimulcastLayer} which is the source of the event i.e. which has
   *     detected the start of a new video frame in the RTP stream that it represents
   * @param pkt the {@code RawPacket} which was received by {@code source} and possibly influenced
   *     the decision that a new view frame was started in the RTP stream represented by {@code
   *     source}
   * @param layers the set of {@code SimulcastLayer}s managed by this {@code SimulcastReceiver}.
   *     Explicitly provided to the method in order to avoid invocations of {@link
   *     #getSimulcastLayers()} because the latter makes a copy at the time of this writing.
   */
  private void simulcastLayerFrameStarted(
      SimulcastLayer source, RawPacket pkt, SimulcastLayer[] layers) {
    // Allow the value of the constant TIMEOUT_ON_FRAME_COUNT to disable (at
    // compile time) the frame-based approach to the detection of layer
    // drops.
    if (TIMEOUT_ON_FRAME_COUNT <= 1) return;

    // Timeouts in layers caused by source may occur only based on the span
    // (of time or received frames) during which source has received
    // TIMEOUT_ON_FRAME_COUNT number of frames. The current method
    // invocation signals the receipt of 1 frame by source.
    int indexOfLastSourceOccurrenceInHistory = -1;
    int sourceFrameCount = 0;
    int ix = 0;

    for (Iterator<SimulcastLayer> it = simulcastLayerFrameHistory.iterator(); it.hasNext(); ++ix) {
      if (it.next() == source) {
        if (indexOfLastSourceOccurrenceInHistory != -1) {
          // Prune simulcastLayerFrameHistory so that it does not
          // become unnecessarily long.
          it.remove();
        } else if (++sourceFrameCount >= TIMEOUT_ON_FRAME_COUNT - 1) {
          // The span of TIMEOUT_ON_FRAME_COUNT number of frames
          // received by source only is to be examined for the
          // purposes of timeouts. The current method invocations
          // signals the receipt of 1 frame by source so
          // TIMEOUT_ON_FRAME_COUNT - 1 occurrences of source in
          // simulcastLayerFrameHistory is enough.
          indexOfLastSourceOccurrenceInHistory = ix;
        }
      }
    }

    if (indexOfLastSourceOccurrenceInHistory != -1) {
      // Presumably, if a SimulcastLayer is active, all SimulcastLayers
      // before it (according to SimulcastLayer's order) are active as
      // well. Consequently, timeouts may occur in SimulcastLayers which
      // are after source.
      boolean maybeTimeout = false;

      for (SimulcastLayer layer : layers) {
        if (maybeTimeout) {
          // There's no point in timing layer out if it's timed out
          // already.
          if (layer.isStreaming()) {
            maybeTimeout(source, pkt, layer, indexOfLastSourceOccurrenceInHistory);
          }
        } else if (layer == source) {
          maybeTimeout = true;
        }
      }
    }

    // As previously stated, the current method invocation signals the
    // receipt of 1 frame by source.
    simulcastLayerFrameHistory.add(0, source);
    // TODO Prune simulcastLayerFrameHistory by forgetting so that it does
    // not become too long.
  }
 /** iterator.remove removes element */
 public void testIteratorRemove() {
   List full = populatedArray(SIZE);
   Iterator it = full.iterator();
   Object first = full.get(0);
   it.next();
   it.remove();
   assertFalse(full.contains(first));
 }
 public Map<String, String> getFormatSpecifierDescriptions() {
   Map<String, String> m = new LinkedHashMap<String, String>();
   Iterator<String> keys = scoreBoardValues.keySet().iterator();
   while (keys.hasNext()) {
     String k = keys.next();
     m.put(k, scoreBoardValues.get(k).getDescription());
   }
   return m;
 }
Beispiel #23
0
 synchronized TestParameters getTest() {
   if (failed) {
     return null;
   }
   if (testIterator.hasNext()) {
     return (TestParameters) testIterator.next();
   }
   return null;
 }
 // Check that the iterator iterates the correct number of times
 private void checkSizes(String msg, int sz, Iterator it, int expectedSize) {
   assertEquals(msg, expectedSize, sz);
   int result = 0;
   while (it.hasNext()) {
     result++;
     it.next();
   }
   assertEquals(msg, expectedSize, result);
 }
Beispiel #25
0
 protected void handleMapKeys() {
   Set set = getMap().keySet();
   Iterator it = set.iterator();
   int count = 0;
   while (it.hasNext()) {
     count++;
     println(it.next());
   }
   println("Total " + count);
 }
Beispiel #26
0
 protected void handleMapValues() {
   Collection set = getMap().values();
   Iterator it = set.iterator();
   int count = 0;
   while (it.hasNext()) {
     count++;
     println(it.next());
   }
   println("Total " + count);
 }
Beispiel #27
0
 /** Stop the executors and clean memory on registered CUObject */
 public static void stop() {
   synchronized (cudaEngines) {
     cuCtxSynchronizeAll();
     for (Iterator<CudaEngine> iterator = cudaEngines.values().iterator(); iterator.hasNext(); ) {
       iterator.next().shutdown();
       iterator.remove();
     }
     //		for (CudaEngine ce : cudaEngines.values()) {
     //			ce.shutdown();
     //		}
   }
 }
Beispiel #28
0
 protected void handleMapEntries() {
   Set set = getMap().entrySet();
   Iterator it = set.iterator();
   int count = 0;
   long time = Clock.currentTimeMillis();
   while (it.hasNext()) {
     count++;
     Map.Entry entry = (Entry) it.next();
     println(entry.getKey() + " : " + entry.getValue());
   }
   println("Total " + count);
 }
Beispiel #29
0
 public BrokerHost getHostForChannel(Channel channel) {
   BrokerHost registeredHost = null;
   lock.lock();
   try {
     if (channel.getDirection() == Direction.OUT) {
       for (Map.Entry<BrokerHost, List<Channel>> e : brokerHostToProducerChannelMap.entrySet()) {
         List<Channel> channels = e.getValue();
         Iterator<Channel> channelIterator = channels.iterator();
         while (channelIterator.hasNext()) {
           Channel c = channelIterator.next();
           if (c.equals(channel)) {
             registeredHost = e.getKey();
             break;
           }
         }
         if (registeredHost != null) {
           break;
         }
       }
     } else if (channel.getDirection() == Direction.IN) {
       for (Map.Entry<BrokerHost, List<Channel>> e : brokerHostToConsumerChannelMap.entrySet()) {
         List<Channel> channels = e.getValue();
         Iterator<Channel> channelIterator = channels.iterator();
         while (channelIterator.hasNext()) {
           Channel c = channelIterator.next();
           if (c.equals(channel)) {
             registeredHost = e.getKey();
             break;
           }
         }
         if (registeredHost != null) {
           break;
         }
       }
     }
   } finally {
     lock.unlock();
   }
   return registeredHost;
 }
 /** headMap returns map with keys in requested range */
 public void testHeadMapContents() {
   ConcurrentNavigableMap map = map5();
   SortedMap sm = map.headMap(four);
   assertTrue(sm.containsKey(one));
   assertTrue(sm.containsKey(two));
   assertTrue(sm.containsKey(three));
   assertFalse(sm.containsKey(four));
   assertFalse(sm.containsKey(five));
   Iterator i = sm.keySet().iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(one, k);
   k = (Integer) (i.next());
   assertEquals(two, k);
   k = (Integer) (i.next());
   assertEquals(three, k);
   assertFalse(i.hasNext());
   sm.clear();
   assertTrue(sm.isEmpty());
   assertEquals(2, map.size());
   assertEquals(four, map.firstKey());
 }