本文整理汇总了Java中java.util.concurrent.ConcurrentMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentMap.put方法的具体用法?Java ConcurrentMap.put怎么用?Java ConcurrentMap.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ConcurrentMap
的用法示例。
在下文中一共展示了ConcurrentMap.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTimeSeriesData
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
private <P extends AbstractPoint, C extends ArrayChunk<P, C>> void addTimeSeriesData(String nodeId,
int version,
String timeSeriesName,
List<C> chunks,
ConcurrentMap<TimeSeriesChunkKey, C> map) {
UUID nodeUuid = checkNodeId(nodeId);
TimeSeriesIndex.checkVersion(version);
Objects.requireNonNull(timeSeriesName);
Objects.requireNonNull(chunks);
Objects.requireNonNull(map);
for (C chunk : chunks) {
TimeSeriesKey key = new TimeSeriesKey(nodeUuid, version, timeSeriesName);
Integer lastNum = timeSeriesLastChunkMap.get(key);
int num;
if (lastNum == null) {
num = 0;
} else {
num = lastNum + 1;
}
timeSeriesLastChunkMap.put(key, num);
map.put(new TimeSeriesChunkKey(key, num), chunk);
}
}
示例2: test_Multi_Replace_MultiInstance
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
@Test
public void test_Multi_Replace_MultiInstance() throws InterruptedException {
final String name = "test_Multi_Replace_MultiInstance";
ConcurrentMap<Integer, Integer> map = BaseTest.createInstance().getMap(name);
for (int i = 0; i < 5; i++) {
map.put(i, 1);
}
final SecureRandom secureRandom = new SecureRandom();
testSingleInstanceConcurrency(100, r -> {
ConcurrentMap<Integer, Integer> map1 = r.getMap(name);
Assert.assertNotNull(map1.replace(secureRandom.nextInt(5), 2));
});
ConcurrentMap<Integer, Integer> testMap = BaseTest.createInstance().getMap(name);
for (Integer value : testMap.values()) {
Assert.assertEquals(2, (int)value);
}
assertMapSize(5, name);
}
示例3: addZKClient
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
/**
* @param group
* @param name
* @param zkClient
*/
private static void addZKClient(String group, String name,
ZKClient zkClient) {
group = group == null ? DEFAULT : group;
logger.info("Add zkclient to zk groups ,gourp is %s, zk name %s", group, name);
ConcurrentMap<String, ZKClient> groups = zkGroups.get(group);
if (groups == null) {
groups = new ConcurrentHashMap<String, ZKClient>();
}
if (groups.containsKey(name)) {
logger.warn(
"zk pools have contains the zk name...override the old and close it....");
close(name);
}
groups.put(name, zkClient);
zkGroups.put(group, groups);
}
示例4: _getStyleContextResolvedIcons
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
/**
* Returns a Map of icon names to Icons for the specified
* styleSheetNodes that have been filtered from the StyleContext and StyleSheetDocument
* and everything merged together.
*/
private ConcurrentMap<String, Icon> _getStyleContextResolvedIcons(
StyleContext context,
StyleSheetDocument document
)
{
Iterator<IconNode> iconNodeIterator = document.getIcons(context);
ConcurrentMap<String, Icon> iconMap = new ConcurrentHashMap<String, Icon>();
while (iconNodeIterator.hasNext())
{
IconNode iconNode = iconNodeIterator.next();
iconMap.put(iconNode.getIconName(), iconNode.getIcon());
}
return iconMap;
}
示例5: buildLinearTopo
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
/**
* buildLinearTopo models the Linear topology from Mininet
*
* Also, use names / ids similar to how mininet uses them
*/
public static final Topology buildLinearTopo(int numSwitches){
Topology t = new Topology();
// Add Switches
ConcurrentMap<String, Switch> switches = t.getSwitches();
ConcurrentMap<String, Link> links = t.getLinks();
for (int i = 0; i < numSwitches; i++) {
String switchID = intToSwitchId(i+1);
switches.put(switchID, new Switch(switchID));
}
// Add links between switches
int numLinks = numSwitches-1; // is A-->B = 2 switches, 1 link.
for (int i = 0; i < numLinks; i++) {
Switch s1 = switches.get(intToSwitchId(i+1));
Switch s2 = switches.get(intToSwitchId(i+2));
linkSwitches(t,s1,s2);
}
return t;
}
示例6: _updateAttributeChange
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
private void _updateAttributeChange(
ConcurrentMap<String, ConcurrentMap<String, AttributeComponentChange>> attrChanges,
ConcurrentMap<String, String> renameMap,
QualifiedComponentChange qAttrChange)
{
// get all the attribute changes for this component after considering possible moves.
// We want to update, so create if necessary
ConcurrentMap<String, AttributeComponentChange> changesForComponent =
_getAttributeChangesAfterHandlingMove(attrChanges,
renameMap,
qAttrChange.getTargetComponentLogicalScopedId(),
true);
AttributeComponentChange attrChange = (AttributeComponentChange)
qAttrChange.getComponentChange();
// update the current AttributeComponentChange for this attribute
String attrName = attrChange.getAttributeName();
changesForComponent.put(attrName, attrChange);
}
示例7: testEvictionAtHeadInsertAtTail
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
public void testEvictionAtHeadInsertAtTail()
{
ConcurrentMap<String, Object> cache = createMap();
_putThree(cache, A_STR, B_STR, C_STR);
cache.put(D_STR, FOUR);
assertOldestEvicted(cache, A_STR);
assertContains(cache, B_STR, C_STR, D_STR);
}
示例8: addRawFieldToCache
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
private static void addRawFieldToCache( Class cls, Field f )
{
ConcurrentMap<String, Field> fieldsByName = _fieldsByName.get( cls );
if( fieldsByName == null )
{
_fieldsByName.put( cls, fieldsByName = new ConcurrentHashMap<>() );
}
fieldsByName.put( f.getName(), f );
}
示例9: getReferenceCountInfoTestHook
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
@Override
protected void getReferenceCountInfoTestHook(
ConcurrentMap<Long, List<RefCountChangeInfo>> stacktraces, long address) {
List<RefCountChangeInfo> updatedList =
new ArrayList<RefCountChangeInfo>(stacktraces.get(address));
RefCountChangeInfo rcci = new RefCountChangeInfo(false, 0, "TestOwner");
updatedList.add(rcci);
stacktraces.put(address, updatedList);
}
示例10: testRemoveValueFail
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
@Test
public void testRemoveValueFail() {
ConcurrentMap<SimpleKey, SimpleValue> map = redisson.getMap("simple");
map.put(new SimpleKey("1"), new SimpleValue("2"));
boolean res = map.remove(new SimpleKey("2"), new SimpleValue("1"));
Assert.assertFalse(res);
boolean res1 = map.remove(new SimpleKey("1"), new SimpleValue("3"));
Assert.assertFalse(res1);
SimpleValue val1 = map.get(new SimpleKey("1"));
Assert.assertEquals("2", val1.getValue());
}
示例11: getIntegerCompTypes
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
public ConcurrentMap<PropTypes, ComparisonTypes> getIntegerCompTypes() {
ConcurrentMap<PropTypes, ComparisonTypes> filterMap = new ConcurrentHashMap<>();
// Event PropTypes.Event was setting by default during instantiation RegExp class
for (RgxNode _node : rgxNode.getElements()) {
if (_node.pType != PropTypes.Event
&& _node.getFilter().isActive()
&& isNumericProp(_node.pType)
) {
filterMap.put(_node.pType, _node.getFilter().getComparisonType());
}
}
return filterMap;
}
示例12: put
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
@Override
public void put(String cacheName, String key, Object value) {
ConcurrentMap<String, Object> cache = getCache(cacheName);
if (cache == null) {
cache = new ConcurrentHashMap<>();
ConcurrentMap<String, Object> oldCache = runtimeCache.putIfAbsent(cacheName, cache);
if (oldCache != null) {
cache = oldCache;
}
}
cache.put(key, value);
}
示例13: testEvictionAtHeadInsertAtHead
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
public void testEvictionAtHeadInsertAtHead()
{
ConcurrentMap<String, Object> cache = createMap();
_putThree(cache, B_STR, C_STR, D_STR);
cache.put(A_STR, ONE);
assertOldestEvicted(cache, B_STR);
assertContains(cache, A_STR, C_STR, D_STR);
}
示例14: testResourcePresentInGoodDir
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testResourcePresentInGoodDir() throws IOException {
String user = "testuser";
DrainDispatcher dispatcher = null;
try {
Configuration conf = new Configuration();
dispatcher = createDispatcher(conf);
EventHandler<LocalizerEvent> localizerEventHandler =
mock(EventHandler.class);
EventHandler<LocalizerEvent> containerEventHandler =
mock(EventHandler.class);
dispatcher.register(LocalizerEventType.class, localizerEventHandler);
dispatcher.register(ContainerEventType.class, containerEventHandler);
ContainerId cId1 = BuilderUtils.newContainerId(1, 1, 1, 1);
LocalizerContext lc1 = new LocalizerContext(user, cId1, null);
LocalResourceRequest req1 =
createLocalResourceRequest(user, 1, 1, LocalResourceVisibility.PUBLIC);
LocalResourceRequest req2 =
createLocalResourceRequest(user, 2, 1, LocalResourceVisibility.PUBLIC);
LocalizedResource lr1 = createLocalizedResource(req1, dispatcher);
LocalizedResource lr2 = createLocalizedResource(req2, dispatcher);
ConcurrentMap<LocalResourceRequest, LocalizedResource> localrsrc =
new ConcurrentHashMap<LocalResourceRequest, LocalizedResource>();
localrsrc.put(req1, lr1);
localrsrc.put(req2, lr2);
LocalDirsHandlerService dirsHandler = mock(LocalDirsHandlerService.class);
List<String> goodDirs = new ArrayList<String>();
// /tmp/somedir2 is bad
goodDirs.add("/tmp/somedir1/");
goodDirs.add("/tmp/somedir2");
Mockito.when(dirsHandler.getLocalDirs()).thenReturn(goodDirs);
Mockito.when(dirsHandler.getLocalDirsForRead()).thenReturn(goodDirs);
LocalResourcesTrackerImpl tracker =
new LocalResourcesTrackerImpl(user, null, dispatcher, localrsrc,
true , conf, new NMNullStateStoreService(), dirsHandler);
ResourceEvent req11Event =
new ResourceRequestEvent(req1, LocalResourceVisibility.PUBLIC, lc1);
ResourceEvent req21Event =
new ResourceRequestEvent(req2, LocalResourceVisibility.PUBLIC, lc1);
// Localize R1 for C1
tracker.handle(req11Event);
// Localize R2 for C1
tracker.handle(req21Event);
dispatcher.await();
// Localize resource1
Path p1 = tracker.getPathForLocalization(req1,
new Path("/tmp/somedir1"), null);
Path p2 = tracker.getPathForLocalization(req2,
new Path("/tmp/somedir2"), null);
ResourceLocalizedEvent rle1 = new ResourceLocalizedEvent(req1, p1, 1);
tracker.handle(rle1);
ResourceLocalizedEvent rle2 = new ResourceLocalizedEvent(req2, p2, 1);
tracker.handle(rle2);
dispatcher.await();
// Remove somedir2 from gooddirs
Assert.assertTrue(tracker.checkLocalResource(lr2));
goodDirs.remove(1);
Assert.assertFalse(tracker.checkLocalResource(lr2));
} finally {
if (dispatcher != null) {
dispatcher.stop();
}
}
}
示例15: testInvalidateAndReloadDuringLoading
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
public void testInvalidateAndReloadDuringLoading()
throws InterruptedException, ExecutionException {
// computation starts; clear() is called, computation finishes
final CountDownLatch computationStarted = new CountDownLatch(2);
final CountDownLatch letGetFinishSignal = new CountDownLatch(1);
final CountDownLatch getFinishedSignal = new CountDownLatch(4);
final String getKey = "get";
final String refreshKey = "refresh";
final String suffix = "Suffix";
CacheLoader<String, String> computeFunction = new CacheLoader<String, String>() {
@Override
public String load(String key) throws InterruptedException {
computationStarted.countDown();
letGetFinishSignal.await();
return key + suffix;
}
};
final LoadingCache<String, String> cache = CacheBuilder.newBuilder()
.build(computeFunction);
ConcurrentMap<String,String> map = cache.asMap();
map.put(refreshKey, refreshKey);
new Thread() {
@Override
public void run() {
cache.getUnchecked(getKey);
getFinishedSignal.countDown();
}
}.start();
new Thread() {
@Override
public void run() {
cache.refresh(refreshKey);
getFinishedSignal.countDown();
}
}.start();
computationStarted.await();
cache.invalidate(getKey);
cache.invalidate(refreshKey);
assertFalse(map.containsKey(getKey));
assertFalse(map.containsKey(refreshKey));
// start new computations
new Thread() {
@Override
public void run() {
cache.getUnchecked(getKey);
getFinishedSignal.countDown();
}
}.start();
new Thread() {
@Override
public void run() {
cache.refresh(refreshKey);
getFinishedSignal.countDown();
}
}.start();
// let computation complete
letGetFinishSignal.countDown();
getFinishedSignal.await();
checkNothingLogged();
// results should be visible
assertEquals(2, cache.size());
assertEquals(getKey + suffix, map.get(getKey));
assertEquals(refreshKey + suffix, map.get(refreshKey));
}