当前位置: 首页>>代码示例>>Java>>正文


Java AtomicReferenceArray.length方法代码示例

本文整理汇总了Java中java.util.concurrent.atomic.AtomicReferenceArray.length方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicReferenceArray.length方法的具体用法?Java AtomicReferenceArray.length怎么用?Java AtomicReferenceArray.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.atomic.AtomicReferenceArray的用法示例。


在下文中一共展示了AtomicReferenceArray.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newResponse

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
@Override
protected NodesStoreFilesMetaData newResponse(Request request, AtomicReferenceArray responses) {
    final List<NodeStoreFilesMetaData> nodeStoreFilesMetaDatas = new ArrayList<>();
    final List<FailedNodeException> failures = new ArrayList<>();
    for (int i = 0; i < responses.length(); i++) {
        Object resp = responses.get(i);
        if (resp instanceof NodeStoreFilesMetaData) { // will also filter out null response for unallocated ones
            nodeStoreFilesMetaDatas.add((NodeStoreFilesMetaData) resp);
        } else if (resp instanceof FailedNodeException) {
            failures.add((FailedNodeException) resp);
        } else {
            logger.warn("unknown response type [{}], expected NodeStoreFilesMetaData or FailedNodeException", resp);
        }
    }
    return new NodesStoreFilesMetaData(clusterName, nodeStoreFilesMetaDatas.toArray(new NodeStoreFilesMetaData[nodeStoreFilesMetaDatas.size()]),
            failures.toArray(new FailedNodeException[failures.size()]));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:TransportNodesListShardStoreMetaData.java

示例2: containsValue

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
/**
 * This method is a convenience for testing. Code should call {@link
 * MapMakerInternalMap#containsValue} directly.
 */
@VisibleForTesting
boolean containsValue(Object value) {
  try {
    if (count != 0) { // read-volatile
      AtomicReferenceArray<ReferenceEntry<K, V>> table = this.table;
      int length = table.length();
      for (int i = 0; i < length; ++i) {
        for (ReferenceEntry<K, V> e = table.get(i); e != null; e = e.getNext()) {
          V entryValue = getLiveValue(e);
          if (entryValue == null) {
            continue;
          }
          if (map.valueEquivalence.equivalent(value, entryValue)) {
            return true;
          }
        }
      }
    }

    return false;
  } finally {
    postReadCleanup();
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:29,代码来源:MapMakerInternalMap.java

示例3: testSegmentRefresh_duplicate

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
public void testSegmentRefresh_duplicate() throws ExecutionException {
  LocalCache<Object, Object> map = makeLocalCache(createCacheBuilder()
      .concurrencyLevel(1));
  Segment<Object, Object> segment = map.segments[0];

  Object key = new Object();
  int hash = map.hash(key);
  AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
  int index = hash & (table.length() - 1);

  // already loading
  DummyEntry<Object, Object> entry = DummyEntry.create(key, hash, null);
  DummyValueReference<Object, Object> valueRef = DummyValueReference.create(null);
  valueRef.setLoading(true);
  entry.setValueReference(valueRef);
  table.set(index, entry);
  assertNull(segment.refresh(key, hash, identityLoader(), false));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:LocalCacheTest.java

示例4: containsValue

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
/**
 * This method is a convenience for testing. Code should call {@link
 * MapMakerInternalMap#containsValue} directly.
 */
@VisibleForTesting
boolean containsValue(Object value) {
  try {
    if (count != 0) { // read-volatile
      AtomicReferenceArray<E> table = this.table;
      int length = table.length();
      for (int i = 0; i < length; ++i) {
        for (E e = table.get(i); e != null; e = e.getNext()) {
          V entryValue = getLiveValue(e);
          if (entryValue == null) {
            continue;
          }
          if (map.valueEquivalence().equivalent(value, entryValue)) {
            return true;
          }
        }
      }
    }

    return false;
  } finally {
    postReadCleanup();
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:29,代码来源:MapMakerInternalMap.java

示例5: newResponse

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
@Override
protected NodesSnapshotStatus newResponse(Request request, AtomicReferenceArray responses) {
    final List<NodeSnapshotStatus> nodesList = new ArrayList<>();
    final List<FailedNodeException> failures = new ArrayList<>();
    for (int i = 0; i < responses.length(); i++) {
        Object resp = responses.get(i);
        if (resp instanceof NodeSnapshotStatus) { // will also filter out null response for unallocated ones
            nodesList.add((NodeSnapshotStatus) resp);
        } else if (resp instanceof FailedNodeException) {
            failures.add((FailedNodeException) resp);
        } else {
            logger.warn("unknown response type [{}], expected NodeSnapshotStatus or FailedNodeException", resp);
        }
    }
    return new NodesSnapshotStatus(clusterName, nodesList.toArray(new NodeSnapshotStatus[nodesList.size()]),
            failures.toArray(new FailedNodeException[failures.size()]));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:TransportNodesSnapshotsStatus.java

示例6: newResponse

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
/**
 * Map the responses into {@code nodeResponseClass} responses and {@link FailedNodeException}s.
 *
 * @param request The associated request.
 * @param nodesResponses All node-level responses
 * @return Never {@code null}.
 * @throws NullPointerException if {@code nodesResponses} is {@code null}
 * @see #newResponse(BaseNodesRequest, List, List)
 */
protected NodesResponse newResponse(NodesRequest request, AtomicReferenceArray nodesResponses) {
    final List<NodeResponse> responses = new ArrayList<>();
    final List<FailedNodeException> failures = new ArrayList<>();

    final boolean accumulateExceptions = accumulateExceptions();
    for (int i = 0; i < nodesResponses.length(); ++i) {
        Object response = nodesResponses.get(i);

        if (response instanceof FailedNodeException) {
            if (accumulateExceptions) {
                failures.add((FailedNodeException)response);
            } else {
                logger.warn("not accumulating exceptions, excluding exception from response", (FailedNodeException)response);
            }
        } else {
            responses.add(nodeResponseClass.cast(response));
        }
    }

    return newResponse(request, responses, failures);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:TransportNodesAction.java

示例7: testEvictEntries

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
public void testEvictEntries() {
  int maxSize = 10;
  LocalCache<Object, Object> map =
      makeLocalCache(createCacheBuilder().concurrencyLevel(1).maximumSize(maxSize));
  Segment<Object, Object> segment = map.segments[0];

  // manually add elements to avoid eviction
  int originalCount = 1024;
  ReferenceEntry<Object, Object> entry = null;
  LinkedHashMap<Object, Object> originalMap = Maps.newLinkedHashMap();
  for (int i = 0; i < originalCount; i++) {
    Object key = new Object();
    Object value = new Object();
    AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
    int hash = map.hash(key);
    int index = hash & (table.length() - 1);
    ReferenceEntry<Object, Object> first = table.get(index);
    entry = map.newEntry(key, hash, first);
    ValueReference<Object, Object> valueRef = map.newValueReference(entry, value, 1);
    entry.setValueReference(valueRef);
    segment.recordWrite(entry, 1, map.ticker.read());
    table.set(index, entry);
    originalMap.put(key, value);
  }
  segment.count = originalCount;
  segment.totalWeight = originalCount;
  assertEquals(originalCount, map.size());
  assertEquals(originalMap, map);

  Iterator<Object> it = originalMap.keySet().iterator();
  for (int i = 0; i < originalCount - maxSize; i++) {
    it.next();
    it.remove();
  }
  segment.evictEntries(entry);
  assertEquals(maxSize, map.size());
  assertEquals(originalMap, map);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:39,代码来源:LocalCacheTest.java

示例8: newResponse

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
@Override
protected ExistsResponse newResponse(ExistsRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
    int successfulShards = 0;
    int failedShards = 0;
    boolean exists = false;
    List<ShardOperationFailedException> shardFailures = null;

    // if docs do exist, the last response will have exists = true (since we early terminate the shard requests)
    for (int i = shardsResponses.length() - 1; i >= 0 ; i--) {
        Object shardResponse = shardsResponses.get(i);
        if (shardResponse == null) {
            // simply ignore non active shards
        } else if (shardResponse instanceof BroadcastShardOperationFailedException) {
            failedShards++;
            if (shardFailures == null) {
                shardFailures = new ArrayList<>();
            }
            shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
        } else {
            successfulShards++;
            if ((exists = ((ShardExistsResponse) shardResponse).exists())) {
                successfulShards = shardsResponses.length() - failedShards;
                break;
            }
        }
    }
    return new ExistsResponse(exists, shardsResponses.length(), successfulShards, failedShards, shardFailures);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:29,代码来源:TransportExistsAction.java

示例9: removeEntry

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
@VisibleForTesting
@GuardedBy("this")
boolean removeEntry(ReferenceEntry<K, V> entry, int hash, RemovalCause cause) {
  int newCount = this.count - 1;
  AtomicReferenceArray<ReferenceEntry<K, V>> table = this.table;
  int index = hash & (table.length() - 1);
  ReferenceEntry<K, V> first = table.get(index);

  for (ReferenceEntry<K, V> e = first; e != null; e = e.getNext()) {
    if (e == entry) {
      ++modCount;
      ReferenceEntry<K, V> newFirst =
          removeValueFromChain(
              first,
              e,
              e.getKey(),
              hash,
              e.getValueReference().get(),
              e.getValueReference(),
              cause);
      newCount = this.count - 1;
      table.set(index, newFirst);
      this.count = newCount; // write-volatile
      return true;
    }
  }

  return false;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:30,代码来源:LocalCache.java

示例10: replace

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
V replace(K key, int hash, V newValue) {
  lock();
  try {
    preWriteCleanup();

    AtomicReferenceArray<E> table = this.table;
    int index = hash & (table.length() - 1);
    E first = table.get(index);

    for (E e = first; e != null; e = e.getNext()) {
      K entryKey = e.getKey();
      if (e.getHash() == hash
          && entryKey != null
          && map.keyEquivalence.equivalent(key, entryKey)) {
        // If the value disappeared, this entry is partially collected,
        // and we should pretend like it doesn't exist.
        V entryValue = e.getValue();
        if (entryValue == null) {
          if (isCollected(e)) {
            int newCount = this.count - 1;
            ++modCount;
            E newFirst = removeFromChain(first, e);
            newCount = this.count - 1;
            table.set(index, newFirst);
            this.count = newCount; // write-volatile
          }
          return null;
        }

        ++modCount;
        setValue(e, newValue);
        return entryValue;
      }
    }

    return null;
  } finally {
    unlock();
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:41,代码来源:MapMakerInternalMap.java

示例11: clear

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
void clear() {
  if (count != 0) { // read-volatile
    lock();
    try {
      long now = map.ticker.read();
      preWriteCleanup(now);

      AtomicReferenceArray<ReferenceEntry<K, V>> table = this.table;
      for (int i = 0; i < table.length(); ++i) {
        for (ReferenceEntry<K, V> e = table.get(i); e != null; e = e.getNext()) {
          // Loading references aren't actually in the map yet.
          if (e.getValueReference().isActive()) {
            K key = e.getKey();
            V value = e.getValueReference().get();
            RemovalCause cause =
                (key == null || value == null) ? RemovalCause.COLLECTED : RemovalCause.EXPLICIT;
            enqueueNotification(
                key, e.getHash(), value, e.getValueReference().getWeight(), cause);
          }
        }
      }
      for (int i = 0; i < table.length(); ++i) {
        table.set(i, null);
      }
      clearReferenceQueues();
      writeQueue.clear();
      accessQueue.clear();
      readCount.set(0);

      ++modCount;
      count = 0; // write-volatile
    } finally {
      unlock();
      postWriteCleanup();
    }
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:38,代码来源:LocalCache.java

示例12: testComputePartiallyCollectedValue

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
public void testComputePartiallyCollectedValue() throws ExecutionException {
  CacheBuilder<Object, Object> builder = createCacheBuilder().concurrencyLevel(1);
  CountingLoader loader = new CountingLoader();
  LocalCache<Object, Object> map = makeLocalCache(builder);
  Segment<Object, Object> segment = map.segments[0];
  AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
  assertEquals(0, loader.getCount());

  Object key = new Object();
  int hash = map.hash(key);
  Object value = new Object();
  int index = hash & (table.length() - 1);

  DummyEntry<Object, Object> entry = DummyEntry.create(key, hash, null);
  DummyValueReference<Object, Object> valueRef = DummyValueReference.create(value);
  entry.setValueReference(valueRef);
  table.set(index, entry);
  segment.count++;

  assertSame(value, map.get(key, loader));
  assertEquals(0, loader.getCount());
  assertEquals(1, segment.count);

  valueRef.clear();
  assertNotSame(value, map.get(key, loader));
  assertEquals(1, loader.getCount());
  assertEquals(1, segment.count);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:29,代码来源:LocalCacheTest.java

示例13: remove

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
boolean remove(Object key, int hash, Object value) {
  lock();
  try {
    preWriteCleanup();

    int newCount = this.count - 1;
    AtomicReferenceArray<E> table = this.table;
    int index = hash & (table.length() - 1);
    E first = table.get(index);

    for (E e = first; e != null; e = e.getNext()) {
      K entryKey = e.getKey();
      if (e.getHash() == hash
          && entryKey != null
          && map.keyEquivalence.equivalent(key, entryKey)) {
        V entryValue = e.getValue();

        boolean explicitRemoval = false;
        if (map.valueEquivalence().equivalent(value, entryValue)) {
          explicitRemoval = true;
        } else if (isCollected(e)) {
          // TODO(kak): Remove this branch
        } else {
          return false;
        }

        ++modCount;
        E newFirst = removeFromChain(first, e);
        newCount = this.count - 1;
        table.set(index, newFirst);
        this.count = newCount; // write-volatile
        return explicitRemoval;
      }
    }

    return false;
  } finally {
    unlock();
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:41,代码来源:MapMakerInternalMap.java

示例14: put

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
V put(K key, int hash, V value, boolean onlyIfAbsent) {
  lock();
  try {
    preWriteCleanup();

    int newCount = this.count + 1;
    if (newCount > this.threshold) { // ensure capacity
      expand();
      newCount = this.count + 1;
    }

    AtomicReferenceArray<ReferenceEntry<K, V>> table = this.table;
    int index = hash & (table.length() - 1);
    ReferenceEntry<K, V> first = table.get(index);

    // Look for an existing entry.
    for (ReferenceEntry<K, V> e = first; e != null; e = e.getNext()) {
      K entryKey = e.getKey();
      if (e.getHash() == hash && entryKey != null
          && map.keyEquivalence.equivalent(key, entryKey)) {
        // We found an existing entry.

        ValueReference<K, V> valueReference = e.getValueReference();
        V entryValue = valueReference.get();

        if (entryValue == null) {
          ++modCount;
          setValue(e, value);
          if (!valueReference.isComputingReference()) {
            enqueueNotification(key, hash, entryValue, RemovalCause.COLLECTED);
            newCount = this.count; // count remains unchanged
          } else if (evictEntries()) { // evictEntries after setting new value
            newCount = this.count + 1;
          }
          this.count = newCount; // write-volatile
          return null;
        } else if (onlyIfAbsent) {
          // Mimic
          // "if (!map.containsKey(key)) ...
          // else return map.get(key);
          recordLockedRead(e);
          return entryValue;
        } else {
          // clobber existing entry, count remains unchanged
          ++modCount;
          enqueueNotification(key, hash, entryValue, RemovalCause.REPLACED);
          setValue(e, value);
          return entryValue;
        }
      }
    }

    // Create a new entry.
    ++modCount;
    ReferenceEntry<K, V> newEntry = newEntry(key, hash, first);
    setValue(newEntry, value);
    table.set(index, newEntry);
    if (evictEntries()) { // evictEntries after setting new value
      newCount = this.count + 1;
    }
    this.count = newCount; // write-volatile
    return null;
  } finally {
    unlock();
    postWriteCleanup();
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:68,代码来源:MapMakerInternalMap.java

示例15: replace

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
boolean replace(K key, int hash, V oldValue, V newValue) {
  lock();
  try {
    preWriteCleanup();

    AtomicReferenceArray<E> table = this.table;
    int index = hash & (table.length() - 1);
    E first = table.get(index);

    for (E e = first; e != null; e = e.getNext()) {
      K entryKey = e.getKey();
      if (e.getHash() == hash
          && entryKey != null
          && map.keyEquivalence.equivalent(key, entryKey)) {
        // If the value disappeared, this entry is partially collected,
        // and we should pretend like it doesn't exist.
        V entryValue = e.getValue();
        if (entryValue == null) {
          if (isCollected(e)) {
            int newCount = this.count - 1;
            ++modCount;
            E newFirst = removeFromChain(first, e);
            newCount = this.count - 1;
            table.set(index, newFirst);
            this.count = newCount; // write-volatile
          }
          return false;
        }

        if (map.valueEquivalence().equivalent(oldValue, entryValue)) {
          ++modCount;
          setValue(e, newValue);
          return true;
        } else {
          // Mimic
          // "if (map.containsKey(key) && map.get(key).equals(oldValue))..."
          return false;
        }
      }
    }

    return false;
  } finally {
    unlock();
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:47,代码来源:MapMakerInternalMap.java


注:本文中的java.util.concurrent.atomic.AtomicReferenceArray.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。