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


Java AtomicReferenceArray.get方法代码示例

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


在下文中一共展示了AtomicReferenceArray.get方法的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: newResponse

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected TasksResponse newResponse(TasksRequest request, AtomicReferenceArray responses) {
    List<TaskResponse> tasks = new ArrayList<>();
    List<FailedNodeException> failedNodeExceptions = new ArrayList<>();
    List<TaskOperationFailure> taskOperationFailures = new ArrayList<>();
    for (int i = 0; i < responses.length(); i++) {
        Object response = responses.get(i);
        if (response instanceof FailedNodeException) {
            failedNodeExceptions.add((FailedNodeException) response);
        } else {
            NodeTasksResponse tasksResponse = (NodeTasksResponse) response;
            if (tasksResponse.results != null) {
                tasks.addAll(tasksResponse.results);
            }
            if (tasksResponse.exceptions != null) {
                taskOperationFailures.addAll(tasksResponse.exceptions);
            }
        }
    }
    return newResponse(request, tasks, taskOperationFailures, failedNodeExceptions);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:TransportTasksAction.java

示例3: 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

示例4: 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

示例5: reclaimKey

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
/**
 * Removes an entry whose key has been garbage collected.
 */
boolean reclaimKey(ReferenceEntry<K, V> entry, int hash) {
  lock();
  try {
    int newCount = 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(),
                RemovalCause.COLLECTED);
        newCount = this.count - 1;
        table.set(index, newFirst);
        this.count = newCount; // write-volatile
        return true;
      }
    }

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

示例6: newResponse

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
@Override
protected NodesInfoResponse newResponse(NodesInfoRequest nodesInfoRequest, AtomicReferenceArray responses) {
    final List<NodeInfo> nodesInfos = new ArrayList<>();
    for (int i = 0; i < responses.length(); i++) {
        Object resp = responses.get(i);
        if (resp instanceof NodeInfo) {
            nodesInfos.add((NodeInfo) resp);
        }
    }
    return new NodesInfoResponse(clusterName, nodesInfos.toArray(new NodeInfo[nodesInfos.size()]));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:TransportNodesInfoAction.java

示例7: reclaimValue

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
/**
 * Removes an entry whose value has been garbage collected.
 */
boolean reclaimValue(K key, int hash, ValueReference<K, V> valueReference) {
  lock();
  try {
    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()) {
      K entryKey = e.getKey();
      if (e.getHash() == hash && entryKey != null
          && map.keyEquivalence.equivalent(key, entryKey)) {
        ValueReference<K, V> v = e.getValueReference();
        if (v == valueReference) {
          ++modCount;
          enqueueNotification(key, hash, valueReference.get(), RemovalCause.COLLECTED);
          ReferenceEntry<K, V> newFirst = removeFromChain(first, e);
          newCount = this.count - 1;
          table.set(index, newFirst);
          this.count = newCount; // write-volatile
          return true;
        }
        return false;
      }
    }

    return false;
  } finally {
    unlock();
    if (!isHeldByCurrentThread()) { // don't cleanup inside of put
      postWriteCleanup();
    }
  }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:38,代码来源:MapMakerInternalMap.java

示例8: containsValue

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
@Override
public boolean containsValue(@Nullable Object value) {
  if (value == null) {
    return false;
  }

  // This implementation is patterned after ConcurrentHashMap, but without the locking. The only
  // way for it to return a false negative would be for the target value to jump around in the map
  // such that none of the subsequent iterations observed it, despite the fact that at every point
  // in time it was present somewhere int the map. This becomes increasingly unlikely as
  // CONTAINS_VALUE_RETRIES increases, though without locking it is theoretically possible.
  final Segment<K, V, E, S>[] segments = this.segments;
  long last = -1L;
  for (int i = 0; i < CONTAINS_VALUE_RETRIES; i++) {
    long sum = 0L;
    for (Segment<K, V, E, S> segment : segments) {
      // ensure visibility of most recent completed write
      int unused = segment.count; // read-volatile

      AtomicReferenceArray<E> table = segment.table;
      for (int j = 0; j < table.length(); j++) {
        for (E e = table.get(j); e != null; e = e.getNext()) {
          V v = segment.getLiveValue(e);
          if (v != null && valueEquivalence().equivalent(value, v)) {
            return true;
          }
        }
      }
      sum += segment.modCount;
    }
    if (sum == last) {
      break;
    }
    last = sum;
  }
  return false;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:38,代码来源:MapMakerInternalMap.java

示例9: 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:zugzug90,项目名称:guava-mock,代码行数:41,代码来源:MapMakerInternalMap.java

示例10: 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:paul-hammant,项目名称:googles-monorepo-demo,代码行数:30,代码来源:LocalCache.java

示例11: clearValueForTesting

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
/** Clears a value that has not yet been set, and thus does not require count to be modified. */
@CanIgnoreReturnValue
boolean clearValueForTesting(
    K key,
    int hash,
    WeakValueReference<K, V, ? extends InternalEntry<K, V, ?>> valueReference) {
  lock();
  try {
    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)) {
        WeakValueReference<K, V, E> v = ((WeakValueEntry<K, V, E>) e).getValueReference();
        if (v == valueReference) {
          E newFirst = removeFromChain(first, e);
          table.set(index, newFirst);
          return true;
        }
        return false;
      }
    }

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

示例12: lvElement

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
private static final <E> Object lvElement(AtomicReferenceArray<Object> buffer, int offset) {
    return buffer.get(offset);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:4,代码来源:SpscLinkedArrayQueue.java

示例13: replace

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

    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()) {
      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.
        ValueReference<K, V> valueReference = e.getValueReference();
        V entryValue = valueReference.get();
        if (entryValue == null) {
          if (isCollected(valueReference)) {
            int newCount = this.count - 1;
            ++modCount;
            enqueueNotification(entryKey, hash, entryValue, RemovalCause.COLLECTED);
            ReferenceEntry<K, V> newFirst = removeFromChain(first, e);
            newCount = this.count - 1;
            table.set(index, newFirst);
            this.count = newCount; // write-volatile
          }
          return null;
        }

        ++modCount;
        enqueueNotification(key, hash, entryValue, RemovalCause.REPLACED);
        setValue(e, newValue);
        return entryValue;
      }
    }

    return null;
  } finally {
    unlock();
    postWriteCleanup();
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:44,代码来源: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,项目名称:s-store,代码行数:68,代码来源:MapMakerInternalMap.java

示例15: remove

import java.util.concurrent.atomic.AtomicReferenceArray; //导入方法依赖的package包/类
@Nullable
V remove(Object key, int hash) {
  lock();
  try {
    long now = map.ticker.read();
    preWriteCleanup(now);

    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()) {
      K entryKey = e.getKey();
      if (e.getHash() == hash
          && entryKey != null
          && map.keyEquivalence.equivalent(key, entryKey)) {
        ValueReference<K, V> valueReference = e.getValueReference();
        V entryValue = valueReference.get();

        RemovalCause cause;
        if (entryValue != null) {
          cause = RemovalCause.EXPLICIT;
        } else if (valueReference.isActive()) {
          cause = RemovalCause.COLLECTED;
        } else {
          // currently loading
          return null;
        }

        ++modCount;
        ReferenceEntry<K, V> newFirst =
            removeValueFromChain(first, e, entryKey, hash, entryValue, valueReference, cause);
        newCount = this.count - 1;
        table.set(index, newFirst);
        this.count = newCount; // write-volatile
        return entryValue;
      }
    }

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


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