public static MultiVariatePieceWiseLinearFunction createSenseSleepFunctionVerbose(
      ScenarioProperties scenario, List<SensorProperties> sensorProperties) {

    NCube domain = createDomain(sensorProperties, scenario);

    // max(0, min(x1 + l1, x2 + l2) - max(x1, x2))

    MultiVariatePieceWiseLinearFunction zero =
        MultiVariatePieceWiseLinearFunctionUtilities.createZeroFunction(domain);

    double l = scenario.getScheduleIntervalLength();

    StopWatch watch = new StopWatch();

    watch.start();
    MultiVariatePieceWiseLinearFunction maxStart = createMaxStartFunction(domain);
    watch.stop();
    System.out.println(
        "Created maxStart in "
            + watch.getTime()
            + ". Simplices "
            + maxStart.getPartitioning().getSimplices().size());

    watch.reset();
    watch.start();
    MultiVariatePieceWiseLinearFunction minEnd = createMinEndFunction(domain, sensorProperties);
    watch.stop();
    System.out.println(
        "Created minEnd in "
            + watch.getTime()
            + ". Simplices "
            + minEnd.getPartitioning().getSimplices().size());

    watch.reset();
    watch.start();
    MultiVariatePieceWiseLinearFunction minMinusMax = minEnd.subtract(maxStart);
    watch.stop();
    System.out.println(
        "Created minMinusMax in "
            + watch.getTime()
            + ". Simplices "
            + minMinusMax.getPartitioning().getSimplices().size());

    watch.reset();
    watch.start();
    MultiVariatePieceWiseLinearFunction overlap = minMinusMax.max(zero);
    System.out.println(
        "Created overlap in "
            + watch.getTime()
            + ". Simplices "
            + overlap.getPartitioning().getSimplices().size());

    MultiVariatePieceWiseLinearFunction result = overlap.subtract(l).multiply(-1.0);

    System.out.println("Simplices " + result.getPartitioning().getSimplices().size());

    return result;
  }
Ejemplo n.º 2
0
    @Override
    public void run() {
      try {
        StopWatch stp2 = new StopWatch();
        stp2.start();
        JSONObject json = new JSONObject();
        job.setStatus("running");
        if (job.progress() == 100.0) {

          finalizeJob(job);
          return;
        }
        Vector<String> ids = new Vector<String>();
        Vector<String> original_names = new Vector<String>();

        String data = job.getNextDataBatch();

        if (data == null || data.equals("")) return;

        String[] lines = data.split("\n");

        if (job.containsId()) {
          for (int i = 0; i < lines.length; i++) {
            if (lines[i].trim().equals("")) continue;
            ids.add(NameUtil.getNameId(lines[i]));
          }
        }

        for (int i = 0; i < lines.length; i++) {
          original_names.add(NameUtil.processName(lines[i], job.containsId()));
        }

        String names = NameUtil.CleanNames(lines, job);

        if (names.equals("")) return;

        if (job.getType() == TnrsJob.NAME_MATCH_JOB) {

          TaxamatchInterface taxa_match = new TaxamatchInterface(tnrsBaseUrl);
          String result = taxa_match.queryTaxamatch(names, job);
          json = (JSONObject) JSONSerializer.toJSON(result);

        } else if (job.getType() == TnrsJob.PARSING_JOB) {

          json = gni_interface.parseNames(names);
        }
        if (job.outstandingNames() == 0) {
          JobHelper.persistJobInfo(baseFolder, job);
        }
        saveResults(job, json, ids, original_names, "");

        job.setStatus("idle");
        stp2.stop();
        log.info("overall :" + stp2.toString());
      } catch (Exception ex) {
        log.error(ExceptionUtils.getFullStackTrace(ex));
        job.setStatus("failed");
        ex.printStackTrace();
      }
    }
Ejemplo n.º 3
0
  protected void testOutgoingConnection() throws MailException {
    StopWatch stopWatch = null;

    if (_log.isDebugEnabled()) {
      stopWatch = new StopWatch();

      stopWatch.start();
    }

    try {
      Transport transport = getTransport();

      transport.isConnected();

      transport.close();
    } catch (Exception e) {
      throw new MailException(MailException.ACCOUNT_OUTGOING_CONNECTION_FAILED, e);
    } finally {
      if (_log.isDebugEnabled()) {
        stopWatch.stop();

        _log.debug("Testing outgoing connection completed in " + stopWatch.getTime() + " ms");
      }
    }
  }
Ejemplo n.º 4
0
  @GET
  @Transactional
  @Path("/user/{userName}/accountBalance")
  @Produces(MediaType.APPLICATION_JSON)
  public Response getAccountBalance(
      @PathParam("apiVersion") String apiVersion,
      @PathParam("userName") String userName,
      @DefaultValue("true") @QueryParam("cache") boolean cache)
      throws JsonProcessingException {
    StopWatch watch = new StopWatch();
    watch.start();

    EntityManager em = emf.createEntityManager();
    if (log.isDebugEnabled()) {
      log.trace("Time to execute getTree Service : {}ms", watch.getTime());
    }
    //		if (!accountValidator.validateAccount(accountId)) {
    //			return
    // Response.status(Response.Status.UNAUTHORIZED).entity(accountValidator.getResponse(accountId)).build();
    //		}
    long accNo = 746353;
    // BossUserRepository userRepo = new BossUserRepository();
    double accountBalance = userRepo.account(accNo);

    watch.stop();
    if (log.isDebugEnabled()) {
      log.trace("Time to execute ACCOUNTDETAILS for a USER : {}ms", watch.getTime());
    }
    return Response.status(Response.Status.OK).entity(accountBalance).build();
  }
  @Test
  public void testListCalendarNames() {
    initializeCredentials();
    FindFolder request = constructFindFolderRequest();
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    FindFolderResponse response = ewsClient.findFolder(request);
    String captured = capture(response);
    log.info("testListCalendarNames response: " + captured);
    stopWatch.stop();
    log.debug("FindFolder request completed in " + stopWatch);
    Assert.assertNotNull(response);

    // now generate a Map?
    Map<String, String> msolCalendars = new LinkedHashMap<String, String>();
    ArrayOfResponseMessagesType responses = response.getResponseMessages();
    List<JAXBElement<? extends ResponseMessageType>> responseList =
        responses
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
    // iterate over responses
    for (JAXBElement<? extends ResponseMessageType> rm : responseList) {
      FindFolderResponseMessageType itemType = (FindFolderResponseMessageType) rm.getValue();
      FindFolderParentType rootFolder = itemType.getRootFolder();
      ArrayOfFoldersType folders = rootFolder.getFolders();
      List<BaseFolderType> folderList = folders.getFoldersAndCalendarFoldersAndContactsFolders();
      for (BaseFolderType baseFolder : folderList) {
        String displayName = baseFolder.getDisplayName();
        String folderId = baseFolder.getFolderId().getId();
        String changeKey = baseFolder.getFolderId().getChangeKey();
        log.debug(displayName + "(id=" + folderId + " : changeKey=" + changeKey + " )");
      }
    }
  }
  @Override
  protected Client createClient(Settings.Builder builder) {
    StopWatch stopWatch = new StopWatch();

    stopWatch.start();

    if (_log.isDebugEnabled()) {
      _log.debug(
          "Starting embedded Elasticsearch cluster " + elasticsearchConfiguration.clusterName());
    }

    NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder();

    nodeBuilder.settings(builder);

    _node = nodeBuilder.node();

    _node.start();

    Client client = _node.client();

    if (_log.isDebugEnabled()) {
      stopWatch.stop();

      _log.debug(
          "Finished starting "
              + elasticsearchConfiguration.clusterName()
              + " in "
              + stopWatch.getTime()
              + " ms");
    }

    return client;
  }
Ejemplo n.º 7
0
 /**
  * 测试哨兵模式
  *
  * <p>one master(one sentinel) - one slave
  */
 @Test
 public void testSentinel() {
   // 哨兵初始化
   HostAndPort sentinelAddr = new HostAndPort("192.168.1.201", 26379);
   Set<String> sentinels = new HashSet<String>();
   sentinels.add(sentinelAddr.toString());
   JedisSentinelPool sentinelPool =
       new JedisSentinelPool("mymaster", sentinels, new GenericObjectPoolConfig());
   // 线程初始化
   StopWatch stopWatch = new StopWatch();
   stopWatch.start();
   AtomicInteger calcCount = new AtomicInteger(0);
   AtomicInteger failCount = new AtomicInteger(0);
   for (int t = 0; t < TIMES; t++) {
     ThreadPool threadPool = new ThreadPool(THREADS);
     SentinelThread sentinelThread = new SentinelThread(sentinelPool, calcCount, failCount);
     threadPool.executeThread(sentinelThread);
     try {
       TimeUnit.SECONDS.sleep(SECONDS);
     } catch (InterruptedException e) {
       Thread.currentThread().interrupt();
       System.err.println("error !!!");
     }
   }
   sentinelPool.close();
   stopWatch.stop();
   // 打印结果
   System.out.println(
       String.format(
           "redis sentinel work finish, times:%d(milliseconds), fails:%d",
           stopWatch.getTime(), failCount.get()));
 }
Ejemplo n.º 8
0
  protected void performWarmUp(SessionFactory sf) {
    log("starting warm up phase");

    warmupStopWatch.start();

    TestContext ctx = new TestContext(this, sf);
    scheduleTasksAndStart(ctx, warmupCyclesCount);

    warmupStopWatch.stop();
  }
  private void waitFor(Id id, Pattern pattern) {
    if (pattern == null) {
      return;
    }

    final StopWatch watch = new StopWatch();
    watch.start();
    logger.info(String.format("Waiting for '%s' to appear in output", pattern.toString()));

    final Container container;

    try {
      container = findContainer(id);
    } catch (DockerException e) {
      throw new OrchestrationException(e);
    }

    if (container == null) {
      logger.warn(String.format("Can not find container %s, not waiting", id));
      return;
    }

    try {
      final LogContainerCmd logContainerCmd =
          docker
              .logContainerCmd(container.getId())
              .withStdErr()
              .withStdOut()
              .withFollowStream()
              .withTimestamps();

      final InputStream stream = logContainerCmd.exec();

      try (final BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
        String line;
        while ((line = reader.readLine()) != null) {
          if (pattern.matcher(line).find()) {
            watch.stop();
            logger.info(String.format("Waited for %s", watch.toString()));
            return;
          }
        }
        throw new OrchestrationException("Container log ended before line appeared in output");
      }
    } catch (Exception e) {
      logger.warn(
          "Unable to obtain logs from container "
              + container.getId()
              + ", will continue without waiting: ",
          e);
    }
  }
Ejemplo n.º 10
0
 @SyncThread(level = 1000)
 private void createVm(
     VmInstanceInventory vm, String rootDiskUuid, List<String> nws, List<String> disks)
     throws ApiSenderException {
   StopWatch watch = new StopWatch();
   watch.start();
   try {
     api.createVmByFullConfig(vm, rootDiskUuid, nws, disks);
   } finally {
     watch.stop();
     timeCost.add(watch.getTime());
     latch.countDown();
   }
 }
 /**
  * Issues a {@link GetUserAvailabilityRequest} for the configured emailAddress, startDate and
  * endDate. Verifies a response, and that the freebusy responses match expectedEventCount.
  */
 @Test
 public void testGetUserAvailability() {
   initializeCredentials();
   GetUserAvailabilityRequest request =
       constructAvailabilityRequest(
           DateHelp.makeDate(startDate), DateHelp.makeDate(endDate), emailAddress);
   StopWatch stopWatch = new StopWatch();
   stopWatch.start();
   GetUserAvailabilityResponse response = ewsClient.getUserAvailability(request);
   stopWatch.stop();
   log.debug("GetUserAvailability request completed in " + stopWatch);
   Assert.assertNotNull(response);
   Assert.assertEquals(
       expectedEventCount, response.getFreeBusyResponseArray().getFreeBusyResponses().size());
 }
 @PostConstruct
 public void createIndex() {
   StopWatch stopWatch = new StopWatch();
   stopWatch.start();
   try {
     getFullTextEntityManager(entityManager) //
         .createIndexer(CLASSES_TO_BE_INDEXED) //
         .batchSizeToLoadObjects(batchSizeToLoadObjects) //
         .threadsToLoadObjects(threadsToLoadObjects) //
         .threadsForSubsequentFetching(threadsForSubsequentFetching) //
         .start();
   } finally {
     stopWatch.stop();
     log.info("Indexed {} in {}", Arrays.toString(CLASSES_TO_BE_INDEXED), stopWatch.toString());
   }
 }
Ejemplo n.º 13
0
  /** @param orgIn */
  private void publishUpdateErrataCacheEvent(Org orgIn) {
    StopWatch sw = new StopWatch();
    if (log.isDebugEnabled()) {
      log.debug("Updating errata cache");
      sw.start();
    }

    UpdateErrataCacheEvent uece = new UpdateErrataCacheEvent(UpdateErrataCacheEvent.TYPE_ORG);
    uece.setOrgId(orgIn.getId());
    MessageQueue.publish(uece);

    if (log.isDebugEnabled()) {
      sw.stop();
      log.debug("Finished Updating errata cache. Took [" + sw.getTime() + "]");
    }
  }
Ejemplo n.º 14
0
  protected void initIndex(SessionFactory sf) {
    log("starting initialize index");

    initIndexStopWatch.start();

    FullTextSession s = Search.getFullTextSession(sf.openSession());
    try {
      s.createIndexer().startAndWait();
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    } finally {
      s.close();
    }

    initIndexStopWatch.stop();
  }
  @Override
  protected Client createClient(Settings.Builder builder) {
    StopWatch stopWatch = new StopWatch();

    stopWatch.start();

    if (_log.isWarnEnabled()) {
      StringBundler sb = new StringBundler(6);

      sb.append("Liferay is configured to use embedded Elasticsearch ");
      sb.append("as its search engine. Do NOT use embedded ");
      sb.append("Elasticsearch in production. Embedded Elasticsearch ");
      sb.append("is useful for development and demonstration purposes. ");
      sb.append("Remote Elasticsearch connections can be configured in ");
      sb.append("the Control Panel.");

      _log.warn(sb);
    }

    if (_log.isDebugEnabled()) {
      _log.debug(
          "Starting embedded Elasticsearch cluster " + elasticsearchConfiguration.clusterName());
    }

    NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder();

    nodeBuilder.settings(builder);

    _node = nodeBuilder.node();

    _node.start();

    Client client = _node.client();

    if (_log.isDebugEnabled()) {
      stopWatch.stop();

      _log.debug(
          "Finished starting "
              + elasticsearchConfiguration.clusterName()
              + " in "
              + stopWatch.getTime()
              + " ms");
    }

    return client;
  }
Ejemplo n.º 16
0
  /** @param args */
  public static void main(String[] args) {
    String idxLocation = args[0];
    try {
      IndexWriter iw =
          new IndexWriter(idxLocation, new StandardAnalyzer(), MaxFieldLength.UNLIMITED);
      LOG.info("opened index " + idxLocation + " starting optimization...");
      StopWatch watch = new StopWatch();
      watch.start();

      iw.optimize();
      iw.close();

      watch.stop();
      LOG.info("done. took " + watch);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 17
0
  protected void initDatabase(SessionFactory sf) {
    log("starting initialize database");

    initDatabaseStopWatch.start();

    BatchSupport batchSupport = new BatchSupport(sf, initialOffset);
    batchSupport.execute(
        "insert into author(id, name) values(?, ?)",
        initialAutorCount,
        new BatchCallback() {
          @Override
          public void initStatement(PreparedStatement ps, long id) throws SQLException {
            ps.setLong(1, id);
            ps.setString(2, "autor" + id);
          }
        });
    batchSupport.execute(
        "insert into book(id, title, summary, rating, totalSold, publicationDate) values(?, ?, ?, ?, ?, ?)",
        initialBookCount,
        new BatchCallback() {
          @Override
          public void initStatement(PreparedStatement ps, long id) throws SQLException {
            ps.setLong(1, id);
            ps.setString(2, "title" + id);
            ps.setString(3, reverse(SUMMARIES[(int) (id % SUMMARIES.length)]));
            ps.setLong(4, -1);
            ps.setLong(5, -1);
            ps.setDate(6, new Date(PUBLICATION_DATE_ZERO.getTime()));
          }
        });
    batchSupport.execute(
        "insert into book_author(book_id, authors_id) values(?, ?)",
        initialBookCount,
        new BatchCallback() {
          @Override
          public void initStatement(PreparedStatement ps, long id) throws SQLException {
            ps.setLong(1, id);
            ps.setLong(2, initialOffset + (id % initialAutorCount));
          }
        });

    initDatabaseStopWatch.stop();
  }
 /**
  * Similar to {@link #testGetUserAvailability()}, but uses {@link FindItem}.
  *
  * @throws JAXBException
  */
 @Test
 public void testFindItemCalendarType() throws JAXBException {
   initializeCredentials();
   FindItem request =
       constructFindItemRequest(
           DateHelp.makeDate(startDate), DateHelp.makeDate(endDate), emailAddress);
   StopWatch stopWatch = new StopWatch();
   stopWatch.start();
   FindItemResponse response = ewsClient.findItem(request);
   stopWatch.stop();
   log.debug("FindItem request completed in " + stopWatch);
   Assert.assertNotNull(response);
   Assert.assertEquals(
       expectedEventCount,
       response
           .getResponseMessages()
           .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages()
           .size());
 }
Ejemplo n.º 19
0
  public void testLotsOfLoanRequests() throws Exception {
    final MuleClient client = new MuleClient();
    Customer c = new Customer("Ross Mason", 1234);
    CustomerQuoteRequest[] requests = new CustomerQuoteRequest[3];
    requests[0] = new CustomerQuoteRequest(c, 100000, 48);
    requests[1] = new CustomerQuoteRequest(c, 1000, 12);
    requests[2] = new CustomerQuoteRequest(c, 10, 24);

    final StopWatch stopWatch = new StopWatch();

    final int numRequests = getNumberOfRequests() + getWarmUpMessages();
    int i = 0;

    int numberOfThreads = 1;

    CountDownLatch latch = new CountDownLatch(numberOfThreads);
    ExceptionHolder exceptionHolder = new ExceptionHolder();
    try {
      for (int x = 0; x < numberOfThreads; x++) {
        Thread thread =
            new Thread(new ClientReceiver(latch, numRequests / numberOfThreads, exceptionHolder));
        thread.start();
      }

      for (i = 0; i < numRequests; i++) {
        if (i == getWarmUpMessages()) {
          stopWatch.start();
        }
        client.dispatch("CustomerRequests", requests[i % 3], null);
      }
    } finally {
      latch.await();
      stopWatch.stop();
      System.out.println("Total running time was: " + stopWatch.getTime() + "ms");
      System.out.println("Requests processed was: " + i);
      int mps = (int) (numRequests / ((double) stopWatch.getTime() / (double) 1000));
      System.out.println("Msg/sec: " + mps + " (warm up msgs = " + getWarmUpMessages() + ")");
      if (exceptionHolder.isExceptionThrown()) {
        exceptionHolder.print();
        fail("Exceptions thrown during async processing");
      }
    }
  }
  public MetadataSegment fetchMetadataOld(String type, String[] levels) throws RetsReplyException {
    // Always need system to get version and date
    MSystem system = findSystemFromHibernate();

    MetadataFinder finder = (MetadataFinder) sMetadataFinders.get(type);
    if (finder != null) {
      StopWatch stopWatch = new StopWatch();
      LOG.debug("Using finder for type: " + type);
      stopWatch.start();
      List metadata = finder.findMetadata(levels, mSessions);
      stopWatch.stop();
      LOG.debug("End finder: " + stopWatch.getTime());
      return new MetadataSegment(metadata, levels, system.getVersionString(), system.getDate());
    } else {
      LOG.warn(
          "Recieved query for unknown metadataResults type: "
              + type
              + ", level="
              + StringUtils.join(levels, ":"));
      throw new RetsReplyException(ReplyCode.INVALID_TYPE, type);
    }
  }
Ejemplo n.º 21
0
  protected void testIncomingConnection() throws MailException {
    StopWatch stopWatch = null;

    if (_log.isDebugEnabled()) {
      stopWatch = new StopWatch();

      stopWatch.start();
    }

    try {
      Store store = getStore(false);

      store.close();
    } catch (Exception e) {
      throw new MailException(MailException.ACCOUNT_INCOMING_CONNECTION_FAILED, e);
    } finally {
      if (_log.isDebugEnabled()) {
        stopWatch.stop();

        _log.debug("Testing incoming connection completed in " + stopWatch.getTime() + " ms");
      }
    }
  }
  /**
   * Creates a new document by document type name. The principal name passed in will be used as the
   * document initiator. If the initiatorPrincipalNm is null or blank, the current user will be
   * used.
   *
   * @see org.kuali.rice.krad.service.DocumentService#getNewDocument(String, String)
   */
  @Override
  public Document getNewDocument(String documentTypeName, String initiatorPrincipalNm)
      throws WorkflowException {

    // argument validation
    String watchName = "DocumentServiceImpl.getNewDocument";
    StopWatch watch = new StopWatch();
    watch.start();
    if (LOG.isDebugEnabled()) {
      LOG.debug(watchName + ": started");
    }
    if (StringUtils.isBlank(documentTypeName)) {
      throw new IllegalArgumentException("invalid (blank) documentTypeName");
    }
    if (GlobalVariables.getUserSession() == null) {
      throw new IllegalStateException(
          "GlobalVariables must be populated with a valid UserSession before a new document can be created");
    }

    // get the class for this docTypeName
    Class<? extends Document> documentClass = getDocumentClassByTypeName(documentTypeName);

    // get the initiator
    Person initiator = null;
    if (StringUtils.isBlank(initiatorPrincipalNm)) {
      initiator = GlobalVariables.getUserSession().getPerson();
    } else {
      initiator =
          KimApiServiceLocator.getPersonService().getPersonByPrincipalName(initiatorPrincipalNm);
      if (initiator == null) {
        initiator = GlobalVariables.getUserSession().getPerson();
      }
    }

    // get the authorization
    DocumentAuthorizer documentAuthorizer =
        getDocumentDictionaryService().getDocumentAuthorizer(documentTypeName);
    DocumentPresentationController documentPresentationController =
        getDocumentDictionaryService().getDocumentPresentationController(documentTypeName);
    // make sure this person is authorized to initiate
    if (LOG.isDebugEnabled()) {
      LOG.debug(
          "calling canInitiate from getNewDocument("
              + documentTypeName
              + ","
              + initiatorPrincipalNm
              + ")");
    }
    if (!documentPresentationController.canInitiate(documentTypeName)
        || !documentAuthorizer.canInitiate(documentTypeName, initiator)) {
      throw new DocumentAuthorizationException(
          initiator.getPrincipalName(), "initiate", documentTypeName);
    }

    // initiate new workflow entry, get the workflow doc
    WorkflowDocument workflowDocument =
        getWorkflowDocumentService().createWorkflowDocument(documentTypeName, initiator);
    UserSessionUtils.addWorkflowDocument(GlobalVariables.getUserSession(), workflowDocument);

    // create a new document header object
    DocumentHeader documentHeader = new DocumentHeader();
    documentHeader.setWorkflowDocument(workflowDocument);
    documentHeader.setDocumentNumber(workflowDocument.getDocumentId());

    // build Document of specified type
    Document document = null;
    try {
      // all maintenance documents have same class
      if (MaintenanceDocumentBase.class.isAssignableFrom(documentClass)) {
        Class<?>[] defaultConstructor = new Class[] {String.class};
        Constructor<? extends Document> cons = documentClass.getConstructor(defaultConstructor);
        if (cons == null) {
          throw new ConfigurationException(
              "Could not find constructor with document type name parameter needed for Maintenance Document Base class");
        }
        document = cons.newInstance(documentTypeName);
      } else {
        // non-maintenance document
        document = documentClass.newInstance();
      }
    } catch (IllegalAccessException e) {
      throw new RuntimeException("Error instantiating Document", e);
    } catch (InstantiationException e) {
      throw new RuntimeException("Error instantiating Document", e);
    } catch (SecurityException e) {
      throw new RuntimeException("Error instantiating Maintenance Document", e);
    } catch (NoSuchMethodException e) {
      throw new RuntimeException(
          "Error instantiating Maintenance Document: No constructor with String parameter found",
          e);
    } catch (IllegalArgumentException e) {
      throw new RuntimeException("Error instantiating Maintenance Document", e);
    } catch (InvocationTargetException e) {
      throw new RuntimeException("Error instantiating Maintenance Document", e);
    }

    document.setDocumentHeader(documentHeader);
    document.setDocumentNumber(documentHeader.getDocumentNumber());

    watch.stop();
    if (LOG.isDebugEnabled()) {
      LOG.debug(watchName + ": " + watch.toString());
    }

    return document;
  }
  @Test
  public void testFindCalendarObject() throws JAXBException {

    initializeCredentials();
    FindItem request =
        constructFindItemRequest(
            DateHelp.makeDate(startDate), DateHelp.makeDate(endDate), emailAddress);
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    FindItemResponse response = ewsClient.findItem(request);
    String captured = capture(response);
    log.info("testFindCalendarObject response: " + captured);
    stopWatch.stop();
    log.debug("FindItem request completed in " + stopWatch);
    Assert.assertNotNull(response);
    Assert.assertEquals(
        expectedEventCount,
        response
            .getResponseMessages()
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages()
            .size());

    List<JAXBElement<? extends ResponseMessageType>> responseList =
        response
            .getResponseMessages()
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();

    for (JAXBElement<? extends ResponseMessageType> rm : responseList) {
      // Class<? extends ResponseMessageType> rmt = rm.getDeclaredType();

      FindItemResponseMessageType itemType = (FindItemResponseMessageType) rm.getValue();
      FindItemParentType rootFolder = itemType.getRootFolder();
      ArrayOfRealItemsType itemArray = rootFolder.getItems();
      List<ItemType> items = itemArray.getItemsAndMessagesAndCalendarItems();

      // ArrayOfRealItemsType itemArray = itemType.getItems();
      Integer itemCount = new Integer(items.size());
      Integer currentItemNum = new Integer(1);

      for (ItemType item : items) {

        CalendarItemType calItem = (CalendarItemType) item;

        StringBuilder sb = new StringBuilder();
        sb.append("\n   ");
        sb.append("ItemId: " + calItem.getItemId().toString() + "\n   ");
        sb.append("ParentFolderId: " + calItem.getParentFolderId().toString() + "\n   ");
        sb.append("ItemClass: " + calItem.getItemClass().toString() + "\n   ");
        sb.append("Subject: " + calItem.getSubject().toString() + "\n   ");
        sb.append("Sensitivity: " + calItem.getSensitivity().toString() + "\n   ");
        sb.append("DateTimeReceived: " + calItem.getDateTimeReceived().toString() + "\n   ");
        sb.append("Size: " + calItem.getSize().toString() + "\n   ");
        sb.append("Importance: " + calItem.getImportance().toString() + "\n   ");
        sb.append("IsSubmitted: " + calItem.isIsSubmitted().toString() + "\n   ");
        sb.append("IsDraft: " + calItem.isIsDraft().toString() + "\n   ");
        sb.append("IsFromMe: " + calItem.isIsFromMe().toString() + "\n   ");
        sb.append("IsResend: " + calItem.isIsResend().toString() + "\n   ");
        sb.append("IsUnmodified: " + calItem.isIsUnmodified().toString() + "\n   ");
        sb.append("DateTimeSent: " + calItem.getDateTimeSent().toString() + "\n   ");
        sb.append("DateTimeCreated: " + calItem.getDateTimeCreated().toString() + "\n   ");
        sb.append("ReminderDueBy: " + calItem.getReminderDueBy().toString() + "\n   ");
        sb.append("ReminderIsSet: " + calItem.isReminderIsSet().toString() + "\n   ");
        sb.append(
            "ReminderMinutesBeforeStart: "
                + calItem.getReminderMinutesBeforeStart().toString()
                + "\n   ");
        sb.append("DisplayCc: " + calItem.getDisplayCc().toString() + "\n   ");
        sb.append("DisplayTo: " + calItem.getDisplayTo().toString() + "\n   ");
        sb.append("HasAttachments: " + calItem.isHasAttachments().toString() + "\n   ");
        sb.append("Culture: " + calItem.getCulture().toString() + "\n   ");
        if (calItem.getEffectiveRights() != null) {
          sb.append(
              "EffectiveRights.isCreateAssociated: "
                  + (calItem.getEffectiveRights() == null
                      ? "false"
                      : new Boolean(calItem.getEffectiveRights().isCreateAssociated()).toString())
                  + "\n   ");
          sb.append(
              "EffectiveRights.isCreateContents: "
                  + new Boolean(calItem.getEffectiveRights().isCreateContents()).toString()
                  + "\n   ");
          sb.append(
              "EffectiveRights.isCreateHierarchy: "
                  + new Boolean(calItem.getEffectiveRights().isCreateHierarchy()).toString()
                  + "\n   ");
          sb.append(
              "EffectiveRights.isDelete: "
                  + new Boolean(calItem.getEffectiveRights().isDelete()).toString()
                  + "\n   ");
          sb.append(
              "EffectiveRights.isModify: "
                  + new Boolean(calItem.getEffectiveRights().isModify()).toString()
                  + "\n   ");
        }
        // sb.append("LastModifiedName: "+calItem.getLastModifiedName().toString()+"\n   ");
        // sb.append("LastModifiedTime: "+calItem.getLastModifiedTime().toString()+"\n   ");
        // sb.append("IsAssociated: "+calItem.isIsAssociated().toString()+"\n   ");
        // sb.append("WebClientReadFormQueryString:
        // "+calItem.getWebClientReadFormQueryString().toString()+"\n   ");
        /// sb.append("WebClientEditFormQueryString:
        // "+calItem.getWebClientEditFormQueryString().toString()+"\n   ");
        // sb.append("UID: "+calItem.getUID().toString()+"\n   ");
        // sb.append("DateTimeStamp: "+calItem.getDateTimeStamp().toString()+"\n   ");
        sb.append("Start: " + calItem.getStart().toString() + "\n   ");
        sb.append("End: " + calItem.getEnd().toString() + "\n   ");
        sb.append("IsAllDayEvent: " + calItem.isIsAllDayEvent().toString() + "\n   ");
        sb.append(
            "LegacyFreeBusyStatus: " + calItem.getLegacyFreeBusyStatus().toString() + "\n   ");
        if (null != calItem.getLocation())
          sb.append("Location: " + calItem.getLocation().toString() + "\n   ");
        sb.append("IsMeeting: " + calItem.isIsMeeting().toString() + "\n   ");
        sb.append("IsCancelled: " + calItem.isIsCancelled().toString() + "\n   ");
        sb.append("IsRecurring: " + calItem.isIsRecurring().toString() + "\n   ");
        // sb.append("MeetingRequestWasSent: "+calItem.getMeetingRequestWasSent().toString()+"\n
        // ");
        sb.append("IsResponseRequested: " + calItem.isIsResponseRequested().toString() + "\n   ");
        sb.append("CalendarItemType: " + calItem.getCalendarItemType().toString() + "\n   ");
        sb.append("MyResponseType: " + calItem.getMyResponseType().toString() + "\n   ");
        sb.append("OrganizerName: " + calItem.getOrganizer().getMailbox().getName() + "\n   ");
        sb.append(
            "OrganizerName: " + calItem.getOrganizer().getMailbox().getMailboxType() + "\n   ");
        sb.append("Duration: " + calItem.getDuration().toString() + "\n   ");
        sb.append("TimeZone: " + calItem.getTimeZone().toString() + "\n   ");
        sb.append(
            "AppointmentSequenceNumber: "
                + calItem.getAppointmentSequenceNumber().toString()
                + "\n   ");
        sb.append("AppointmentState: " + calItem.getAppointmentState().toString() + "\n   ");

        // log.debug("FoundCalendarItem ("+currentItemNum.toString()+" of
        // "+itemCount.toString()+"):" + sb.toString());
        currentItemNum++;
      }

      // ItemType item = itemArray.getItemsAndMessagesAndCalendarItems().get(0);

      // Fields[] fields = rmt.getFields();
    }
  }
Ejemplo n.º 24
0
  @Override
  public void drive() {
    // A Consumer is not thread-safe
    // {@see
    // http://kafka.apache.org/090/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html}
    // {@see
    // http://kafka.apache.org/090/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#multithreaded}
    try (KafkaConsumer<byte[], byte[]> consumer =
        new KafkaConsumer<>(consumerDefinition.getKafkaConfig())) {

      String topic = consumerDefinition.getTopic();
      log.info("Subscribing to {}", topic);
      if (consumerRebalanceListener == null) {
        consumer.subscribe(Collections.singletonList(topic));
      } else {
        consumer.subscribe(Collections.singletonList(topic), consumerRebalanceListener);
      }

      long messagesToReceive = consumerDefinition.getMessagesToReceive();
      log.info("Expecting {} messages", messagesToReceive);

      StopWatch stopWatch = new StopWatch();
      stopWatch.start();

      do {
        ConsumerRecords<byte[], byte[]> records =
            consumer.poll(consumerDefinition.getPollTimeout());
        if (records == null) {
          throw new IllegalStateException("null ConsumerRecords polled");
        } else {
          if (records.count() == 0) {
            try {
              log.info("No records fetched, pausing");
              Thread.sleep(1000);
            } catch (InterruptedException e) {
              throw new RuntimeException(e);
            }
          } else {
            if (log.isTraceEnabled()) {
              log.trace("Fetched {} records", records.count());
            }
            for (ConsumerRecord<byte[], byte[]> record : records) {
              recordsFetched += 1;
              applyReceiveDelay();
              if (recordsFetched % consumerDefinition.getReportReceivedEvery() == 0) {
                log.info("Received {} messages", recordsFetched);
              }
            }
          }
        }

        if (isShutdownRequested()) {
          break;
        }
        stopWatch.split();
      } while ((recordsFetched < messagesToReceive)
          && (stopWatch.getSplitTime() < consumerDefinition.getTestRunTimeout()));

      stopWatch.stop();
      if (isShutdownRequested()) {
        log.info("Shutting down");
      } else {
        long runTime = stopWatch.getTime();
        log.info("Done. Consumer received {} msgs in {} ms", messagesToReceive, runTime);

        double averageThroughput = (1000d / runTime) * messagesToReceive;
        log.info("Average throughput: {} msg/s", averageThroughput);
      }

    } finally {
      log.debug("Consumer closed");
      if (completionLatch != null) {
        completionLatch.countDown();
      }
    }
  }
Ejemplo n.º 25
0
  @Test
  public void testPutQueryDelete() throws ExecutionException, InterruptedException {
    int numItems = 1;
    String x;
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
    PerformanceTestObject o = new PerformanceTestObject();
    o.setS1("first to create domain");
    em.persist(o);
    StopWatch stopWatch = new StopWatch();

    String s1a = "attribute1";
    String s2a = "attribute2";
    Future<PerformanceTestObject> lastFuture = null;
    stopWatch.start();
    for (int i = 0; i < numItems; i++) {
      o = new PerformanceTestObject();
      o.setS1(s1a);
      o.setS2(s2a);
      lastFuture = em.persistAsync(o);
    }
    lastFuture.get(); // not 100% accurate, but good enough
    stopWatch.stop();
    System.out.println(
        "puts duration="
            + stopWatch.getTime()
            + ", "
            + em.getTotalOpStats().getPuts()
            + " items put.");

    Thread.sleep(5000);

    stopWatch.reset();
    stopWatch.start();
    Query query = em.createQuery("select o from PerformanceTestObject o");
    List<PerformanceTestObject> resultList = query.getResultList();
    System.out.println("iterating result list...");
    int i = 0;
    for (PerformanceTestObject performanceTestObject : resultList) {

      i++;
      if (i % 100 == 0) {
        System.out.println(i);
      }
    }
    stopWatch.stop();
    System.out.println(
        "query ALL duration="
            + stopWatch.getTime()
            + ", "
            + em.getTotalOpStats().getGets()
            + " items got.");

    stopWatch.reset();
    stopWatch.start();
    System.out.println("Deleting ALL...");
    for (PerformanceTestObject performanceTestObject : resultList) {
      lastFuture = em.removeAsync(o);
    }
    lastFuture.get();
    stopWatch.stop();
    System.out.println(
        "delete duration=" + stopWatch.getTime() + ", " + resultList.size() + " items deleted.");
    System.out.println("sleeping...");
    Thread.sleep(30000);

    em.close();
  }
 @Override
 public Observable<Void> stop() {
   stopWatch.stop();
   stopWatchState = STATE_STOPPED;
   return Observable.just(null);
 }
  /** @see DataSetEvaluator#evaluate(DataSetDefinition, EvaluationContext) */
  @SuppressWarnings("unchecked")
  public DataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext context)
      throws EvaluationException {

    PatientDataSetDefinition dsd = (PatientDataSetDefinition) dataSetDefinition;
    context = ObjectUtil.nvl(context, new EvaluationContext());

    SimpleDataSet dataSet = new SimpleDataSet(dsd, context);
    dataSet.setSortCriteria(dsd.getSortCriteria());

    // Construct a new EvaluationContext based on the passed filters
    Cohort c = context.getBaseCohort();
    if (dsd.getRowFilters() != null) {
      for (Mapped<? extends CohortDefinition> q : dsd.getRowFilters()) {
        Cohort s = Context.getService(CohortDefinitionService.class).evaluate(q, context);
        c = CohortUtil.intersectNonNull(c, s);
      }
    }
    if (c == null) {
      c =
          Context.getService(CohortDefinitionService.class)
              .evaluate(new AllPatientsCohortDefinition(), context);
    }

    EvaluationContext ec = context.shallowCopy();
    if (!CohortUtil.areEqual(ec.getBaseCohort(), c)) {
      ec.setBaseCohort(c);
    }

    // Evaluate each specified ColumnDefinition for all of the included rows and add these to the
    // dataset
    for (RowPerObjectColumnDefinition cd : dsd.getColumnDefinitions()) {

      if (log.isDebugEnabled()) {
        log.debug("Evaluating column: " + cd.getName());
        log.debug(
            "With Data Definition: "
                + DefinitionUtil.format(cd.getDataDefinition().getParameterizable()));
        log.debug("With Mappings: " + cd.getDataDefinition().getParameterMappings());
        log.debug("With Parameters: " + ec.getParameterValues());
      }
      StopWatch sw = new StopWatch();
      sw.start();

      MappedData<? extends PatientDataDefinition> dataDef =
          (MappedData<? extends PatientDataDefinition>) cd.getDataDefinition();
      EvaluatedPatientData data =
          Context.getService(PatientDataService.class).evaluate(dataDef, ec);

      for (Integer id : c.getMemberIds()) {
        for (DataSetColumn column : cd.getDataSetColumns()) {
          Object val = data.getData().get(id);
          val = DataUtil.convertData(val, dataDef.getConverters());
          dataSet.addColumnValue(id, column, val);
        }
      }

      sw.stop();
      if (log.isDebugEnabled()) {
        log.debug("Evaluated column. Duration: " + sw.toString());
      }
    }

    return dataSet;
  }
Ejemplo n.º 28
0
  public void resolveNames(Long batchSize) {
    StopWatch watchForEntireRun = new StopWatch();
    watchForEntireRun.start();
    StopWatch watchForBatch = new StopWatch();
    watchForBatch.start();
    Long count = 0L;

    Index<Node> studyIndex = graphService.index().forNodes("studies");
    IndexHits<Node> studies = studyIndex.query("title", "*");
    for (Node studyNode : studies) {
      final Study study1 = new Study(studyNode);
      final Iterable<Relationship> specimens = study1.getSpecimens();
      for (Relationship collected : specimens) {
        Specimen specimen = new Specimen(collected.getEndNode());
        final Relationship classifiedAs =
            specimen
                .getUnderlyingNode()
                .getSingleRelationship(RelTypes.CLASSIFIED_AS, Direction.OUTGOING);
        if (classifiedAs == null) {
          final Relationship describedAs =
              specimen
                  .getUnderlyingNode()
                  .getSingleRelationship(RelTypes.ORIGINALLY_DESCRIBED_AS, Direction.OUTGOING);
          final TaxonNode describedAsTaxon = new TaxonNode(describedAs.getEndNode());
          try {
            if (taxonFilter.shouldInclude(describedAsTaxon)) {
              TaxonNode resolvedTaxon = taxonIndex.getOrCreateTaxon(describedAsTaxon);
              if (resolvedTaxon != null) {
                specimen.classifyAs(resolvedTaxon);
              }
            }
          } catch (NodeFactoryException e) {
            LOG.warn(
                "failed to create taxon with name ["
                    + describedAsTaxon.getName()
                    + "] and id ["
                    + describedAsTaxon.getExternalId()
                    + "]",
                e);
          } finally {
            count++;
            if (count % batchSize == 0) {
              watchForBatch.stop();
              final long duration = watchForBatch.getTime();
              if (duration > 0) {
                LOG.info(
                    "resolved batch of ["
                        + batchSize
                        + "] names in "
                        + getProgressMsg(batchSize, duration));
              }
              watchForBatch.reset();
              watchForBatch.start();
            }
          }
        }
      }
    }
    studies.close();
    watchForEntireRun.stop();
    LOG.info(
        "resolved [" + count + "] names in " + getProgressMsg(count, watchForEntireRun.getTime()));
  }