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


Java AtomicInteger.addAndGet方法代碼示例

本文整理匯總了Java中java.util.concurrent.atomic.AtomicInteger.addAndGet方法的典型用法代碼示例。如果您正苦於以下問題:Java AtomicInteger.addAndGet方法的具體用法?Java AtomicInteger.addAndGet怎麽用?Java AtomicInteger.addAndGet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.atomic.AtomicInteger的用法示例。


在下文中一共展示了AtomicInteger.addAndGet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: highestStampForDir

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
private static boolean highestStampForDir(File file, AtomicReference<File> newestFile, AtomicLong result, AtomicInteger crc) {
    if (file.getName().equals(".nbattrs")) { // NOI18N
        return true;
    }

    File[] children = file.listFiles();
    if (children == null) {
        if (crc != null) {
            crc.addAndGet(file.getName().length());
        }
        long time = file.lastModified();
        if (time > result.longValue()) {
            newestFile.set(file);
            result.set(time);
        }
        return false;
    }
    
    for (File f : children) {
        highestStampForDir(f, newestFile, result, crc);
    }
    return true;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:Stamps.java

示例2: checkPath

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
private void checkPath(String path, MetricMinMaxChecker metricMinMaxChecker, AtomicInteger hiddenCounter) throws IOException {
    AppendableList appendableList = new AppendableList();
    metricSearch.search(path, appendableList);

    for (MetricDescription metric : appendableList.getSortedList()) {
        if (metric.isDir()) {
            checkPath(metric.getName() + MetricTree.ALL_PATTERN, metricMinMaxChecker, hiddenCounter);
        } else {
            metricMinMaxChecker.addToCheck(metric.getName());
        }
    }

    if (path.equals(MetricTree.ALL_PATTERN) || metricMinMaxChecker.needCheckInDb()) {
        final int hiddenMetricCount = hideMetricsBetween(metricMinMaxChecker.minMetric, metricMinMaxChecker.maxMetric);
        hiddenCounter.addAndGet(hiddenMetricCount);
        metricMinMaxChecker.reset();
    }
}
 
開發者ID:yandex,項目名稱:graphouse,代碼行數:19,代碼來源:AutoHideService.java

示例3: readObject

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
/**
 * Reads a DER object from the stream.
 * 
 * @param limit The maximum allowable object length.
 * @param bytesRead Will be updated with the number of bytes read from the stream.
 * @return A DER object read from the stream.
 */
public DerObject readObject(int limit, AtomicInteger bytesRead)
    throws IOException, DerEncodingException {

  AtomicInteger innerBytesRead = new AtomicInteger(0);
  DerObject obj = new DerObject();
  obj.setTag(readTag(innerBytesRead));
  obj.setLength(readLength(innerBytesRead));
  if (innerBytesRead.get() + obj.getLength() > limit) {
    throw new DerEncodingException(
        "Object length [" + obj.getLength() + "] is larger than allowed.");
  }
  bytesRead.addAndGet(innerBytesRead.get());

  if (obj.getLength() > 0) {
    obj.setValue(readValue(obj.getLength(), bytesRead));
  } else {
    obj.setValue(new byte[] {});
  }
  return obj;
}
 
開發者ID:hyperledger,項目名稱:quilt,代碼行數:28,代碼來源:DerInputStream.java

示例4: sliceException

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
@Override
public JSFExceptionData sliceException() {
    JSFExceptionData exceptionData = new JSFExceptionData(interfaceId, methodName, host, port);
    exceptionData.setCollectTime(System.currentTimeMillis());
    for (Map.Entry<String, AtomicInteger> entry : exceptionStats.entrySet()) {
        try {
            String key = entry.getKey();
            AtomicInteger aNum = entry.getValue();
            if (aNum != null) {
                Integer num = aNum.get();
                if (num > 0) {
                    ExceptionDetail detail = new ExceptionDetail(key, num);
                    exceptionData.addDetail(detail);
                }
                aNum.addAndGet(-1 * num);
            }
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    int times = exceptionTimes.get();
    exceptionData.setTimes(times); // 設置錯誤總次數
    exceptionTimes.addAndGet(-times); // 減去已經獲取
    return exceptionData;
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:26,代碼來源:ProviderMetricMonitor.java

示例5: deleteTicket

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
@Override
public int deleteTicket(final String ticketId) {
    final AtomicInteger count = new AtomicInteger(0);

    if (StringUtils.isBlank(ticketId)) {
        return count.intValue();
    }

    final Ticket ticket = getTicket(ticketId);
    if (ticket == null) {
        return count.intValue();
    }

    if (ticket instanceof TicketGrantingTicket) {
        if (ticket instanceof ProxyGrantingTicket) {
            LOGGER.debug("Removing proxy-granting ticket [{}]", ticketId);
        }

        LOGGER.debug("Removing children of ticket [{}] from the registry.", ticket.getId());
        final TicketGrantingTicket tgt = (TicketGrantingTicket) ticket;
        count.addAndGet(deleteChildren(tgt));

        final Collection<ProxyGrantingTicket> proxyGrantingTickets = tgt.getProxyGrantingTickets();
        proxyGrantingTickets.stream().map(Ticket::getId).forEach(t -> count.addAndGet(this.deleteTicket(t)));
    }
    LOGGER.debug("Removing ticket [{}] from the registry.", ticket);

    if (deleteSingleTicket(ticketId)) {
        count.incrementAndGet();
    }

    return count.intValue();
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:34,代碼來源:AbstractTicketRegistry.java

示例6: testShutdown

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
@Test(timeout=180000)
public void testShutdown() throws Exception {
  final AtomicInteger bytesRead = new AtomicInteger(0);
  final AtomicBoolean failed = new AtomicBoolean(false);
  final DomainSocket[] socks = DomainSocket.socketpair();
  Runnable reader = new Runnable() {
    @Override
    public void run() {
      while (true) {
        try {
          int ret = socks[1].getInputStream().read();
          if (ret == -1) return;
          bytesRead.addAndGet(1);
        } catch (IOException e) {
          DomainSocket.LOG.error("reader error", e);
          failed.set(true);
          return;
        }
      }
    }
  };
  Thread readerThread = new Thread(reader);
  readerThread.start();
  socks[0].getOutputStream().write(1);
  socks[0].getOutputStream().write(2);
  socks[0].getOutputStream().write(3);
  Assert.assertTrue(readerThread.isAlive());
  socks[0].shutdown();
  readerThread.join();
  Assert.assertFalse(failed.get());
  Assert.assertEquals(3, bytesRead.get());
  IOUtils.cleanup(null, socks);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:34,代碼來源:TestDomainSocket.java

示例7: execute

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
private MemgraphCypherScope execute(
        MemgraphCypherQueryContext ctx,
        ImmutableList<CypherClause> clauses,
        AtomicInteger clauseIndex,
        MemgraphCypherScope previousScope
) {
    MemgraphCypherScope results;
    CypherClause clause = clauses.get(clauseIndex.get());
    if (clause instanceof CypherCreateClause) {
        results = ctx.getCreateClauseExecutor().execute(ctx, (CypherCreateClause) clause, previousScope);
    } else if (clause instanceof CypherReturnClause) {
        results = ctx.getReturnClauseExecutor().execute(ctx, (CypherReturnClause) clause, previousScope);
    } else if (clause instanceof CypherMatchClause) {
        List<CypherMatchClause> matchClauses = getSimilarClauses(clauses, clauseIndex.get(), CypherMatchClause.class);
        results = ctx.getMatchClauseExecutor().execute(ctx, matchClauses, previousScope);
        clauseIndex.addAndGet(matchClauses.size() - 1);
    } else if (clause instanceof CypherUnwindClause) {
        List<CypherUnwindClause> unwindClauses = getSimilarClauses(clauses, clauseIndex.get(), CypherUnwindClause.class);
        results = ctx.getUnwindClauseExecutor().execute(ctx, unwindClauses, previousScope);
        clauseIndex.addAndGet(unwindClauses.size() - 1);
    } else if (clause instanceof CypherWithClause) {
        results = ctx.getWithClauseExecutor().execute(ctx, (CypherWithClause) clause, previousScope);
    } else if (clause instanceof CypherMergeClause) {
        results = ctx.getMergeClauseExecutor().execute(ctx, (CypherMergeClause) clause, previousScope);
    } else if (clause instanceof CypherDeleteClause) {
        results = ctx.getDeleteClauseExecutor().execute(ctx, (CypherDeleteClause) clause, previousScope);
    } else if (clause instanceof CypherSetClause) {
        results = ctx.getSetClauseExecutor().execute(ctx, (CypherSetClause) clause, previousScope);
    } else if (clause instanceof CypherRemoveClause) {
        results = ctx.getRemoveClauseExecutor().execute(ctx, (CypherRemoveClause) clause, previousScope);
    } else {
        throw new MemgraphException("clause not implemented \"" + clause.getClass().getName() + "\": " + clause);
    }
    return results;
}
 
開發者ID:mware-solutions,項目名稱:memory-graph,代碼行數:36,代碼來源:QueryExecutor.java

示例8: testGroupOrSplitPresplit

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
/**
 * This test splits a table and attempts to bulk load.  The bulk import files
 * should be split before atomically importing.
 */
@Test (timeout=120000)
public void testGroupOrSplitPresplit() throws Exception {
  final TableName table = TableName.valueOf("groupOrSplitPresplit");
  try (Connection connection = ConnectionFactory.createConnection(util.getConfiguration())) {
    setupTable(connection, table, 10);
    populateTable(connection, table, 1);
    assertExpectedTable(connection, table, ROWCOUNT, 1);
    forceSplit(table);

    final AtomicInteger countedLqis= new AtomicInteger();
    LoadIncrementalHFiles lih = new LoadIncrementalHFiles(
        util.getConfiguration()) {
      @Override
      protected List<LoadQueueItem> groupOrSplit(
          Multimap<ByteBuffer, LoadQueueItem> regionGroups,
          final LoadQueueItem item, final Table htable,
          final Pair<byte[][], byte[][]> startEndKeys) throws IOException {
        List<LoadQueueItem> lqis = super.groupOrSplit(regionGroups, item, htable, startEndKeys);
        if (lqis != null) {
          countedLqis.addAndGet(lqis.size());
        }
        return lqis;
      }
    };

    // create HFiles for different column families
    Path bulk = buildBulkFiles(table, 2);
    try (Table t = connection.getTable(table)) {
      lih.doBulkLoad(bulk, (HTable)t);
    }
    assertExpectedTable(connection, table, ROWCOUNT, 2);
    assertEquals(20, countedLqis.get());
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:39,代碼來源:TestLoadIncrementalHFilesSplitRecovery.java

示例9: testConsumerCanThrowExceptions

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
public void testConsumerCanThrowExceptions() {
    AtomicInteger received = new AtomicInteger(0);
    AtomicInteger notified = new AtomicInteger(0);

    AsyncIOProcessor<Object> processor = new AsyncIOProcessor<Object>(logger, scaledRandomIntBetween(1, 2024)) {
        @Override
        protected void write(List<Tuple<Object, Consumer<Exception>>> candidates) throws IOException {
            received.addAndGet(candidates.size());
        }
    };
    processor.put(new Object(), (e) -> {notified.incrementAndGet();throw new RuntimeException();});
    processor.put(new Object(), (e) -> {notified.incrementAndGet();throw new RuntimeException();});
    assertEquals(2, notified.get());
    assertEquals(2, received.get());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:AsyncIOProcessorTests.java

示例10: testRemovalListener_expireAfterWrite

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
public void testRemovalListener_expireAfterWrite() {
  FakeTicker ticker = new FakeTicker();
  final AtomicInteger evictionCount = new AtomicInteger();
  final AtomicInteger applyCount = new AtomicInteger();
  final AtomicInteger totalSum = new AtomicInteger();

  RemovalListener<Integer, AtomicInteger> removalListener =
      new RemovalListener<Integer, AtomicInteger>() {
        @Override
        public void onRemoval(RemovalNotification<Integer, AtomicInteger> notification) {
          if (notification.wasEvicted()) {
            evictionCount.incrementAndGet();
            totalSum.addAndGet(notification.getValue().get());
          }
        }
      };

  CacheLoader<Integer, AtomicInteger> loader = new CacheLoader<Integer, AtomicInteger>() {
    @Override public AtomicInteger load(Integer key) {
      applyCount.incrementAndGet();
      return new AtomicInteger();
    }
  };

  LoadingCache<Integer, AtomicInteger> cache = CacheBuilder.newBuilder()
      .removalListener(removalListener)
      .expireAfterWrite(10, MILLISECONDS)
      .ticker(ticker)
      .build(loader);

  // Increment 100 times
  for (int i = 0; i < 100; ++i) {
    cache.getUnchecked(10).incrementAndGet();
    ticker.advance(1, MILLISECONDS);
  }

  assertEquals(evictionCount.get() + 1, applyCount.get());
  int remaining = cache.getUnchecked(10).get();
  assertEquals(100, totalSum.get() + remaining);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:41,代碼來源:CacheExpirationTest.java

示例11: leaveBufferSlot

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
/**
 * Leave buffer slot after processing all messages (reading message headers and dispatching creation). Is called by MessageCreationCoordinator.
 *
 * @param p_messageCounter
 *         the slot's message counter
 * @param p_incomingBuffer
 *         the processed incoming buffer
 */
private void leaveBufferSlot(final AtomicInteger p_messageCounter, final IncomingBufferQueue.IncomingBuffer p_incomingBuffer) {
    // Message counter was incremented during entering the slot -> decrement now as all message headers were read
    int counter = p_messageCounter.addAndGet(-(2 * m_messageHandlerPoolSize - m_messageHandlers.pushLeftHeaders()));
    if (counter == 0) {
        // Message handlers created and de-serialized all messages for this buffer already -> return incoming buffer
        returnProcessedBuffer(p_incomingBuffer.getDirectBuffer(), p_incomingBuffer.getBufferHandle());
    }
    // Increment slot number
    m_slotPosition = m_slotPosition + 1 & 0x7FFFFFFF;
}
 
開發者ID:hhu-bsinfo,項目名稱:dxram,代碼行數:19,代碼來源:AbstractPipeIn.java

示例12: readValue

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
/**
 * Reads a raw value from the DER encoded stream.
 * 
 * @param length The number of bytes to read.
 * @param bytesRead Will be updated with the number of bytes read.
 * @return The raw value read from the stream.
 */
public byte[] readValue(int length, AtomicInteger bytesRead)
    throws IOException, DerEncodingException {

  byte[] buffer = new byte[length];
  if (in.read(buffer, 0, length) < length) {
    throw new DerEncodingException("End of stream found reading value.");
  }
  bytesRead.addAndGet(length);

  return buffer;
}
 
開發者ID:hyperledger,項目名稱:quilt,代碼行數:19,代碼來源:DerInputStream.java

示例13: readCondition

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
/**
 * Reads a DER encoded condition from the input stream.
 *
 * @param in        The input stream containing the DER encoded condition.
 * @param bytesRead will be updated with the number of bytes read from the stream.
 * @return The condition read from the stream.
 * @throws DerEncodingException when DER encoding fails for any reason.
 * @throws IOException          if any I/O operation fails for any reason.
 */
public static Condition readCondition(DerInputStream in, AtomicInteger bytesRead)
    throws DerEncodingException, IOException {

  int tag = in.readTag(bytesRead, DerTag.CONSTRUCTED, DerTag.TAGGED);
  CryptoConditionType type = CryptoConditionType.valueOf(tag);
  int length = in.readLength(bytesRead);

  AtomicInteger innerBytesRead = new AtomicInteger();
  byte[] fingerprint =
      in.readTaggedObject(0, length - innerBytesRead.get(), innerBytesRead).getValue();
  long cost = new BigInteger(
      in.readTaggedObject(1, length - innerBytesRead.get(), innerBytesRead).getValue())
      .longValue();
  EnumSet<CryptoConditionType> subtypes = null;
  if (type == CryptoConditionType.PREFIX_SHA256 || type == CryptoConditionType.THRESHOLD_SHA256) {
    subtypes = CryptoConditionType.getEnumOfTypesFromBitString(
        in.readTaggedObject(2, length - innerBytesRead.get(), innerBytesRead).getValue());
  }
  bytesRead.addAndGet(innerBytesRead.get());

  switch (type) {
    case PREIMAGE_SHA256:
      return new PreimageSha256Condition(cost, fingerprint);
    case PREFIX_SHA256:
      return new PrefixSha256Condition(cost, fingerprint, subtypes);
    case THRESHOLD_SHA256:
      return new ThresholdSha256Condition(cost, fingerprint, subtypes);
    case RSA_SHA256:
      return new RsaSha256Condition(cost, fingerprint);
    case ED25519_SHA256:
      return new Ed25519Sha256Condition(fingerprint);
    default:
      throw new DerEncodingException("Unknown condition type: " + type);
  }
}
 
開發者ID:hyperledger,項目名稱:quilt,代碼行數:45,代碼來源:CryptoConditionReader.java

示例14: processSpeculatorEvent

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
private synchronized void processSpeculatorEvent(SpeculatorEvent event) {
  switch (event.getType()) {
    case ATTEMPT_STATUS_UPDATE:
      statusUpdate(event.getReportedStatus(), event.getTimestamp());
      break;

    case TASK_CONTAINER_NEED_UPDATE:
    {
      AtomicInteger need = containerNeed(event.getTaskID());
      need.addAndGet(event.containersNeededChange());
      break;
    }

    case ATTEMPT_START:
    {
      LOG.info("ATTEMPT_START " + event.getTaskID());
      estimator.enrollAttempt
          (event.getReportedStatus(), event.getTimestamp());
      break;
    }
    
    case JOB_CREATE:
    {
      LOG.info("JOB_CREATE " + event.getJobID());
      estimator.contextualize(getConfig(), context);
      break;
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:30,代碼來源:DefaultSpeculator.java

示例15: handleUpdate

import java.util.concurrent.atomic.AtomicInteger; //導入方法依賴的package包/類
public void handleUpdate(ServerInfo serverInfo)
{
    for (MobImpl mob : this.mobs.values())
    {
        if (mob.getMob().getTargetGroup().equals(serverInfo.getServiceId().getGroup()))
        {
            updateCustom(mob.getMob(), mob.getDisplayMessage());
            Bukkit.getPluginManager().callEvent(new BukkitMobUpdateEvent(mob.getMob()));
            mob.getServerPosition().clear();
            filter(serverInfo.getServiceId().getGroup());
            Collection<ServerInfo> serverInfos = filter(serverInfo.getServiceId().getGroup());
            final AtomicInteger index = new AtomicInteger(0);
            for (ServerInfo server : serverInfos)
            {
                if (server.isOnline() && server.getServerState().equals(ServerState.LOBBY) && !server.getServerConfig().isHideServer())
                {
                    while (mobConfig.getDefaultItemInventory().containsKey((index.get() + 1)))
                    {
                        index.addAndGet(1);
                    }
                    if ((mobConfig.getInventorySize() - 1) <= index.get()) break;

                    final int value = index.get();
                    Bukkit.getScheduler().runTask(CloudServer.getInstance().getPlugin(), new Runnable() {
                        @Override
                        public void run()
                        {
                            mob.getInventory().setItem(value, transform(mobConfig.getItemLayout(), server));
                            mob.getServerPosition().put(value, server.getServiceId().getServerId());
                        }
                    });
                    index.addAndGet(1);
                }
            }

            while (index.get() < (mob.getInventory().getSize()))
            {
                if (!mobConfig.getDefaultItemInventory().containsKey(index.get() + 1))
                    mob.getInventory().setItem(index.get(), new ItemStack(Material.AIR));
                index.addAndGet(1);
            }
        }
    }
}
 
開發者ID:Dytanic,項目名稱:CloudNet,代碼行數:45,代碼來源:MobSelector.java


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