Package org.apache.commons.lang.time

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


                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();

            String wagonProtocol = new URL( this.remoteRepository.getUrl() ).getProtocol();

            final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(
                new WagonFactoryRequest( wagonProtocol, this.remoteRepository.getExtraHeaders() ).networkProxy(
                    this.networkProxy )
            );
            // FIXME olamy having 2 config values
            wagon.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
            wagon.setTimeout( remoteRepository.getTimeout() * 1000 );

            if ( wagon instanceof AbstractHttpClientWagon )
            {
                HttpConfiguration httpConfiguration = new HttpConfiguration();
                HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
                httpMethodConfiguration.setUsePreemptive( true );
                httpMethodConfiguration.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
                httpConfiguration.setGet( httpMethodConfiguration );
                AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
            }

            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, remoteRepository );
            IndexUpdateRequest request = new IndexUpdateRequest( indexingContext, resourceFetcher );
            request.setForceFullUpdate( this.fullDownload );
            request.setLocalIndexCacheDir( indexCacheDirectory );

            this.indexUpdater.fetchAndUpdateIndex( request );
            stopWatch.stop();
            log.info( "time update index from remote for repository {}: {} s", this.remoteRepository.getId(),
                      ( stopWatch.getTime() / 1000 ) );

            // index packing optionnal ??
            //IndexPackingRequest indexPackingRequest =
            //    new IndexPackingRequest( indexingContext, indexingContext.getIndexDirectoryFile() );
            //indexPacker.packIndex( indexPackingRequest );
View Full Code Here


        {
            throw new ArchivaException(
                "Unable to initialize the Redback Security Environment, " + "no Environment Check components found." );
        }

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

        List<String> violations = new ArrayList<>();

        for ( Entry<String, EnvironmentCheck> entry : checkers.entrySet() )
        {
            EnvironmentCheck check = entry.getValue();
            List<String> v = new ArrayList<>();
            check.validateEnvironment( v );
            log.info( "Environment Check: {} -> {} violation(s)", entry.getKey(), v.size() );
            for ( String s : v )
            {
                violations.add( "[" + entry.getKey() + "] " + s );
            }
        }

        if ( CollectionUtils.isNotEmpty( violations ) )
        {
            StringBuilder msg = new StringBuilder();
            msg.append( "EnvironmentCheck Failure.\n" );
            msg.append( "======================================================================\n" );
            msg.append( " ENVIRONMENT FAILURE !! \n" );
            msg.append( "\n" );

            for ( String violation : violations )
            {
                msg.append( violation ).append( "\n" );
            }

            msg.append( "\n" );
            msg.append( "======================================================================" );
            log.error( msg.toString() );

            throw new ArchivaException( "Unable to initialize Redback Security Environment, [" + violations.size()
                                            + "] violation(s) encountered, See log for details." );
        }

        stopWatch.stop();
        log.info( "time to execute all EnvironmentCheck: {} ms", stopWatch.getTime() );
    }
View Full Code Here

    @Override
    public RepositoryStatistics getLastStatistics( MetadataRepository metadataRepository, String repositoryId )
        throws MetadataRepositoryException
    {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        // TODO: consider a more efficient implementation that directly gets the last one from the content repository
        List<String> scans = metadataRepository.getMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID );
        if ( scans == null )
        {
            return null;
        }
        Collections.sort( scans );
        if ( !scans.isEmpty() )
        {
            String name = scans.get( scans.size() - 1 );
            RepositoryStatistics repositoryStatistics =
                RepositoryStatistics.class.cast( metadataRepository.getMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID,
                                                                            name ));
            stopWatch.stop();
            log.debug( "time to find last RepositoryStatistics: {} ms", stopWatch.getTime() );
            return repositoryStatistics;
        }
        else
        {
            return null;
View Full Code Here

        if ( !StringUtils.equals( repositorySessionFactoryBean.getId(), "jcr" ) )
        {
            return;
        }

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

        metadataFacetFactories = applicationContext.getBeansOfType( MetadataFacetFactory.class );
        // olamy with spring the "id" is now "metadataFacetFactory#hint"
        // whereas was only hint with plexus so let remove  metadataFacetFactory#
        Map<String, MetadataFacetFactory> cleanedMetadataFacetFactories =
            new HashMap<>( metadataFacetFactories.size() );

        for ( Map.Entry<String, MetadataFacetFactory> entry : metadataFacetFactories.entrySet() )
        {
            cleanedMetadataFacetFactories.put( StringUtils.substringAfterLast( entry.getKey(), "#" ),
                                               entry.getValue() );
        }

        metadataFacetFactories = cleanedMetadataFacetFactories;

        JcrMetadataRepository metadataRepository = null;
        try
        {
            metadataRepository = new JcrMetadataRepository( metadataFacetFactories, repository );
            JcrMetadataRepository.initialize( metadataRepository.getJcrSession() );
        }
        catch ( RepositoryException e )
        {
            throw new RuntimeException( e.getMessage(), e );
        }
        finally
        {
            if ( metadataRepository != null )
            {
                metadataRepository.close();
            }
        }

        stopWatch.stop();
        logger.info( "time to initialize JcrRepositorySessionFactory: {}", stopWatch.getTime() );
    }
View Full Code Here

     * @throws MalformedURLException in case of a bad document URL
     * @throws IOException in case of I/O errors
     * @throws ServiceException in case of Google Data API errors
     */
    public InputStream downloadFile(String exportUrl) throws IOException, MalformedURLException, ServiceException {
        StopWatch watch = new StopWatch();
        watch.start();
        logger.info("Retrieving content for document from: " + exportUrl);

        MediaContent mc = new MediaContent();
        mc.setUri(exportUrl);
        MediaSource ms = service.getMedia(mc);

        InputStream inStream = ms.getInputStream();

        watch.stop();
        logger.info("Got content stream in " + watch.getTime() + " ms");

        return inStream;
    }
View Full Code Here

     * @throws IOException in case of I/O errors
     * @throws ServiceException in case of Google Data API errors
     */
    public void downloadFile(String exportUrl, OutputStream out) throws IOException, MalformedURLException,
            ServiceException {
        StopWatch watch = new StopWatch();
        watch.start();
        logger.info("Exporting document from: " + exportUrl);

        MediaContent mc = new MediaContent();
        mc.setUri(exportUrl);
        MediaSource ms = service.getMedia(mc);

        InputStream inStream = null;

        try {
            inStream = ms.getInputStream();
            IOUtils.copy(inStream, out);
            out.flush();
        } finally {
            IOUtils.closeQuietly(inStream);
        }

        watch.stop();
        logger.info("Downloaded file in " + watch.getTime() + " ms");
    }
View Full Code Here

     * @return the default document upload folder in Google Docs
     * @throws IOException in case of I/O errors
     * @throws ServiceException in case of Google Data API errors
     */
    protected DocumentListEntry getDefaultTargetFolder() throws IOException, ServiceException {
        StopWatch watch = new StopWatch();
        watch.start();
        DocumentListEntry folder = null;
        DocumentListFeed feed = service.getFeed(new URL("https://docs.google.com/"
                + "feeds/default/private/full/folder%3Aroot/contents/-/folder?title=" + defaultTargetFolderName),
                DocumentListFeed.class);
        List<DocumentListEntry> entries = feed.getEntries();

        if (!entries.isEmpty()) {
            folder = entries.get(0);
        } else {
            DocumentListEntry newEntry = new FolderEntry();
            newEntry.setTitle(new PlainTextConstruct(defaultTargetFolderName));
            folder = service.insert(new URL("https://docs.google.com/feeds/default/private/full/"), newEntry);
        }

        watch.stop();
        logger.info("Getting target folder took " + watch.getTime() + " ms");

        return folder;
    }
View Full Code Here

     * @return the uploaded document entry
     * @throws IOException in case of I/O errors
     * @throws ServiceException in case of Google Data API errors
     */
    protected DocumentListEntry upload(File file, URL targetFolderUri) throws IOException, ServiceException {
        StopWatch watch = new StopWatch();
        watch.start();
        logger.info("Uploading content for: " + file.getName());
        DocumentListEntry newDocument = new DocumentListEntry();
        String mimeType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
        newDocument.setFile(file, mimeType);
        newDocument.setTitle(new PlainTextConstruct(file.getName()));

        DocumentListEntry uploadedFile = service.insert(targetFolderUri, newDocument);

        watch.stop();
        logger.info("File " + file + " uploaded in " + watch.getTime() + " ms");

        return uploadedFile;
    }
View Full Code Here

     * @throws IOException in case of I/O errors
     * @throws ServiceException in case of Google Data API errors
     */
    protected DocumentListEntry upload(InputStream fileStream, String documentTitle, String mimeType,
            URL targetFolderUri) throws IOException, ServiceException {
        StopWatch watch = new StopWatch();
        watch.start();
        logger.info("Uploading content for: " + documentTitle);

        DocumentListEntry newDocument = new DocumentListEntry();
        newDocument.setTitle(new PlainTextConstruct(documentTitle));

        MediaContent content = new MediaContent();
        content.setMediaSource(new MediaStreamSource(fileStream, mimeType));
        content.setMimeType(new ContentType(mimeType));
        newDocument.setContent(content);

        DocumentListEntry uploadedFile = service.insert(targetFolderUri, newDocument);

        watch.stop();
        logger.info("File " + documentTitle + " uploaded in " + watch.getTime() + " ms");

        return uploadedFile;
    }
View Full Code Here

           
            if( req != null && m_akismet != null )
            {
                log.debug("Calling Akismet to check for spam...");

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

                String ipAddress     = req.getRemoteAddr();
                String userAgent     = req.getHeader("User-Agent");
                String referrer      = req.getHeader( "Referer");
                String permalink     = context.getViewURL( context.getPage().getName() );
                String commentType   = context.getRequestContext().equals(WikiContext.COMMENT) ? "comment" : "edit";
                String commentAuthor = context.getCurrentUser().getName();
                String commentAuthorEmail = null;
                String commentAuthorURL   = null;

                boolean isSpam = m_akismet.commentCheck( ipAddress,
                                                         userAgent,
                                                         referrer,
                                                         permalink,
                                                         commentType,
                                                         commentAuthor,
                                                         commentAuthorEmail,
                                                         commentAuthorURL,
                                                         change.toString(),
                                                         null );

                sw.stop();

                log.debug("Akismet request done in: "+sw);

                if( isSpam )
                {
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.