public synchronized void registerBestShareForChunk(
     BigInteger lowestInChunk, long nonce, PlotFile plotFile) {
   if (lowestInChunk.compareTo(deadline) < 0) {
     deadline = lowestInChunk;
     shareExecutor.execute(new SubmitShare(nonce, plotFile, deadline));
   }
 }
Пример #2
0
 /**
  * Saves the entity.
  *
  * @return the SUCCESS result
  */
 public String save() throws Exception {
   TargetList originalTargetList = saveEntity();
   final Collection<ChangeLog> changeLogs = changeLog(originalTargetList, targetList);
   if ("Campaign".equals(this.getRelationKey())) {
     Campaign campaign =
         campaignService.getEntityById(Campaign.class, Integer.valueOf(this.getRelationValue()));
     Set<Campaign> campaigns = targetList.getCampaigns();
     if (campaigns == null) {
       campaigns = new HashSet<Campaign>();
     }
     campaigns.add(campaign);
   }
   targetList = getBaseService().makePersistent(targetList);
   this.setId(targetList.getId());
   this.setSaveFlag("true");
   if (changeLogs != null) {
     taskExecutor.execute(
         new Runnable() {
           public void run() {
             batchInserChangeLogs(changeLogs);
           }
         });
   }
   return SUCCESS;
 }
  public void stopAndRestartMining() {

    for (PlotFileMiner miner : minerThreads) {
      miner.stop();
      miner.plotFile.addIncomplete();
      LOGGER.info("Stopped mining {" + miner.plotFile.getUUID() + "} due to block change");
    }
    minerThreads.clear();
    this.processing = null;
    while (this.processing == null) {
      this.processing = netStateService.getCurrentState();
      if (this.processing == null)
        try {
          Thread.sleep(500);
        } catch (Exception ex) {
        }
    }

    deadline =
        new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
    for (PlotFile plotFile : plotService.getPlots()) {
      PlotFileMiner miner = new PlotFileMiner(plotFile);
      minerThreads.add(miner);
      executor.execute(miner);
    }
  }
 @Test
 public void testMultiPlex() throws Exception {
   TaskExecutor executor = new SimpleAsyncTaskExecutor();
   final CountDownLatch latch = new CountDownLatch(100);
   final Set<Integer> results = new HashSet<Integer>();
   for (int i = 100; i < 200; i++) {
     results.add(i);
     final int j = i;
     executor.execute(
         new Runnable() {
           public void run() {
             String result = gw.send(j + "Hello world!"); // first 3 bytes is correlationid
             assertEquals(j + "Hello world!:echo", result);
             results.remove(j);
             latch.countDown();
           }
         });
   }
   assertTrue(latch.await(10, TimeUnit.SECONDS));
   assertEquals(0, results.size());
 }
Пример #5
0
 @PostConstruct
 void importAndWatch() throws Exception {
   LOGGER.debug("Starting initial import of documents from directory {}", baseDir);
   taskExecutor.execute(
       () -> {
         try {
           importFrom(baseDir);
           watcherDao.watch(baseDir);
         } catch (IOException e) {
           LOGGER.error("Couldn't proceed with initial import or watch due to exception", e);
         }
       });
 }
 @Override
 public void onApplicationEvent(ApplicationEvent event) {
   if (startedDeployedWar(event) || startedEmbeddedServer(event)) {
     executor.execute(
         new Runnable() {
           @Override
           public void run() {
             registrator.register();
           }
         });
   } else if (admin.isAutoDeregistration() && event instanceof ContextClosedEvent) {
     registrator.deregister();
   }
 }
Пример #7
0
  /** Mass update entity record information */
  public String massUpdate() throws Exception {
    saveEntity();
    String[] fieldNames = this.massUpdate;
    if (fieldNames != null) {
      Collection<String> feildNameCollection = new ArrayList<String>();
      for (int i = 0; i < fieldNames.length; i++) {
        feildNameCollection.add(fieldNames[i]);
        if ("reminder_pop".equals(fieldNames[i])) {
          feildNameCollection.add("reminder_email");
          feildNameCollection.add("reminder_option_pop");
          feildNameCollection.add("reminder_option_email");
        }
      }

      String[] selectIDArray = this.seleteIDs.split(",");
      Collection<Call> calls = new ArrayList<Call>();
      User loginUser = this.getLoginUser();
      User user = userService.getEntityById(User.class, loginUser.getId());
      Collection<ChangeLog> allChangeLogs = new ArrayList<ChangeLog>();
      for (String IDString : selectIDArray) {
        int id = Integer.parseInt(IDString);
        Call callInstance = this.baseService.getEntityById(Call.class, id);
        Call originalCall = callInstance.clone();
        for (String fieldName : feildNameCollection) {
          Object value = BeanUtil.getFieldValue(call, fieldName);
          BeanUtil.setFieldValue(callInstance, fieldName, value);
        }
        callInstance.setUpdated_by(user);
        callInstance.setUpdated_on(new Date());
        Collection<ChangeLog> changeLogs = changeLog(originalCall, callInstance);
        allChangeLogs.addAll(changeLogs);
        calls.add(callInstance);
      }
      final Collection<ChangeLog> changeLogsForSave = allChangeLogs;
      if (calls.size() > 0) {
        this.baseService.batchUpdate(calls);
        taskExecutor.execute(
            new Runnable() {
              public void run() {
                batchInserChangeLogs(changeLogsForSave);
              }
            });
      }
    }
    return SUCCESS;
  }
 @Override
 public void afterPropertiesSet() throws LiquibaseException {
   if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
     taskExecutor.execute(
         new Runnable() {
           @Override
           public void run() {
             try {
               log.warn(
                   "Starting Liquibase asynchronously, your database might not be ready at startup!");
               initDb();
             } catch (LiquibaseException e) {
               e.printStackTrace();
             }
           }
         });
   } else {
     log.debug("Starting Liquibase synchronously");
     initDb();
   }
 }
Пример #9
0
 /**
  * Saves the entity.
  *
  * @return the SUCCESS result
  */
 public String save() throws Exception {
   Call originalCall = saveEntity();
   final Collection<ChangeLog> changeLogs = changeLog(originalCall, call);
   // Validate Reminder Email Template
   if (call.isReminder_email() && reminderTemplateID == null) {
     String errorMessage = getText("error.reminderEamilTemplate");
     super.addActionError(errorMessage);
     return INPUT;
   }
   call = getbaseService().makePersistent(call);
   this.setId(call.getId());
   this.setSaveFlag("true");
   if (changeLogs != null) {
     taskExecutor.execute(
         new Runnable() {
           public void run() {
             batchInserChangeLogs(changeLogs);
           }
         });
   }
   return SUCCESS;
 }
 @Override
 public void afterPropertiesSet() throws LiquibaseException {
   if (env.acceptsProfiles(
       Constants.SPRING_PROFILE_DEVELOPMENT, Constants.SPRING_PROFILE_HEROKU)) {
     taskExecutor.execute(
         () -> {
           try {
             log.warn(
                 "Starting Liquibase asynchronously, your database might not be ready at startup!");
             initDb();
           } catch (LiquibaseException e) {
             log.error(
                 "Liquibase could not start correctly, your database is NOT ready: {}",
                 e.getMessage(),
                 e);
           }
         });
   } else {
     log.debug("Starting Liquibase synchronously");
     initDb();
   }
 }
  public void execute() {
    PlannedCollection plannedCollection = plannedCollectionProvider.findNextPlannedCollection();

    while (plannedCollection != null) {
      ProviderConfig providerConfig = plannedCollection.getProviderConfig();
      CollectionState collectionState = plannedCollection.getCollectionState();
      logger.debug(
          "Planning to execute data collection for configuration '"
              + providerConfig.getConfigId()
              + "' of data provider '"
              + providerConfig.getProviderId()
              + "'");
      collectionState.setState(State.PENDING);
      collectionState.setException(null);
      collectionStateService.saveCollectionState(collectionState);
      // execute task
      DataCollectionTask dataCollectionTask = dataCollectionTaskFactory.getObject();
      dataCollectionTask.init(providerConfig, collectionState);
      taskExecutor.execute(dataCollectionTask);

      plannedCollection = plannedCollectionProvider.findNextPlannedCollection();
    }
  }
 private void startReceivingServices() {
   List<LibraryReceiverService> libraryReceiverServices = new ArrayList<>();
   libraryReceiverServices.add(libraryPresenceService);
   libraryReceiverServices.add(libraryMetadataService);
   libraryReceiverServices.add(libraryAdditionService);
   libraryReceiverServices.add(libraryDeletionService);
   workerThreads = new CountDownLatch(libraryReceiverServices.size());
   for (final LibraryReceiverService libraryReceiverService : libraryReceiverServices) {
     taskExecutor.execute(
         new Runnable() {
           @Override
           public void run() {
             try {
               libraryReceiverService.receive();
             } catch (Throwable t) {
               LOG.error("Unexpected error caught during scanning!", t);
               t.printStackTrace();
             } finally {
               workerThreads.countDown();
             }
           }
         });
   }
 }
Пример #13
0
 /** Mass update entity record information */
 public String massUpdate() throws Exception {
   saveEntity();
   String[] fieldNames = this.massUpdate;
   if (fieldNames != null) {
     String[] selectIDArray = this.seleteIDs.split(",");
     Collection<TargetList> targetLists = new ArrayList<TargetList>();
     User loginUser = this.getLoginUser();
     User user = userService.getEntityById(User.class, loginUser.getId());
     Collection<ChangeLog> allChangeLogs = new ArrayList<ChangeLog>();
     for (String IDString : selectIDArray) {
       int id = Integer.parseInt(IDString);
       TargetList targetListInstance = this.baseService.getEntityById(TargetList.class, id);
       TargetList originalTargetList = targetListInstance.clone();
       for (String fieldName : fieldNames) {
         Object value = BeanUtil.getFieldValue(targetList, fieldName);
         BeanUtil.setFieldValue(targetListInstance, fieldName, value);
       }
       targetListInstance.setUpdated_by(user);
       targetListInstance.setUpdated_on(new Date());
       Collection<ChangeLog> changeLogs = changeLog(originalTargetList, targetListInstance);
       allChangeLogs.addAll(changeLogs);
       targetLists.add(targetListInstance);
     }
     final Collection<ChangeLog> changeLogsForSave = allChangeLogs;
     if (targetLists.size() > 0) {
       this.baseService.batchUpdate(targetLists);
       taskExecutor.execute(
           new Runnable() {
             public void run() {
               batchInserChangeLogs(changeLogsForSave);
             }
           });
     }
   }
   return SUCCESS;
 }
 public void printMessages() {
   taskExecutor.execute(new getLocation());
   taskExecutor.execute(new pushToClient());
 }
 @Scheduled(fixedDelay = 2000)
 public void executePropagation() {
   taskExecutor.execute(propagationExecutor);
 }
Пример #16
0
 public void run(int initialWait, int retryInterval, int maxRetryCount, RetryTask retryTask) {
   taskExecutor.execute(new RetryRunnable(initialWait, retryInterval, maxRetryCount, retryTask));
 }
Пример #17
0
 public void enqueueTasks() {
   for (int i = 0; i < 25; i++) {
     taskExecutor.execute(new HelloWorldCountDownTask("Task " + i));
   }
 }