Java Code Examples for java.util.concurrent.ConcurrentMap#entrySet()

The following examples show how to use java.util.concurrent.ConcurrentMap#entrySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CPUManager.java    From TAB with Apache License 2.0 6 votes vote down vote up
public Map<Object, Float> getUsage(){
	Map<Object, Long> nanoMap = new HashMap<Object, Long>();
	Object key;
	synchronized (lastMinute) {
		for (ConcurrentMap<String, Long> second : lastMinute) {
			for (Entry<String, Long> nanos : second.entrySet()) {
				key = nanos.getKey();
				if (!nanoMap.containsKey(key)) nanoMap.put(key, 0L);
				nanoMap.put(key, nanoMap.get(key)+nanos.getValue());
			}
		}
	}
	Map<Object, Float> percentMap = new HashMap<Object, Float>();
	long nanotime;
	float percent;
	for (Entry<Object, Long> entry : nanoMap.entrySet()) {
		nanotime = entry.getValue(); //nano seconds total (last minute)
		nanotime /= lastMinute.size(); //average nanoseconds per buffer (0.1 second)
		percent = (float) nanotime / bufferSizeMillis / 1000000; //relative usage (0-1)
		percent *= 100; //relative into %
		percentMap.put(entry.getKey(), percent);
	}
	return sortByValue(percentMap);
}
 
Example 2
Source File: ConsumerServiceImpl.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
public List<String> findAddressesByApplication(String application) {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);

    if(consumerUrls == null)
        return ret;

    for (Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
                String addr = u.getAddress();
                if (addr != null) ret.add(addr);
            }
        }
    }

    return ret;
}
 
Example 3
Source File: ProviderServiceImpl.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public List<String> findAddressesByApplication(String application) {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    for(Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for(Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if(application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
                String addr = u.getAddress();
                if(addr != null) ret.add(addr);
            }
        }
    }
    
    return ret;
}
 
Example 4
Source File: ProviderServiceImpl.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public List<String> findServicesByAddress(String address) {
    List<String> ret = new ArrayList<String>();
    
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(providerUrls == null || address == null || address.length() == 0) return ret;
    
    for(Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for(Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if(address.equals(u.getAddress())) {
                ret.add(e1.getKey());
                break;
            }
        }
    }
    
    return ret;
}
 
Example 5
Source File: ProviderServiceImpl.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public List<String> findServicesByApplication(String application) {
    List<String> ret = new ArrayList<String>();
    
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(providerUrls == null || application == null || application.length() == 0) return ret;
    
    for(Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for(Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if(application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
                ret.add(e1.getKey());
                break;
            }
        }
    }
    
    return ret;
}
 
Example 6
Source File: ProviderServiceImpl.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public List<String> findServicesByAddress(String address) {
    List<String> ret = new ArrayList<String>();
    
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(providerUrls == null || address == null || address.length() == 0) return ret;
    
    for(Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for(Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if(address.equals(u.getAddress())) {
                ret.add(e1.getKey());
                break;
            }
        }
    }
    
    return ret;
}
 
Example 7
Source File: ConcurrentConsumption.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
/**
 * 将过期未应答的且已经不是并行消费的进行清理
 */
private void cleanExpireQueue() {
    ConcurrentMap<ConsumePartition, ConcurrentLinkedQueue<PartitionSegment>> expired = expireQueueMap;
    List<ConsumePartition> removed = new ArrayList<>();
    for (Map.Entry<ConsumePartition, ConcurrentLinkedQueue<PartitionSegment>> entry : expired.entrySet()) {
        ConsumePartition consumePartition = entry.getKey();
        try {
            org.joyqueue.domain.Consumer.ConsumerPolicy policy = clusterManager.getConsumerPolicy(TopicName.parse(consumePartition.getTopic()), consumePartition.getApp());
            if (!policy.isConcurrent()) {
                removed.add(consumePartition);

            }
        } catch (Exception e) {
            logger.warn("clean expire error", e.getMessage());
        }
    }


    ConcurrentMap<ConsumePartition, AtomicInteger> consumerCounter = consumerSegmentNumMap;
    ConcurrentMap<ConsumePartition, List<Position>> concurrentConsumeCacheMap = concurrentConsumeCache;
    removed.forEach(ele -> {
        expired.remove(ele);
        consumerCounter.remove(ele);
        concurrentConsumeCacheMap.remove(ele);
    });
}
 
Example 8
Source File: ConsumerServiceImpl.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public List<String> findServicesByAddress(String address) {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
    if(consumerUrls == null || address == null || address.length() == 0) return ret;
    
    for(Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for(Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if(address.equals(u.getAddress())) {
                ret.add(e1.getKey());
                break;
            }
        }
    }
    
    return ret;
}
 
Example 9
Source File: ProviderServiceImpl.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public List<String> findAddressesByApplication(String application) {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    for(Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for(Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if(application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
                String addr = u.getAddress();
                if(addr != null) ret.add(addr);
            }
        }
    }
    
    return ret;
}
 
Example 10
Source File: ProviderServiceImpl.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public List<String> findServicesByApplication(String application) {
    List<String> ret = new ArrayList<String>();
    
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(providerUrls == null || application == null || application.length() == 0) return ret;
    
    for(Map.Entry<String, Map<Long, URL>> e1 : providerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for(Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if(application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
                ret.add(e1.getKey());
                break;
            }
        }
    }
    
    return ret;
}
 
Example 11
Source File: GridServiceProcessor.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param futs Futs.
 * @param err Exception.
 */
private void cancelFutures(ConcurrentMap<String, ? extends GridFutureAdapter<?>> futs, Exception err) {
    for (Map.Entry<String, ? extends GridFutureAdapter<?>> entry : futs.entrySet()) {
        GridFutureAdapter fut = entry.getValue();

        fut.onDone(err);

        futs.remove(entry.getKey(), fut);
    }
}
 
Example 12
Source File: RegisterBrokerBody.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static ConcurrentMap<String, TopicConfig> cloneTopicConfigTable(
    ConcurrentMap<String, TopicConfig> topicConfigConcurrentMap) {
    ConcurrentHashMap<String, TopicConfig> result = new ConcurrentHashMap<String, TopicConfig>();
    if (topicConfigConcurrentMap != null) {
        for (Map.Entry<String, TopicConfig> entry : topicConfigConcurrentMap.entrySet()) {
            result.put(entry.getKey(), entry.getValue());
        }
    }
    return result;

}
 
Example 13
Source File: Assert.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the given stream produces the same values than the given iterator, in any order.
 * This method is designed for use with parallel streams, but works with sequential streams too.
 *
 * @param  <E>       the type of values to test.
 * @param  expected  the expected values.
 * @param  actual    the stream to compare with the expected values.
 *
 * @since 0.8
 */
public static <E> void assertParallelStreamEquals(final Iterator<E> expected, final Stream<E> actual) {
    final Integer ONE = 1;          // For doing autoboxing only once.
    final ConcurrentMap<E,Integer> count = new ConcurrentHashMap<>();
    while (expected.hasNext()) {
        count.merge(expected.next(), ONE, (old, one) -> old + 1);
    }
    /*
     * Following may be parallelized in an arbitrary amount of threads.
     */
    actual.forEach((value) -> {
        if (count.computeIfPresent(value, (key, old) -> old - 1) == null) {
            fail("Stream returned unexpected value: " + value);
        }
    });
    /*
     * Back to sequential order, verify that all elements have been traversed
     * by the stream and no more.
     */
    for (final Map.Entry<E,Integer> entry : count.entrySet()) {
        int n = entry.getValue();
        if (n != 0) {
            final String message;
            if (n < 0) {
                message = "Stream returned too many occurrences of %s%n%d extraneous were found.";
            } else {
                message = "Stream did not returned all expected occurrences of %s%n%d are missing.";
            }
            fail(String.format(message, entry.getKey(), StrictMath.abs(n)));
        }
    }
}
 
Example 14
Source File: CommonHttpPipeline.java    From zuul-netty with Apache License 2.0 5 votes vote down vote up
private void addZuulPostFilters(ChannelPipeline pipeline, ConcurrentMap<ZuulPostFilter, Path> filters) {
    for (Map.Entry<ZuulPostFilter, Path> entry : filters.entrySet()) {
        String name = entry.getValue().toString();
        pipeline.addLast(name, new HttpResponseFrameworkHandler(name, entry.getKey()));
    }

}
 
Example 15
Source File: DecompilerCachingTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private String getCacheSizeFailureMessage(int expected) {
	StringBuilder buffy = new StringBuilder("Cache size is not as expected - expected " +
		expected + "; found " + cache.size() + "\nEntries in cache:\n");
	ConcurrentMap<Function, DecompileResults> map = cache.asMap();
	Set<Entry<Function, DecompileResults>> entries = map.entrySet();
	for (Entry<Function, DecompileResults> entry : entries) {
		Function key = entry.getKey();
		buffy.append('\t').append(key.getName()).append('\n');
	}
	return buffy.toString();
}
 
Example 16
Source File: GroupMetadata.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
public List<GroupMemberMetadata> getMemberList() {
    ConcurrentMap<String, org.joyqueue.broker.coordinator.group.domain.GroupMemberMetadata> members = getMembers();
    if (MapUtils.isEmpty(members)) {
        return Collections.emptyList();
    }
    List<GroupMemberMetadata> result = Lists.newArrayListWithExpectedSize(members.size());
    for (Map.Entry<String, org.joyqueue.broker.coordinator.group.domain.GroupMemberMetadata> entry : members.entrySet()) {
        result.add((GroupMemberMetadata) entry.getValue());
    }
    return result;
}
 
Example 17
Source File: BaseContext.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
public void endContext(Long key) {
    final ConcurrentMap<Contextual<?>, Instance<?>> storage = storages.remove(key);
    if (storage == null) {
        return;
    }

    for (final Map.Entry<Contextual<?>, Instance<?>> entry : storage.entrySet()) {
        final Instance<?> instance = entry.getValue();
        Contextual.class.cast(entry.getKey()).destroy(instance.value, instance.cc);
    }
    storage.clear();
}
 
Example 18
Source File: RegisterBrokerBody.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 克隆topicconfigtable
 * @param topicConfigConcurrentMap topicconfigtable
 * @return ;
 */
public static ConcurrentMap<String, TopicConfig> cloneTopicConfigTable(
    ConcurrentMap<String, TopicConfig> topicConfigConcurrentMap) {
    ConcurrentHashMap<String, TopicConfig> result = new ConcurrentHashMap<String, TopicConfig>();
    if (topicConfigConcurrentMap != null) {
        for (Map.Entry<String, TopicConfig> entry : topicConfigConcurrentMap.entrySet()) {
            result.put(entry.getKey(), entry.getValue());
        }
    }
    return result;

}
 
Example 19
Source File: UrlUtils.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * 服务端注册的所有注册中心对应的URL
 *
 * @author yulei
 * @since 2019/8/27
 * @since 2019/11/29 modify by wlh 增加注册中心serviceIP和servicePort属性到url的Parameter中
 */
public static List<URL> getAllProviderRegisterURLs() {
  Properties properties = SystemConfig.getProperties();
  if (properties == null) {
    logger.error("读取配置文件错误,无法获取配置信息");
    return null;
  }

  ConcurrentMap<String, RegistryCenter> allConfMap = AllRegisterCenterConf.getAllConfMap();
  List<URL> urlList = new ArrayList<>(allConfMap.size());

  String addresses, addrKey;
  URL url;

  for (Map.Entry<String, RegistryCenter> entry : allConfMap.entrySet()) {
    addrKey = entry.getKey();
    addresses = properties.getProperty(addrKey);
    if (StringUtils.isEmpty(addresses)) {
      continue;
    }

    RegistryCenter registryCenter = entry.getValue();
    url = getZkUrlByAddress(addresses, addrKey, registryCenter.getServiceIp(), registryCenter.getServicePort());

    if (url != null) {
      urlList.add(url);
    }
  }

  return urlList;
}
 
Example 20
Source File: OperationAllocationDependencyGraphFormatter.java    From kieker with Apache License 2.0 4 votes vote down vote up
private void createGraph(final ElementGrouping grouping, final StringBuilder builder, final boolean useShortLabels) {
	final ConcurrentMap<ExecutionContainer, Set<AllocationComponent>> allocationComponentGrouping = grouping.getAllocationComponentGrouping();
	final ConcurrentMap<AllocationComponent, Set<DependencyGraphNode<AllocationComponentOperationPair>>> operationGrouping = grouping.getOperationGrouping();

	for (final Entry<ExecutionContainer, Set<AllocationComponent>> containerComponentEntry : allocationComponentGrouping.entrySet()) {
		final ExecutionContainer executionContainer = containerComponentEntry.getKey();

		// If the current execution container is the root container, just build a simple node
		// and go on
		if (executionContainer.isRootContainer()) {
			builder.append(DotFactory.createNode("",
					AbstractDependencyGraphFormatter.createNodeId(executionContainer.getId()),
					executionContainer.getName(),
					DotFactory.DOT_SHAPE_NONE,
					null, // style
					null, // framecolor
					null, // fillcolor
					null, // fontcolor
					DotFactory.DOT_DEFAULT_FONTSIZE, // fontsize
					null, // imagefilename
					null, // misc
					null)); // tooltip

			continue;
		}

		// If it is a common container, create the cluster for the execution container...
		builder.append(DotFactory.createCluster("",
				AbstractDependencyGraphFormatter.createContainerId(executionContainer),
				OperationAllocationDependencyGraphFormatter.createContainerNodeLabel(executionContainer),
				DotFactory.DOT_SHAPE_BOX, // shape
				DotFactory.DOT_STYLE_FILLED, // style
				null, // framecolor
				DotFactory.DOT_FILLCOLOR_WHITE, // fillcolor
				null, // fontcolor
				DotFactory.DOT_DEFAULT_FONTSIZE, // fontsize
				null)); // misc

		// ...then, create clusters for the contained allocation components.
		for (final AllocationComponent allocationComponent : containerComponentEntry.getValue()) {
			builder.append(DotFactory.createCluster("",
					AbstractDependencyGraphFormatter.createAllocationComponentId(allocationComponent),
					OperationAllocationDependencyGraphFormatter.createAllocationComponentNodeLabel(allocationComponent, useShortLabels),
					DotFactory.DOT_SHAPE_BOX,
					DotFactory.DOT_STYLE_FILLED, // style
					null, // framecolor
					DotFactory.DOT_FILLCOLOR_WHITE, // fillcolor
					null, // fontcolor
					DotFactory.DOT_DEFAULT_FONTSIZE, // fontsize
					null)); // misc

			// Print the nodes for the operations
			for (final DependencyGraphNode<AllocationComponentOperationPair> node : operationGrouping.get(allocationComponent)) {
				final Operation operation = node.getEntity().getOperation();

				builder.append(DotFactory.createNode("",
						AbstractDependencyGraphFormatter.createNodeId(node),
						this.createOperationNodeLabel(operation, node),
						DotFactory.DOT_SHAPE_OVAL,
						DotFactory.DOT_STYLE_FILLED, // style
						AbstractGraphFormatter.getDotRepresentation(node.getColor()), // framecolor
						AbstractDependencyGraphFormatter.getNodeFillColor(node), // fillcolor
						null, // fontcolor
						DotFactory.DOT_DEFAULT_FONTSIZE, // fontsize
						null, // imagefilename
						null, // misc
						node.getDescription() // tooltip
				));
			}

			builder.append("}\n");
		}
		builder.append("}\n");
	}
}