Package org.apache.commons.lang.time

Examples of org.apache.commons.lang.time.StopWatch


        }

        // Holds any exception that was thrown during startup
        final ObjectHolder errorHolder = new ObjectHolder();

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

        // Start the server int a seperate thread
        Thread t = new Thread("Geronimo Server Runner") {
            public void run() {
                try {
View Full Code Here


    HTableDescriptor tableDesc = table.getTableDescriptor();
    byte[] startKey = null;
    Get get = null;
    Scan scan = null;
    ResultScanner rs = null;
    StopWatch stopWatch = new StopWatch();
    for (HColumnDescriptor column : tableDesc.getColumnFamilies()) {
      stopWatch.reset();
      startKey = region.getStartKey();
      // Can't do a get on empty start row so do a Scan of first element if any instead.
      if (startKey.length > 0) {
        get = new Get(startKey);
        get.addFamily(column.getName());
      } else {
        scan = new Scan();
        scan.setCaching(1);
        scan.addFamily(column.getName());
        scan.setMaxResultSize(1L);
      }

      try {
        if (startKey.length > 0) {
          stopWatch.start();
          table.get(get);
          stopWatch.stop();
          sink.publishReadTiming(region, column, stopWatch.getTime());
        } else {
          stopWatch.start();
          rs = table.getScanner(scan);
          stopWatch.stop();
          sink.publishReadTiming(region, column, stopWatch.getTime());
        }
      } catch (Exception e) {
        sink.publishReadFailure(region, column, e);
      } finally {
        if (rs != null) {
View Full Code Here

      HRegionInfo region = null;
      HTable table = null;
      Get get = null;
      byte[] startKey = null;
      Scan scan = null;
      StopWatch stopWatch = new StopWatch();
      // monitor one region on every region server
      for (Map.Entry<String, List<HRegionInfo>> entry : rsAndRMap.entrySet()) {
        stopWatch.reset();
        serverName = entry.getKey();
        // always get the first region
        region = entry.getValue().get(0);
        try {
          tableName = region.getTable().getNameAsString();
          table = new HTable(this.admin.getConfiguration(), tableName);
          startKey = region.getStartKey();
          // Can't do a get on empty start row so do a Scan of first element if any instead.
          if(startKey.length > 0) {
            get = new Get(startKey);
            stopWatch.start();
            table.get(get);
            stopWatch.stop();
          } else {
            scan = new Scan();
            scan.setCaching(1);
            scan.setMaxResultSize(1L);
            stopWatch.start();
            table.getScanner(scan);
            stopWatch.stop();
          }
          this.getSink().publishReadTiming(tableName, serverName, stopWatch.getTime());
        } catch (TableNotFoundException tnfe) {
          // This is ignored because it doesn't imply that the regionserver is dead
        } catch (TableNotEnabledException tnee) {
          // This is considered a success since we got a response.
          LOG.debug("The targeted table was disabled.  Assuming success.");
View Full Code Here

        }

        // Holds any exception that was thrown during startup
        final ObjectHolder errorHolder = new ObjectHolder();

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

        // Start the server int a seperate thread
        Thread t = new Thread("Geronimo Server Runner") {
            public void run() {
                try {
View Full Code Here

    MRPipelineExecution exec = pipeline.runAsync();

    // Wait until both of the two jobs are submitted.
    List<MRJob> jobs = exec.getJobs();
    assertEquals(2, jobs.size());
    StopWatch watch = new StopWatch();
    watch.start();
    int numOfJobsSubmitted = 0;
    while (numOfJobsSubmitted < 2 && watch.getTime() < 10000) {
      numOfJobsSubmitted = 0;
      for (MRJob job : jobs) {
        if (job.getJobState() == MRJob.State.RUNNING) {
          numOfJobsSubmitted++;
        }
      }
      Thread.sleep(100);
    }
    assertEquals(2, numOfJobsSubmitted);

    // Kill one of them.
    Job job0 = jobs.get(0).getJob();
    job0.killJob();

    // Expect the pipeline exits and the other job is killed.
    StopWatch watch2 = new StopWatch();
    watch2.start();
    Job job1 = jobs.get(1).getJob();
    while (!job1.isComplete() && watch2.getTime() < 10000) {
      Thread.sleep(100);
    }
    assertTrue(job1.isComplete());
    assertEquals(PipelineExecution.Status.FAILED, exec.getStatus());
  }
View Full Code Here

        }

        // Holds any exception that was thrown during startup
        final ObjectHolder errorHolder = new ObjectHolder();

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

        // Start the server int a seperate thread
        Thread t = new Thread("Geronimo Server Runner") {
            public void run() {
                try {
View Full Code Here

            return null;
        }

        runningGroups.add( groupId );

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

        File mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();

        String tempRepoId = mergedIndexDirectory.getName();

        try
        {
            File indexLocation = new File( mergedIndexDirectory, indexMergerRequest.getMergedIndexPath() );
            IndexingContext indexingContext =
                indexer.addIndexingContext( tempRepoId, tempRepoId, mergedIndexDirectory, indexLocation, null, null,
                                            mavenIndexerUtils.getAllIndexCreators() );

            for ( String repoId : indexMergerRequest.getRepositoriesIds() )
            {
                IndexingContext idxToMerge = indexer.getIndexingContexts().get( repoId );
                if ( idxToMerge != null )
                {
                    indexingContext.merge( idxToMerge.getIndexDirectory() );
                }
            }

            indexingContext.optimize();

            if ( indexMergerRequest.isPackIndex() )
            {
                IndexPackingRequest request = new IndexPackingRequest( indexingContext, indexLocation );
                indexPacker.packIndex( request );
            }

            if ( indexMergerRequest.isTemporary() )
            {
                temporaryGroupIndexes.add( new TemporaryGroupIndex( mergedIndexDirectory, tempRepoId, groupId,
                                                                    indexMergerRequest.getMergedIndexTtl() ) );
            }
            stopWatch.stop();
            log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(),
                      stopWatch.getTime() );
            return indexingContext;
        }
        catch ( IOException e )
        {
            throw new IndexMergerException( e.getMessage(), e );
View Full Code Here

                return;
            }
            this.runningRemoteDownloadIds.add( this.remoteRepository.getId() );
        }
        File tempIndexDirectory = null;
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        try
        {
            log.info( "start download remote index for remote repository " + this.remoteRepository.getId() );
            IndexingContext indexingContext = remoteRepositoryAdmin.createIndexContext( this.remoteRepository );

            // create a temp directory to download files
            tempIndexDirectory = new File( indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex" );
            File indexCacheDirectory = new File( indexingContext.getIndexDirectoryFile().getParent(), ".indexCache" );
            indexCacheDirectory.mkdirs();
            if ( tempIndexDirectory.exists() )
            {
                FileUtils.deleteDirectory( tempIndexDirectory );
            }
            tempIndexDirectory.mkdirs();
            tempIndexDirectory.deleteOnExit();
            String baseIndexUrl = indexingContext.getIndexUpdateUrl();

            final Wagon wagon = wagonFactory.getWagon( new URL( this.remoteRepository.getUrl() ).getProtocol() );
            setupWagonReadTimeout( wagon );

            // TODO transferListener
            wagon.addTransferListener( new DownloadListener() );
            ProxyInfo proxyInfo = null;
            if ( this.networkProxy != null )
            {
                proxyInfo = new ProxyInfo();
                proxyInfo.setHost( this.networkProxy.getHost() );
                proxyInfo.setPort( this.networkProxy.getPort() );
                proxyInfo.setUserName( this.networkProxy.getUsername() );
                proxyInfo.setPassword( this.networkProxy.getPassword() );
            }
            AuthenticationInfo authenticationInfo = null;
            if ( this.remoteRepository.getUserName() != null )
            {
                authenticationInfo = new AuthenticationInfo();
                authenticationInfo.setUserName( this.remoteRepository.getUserName() );
                authenticationInfo.setPassword( this.remoteRepository.getPassword() );
            }
            wagon.connect( new Repository( this.remoteRepository.getId(), baseIndexUrl ), authenticationInfo,
                           proxyInfo );

            File indexDirectory = indexingContext.getIndexDirectoryFile();
            if ( !indexDirectory.exists() )
            {
                indexDirectory.mkdirs();
            }

            ResourceFetcher resourceFetcher = new WagonResourceFetcher( log, tempIndexDirectory, wagon );
            IndexUpdateRequest request = new IndexUpdateRequest( indexingContext, resourceFetcher );
            request.setForceFullUpdate( this.fullDownload );
            request.setLocalIndexCacheDir( indexCacheDirectory );

            this.indexUpdater.fetchAndUpdateIndex( request );
            stopWatch.stop();
            log.info( "time to download remote repository index for repository {}: {} s", this.remoteRepository.getId(),
                      ( stopWatch.getTime() / 1000 ) );
        }
        catch ( MalformedURLException e )
        {
            log.error( e.getMessage(), e );
            throw new RuntimeException( e.getMessage(), e );
View Full Code Here

        }

        // Holds any exception that was thrown during startup
        final ObjectHolder errorHolder = new ObjectHolder();

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

        // Start the server int a seperate thread
        Thread t = new Thread("Geronimo Server Runner") {
            public void run() {
                try {
View Full Code Here

                // the batch size can be overriden by the request
                final int resultIterationBatchSize = (Integer) requestMessage.optionalArgs(Tokens.ARGS_BATCH_SIZE).orElse(settings.resultIterationBatchSize);

                // timer for the total serialization time
                final StopWatch stopWatch = new StopWatch();

                final EventExecutorGroup executorService = ctx.executor();
                final Future<?> iteration = executorService.submit((Callable<Void>) () -> {
                    logger.debug("Preparing to iterate results from - {} - in thread [{}]", requestMessage, Thread.currentThread().getName());

                    stopWatch.start();

                    List<Object> aggregate = new ArrayList<>(resultIterationBatchSize);
                    while (itty.hasNext()) {
                        aggregate.add(itty.next());

                        // send back a page of results if batch size is met or if it's the end of the results being
                        // iterated
                        if (aggregate.size() == resultIterationBatchSize || !itty.hasNext()) {
                            ctx.writeAndFlush(ResponseMessage.build(requestMessage)
                                    .code(ResponseStatusCode.SUCCESS)
                                    .result(aggregate).create());
                            aggregate = new ArrayList<>(resultIterationBatchSize);
                        }

                        stopWatch.split();
                        if (stopWatch.getSplitTime() > settings.serializedResponseTimeout)
                            throw new TimeoutException("Serialization of the entire response exceeded the serializeResponseTimeout setting");

                        stopWatch.unsplit();
                    }

                    return null;
                });

                iteration.addListener(f -> {
                    stopWatch.stop();

                    if (!f.isSuccess()) {
                        final String errorMessage = String.format("Response iteration and serialization exceeded the configured threshold for request [%s] - %s", msg, f.cause().getMessage());
                        logger.warn(errorMessage);
                        ctx.writeAndFlush(ResponseMessage.build(requestMessage).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage(errorMessage).create());
View Full Code Here

TOP

Related Classes of org.apache.commons.lang.time.StopWatch

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.