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


Java AtomicReferenceArray类代码示例

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


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

示例1: offer

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
public boolean offer(E e) {
    if (e == null) {
        throw new NullPointerException("Null is not a valid element");
    }
    AtomicReferenceArray<E> buffer = this.buffer;
    int mask = this.mask;
    long index = this.producerIndex.get();
    int offset = calcElementOffset(index, mask);
    if (index >= this.producerLookAhead) {
        int step = this.lookAheadStep;
        if (lvElement(buffer, calcElementOffset(((long) step) + index, mask)) == null) {
            this.producerLookAhead = ((long) step) + index;
        } else if (lvElement(buffer, offset) != null) {
            return false;
        }
    }
    soProducerIndex(1 + index);
    soElement(buffer, offset, e);
    return true;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:SpscAtomicArrayQueue.java

示例2: removeEntry

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
@GuardedBy("Segment.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;
      enqueueNotification(e.getKey(), hash, e.getValueReference().get(), cause);
      ReferenceEntry<K, V> newFirst = removeFromChain(first, e);
      newCount = this.count - 1;
      table.set(index, newFirst);
      this.count = newCount; // write-volatile
      return true;
    }
  }

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

示例3: newResponse

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
@Override
protected NodesGatewayMetaState newResponse(Request request, AtomicReferenceArray responses) {
    final List<NodeGatewayMetaState> 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 NodeGatewayMetaState) { // will also filter out null response for unallocated ones
            nodesList.add((NodeGatewayMetaState) resp);
        } else if (resp instanceof FailedNodeException) {
            failures.add((FailedNodeException) resp);
        } else {
            logger.warn("unknown response type [{}], expected NodeLocalGatewayMetaState or FailedNodeException", resp);
        }
    }
    return new NodesGatewayMetaState(clusterName, nodesList.toArray(new NodeGatewayMetaState[nodesList.size()]),
            failures.toArray(new FailedNodeException[failures.size()]));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:TransportNodesListGatewayMetaState.java

示例4: start

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
public void start() {
    if (shardsIts.size() == 0) {
        // no shards
        try {
            listener.onResponse(newResponse(request, new AtomicReferenceArray(0), clusterState));
        } catch (Exception e) {
            listener.onFailure(e);
        }
        return;
    }
    // count the local operations, and perform the non local ones
    int shardIndex = -1;
    for (final ShardIterator shardIt : shardsIts) {
        shardIndex++;
        final ShardRouting shard = shardIt.nextOrNull();
        if (shard != null) {
            performOperation(shardIt, shard, shardIndex);
        } else {
            // really, no shards active in this group
            onOperation(null, shardIt, shardIndex, new NoShardAvailableActionException(shardIt.shardId()));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TransportBroadcastAction.java

示例5: 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:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:TransportTasksAction.java

示例6: arrayFrom

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
private ArrayList arrayFrom(AtomicReferenceArray atomicArray) {

        // cache atomic array length in variable
        int len = atomicArray.length();

        // create new arraylist
        ArrayList newList = new ArrayList<>(atomicArray.length());

        // iterate over atomic array and copy to arraylist
        for (int i = 0; i < len; i++) {
            newList.add(atomicArray.get(i));
        }

        // return new arraylist
        return newList;
    }
 
开发者ID:nascentdigital,项目名称:standby,代码行数:17,代码来源:AllPromise.java

示例7: arrayFrom

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
private ArrayList<TElement> arrayFrom(AtomicReferenceArray<TElement> atomicArray) {

        // cache atomic array length in variable
        int len = atomicArray.length();

        // create new arraylist
        ArrayList<TElement> newList = new ArrayList<>(atomicArray.length());

        // iterate over atomic array and copy to arraylist
        for (int i = 0; i < len; i++) {
            newList.add(atomicArray.get(i));
        }

        // return new arraylist
        return newList;
    }
 
开发者ID:nascentdigital,项目名称:standby,代码行数:17,代码来源:CollectionWhenPromise.java

示例8: offer

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
public final boolean offer(T e) {
    if (e == null) {
        throw new NullPointerException();
    }
    AtomicReferenceArray<Object> buffer = this.producerBuffer;
    long index = lpProducerIndex();
    int mask = this.producerMask;
    int offset = calcWrappedOffset(index, mask);
    if (index < this.producerLookAhead) {
        return writeToQueue(buffer, e, index, offset);
    }
    int lookAheadStep = this.producerLookAheadStep;
    if (lvElement(buffer, calcWrappedOffset(((long) lookAheadStep) + index, mask)) == null) {
        this.producerLookAhead = (((long) lookAheadStep) + index) - 1;
        return writeToQueue(buffer, e, index, offset);
    } else if (lvElement(buffer, calcWrappedOffset(1 + index, mask)) != null) {
        return writeToQueue(buffer, e, index, offset);
    } else {
        resize(buffer, index, offset, e, (long) mask);
        return true;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:SpscUnboundedAtomicArrayQueue.java

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

示例10: removeEntryForTesting

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
@GuardedBy("this")
boolean removeEntryForTesting(E entry) {
  int hash = entry.getHash();
  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()) {
    if (e == entry) {
      ++modCount;
      E newFirst = removeFromChain(first, e);
      newCount = this.count - 1;
      table.set(index, newFirst);
      this.count = newCount; // write-volatile
      return true;
    }
  }

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

示例11: clear

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
void clear() {
  if (count != 0) {
    lock();
    try {
      AtomicReferenceArray<E> table = this.table;
      for (int i = 0; i < table.length(); ++i) {
        table.set(i, null);
      }
      maybeClearReferenceQueues();
      readCount.set(0);

      ++modCount;
      count = 0; // write-volatile
    } finally {
      unlock();
    }
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:MapMakerInternalMap.java

示例12: testIndexing

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
/**
 * get and set for out of bound indices throw IndexOutOfBoundsException
 */
public void testIndexing() {
    AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<>(SIZE);
    for (int index : new int[] { -1, SIZE }) {
        final int j = index;
        final Runnable[] tasks = {
            () -> aa.getPlain(j),
            () -> aa.getOpaque(j),
            () -> aa.getAcquire(j),
            () -> aa.setPlain(j, null),
            () -> aa.setOpaque(j, null),
            () -> aa.setRelease(j, null),
            () -> aa.compareAndExchange(j, null, null),
            () -> aa.compareAndExchangeAcquire(j, null, null),
            () -> aa.compareAndExchangeRelease(j, null, null),
            () -> aa.weakCompareAndSetPlain(j, null, null),
            () -> aa.weakCompareAndSetVolatile(j, null, null),
            () -> aa.weakCompareAndSetAcquire(j, null, null),
            () -> aa.weakCompareAndSetRelease(j, null, null),
        };

        assertThrows(IndexOutOfBoundsException.class, tasks);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:AtomicReferenceArray9Test.java

示例13: newResponse

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
@Override
protected NodesGatewayStartedShards newResponse(Request request, AtomicReferenceArray responses) {
    final List<NodeGatewayStartedShards> 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 NodeGatewayStartedShards) { // will also filter out null response for unallocated ones
            nodesList.add((NodeGatewayStartedShards) resp);
        } else if (resp instanceof FailedNodeException) {
            failures.add((FailedNodeException) resp);
        } else {
            logger.warn("unknown response type [{}], expected NodeLocalGatewayStartedShards or FailedNodeException", resp);
        }
    }
    return new NodesGatewayStartedShards(clusterName, nodesList.toArray(new NodeGatewayStartedShards[nodesList.size()]),
            failures.toArray(new FailedNodeException[failures.size()]));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:TransportNodesListGatewayStartedShards.java

示例14: reclaimKey

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
/** Removes an entry whose key has been garbage collected. */
@CanIgnoreReturnValue
boolean reclaimKey(E entry, int hash) {
  lock();
  try {
    int newCount = 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()) {
      if (e == entry) {
        ++modCount;
        E newFirst = removeFromChain(first, e);
        newCount = this.count - 1;
        table.set(index, newFirst);
        this.count = newCount; // write-volatile
        return true;
      }
    }

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

示例15: testRemoveEntry

import java.util.concurrent.atomic.AtomicReferenceArray; //导入依赖的package包/类
public void testRemoveEntry() {
  MapMakerInternalMap<Object, Object, ?, ?> map =
      makeMap(createMapMaker().concurrencyLevel(1).initialCapacity(1));
  Segment<Object, Object, ?, ?> segment = map.segments[0];
  AtomicReferenceArray<? extends InternalEntry<Object, Object, ?>> table = segment.table;
  assertEquals(1, table.length());

  Object key = new Object();
  Object value = new Object();
  int hash = map.hash(key);
  InternalEntry<Object, Object, ?> entry = segment.newEntryForTesting(key, hash, null);
  segment.setValueForTesting(entry, value);

  // remove absent
  assertFalse(segment.removeTableEntryForTesting(entry));

  segment.setTableEntryForTesting(0, entry);
  segment.count = 1;
  assertTrue(segment.removeTableEntryForTesting(entry));
  assertEquals(0, segment.count);
  assertNull(table.get(0));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:23,代码来源:MapMakerInternalMapTest.java


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