@Override public Map<String, TokenHostConnectionPoolPartition<CL>> getPartitions() { Map<String, TokenHostConnectionPoolPartition<CL>> result = Maps.newHashMap(); for (Entry<RingPosition, TokenHostConnectionPoolPartition<CL>> entry : tokenToPartitionMap.entrySet()) { result.put(entry.getKey().toString(), entry.getValue()); } return result; }
@Override public Map<String, TokenHostConnectionPoolPartition<CL>> getPartitions() { Map<String, TokenHostConnectionPoolPartition<CL>> result = Maps.newHashMap(); for (Entry<BigInteger, TokenHostConnectionPoolPartition<CL>> entry : tokenToPartitionMap.entrySet()) { result.put(entry.getKey().toString(), entry.getValue()); } return result; }
/** * Returns true if this provider has an instance for the class provided * More specifically, if it contains at least one dependency from which the provided class is assignable * This check also queries any named dependencies this provider has * * @param klass the class to check for * @return true if an instance of the class exists in this provider */ public boolean has(Class<?> klass) { for (Map.Entry<Class<?>, Object> e : instances.entrySet()) { if (klass.isAssignableFrom(e.getKey())) { return true; } } for (Map.Entry<String, Object> e : named.entrySet()) { Object val = e.getValue(); if (val != null && klass.isAssignableFrom(val.getClass())) { return true; } } return false; }
/** * Returns true if this provider has an instance for the class provided * More specifically, if it contains at least one dependency from which the provided class is assignable * This check also queries any named dependencies this provider has * * @param klass the class to check for * @return true if an instance of the class exists in this provider */ public boolean has(Class<?> klass) { for (Map.Entry<Class<?>, Object> e : instances.entrySet()) { if (klass.isAssignableFrom(e.getKey())) { return true; } } for (Map.Entry<String, Object> e : named.entrySet()) { Object val = e.getValue(); if (val != null && klass.isAssignableFrom(val.getClass())) { return true; } } return false; }
/** * Get the instance available for the provided class * More specifically, the first dependency from which the provided class is assignable * Like {@link #has(Class)} this method returns a match from named dependencies if one is found * * @param klass the class to get the instance for * @return the instance or null if no instance exists, use {@link #has(Class)} to ensure an instance exists first */ public Object get(Class<?> klass) { for (Map.Entry<Class<?>, Object> e : instances.entrySet()) { if (klass.isAssignableFrom(e.getKey())) { return e.getValue(); } } for (Map.Entry<String, Object> e : named.entrySet()) { Object val = e.getValue(); if (val != null && klass.isAssignableFrom(val.getClass())) { return val; } } return null; }
/** * Get the instance available for the provided class * More specifically, the first dependency from which the provided class is assignable * Like {@link #has(Class)} this method returns a match from named dependencies if one is found * * @param klass the class to get the instance for * @return the instance or null if no instance exists, use {@link #has(Class)} to ensure an instance exists first */ public Object get(Class<?> klass) { for (Map.Entry<Class<?>, Object> e : instances.entrySet()) { if (klass.isAssignableFrom(e.getKey())) { return e.getValue(); } } for (Map.Entry<String, Object> e : named.entrySet()) { Object val = e.getValue(); if (val != null && klass.isAssignableFrom(val.getClass())) { return val; } } return null; }
private void schedule() { queueSize.acquireUninterruptibly(); for (Map.Entry<String,WeightedQueue> request : queues.entrySet()) { WeightedQueue queue = request.getValue(); //Using the weight, process that many requests at a time (for that scheduler id) for (int i=0; i<queue.weight; i++) { Thread t = queue.poll(); if (t == null) break; else { taskCount.acquireUninterruptibly(); queueSize.acquireUninterruptibly(); } } } queueSize.release(); }
private void schedule() { queueSize.acquireUninterruptibly(); for (Map.Entry<String,WeightedQueue> request : queues.entrySet()) { WeightedQueue queue = request.getValue(); //Using the weight, process that many requests at a time (for that scheduler id) for (int i=0; i<queue.weight; i++) { Thread t = queue.poll(); if (t == null) break; else { taskCount.acquireUninterruptibly(); queueSize.acquireUninterruptibly(); } } } queueSize.release(); }
private void schedule() { queueSize.acquireUninterruptibly(); for (Map.Entry<String,WeightedQueue> request : queues.entrySet()) { WeightedQueue queue = request.getValue(); //Using the weight, process that many requests at a time (for that scheduler id) for (int i=0; i<queue.weight; i++) { Thread t = queue.poll(); if (t == null) break; else { taskCount.acquireUninterruptibly(); queueSize.acquireUninterruptibly(); } } } queueSize.release(); }
/** * Removes all references of the given object from the dependency provider * * @param i the object to remove occurrences of * @return true if the object was found and removed, false otherwise */ public boolean remove(Object i) { if (i == null) { return false; } List<Map.Entry<Class<?>, Object>> entries = new ArrayList<>(); for (Map.Entry<Class<?>, Object> e : instances.entrySet()) { if (e.getValue() == i) { entries.add(e); } } for (Map.Entry<Class<?>, Object> e : entries) { instances.remove(e.getKey()); } return entries.size() > 0; }
/** * Returns a string representation of this map. The string representation consists of a list of key-value mappings in * the order returned by the map's <tt>entrySet</tt> view's iterator, enclosed in braces (<tt>"{}"</tt>). Adjacent * mappings are separated by the characters <tt>", "</tt> (comma and space). Each key-value mapping is rendered as the * key followed by an equals sign (<tt>"="</tt>) followed by the associated value. Keys and values are converted to * strings as by {@link String#valueOf(Object)}. * * @return a string representation of this map */ @Override public String toString() { Iterator<Entry<TypeK, TypeV>> i = entrySet().iterator(); if (!i.hasNext()) return "{}"; StringBuilder sb = new StringBuilder(); sb.append('{'); for (;;) { Entry<TypeK, TypeV> e = i.next(); TypeK key = e.getKey(); TypeV value = e.getValue(); sb.append(key == this ? "(this Map)" : key); sb.append('='); sb.append(value == this ? "(this Map)" : value); if (!i.hasNext()) return sb.append('}').toString(); sb.append(", "); } }
/** * Removes all references of the given object from the dependency provider * * @param i the object to remove occurrences of * @return true if the object was found and removed, false otherwise */ public boolean remove(Object i) { if (i == null) { return false; } List<Map.Entry<Class<?>, Object>> entries = new ArrayList<>(); for (Map.Entry<Class<?>, Object> e : instances.entrySet()) { if (e.getValue() == i) { entries.add(e); } } for (Map.Entry<Class<?>, Object> e : entries) { instances.remove(e.getKey()); } return entries.size() > 0; }
private void schedule() { queueSize.acquireUninterruptibly(); for (Map.Entry<String,WeightedQueue> request : queues.entrySet()) { WeightedQueue queue = request.getValue(); //Using the weight, process that many requests at a time (for that scheduler id) for (int i=0; i<queue.weight; i++) { Thread t = queue.poll(); if (t == null) break; else { taskCount.acquireUninterruptibly(); queueSize.acquireUninterruptibly(); } } } queueSize.release(); }
Iterator<Entry<TypeK,TypeV>> i = entrySet().iterator(); if( !i.hasNext()) return "{}";
/** * @return a collection of dirty CFIDs for this segment file. */ public synchronized Collection<UUID> getDirtyCFIDs() { if (cfClean.isEmpty() || cfDirty.isEmpty()) return cfDirty.keySet(); List<UUID> r = new ArrayList<>(cfDirty.size()); for (Map.Entry<UUID, AtomicInteger> dirty : cfDirty.entrySet()) { UUID cfId = dirty.getKey(); AtomicInteger dirtyPos = dirty.getValue(); AtomicInteger cleanPos = cfClean.get(cfId); if (cleanPos == null || cleanPos.intValue() < dirtyPos.intValue()) r.add(dirty.getKey()); } return r; }
/** * @return a collection of dirty CFIDs for this segment file. */ public synchronized Collection<UUID> getDirtyCFIDs() { if (cfClean.isEmpty() || cfDirty.isEmpty()) return cfDirty.keySet(); List<UUID> r = new ArrayList<>(cfDirty.size()); for (Map.Entry<UUID, IntegerInterval> dirty : cfDirty.entrySet()) { UUID cfId = dirty.getKey(); IntegerInterval dirtyInterval = dirty.getValue(); IntegerInterval.Set cleanSet = cfClean.get(cfId); if (cleanSet == null || !cleanSet.covers(dirtyInterval)) r.add(dirty.getKey()); } return r; }
/** * @return a collection of dirty CFIDs for this segment file. */ public synchronized Collection<UUID> getDirtyCFIDs() { if (cfClean.isEmpty() || cfDirty.isEmpty()) return cfDirty.keySet(); List<UUID> r = new ArrayList<>(cfDirty.size()); for (Map.Entry<UUID, IntegerInterval> dirty : cfDirty.entrySet()) { UUID cfId = dirty.getKey(); IntegerInterval dirtyInterval = dirty.getValue(); IntegerInterval.Set cleanSet = cfClean.get(cfId); if (cleanSet == null || !cleanSet.covers(dirtyInterval)) r.add(dirty.getKey()); } return r; }
/** * @return a collection of dirty CFIDs for this segment file. */ public synchronized Collection<UUID> getDirtyCFIDs() { if (cfClean.isEmpty() || cfDirty.isEmpty()) return cfDirty.keySet(); List<UUID> r = new ArrayList<>(cfDirty.size()); for (Map.Entry<UUID, IntegerInterval> dirty : cfDirty.entrySet()) { UUID cfId = dirty.getKey(); IntegerInterval dirtyInterval = dirty.getValue(); IntegerInterval.Set cleanSet = cfClean.get(cfId); if (cleanSet == null || !cleanSet.covers(dirtyInterval)) r.add(dirty.getKey()); } return r; }
/** * Clean up resources associated with the conn pool */ @Override public void shutdown() { ConnectionPoolMBeanManager.getInstance().unregisterMonitor(config.getName(), this); for (Entry<Host, HostConnectionPool<CL>> pool : hosts.entrySet()) { pool.getValue().shutdown(); } config.getLatencyScoreStrategy().shutdown(); config.shutdown(); }
/** * Clean up resources associated with the conn pool */ @Override public void shutdown() { ConnectionPoolMBeanManager.getInstance().unregisterMonitor(config.getName(), this); for (Entry<Host, HostConnectionPool<CL>> pool : hosts.entrySet()) { pool.getValue().shutdown(); } config.getLatencyScoreStrategy().shutdown(); config.shutdown(); }