public void prepare(String query, InetAddress toExclude) throws InterruptedException { for (Map.Entry<Host, HostConnectionPool> entry : pools.entrySet()) { if (entry.getKey().getAddress().equals(toExclude)) continue; // Let's not wait too long if we can't get a connection. Things // will fix themselves once the user tries a query anyway. Connection c = null; try { c = entry.getValue().borrowConnection(200, TimeUnit.MILLISECONDS); c.write(new PrepareMessage(query)).get(); } catch (ConnectionException e) { // Again, not being able to prepare the query right now is no big deal, so just ignore } catch (BusyConnectionException e) { // Same as above } catch (TimeoutException e) { // Same as above } catch (ExecutionException e) { // We shouldn't really get exception while preparing a // query, so log this (but ignore otherwise as it's not a big deal) logger.error( String.format( "Unexpected error while preparing query (%s) on %s", query, entry.getKey()), e); } finally { if (c != null) entry.getValue().returnConnection(c); } } }
public void doFunctionalQueryTest(IMap imap) { Employee em = new Employee("joe", 33, false, 14.56); imap.put("1", new Employee("joe", 33, false, 14.56)); imap.put("2", new Employee("ali", 23, true, 15.00)); for (int i = 3; i < 103; i++) { imap.put( String.valueOf(i), new Employee("name" + i, i % 60, ((i % 2) == 1), Double.valueOf(i))); } Set<Map.Entry> entries = imap.entrySet(); assertEquals(102, entries.size()); int itCount = 0; for (Map.Entry entry : entries) { Employee c = (Employee) entry.getValue(); itCount++; } assertEquals(102, itCount); EntryObject e = new PredicateBuilder().getEntryObject(); Predicate predicate = e.is("active").and(e.get("age").equal(23)); entries = imap.entrySet(predicate); assertEquals(3, entries.size()); for (Map.Entry entry : entries) { Employee c = (Employee) entry.getValue(); assertEquals(c.getAge(), 23); assertTrue(c.isActive()); } imap.remove("2"); entries = imap.entrySet(predicate); assertEquals(2, entries.size()); for (Map.Entry entry : entries) { Employee c = (Employee) entry.getValue(); assertEquals(c.getAge(), 23); assertTrue(c.isActive()); } }
@SuppressWarnings("unchecked") private void addFields( DataConfig.Entity entity, DocWrapper doc, Map<String, Object> arow, VariableResolver vr) { for (Map.Entry<String, Object> entry : arow.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value == null) continue; if (key.startsWith("$")) continue; List<DataConfig.Field> field = entity.colNameVsField.get(key); if (field == null && dataImporter.getSchema() != null) { // This can be a dynamic field or a field which does not have an entry in data-config ( an // implicit field) SchemaField sf = dataImporter.getSchema().getFieldOrNull(key); if (sf == null) { sf = dataImporter.getConfig().lowerNameVsSchemaField.get(key.toLowerCase(Locale.ENGLISH)); } if (sf != null) { addFieldToDoc(entry.getValue(), sf.getName(), 1.0f, sf.multiValued(), doc); } // else do nothing. if we add it it may fail } else { if (field != null) { for (DataConfig.Field f : field) { String name = f.getName(); if (f.dynamicName) { name = vr.replaceTokens(name); } if (f.toWrite) addFieldToDoc(entry.getValue(), name, f.boost, f.multiValued, doc); } } } } }
private synchronized void addNewAgent( int agentId, SocketChannel socket, String agentName, String agentIP, int agentPort, int flags) { if (agentIP.equals(":same")) { InetAddress agentAddress = socket.socket().getInetAddress(); agentIP = agentAddress.getHostAddress(); } Log.info( "New agent id=" + agentId + " name=" + agentName + " address=" + agentIP + ":" + agentPort + " flags=" + flags); AgentInfo agentInfo = new AgentInfo(); agentInfo.agentId = agentId; agentInfo.flags = flags; agentInfo.socket = socket; agentInfo.agentName = agentName; agentInfo.agentIP = agentIP; agentInfo.agentPort = agentPort; agentInfo.outputBuf = new MVByteBuffer(1024); agentInfo.inputBuf = new MVByteBuffer(1024); agents.put(socket, agentInfo); NewAgentMessage newAgentMessage = new NewAgentMessage(agentId, agentName, agentIP, agentPort, flags); for (Map.Entry<SocketChannel, AgentInfo> entry : agents.entrySet()) { if (entry.getKey() == socket) continue; // Tell other agents about the new one synchronized (entry.getValue().outputBuf) { Message.toBytes(newAgentMessage, entry.getValue().outputBuf); } // Tell new agent about other agents NewAgentMessage otherAgentMessage = new NewAgentMessage( entry.getValue().agentId, entry.getValue().agentName, entry.getValue().agentIP, entry.getValue().agentPort, entry.getValue().flags); synchronized (agentInfo.outputBuf) { Message.toBytes(otherAgentMessage, agentInfo.outputBuf); } } messageIO.addAgent(agentInfo); messageIO.outputReady(); }
/** @throws Exception If failed. */ public void testAffinityPut() throws Exception { Thread.sleep(2 * TOP_REFRESH_FREQ); assertEquals(NODES_CNT, client.compute().refreshTopology(false, false).size()); Map<UUID, Grid> gridsByLocNode = new HashMap<>(NODES_CNT); GridClientData partitioned = client.data(PARTITIONED_CACHE_NAME); GridClientCompute compute = client.compute(); for (int i = 0; i < NODES_CNT; i++) gridsByLocNode.put(grid(i).localNode().id(), grid(i)); for (int i = 0; i < 100; i++) { String key = "key" + i; UUID primaryNodeId = grid(0).mapKeyToNode(PARTITIONED_CACHE_NAME, key).id(); assertEquals("Affinity mismatch for key: " + key, primaryNodeId, partitioned.affinity(key)); assertEquals(primaryNodeId, partitioned.affinity(key)); // Must go to primary node only. Since backup count is 0, value must present on // primary node only. partitioned.put(key, "val" + key); for (Map.Entry<UUID, Grid> entry : gridsByLocNode.entrySet()) { Object val = entry.getValue().cache(PARTITIONED_CACHE_NAME).peek(key); if (primaryNodeId.equals(entry.getKey())) assertEquals("val" + key, val); else assertNull(val); } } // Now check that we will see value in near cache in pinned mode. for (int i = 100; i < 200; i++) { String pinnedKey = "key" + i; UUID primaryNodeId = grid(0).mapKeyToNode(PARTITIONED_CACHE_NAME, pinnedKey).id(); UUID pinnedNodeId = F.first(F.view(gridsByLocNode.keySet(), F.notEqualTo(primaryNodeId))); GridClientNode node = compute.node(pinnedNodeId); partitioned.pinNodes(node).put(pinnedKey, "val" + pinnedKey); for (Map.Entry<UUID, Grid> entry : gridsByLocNode.entrySet()) { Object val = entry.getValue().cache(PARTITIONED_CACHE_NAME).peek(pinnedKey); if (primaryNodeId.equals(entry.getKey()) || pinnedNodeId.equals(entry.getKey())) assertEquals("val" + pinnedKey, val); else assertNull(val); } } }
/** entrySet contains all pairs */ public void testEntrySet() { ConcurrentNavigableMap map = map5(); Set s = map.entrySet(); assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); assertTrue( (e.getKey().equals(one) && e.getValue().equals("A")) || (e.getKey().equals(two) && e.getValue().equals("B")) || (e.getKey().equals(three) && e.getValue().equals("C")) || (e.getKey().equals(four) && e.getValue().equals("D")) || (e.getKey().equals(five) && e.getValue().equals("E"))); } }
/** entrySet contains all pairs */ public void testDescendingEntrySet() { ConcurrentNavigableMap map = dmap5(); Set s = map.entrySet(); assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); assertTrue( (e.getKey().equals(m1) && e.getValue().equals("A")) || (e.getKey().equals(m2) && e.getValue().equals("B")) || (e.getKey().equals(m3) && e.getValue().equals("C")) || (e.getKey().equals(m4) && e.getValue().equals("D")) || (e.getKey().equals(m5) && e.getValue().equals("E"))); } }
/** * Updates partition map in all caches. * * @param msg Partitions full messages. */ private void updatePartitionFullMap(GridDhtPartitionsFullMessage msg) { for (Map.Entry<Integer, GridDhtPartitionFullMap> entry : msg.partitions().entrySet()) { Integer cacheId = entry.getKey(); GridCacheContext cacheCtx = cctx.cacheContext(cacheId); if (cacheCtx != null) cacheCtx.topology().update(exchId, entry.getValue()); else { ClusterNode oldest = CU.oldestAliveCacheServerNode(cctx, AffinityTopologyVersion.NONE); if (oldest != null && oldest.isLocal()) cctx.exchange().clientTopology(cacheId, this).update(exchId, entry.getValue()); } } }
@Override public void destroy() { super.destroy(); try { expireFuture.cancel(true); } catch (Throwable t) { LOGGER.warn(t.getMessage(), t); } try { for (Notifier notifier : notifiers.values()) { notifier.shutdown(); } } catch (Throwable t) { LOGGER.warn(t.getMessage(), t); } for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) { JedisPool jedisPool = entry.getValue(); try { jedisPool.destroy(); } catch (Throwable t) { LOGGER.warn( "Failed to destroy the redis registry client. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t); } } }
/** Checks consistency after all operations. */ private void consistencyCheck() { if (CONSISTENCY_CHECK) { assert lock.writeLock().isHeldByCurrentThread(); if (node2part == null) return; for (Map.Entry<UUID, GridDhtPartitionMap> e : node2part.entrySet()) { for (Integer p : e.getValue().keySet()) { Set<UUID> nodeIds = part2node.get(p); assert nodeIds != null : "Failed consistency check [part=" + p + ", nodeId=" + e.getKey() + ']'; assert nodeIds.contains(e.getKey()) : "Failed consistency check [part=" + p + ", nodeId=" + e.getKey() + ", nodeIds=" + nodeIds + ']'; } } for (Map.Entry<Integer, Set<UUID>> e : part2node.entrySet()) { for (UUID nodeId : e.getValue()) { GridDhtPartitionMap map = node2part.get(nodeId); assert map != null : "Failed consistency check [part=" + e.getKey() + ", nodeId=" + nodeId + ']'; assert map.containsKey(e.getKey()) : "Failed consistency check [part=" + e.getKey() + ", nodeId=" + nodeId + ']'; } } } }
public Object call() { final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine e = scriptEngineManager.getEngineByName("javascript"); if (map != null) { for (Map.Entry<String, Object> entry : map.entrySet()) { e.put(entry.getKey(), entry.getValue()); } } e.put("hazelcast", hazelcastInstance); try { // For new JavaScript engine called Nashorn we need the compatibility script if (e.getFactory().getEngineName().toLowerCase().contains("nashorn")) { e.eval("load('nashorn:mozilla_compat.js');"); } e.eval("importPackage(java.lang);"); e.eval("importPackage(java.util);"); e.eval("importPackage(com.hazelcast.core);"); e.eval("importPackage(com.hazelcast.config);"); e.eval("importPackage(java.util.concurrent);"); e.eval("importPackage(org.junit);"); return e.eval(script); } catch (ScriptException e1) { throw new RuntimeException(e1); } }
private void deferExpired() { for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) { JedisPool jedisPool = entry.getValue(); try { Jedis jedis = jedisPool.getResource(); try { for (Node node : new HashSet<Node>(getRegistered())) { String key = NodeRegistryUtils.getNodeTypePath(clusterName, node.getNodeType()); if (jedis.hset( key, node.toFullString(), String.valueOf(SystemClock.now() + expirePeriod)) == 1) { jedis.publish(key, Constants.REGISTER); } } if (lock.acquire(jedis)) { clean(jedis); } if (!replicate) { break; // 如果服务器端已同步数据,只需写入单台机器 } } finally { jedis.close(); } } catch (Throwable t) { LOGGER.warn( "Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t); } } }
public UnfilteredRowIterator next() { Map.Entry<PartitionPosition, AtomicBTreePartition> entry = iter.next(); // Actual stored key should be true DecoratedKey assert entry.getKey() instanceof DecoratedKey; DecoratedKey key = (DecoratedKey) entry.getKey(); ClusteringIndexFilter filter = dataRange.clusteringIndexFilter(key); return filter.getUnfilteredRowIterator(columnFilter, entry.getValue()); }
private Map<String, String> buildMapping() { Map<String, String> extensionMapping = new LinkedHashMap<String, String>(); // force inclusion of unknow item to manage unknown files extensionMapping.put( DocumentType.UNKNOWN.getExtension(), DocumentType.UNKNOWN.getDefaultHeaderTypeName()); for (Map.Entry<String, String> entry : mapping.entrySet()) { extensionMapping.put(entry.getKey().toLowerCase(), entry.getValue().toLowerCase()); } if (useDefaultMapping) { for (Map.Entry<String, String> entry : defaultMapping().entrySet()) { if (!extensionMapping.containsKey(entry.getKey())) { extensionMapping.put(entry.getKey(), entry.getValue()); } } } return extensionMapping; }
@Override protected void doSubscribe(Node node, NotifyListener listener) { List<NodeType> listenNodeTypes = node.getListenNodeTypes(); if (CollectionUtils.isEmpty(listenNodeTypes)) { return; } for (NodeType listenNodeType : listenNodeTypes) { String listenNodePath = NodeRegistryUtils.getNodeTypePath(clusterName, listenNodeType); Notifier notifier = notifiers.get(listenNodePath); if (notifier == null) { Notifier newNotifier = new Notifier(listenNodePath); notifiers.putIfAbsent(listenNodePath, newNotifier); notifier = notifiers.get(listenNodePath); if (notifier == newNotifier) { notifier.start(); } } boolean success = false; NodeRegistryException exception = null; for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) { JedisPool jedisPool = entry.getValue(); try { Jedis jedis = jedisPool.getResource(); try { doNotify( jedis, Collections.singletonList(listenNodePath), Collections.singletonList(listener)); success = true; break; // 只需读一个服务器的数据 } finally { jedis.close(); } } catch (Throwable t) { exception = new NodeRegistryException( "Failed to unregister node to redis registry. registry: " + entry.getKey() + ", node: " + node + ", cause: " + t.getMessage(), t); } } if (exception != null) { if (success) { LOGGER.warn(exception.getMessage(), exception); } else { throw exception; } } } }
/** headMap returns map with keys in requested range */ public void testDescendingTailMapContents() { ConcurrentNavigableMap map = dmap5(); SortedMap sm = map.tailMap(m2); assertFalse(sm.containsKey(m1)); assertTrue(sm.containsKey(m2)); assertTrue(sm.containsKey(m3)); assertTrue(sm.containsKey(m4)); assertTrue(sm.containsKey(m5)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer) (i.next()); assertEquals(m2, k); k = (Integer) (i.next()); assertEquals(m3, k); k = (Integer) (i.next()); assertEquals(m4, k); k = (Integer) (i.next()); assertEquals(m5, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry) (ei.next()); assertEquals(m2, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(m3, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(m4, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(m4); assertEquals(m4, ssm.firstKey()); assertEquals(m5, ssm.lastKey()); assertEquals("D", ssm.remove(m4)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
/** headMap returns map with keys in requested range */ public void testTailMapContents() { ConcurrentNavigableMap map = map5(); SortedMap sm = map.tailMap(two); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertTrue(sm.containsKey(four)); assertTrue(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer) (i.next()); assertEquals(two, k); k = (Integer) (i.next()); assertEquals(three, k); k = (Integer) (i.next()); assertEquals(four, k); k = (Integer) (i.next()); assertEquals(five, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry) (ei.next()); assertEquals(two, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(three, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(four, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry) (ei.next()); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(four); assertEquals(four, ssm.firstKey()); assertEquals(five, ssm.lastKey()); assertEquals("D", ssm.remove(four)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
private int findMinLocalDeletionTime( Iterator<Map.Entry<PartitionPosition, AtomicBTreePartition>> iterator) { int minLocalDeletionTime = Integer.MAX_VALUE; while (iterator.hasNext()) { Map.Entry<PartitionPosition, AtomicBTreePartition> entry = iterator.next(); minLocalDeletionTime = Math.min(minLocalDeletionTime, entry.getValue().stats().minLocalDeletionTime); } return minLocalDeletionTime; }
/** * Updates partition map in all caches. * * @param msg Partitions single message. */ private void updatePartitionSingleMap(GridDhtPartitionsSingleMessage msg) { for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg.partitions().entrySet()) { Integer cacheId = entry.getKey(); GridCacheContext cacheCtx = cctx.cacheContext(cacheId); GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() : cctx.exchange().clientTopology(cacheId, this); top.update(exchId, entry.getValue()); } }
public void addEnvToIntent(Intent intent) { Map<String, String> envMap = System.getenv(); Set<Map.Entry<String, String>> envSet = envMap.entrySet(); Iterator<Map.Entry<String, String>> envIter = envSet.iterator(); int c = 0; while (envIter.hasNext()) { Map.Entry<String, String> entry = envIter.next(); intent.putExtra("env" + c, entry.getKey() + "=" + entry.getValue()); c++; } }
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); }
protected List<Object> executeInConcurrency( SqlSessionCallback action, SortedMap<String, DataSource> dsMap) { List<ConcurrentShardRequest> requests = Lists.newArrayList(); for (Map.Entry<String, DataSource> entry : dsMap.entrySet()) { ConcurrentShardRequest request = new ConcurrentShardRequest(); request.setAction(action); request.setDataSource(entry.getValue()); request.setExecutor(dataSourceSpecificExecutors.get(entry.getKey())); requests.add(request); } return getConcurrentShardRequestProcessor().process(requests); }
/** * Returns a grouped and sorted map of all registered metrics which match then given {@link * MetricPredicate}. * * @param predicate a predicate which metrics have to match to be in the results * @return all registered metrics which match {@code predicate}, sorted by name */ public SortedMap<String, SortedMap<MetricName, Metric>> getGroupedMetrics( MetricPredicate predicate) { final SortedMap<String, SortedMap<MetricName, Metric>> groups = new TreeMap<String, SortedMap<MetricName, Metric>>(); for (Map.Entry<MetricName, Metric> entry : metrics.entrySet()) { final String qualifiedTypeName = entry.getKey().getGroup() + "." + entry.getKey().getType(); if (predicate.matches(entry.getKey(), entry.getValue())) { final String scopedName; if (entry.getKey().hasScope()) { scopedName = qualifiedTypeName + "." + entry.getKey().getScope(); } else { scopedName = qualifiedTypeName; } SortedMap<MetricName, Metric> group = groups.get(scopedName); if (group == null) { group = new TreeMap<MetricName, Metric>(); groups.put(scopedName, group); } group.put(entry.getKey(), entry.getValue()); } } return Collections.unmodifiableSortedMap(groups); }
public void run() { // each file is processed into a local hash table and then merged with the global results // this will cause much less contention on the global table, but still avoids a sequential // update Hashtable<String, Integer> local_results = new Hashtable<String, Integer>(WordCountJ.HASH_SIZE, WordCountJ.LF); // grab a file to work on String cf; while ((cf = files.poll()) != null) { try { BufferedReader input = new BufferedReader(new FileReader(cf)); String text; // well go line-by-line... maybe this is not the fastest while ((text = input.readLine()) != null) { // parse words Matcher matcher = pattern.matcher(text); while (matcher.find()) { String word = matcher.group(1); if (local_results.containsKey(word)) { local_results.put(word, 1 + local_results.get(word)); } else { local_results.put(word, 1); } } } input.close(); } catch (Exception e) { System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); return; } // merge local hashmap with shared one,could have a // seperate thread do this but that might be cheating Iterator<Map.Entry<String, Integer>> updates = local_results.entrySet().iterator(); while (updates.hasNext()) { Map.Entry<String, Integer> kv = updates.next(); String k = kv.getKey(); Integer v = kv.getValue(); synchronized (results) { if (results.containsKey(k)) { results.put(k, v + results.get(k)); } else { results.put(k, v); } } } local_results.clear(); } }
void doStatusCheck() { long now = System.currentTimeMillis(); Set<InetAddress> eps = endpointStateMap_.keySet(); for (InetAddress endpoint : eps) { if (endpoint.equals(localEndpoint_)) continue; FailureDetector.instance.interpret(endpoint); EndpointState epState = endpointStateMap_.get(endpoint); if (epState != null) { long duration = now - epState.getUpdateTimestamp(); if (StorageService.instance.getTokenMetadata().isMember(endpoint)) epState.setHasToken(true); // check if this is a fat client. fat clients are removed automatically from // gosip after FatClientTimeout if (!epState.getHasToken() && !epState.isAlive() && !justRemovedEndpoints_.containsKey(endpoint) && (duration > FatClientTimeout_)) { logger_.info( "FatClient " + endpoint + " has been silent for " + FatClientTimeout_ + "ms, removing from gossip"); removeEndpoint( endpoint); // will put it in justRemovedEndpoints to respect quarantine delay evictFromMembership(endpoint); // can get rid of the state immediately } if (!epState.isAlive() && (duration > aVeryLongTime_)) { evictFromMembership(endpoint); } } } if (!justRemovedEndpoints_.isEmpty()) { Map<InetAddress, Long> copy = new HashMap<InetAddress, Long>(justRemovedEndpoints_); for (Map.Entry<InetAddress, Long> entry : copy.entrySet()) { if ((now - entry.getValue()) > QUARANTINE_DELAY) { if (logger_.isDebugEnabled()) logger_.debug( QUARANTINE_DELAY + " elapsed, " + entry.getKey() + " gossip quarantine over"); justRemovedEndpoints_.remove(entry.getKey()); } } } }
/** * Re-initializes the fields which store information about the currently held data. Empties * <tt>data</tt>. */ private void reinit() { firstSeq = lastSeq = timestamp = -1; pictureId = -1; empty = true; haveEnd = haveStart = false; frameLength = 0; Iterator<Map.Entry<Long, Container>> it = data.entrySet().iterator(); Map.Entry<Long, Container> e; while (it.hasNext()) { e = it.next(); free.offer(e.getValue()); it.remove(); } }
/** pollLastEntry returns entries in order */ public void testDescendingPollLastEntry() { ConcurrentNavigableMap map = dmap5(); Map.Entry e = map.pollLastEntry(); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(m4, e.getKey()); map.put(m5, "E"); e = map.pollLastEntry(); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(m3, e.getKey()); map.remove(m2); e = map.pollLastEntry(); assertEquals(m1, e.getKey()); try { e.setValue("E"); shouldThrow(); } catch (UnsupportedOperationException success) { } e = map.pollLastEntry(); assertNull(e); }
/** pollLastEntry returns entries in order */ public void testPollLastEntry() { ConcurrentNavigableMap map = map5(); Map.Entry e = map.pollLastEntry(); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(four, e.getKey()); map.put(five, "E"); e = map.pollLastEntry(); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); e = map.pollLastEntry(); assertEquals(three, e.getKey()); map.remove(two); e = map.pollLastEntry(); assertEquals(one, e.getKey()); try { e.setValue("E"); shouldThrow(); } catch (UnsupportedOperationException success) { } e = map.pollLastEntry(); assertNull(e); }
boolean allAvailable() { for (Map.Entry<String, PluginSpec> plugin : plugins.entrySet()) { PluginSpec pluginSpec = plugin.getValue(); if (pluginSpec.running < pluginSpec.expected) { System.err.println( "STILL waiting for " + pluginSpec.pluginType + " expected " + pluginSpec.expected + " running " + pluginSpec.running); return false; } } return true; }
/** * Makes <tt>RTCPSDES</tt> packets for all the RTP streams that we're sending. * * @return a <tt>List</tt> of <tt>RTCPSDES</tt> packets for all the RTP streams that we're * sending. */ private RTCPSDESPacket makeSDESPacket() { Collection<RTCPSDES> sdesChunks = new ArrayList<RTCPSDES>(); // Create an SDES for our own SSRC. RTCPSDES ownSDES = new RTCPSDES(); SSRCInfo ourinfo = getStream().getStreamRTPManager().getSSRCCache().ourssrc; ownSDES.ssrc = (int) getLocalSSRC(); Collection<RTCPSDESItem> ownItems = new ArrayList<RTCPSDESItem>(); ownItems.add(new RTCPSDESItem(RTCPSDESItem.CNAME, ourinfo.sourceInfo.getCNAME())); // Throttle the source description bandwidth. See RFC3550#6.3.9 // Allocation of Source Description Bandwidth. if (sdesCounter % 3 == 0) { if (ourinfo.name != null && ourinfo.name.getDescription() != null) ownItems.add(new RTCPSDESItem(RTCPSDESItem.NAME, ourinfo.name.getDescription())); if (ourinfo.email != null && ourinfo.email.getDescription() != null) ownItems.add(new RTCPSDESItem(RTCPSDESItem.EMAIL, ourinfo.email.getDescription())); if (ourinfo.phone != null && ourinfo.phone.getDescription() != null) ownItems.add(new RTCPSDESItem(RTCPSDESItem.PHONE, ourinfo.phone.getDescription())); if (ourinfo.loc != null && ourinfo.loc.getDescription() != null) ownItems.add(new RTCPSDESItem(RTCPSDESItem.LOC, ourinfo.loc.getDescription())); if (ourinfo.tool != null && ourinfo.tool.getDescription() != null) ownItems.add(new RTCPSDESItem(RTCPSDESItem.TOOL, ourinfo.tool.getDescription())); if (ourinfo.note != null && ourinfo.note.getDescription() != null) ownItems.add(new RTCPSDESItem(RTCPSDESItem.NOTE, ourinfo.note.getDescription())); } sdesCounter++; ownSDES.items = ownItems.toArray(new RTCPSDESItem[ownItems.size()]); sdesChunks.add(ownSDES); for (Map.Entry<Integer, byte[]> entry : cnameRegistry.entrySet()) { RTCPSDES sdes = new RTCPSDES(); sdes.ssrc = entry.getKey(); sdes.items = new RTCPSDESItem[] {new RTCPSDESItem(RTCPSDESItem.CNAME, entry.getValue())}; } RTCPSDES[] sps = sdesChunks.toArray(new RTCPSDES[sdesChunks.size()]); RTCPSDESPacket sp = new RTCPSDESPacket(sps); return sp; }