Package java.util.concurrent

Examples of java.util.concurrent.ExecutorCompletionService


   @SuppressWarnings("unchecked")
   @Override
   public void process(KeyFilter keyFilter, CacheLoaderTask cacheLoaderTask, Executor executor, boolean loadValues, boolean loadMetadata) {

      int batchSize = 100;
      ExecutorCompletionService ecs = new ExecutorCompletionService(executor);
      int tasks = 0;
      final TaskContext taskContext = new TaskContextImpl();

      List<Map.Entry<byte[], byte[]>> entries = new ArrayList<Map.Entry<byte[], byte[]>>(batchSize);
      DBIterator it = db.iterator(new ReadOptions().fillCache(false));
View Full Code Here


        }

    }

    private void concurrentProcess(Map<Long, List<AlarmRule>> rules) {
        ExecutorCompletionService completionExecutor = new ExecutorCompletionService(executor);
        List<Future> futures = new ArrayList<Future>();
        for (Entry<Long, List<AlarmRule>> entry : rules.entrySet()) {
            final List<AlarmRule> alarmRules = entry.getValue();
            futures.add(completionExecutor.submit(new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    pipelineMonitor.explore(alarmRules);
                    return null;
                }
            }));
        }

        List<Throwable> exceptions = new ArrayList<Throwable>();
        int index = 0;
        int size = futures.size();
        while (index < size) {
            try {
                Future<?> future = completionExecutor.take();
                future.get();
            } catch (InterruptedException e) {
                exceptions.add(e);
            } catch (ExecutionException e) {
                exceptions.add(e);
View Full Code Here

   private AtomicReference<ExecutionException> firstException = new AtomicReference<ExecutionException>();
   private AtomicLong scheduled = new AtomicLong();
   private AtomicLong completed = new AtomicLong();

   public ExecutorAllCompletionService(Executor executor) {
      this.executorService = new ExecutorCompletionService(executor);
   }
View Full Code Here

   }

   @Override
   public void process(final KeyFilter filter, final CacheLoaderTask task, Executor executor, boolean fetchValue, boolean fetchMetadata) {
      scanForUnknownDirectories();
      ExecutorCompletionService ecs = new ExecutorCompletionService(executor);

      final TaskContextImpl taskContext = new TaskContextImpl();
      int count = 0;
      for (final DirectoryLoaderAdaptor dir : openDirectories.values()) {
         ecs.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
               final HashSet<MarshalledEntry> allInternalEntries = new HashSet<MarshalledEntry>();
               dir.loadAllEntries(allInternalEntries, Integer.MAX_VALUE, ctx.getMarshaller());
               for (MarshalledEntry me : allInternalEntries) {
View Full Code Here

    throws InterruptedException, ExecutionException, TimeoutException
  {
    int i = paramCollection.size();
    Preconditions.checkArgument(i > 0);
    ArrayList localArrayList = new ArrayList(i);
    ExecutorCompletionService localExecutorCompletionService = new ExecutorCompletionService(this);
    try
    {
      Object localObject1 = null;
      long l1 = paramBoolean ? System.nanoTime() : 0L;
      Iterator localIterator1 = paramCollection.iterator();
      localArrayList.add(localExecutorCompletionService.submit((Callable)localIterator1.next()));
      i--;
      int j = 1;
      while (true)
      {
        Future localFuture1 = localExecutorCompletionService.poll();
        if (localFuture1 == null)
          if (i > 0)
          {
            i--;
            localArrayList.add(localExecutorCompletionService.submit((Callable)localIterator1.next()));
            j++;
          }
          else
          {
            if (j == 0)
              break;
            if (paramBoolean)
            {
              localFuture1 = localExecutorCompletionService.poll(paramLong, TimeUnit.NANOSECONDS);
              if (localFuture1 == null)
                throw new TimeoutException();
              long l2 = System.nanoTime();
              paramLong -= l2 - l1;
              l1 = l2;
            }
            else
            {
              localFuture1 = localExecutorCompletionService.take();
            }
          }
        if (localFuture1 != null)
        {
          j--;
View Full Code Here

   public void process(KeyFilter keyFilter, CacheLoaderTask cacheLoaderTask, Executor executor, boolean fetchValue, boolean fetchMetadata) {
      try {
         Set<Object> keys = loader.loadAllKeys(null);

         int batchSize = 1000;
         ExecutorCompletionService ecs = new ExecutorCompletionService(executor);
         int tasks = 0;
         final TaskContext taskContext = new TaskContextImpl();
         Set<Object> entries = new HashSet<Object>(batchSize);
         for (Object key : keys) {
            if (keyFilter == null || keyFilter.shouldLoadKey(key))
View Full Code Here

            }
        }
    }

    private void concurrentProcess(Map<Long, List<AlarmRule>> rules) {
        ExecutorCompletionService completionExecutor = new ExecutorCompletionService(executor);
        List<Future> futures = new ArrayList<Future>();
        for (Entry<Long, List<AlarmRule>> entry : rules.entrySet()) {
            final List<AlarmRule> alarmRules = entry.getValue();
            futures.add(completionExecutor.submit(new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    pipelineMonitor.explore(alarmRules);
                    return null;
                }
            }));
        }

        List<Throwable> exceptions = new ArrayList<Throwable>();
        int index = 0;
        int size = futures.size();
        while (index < size) {
            try {
                Future<?> future = completionExecutor.take();
                future.get();
            } catch (InterruptedException e) {
                exceptions.add(e);
            } catch (ExecutionException e) {
                exceptions.add(e);
View Full Code Here

            pipelineMonitor.explore(alarmRules);
        }
    }

    private void concurrentProcess(List<Long> channelIds) {
        ExecutorCompletionService completionExecutor = new ExecutorCompletionService(executor);
        List<Future> futures = new ArrayList<Future>();
        for (final Long channelId : channelIds) {
            futures.add(completionExecutor.submit(new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    ChannelStatus status = arbitrateManageService.channelEvent().status(channelId);
                    if (status.isPause()) {
                        restartAlarmRecovery.recovery(channelId);
                    }
                    return null;
                }
            }));
        }

        List<Throwable> exceptions = new ArrayList<Throwable>();
        int index = 0;
        int size = futures.size();
        while (index < size) {
            try {
                Future<?> future = completionExecutor.take();
                future.get();
            } catch (InterruptedException e) {
                exceptions.add(e);
            } catch (ExecutionException e) {
                exceptions.add(e);
View Full Code Here

   public void purge(Executor threadPool, PurgeListener task) {
      Connection conn = null;
      PreparedStatement ps = null;
      ResultSet rs = null;
      Collection<Bucket> expiredBuckets = new ArrayList<Bucket>(BATCH_SIZE);
      ExecutorCompletionService ecs = new ExecutorCompletionService(threadPool);
      BlockingQueue<Bucket> emptyBuckets = new LinkedBlockingQueue<Bucket>();
      // We have to lock and unlock the buckets in the same thread - executor can execute
      // the BucketPurger task in different thread. That's why we can't unlock the locks
      // there but have to send them to this thread through this queue.
      int tasksScheduled = 0;
      int tasksCompleted = 0;
      try {
         String sql = tableManipulation.getSelectExpiredRowsSql();
         conn = connectionFactory.getConnection();
         ps = conn.prepareStatement(sql);
         ps.setLong(1, ctx.getTimeService().wallClockTime());
         rs = ps.executeQuery();
         while (rs.next()) {
            Integer bucketId = rs.getInt(2);
            if (immediateLockForWriting(bucketId)) {
               if (log.isTraceEnabled()) {
                  log.tracef("Adding bucket keyed %s for purging.", bucketId);
               }
               InputStream binaryStream = rs.getBinaryStream(1);
               Bucket bucket = unmarshallBucket(binaryStream);
               bucket.setBucketId(bucketId);
               expiredBuckets.add(bucket);
               if (expiredBuckets.size() == BATCH_SIZE) {
                  ++tasksScheduled;
                  ecs.submit(new BucketPurger(expiredBuckets, task, ctx.getMarshaller(), conn, emptyBuckets));
                  expiredBuckets = new ArrayList<Bucket>(BATCH_SIZE);
               }
            } else {
               if (log.isTraceEnabled()) {
                  log.tracef("Could not acquire write lock for %s, this won't be purged even though it has expired elements", bucketId);
               }
            }
            // continuously unlock already purged buckets - we don't want to run out of memory by storing
            // them in unlimited collection
            tasksCompleted += unlockCompleted(ecs, false); // cannot throw InterruptedException
         }

         if (!expiredBuckets.isEmpty()) {
            ++tasksScheduled;
            ecs.submit(new BucketPurger(expiredBuckets, task, ctx.getMarshaller(), conn, emptyBuckets));
         }
         // wait until all tasks have completed
         try {
            while (tasksCompleted < tasksScheduled) {
               tasksCompleted += unlockCompleted(ecs, true);
View Full Code Here

        long[] gridLoc = trIter.nextMetaGridLocation(new long[3]);

        // six concurrent requests max
        ExecutorService requests = Executors.newFixedThreadPool(6);
        ExecutorCompletionService completer = new ExecutorCompletionService(requests);

        List<Future<ConveyorTile>> futures = new ArrayList<Future<ConveyorTile>>();
        while (gridLoc != null) {
            Map<String, String> fullParameters = tr.getParameters();

            final ConveyorTile tile = new ConveyorTile(storageBroker, layerName, tr.getGridSetId(), gridLoc,
                    tr.getMimeType(), fullParameters, null, null);
            futures.add(completer.submit(new Callable<ConveyorTile>() {

                public ConveyorTile call() throws Exception {
                    try {
                        return tl.getTile(tile);
                    } catch (OutsideCoverageException oce) {
View Full Code Here

TOP

Related Classes of java.util.concurrent.ExecutorCompletionService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.