當前位置: 首頁>>代碼示例>>Java>>正文


Java ConcurrentMap.put方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:24,代碼來源:MapDbAppStorage.java

示例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);

}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:23,代碼來源:RedissonConcurrentMapTest.java

示例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);
}
 
開發者ID:ShawnShoper,項目名稱:x-job,代碼行數:22,代碼來源:ZKPool.java

示例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;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:22,代碼來源:FileSystemStyleCache.java

示例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;
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:27,代碼來源:TopologyBuilder.java

示例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);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:22,代碼來源:SessionChangeManager.java

示例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);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:11,代碼來源:LRUCopyOnWriteArrayMapTest.java

示例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 );
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:10,代碼來源:ReflectUtil.java

示例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);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:10,代碼來源:ReferenceCountHelperImplTest.java

示例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());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:15,代碼來源:RedissonMapTest.java

示例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;
    }
 
開發者ID:ripreal,項目名稱:V8LogScanner,代碼行數:16,代碼來源:RegExp.java

示例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);
}
 
開發者ID:BriData,項目名稱:DBus,代碼行數:13,代碼來源:MemLocalCache.java

示例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);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:11,代碼來源:LRUCopyOnWriteArrayMapTest.java

示例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();
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:67,代碼來源:TestLocalResourcesTrackerImpl.java

示例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));
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:72,代碼來源:CacheLoadingTest.java


注:本文中的java.util.concurrent.ConcurrentMap.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。