Example usage for org.apache.commons.lang.time StopWatch StopWatch

List of usage examples for org.apache.commons.lang.time StopWatch StopWatch

Introduction

In this page you can find the example usage for org.apache.commons.lang.time StopWatch StopWatch.

Prototype

public StopWatch() 

Source Link

Document

Constructor.

Usage

From source file:com.liferay.portal.mobile.device.wurfl.WURFLKnownDevices.java

protected void loadWURFLDevices() {
    if (_initialized) {
        return;//  w  w  w . j  a v  a  2 s.com
    }

    WURFLUtils wurflUtils = _wurflHolder.getWURFLUtils();

    if (wurflUtils == null) {
        _log.error("Unable to load WURFL devices");

        return;
    }

    StopWatch stopWatch = null;

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

        stopWatch.start();

        _log.debug("Loading database");
    }

    Map<String, VersionableName> brands = new HashMap<String, VersionableName>();
    Map<String, VersionableName> browsers = new HashMap<String, VersionableName>();
    Map<String, VersionableName> operatingSystems = new HashMap<String, VersionableName>();

    for (Object deviceIdObject : wurflUtils.getAllDevicesId()) {
        String deviceId = (String) deviceIdObject;

        Device device = wurflUtils.getDeviceById(deviceId);

        updateVersionableCapability(device, brands, WURFLConstants.BRAND_NAME, WURFLConstants.MODEL_NAME,
                WURFLConstants.MARKETING_NAME);

        updateVersionableCapability(device, browsers, WURFLConstants.MOBILE_BROWSER,
                WURFLConstants.MOBILE_BROWSER_VERSION, null);

        updateVersionableCapability(device, operatingSystems, WURFLConstants.DEVICE_OS,
                WURFLConstants.DEVICE_OS_VERSION, null);

        updateCapability(device, _pointingMethods, WURFLConstants.POINTING_METHOD);

        updateDevicesIds(device, WURFLConstants.DEVICE_OS);
    }

    _brands = new TreeSet<VersionableName>(brands.values());
    _browsers = new TreeSet<VersionableName>(browsers.values());
    _operatingSystems = new TreeSet<VersionableName>(operatingSystems.values());

    if (_log.isDebugEnabled()) {
        _log.debug("Loaded database in " + stopWatch.getTime() + " ms");
    }

    _initialized = true;
}

From source file:biz.netcentric.cq.tools.actool.aceservicejmx.impl.AceServiceMBeanImpl.java

@Override
public String pathBasedDump() {
    StopWatch sw = new StopWatch();
    sw.start();//from ww  w.  j a v  a 2  s . co  m
    String dump = dumpservice.getCompletePathBasedDumpsAsString();
    sw.stop();
    LOG.info("path based dump took: " + sw.getTime() + " ms");
    return dump;
}

From source file:com.continuuity.weave.yarn.YarnWeaveController.java

@Override
protected void doStartUp() {
    super.doStartUp();

    // Submit and poll the status of the yarn application
    try {/*from   w ww. j  a va  2 s  . c o m*/
        processController = startUp.call();

        YarnApplicationReport report = processController.getReport();
        LOG.debug("Application {} submit", report.getApplicationId());

        YarnApplicationState state = report.getYarnApplicationState();
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        stopWatch.split();
        long maxTime = TimeUnit.MILLISECONDS.convert(Constants.APPLICATION_MAX_START_SECONDS, TimeUnit.SECONDS);

        LOG.info("Checking yarn application status");
        while (!hasRun(state) && stopWatch.getSplitTime() < maxTime) {
            report = processController.getReport();
            state = report.getYarnApplicationState();
            LOG.debug("Yarn application status: {}", state);
            TimeUnit.SECONDS.sleep(1);
            stopWatch.split();
        }
        LOG.info("Yarn application is in state {}", state);
        if (state != YarnApplicationState.RUNNING) {
            LOG.info("Yarn application is not in running state. Shutting down controller.",
                    Constants.APPLICATION_MAX_START_SECONDS);
            forceShutDown();
        } else {
            try {
                URL resourceUrl = URI
                        .create(String.format("http://%s:%d", report.getHost(), report.getRpcPort()))
                        .resolve(TrackerService.PATH).toURL();
                resourcesClient = new ResourceReportClient(resourceUrl);
            } catch (IOException e) {
                resourcesClient = null;
            }
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:net.craigstars.game.services.GameControllerTest.java

public void testGenerateTurn() {
    String token = getNextToken();
    User user = getUser();/*from  w w  w .j a  v  a2s . co m*/
    Game game = gameController.createGame(user, token, Size.Tiny, Density.Sparse, 2);

    Race race = getRace();
    gameController.joinGame(race.getUser(), race, game.getId());

    // join an ai player
    User aiUser = getUser(token + "-ai");
    aiUser.setAi(true);
    dao.getUserDao().save(aiUser);
    Race aiRace = getRace(user, token + "-ai");
    gameController.joinGame(aiUser, aiRace, game.getId());

    game = gameController.getGame(game.getId());

    log.debug("\n\n\n\nStarting generateTurn\n\n\n\n");
    StopWatch watch = new StopWatch();
    watch.start();

    int numYears = 50;
    // generate a bunch of turns
    for (int i = 0; i < numYears; i++) {
        gameController.submitTurn(user, game.getId());
    }
    watch.stop();
    log.debug("\n\n\nTime: {}ms", watch.getTime());

    game = gameController.getGame(game.getId());

    assertEquals(2400 + numYears, game.getYear());

}

From source file:de.thischwa.pmcms.gui.listener.ListenerExportSite.java

@Override
public void widgetSelected(SelectionEvent e) {
    RenderData renderData = InitializationManager.getBean(RenderData.class);
    SiteHolder siteHolder = InitializationManager.getBean(SiteHolder.class);
    ExportRenderer exportRenderer = InitializationManager.getBean(ExportRenderer.class);
    final Shell shell = e.display.getActiveShell();
    StringBuilder messages = new StringBuilder();
    Site site = siteHolder.getSite();//from w  w  w .  j a v  a2 s  .co m
    exportRenderer.setSite(site);
    exportRenderer.setMessages(messages);
    exportRenderer.setDisplay(e.display);
    exportRenderer.init();
    if (!exportRenderer.isValidToExport()) {
        MessageBox mbNotValid = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
        mbNotValid.setText(LabelHolder.get("popup.error")); //$NON-NLS-1$
        mbNotValid.setMessage(LabelHolder.get("task.export.error.notvalid") + "\n\n" + messages.toString()); //$NON-NLS-1$
        mbNotValid.open();
        return;
    }
    try {
        StopWatch watch = new StopWatch();
        watch.start();
        DialogManager.startProgressDialog(shell, exportRenderer);
        watch.stop();
        isInterruptByUser = exportRenderer.isInterruptByUser();
        if (!isInterruptByUser)
            logger.info("Time to export: " + watch);
        if (showExportInfo) {
            if (isInterruptByUser) {
                MessageBox mbInterrupted = new MessageBox(shell);
                mbInterrupted.setText(LabelHolder.get("popup.info")); //$NON-NLS-1$
                mbInterrupted.setMessage(LabelHolder.get("task.export.interrupted")); //$NON-NLS-1$
                mbInterrupted.open();
            } else {
                MessageBox mbExported = new MessageBox(shell);
                mbExported.setText(LabelHolder.get("popup.info")); //$NON-NLS-1$
                mbExported.setMessage(LabelHolder.get("task.export.ok") //$NON-NLS-1$
                        + PoPathInfo.getSiteExportDirectory(site).getAbsolutePath());
                mbExported.open();
            }
        }
        failed = false;
        if (!isInterruptByUser) {
            Collection<File> usedFiles = renderData.getFilesToCopy();
            if (CollectionUtils.isNotEmpty(usedFiles)) {
                DialogManager.startDialogUnusedImages(e.display.getActiveShell(), site, usedFiles,
                        InitializationManager.getAllowedImageExtensions());
            }
        }
        renderData.clear();
    } catch (Exception ex) {
        logger.error("While eport: " + ex.getMessage(), ex);
        ex.printStackTrace();
        messages = new StringBuilder();
        messages.append(LabelHolder.get("task.export.error.exception") + "\n\n");
        messages.append(ex.toString());
        MessageBox mbNotValid = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
        mbNotValid.setText(LabelHolder.get("popup.warning")); //$NON-NLS-1$
        mbNotValid.setMessage(messages.toString());
        mbNotValid.open();
    }
}

From source file:de.unisb.cs.st.javalanche.mutation.util.DBPerformanceTest.java

private void testInsert() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from  w w  w .j  a  v  a2 s . c o  m*/
    QueryManager.saveMutations(getMutations());
    stopWatch.stop();
    System.out.println("Inserting " + LIMIT + " mutations took "
            + DurationFormatUtils.formatDurationHMS(stopWatch.getTime()));

}

From source file:gov.nasa.ensemble.core.jscience.xml.XMLProfilesResource.java

@Override
@SuppressWarnings("unchecked")
protected void doLoad(InputStream inputStream, Map<?, ?> options) {
    String extension = getURI().fileExtension();
    if (!SUPPORTED_EXTENSIONS.contains(extension.toLowerCase())) {
        LOGGER.warn("\"" + extension + "\" is not a standard extension for a ProfileResource.");
    }/* ww  w .j av  a  2  s.  co m*/
    ProfilesParser parser = XMLProfileParser.getInstance();
    inputStream = ProgressMonitorInputStream.wrapInputStream(this, inputStream, options);
    StopWatch sw = new StopWatch();
    sw.start();
    try {
        parser.parse(getURI(), inputStream);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
    sw.stop();
    LOGGER.debug("Loaded profiles from " + getURI() + " in " + sw.toString());
    List<Profile> profiles = parser.getProfiles();
    if (profiles != null) {
        getContents().addAll(profiles);
    }
    setModified(false);
}

From source file:com.liferay.portal.security.ldap.internal.exportimport.LDAPUserExporterImpl.java

@Override
public void exportUser(Contact contact, Map<String, Serializable> contactExpandoAttributes) throws Exception {

    long companyId = contact.getCompanyId();

    StopWatch stopWatch = new StopWatch();

    if (_log.isDebugEnabled()) {
        stopWatch.start();//w w w  .  j  a  v a2s. com

        _log.debug("Exporting contact " + contact);
    }

    if (!_ldapSettings.isExportEnabled(companyId)) {
        return;
    }

    User user = _userLocalService.getUserByContactId(contact.getContactId());

    if (user.isDefaultUser() || (user.getStatus() != WorkflowConstants.STATUS_APPROVED)) {

        return;
    }

    long ldapServerId = _portalLDAP.getLdapServerId(companyId, user.getScreenName(), user.getEmailAddress());

    LdapContext ldapContext = _portalLDAP.getContext(ldapServerId, companyId);

    try {
        if (ldapContext == null) {
            return;
        }

        Properties contactMappings = _ldapSettings.getContactMappings(ldapServerId, companyId);
        Properties contactExpandoMappings = _ldapSettings.getContactExpandoMappings(ldapServerId, companyId);

        Binding binding = _portalLDAP.getUser(ldapServerId, contact.getCompanyId(), user.getScreenName(),
                user.getEmailAddress());

        if (binding == null) {
            Properties userMappings = _ldapSettings.getUserMappings(ldapServerId, companyId);

            binding = addUser(ldapServerId, ldapContext, user, userMappings);
        }

        Name name = new CompositeName();

        name.add(binding.getNameInNamespace());

        Modifications modifications = _portalToLDAPConverter.getLDAPContactModifications(contact,
                contactExpandoAttributes, contactMappings, contactExpandoMappings);

        if (modifications == null) {
            return;
        }

        ModificationItem[] modificationItems = modifications.getItems();

        ldapContext.modifyAttributes(name, modificationItems);
    } finally {
        if (ldapContext != null) {
            ldapContext.close();
        }

        if (_log.isDebugEnabled()) {
            _log.debug(StringBundler.concat("Finished exporting contact ", String.valueOf(contact), " in ",
                    String.valueOf(stopWatch.getTime()), "ms"));
        }
    }
}

From source file:com.couchbase.graph.CBGraphPerfTest.java

@Test
@RunIf(value = PerfEnabledChecker.class)
public void testCreateBinaryTreeWithDepthOf10() {
    System.out.println("-- testCreateBinaryTreeWithDepthOf10");

    //Create a root node
    String uuid = UUID.randomUUID().toString();

    Vertex root = graph.addVertex(uuid);

    StopWatch sw = new StopWatch();
    sw.start();/*from   w  w w  .j a v a  2  s.  co m*/

    add2Vertices(root, 0, 10);
    //add2Vertices(root, 0, 14);

    sw.stop();
    System.out.println("Binary tree with a depth of 10 added in " + sw.getTime() + " ms");

    //Traverse the tree  
    sw = new StopWatch();
    sw.start();

    for (int i = 0; i < 10; i++) {

        Vertex left = root.getVertices(Direction.OUT, "to left").iterator().next();
        root = left;
    }

    sw.stop();
    System.out.println("Traversed tree in " + sw.getTime() + " ms");
}

From source file:com.qualogy.qafe.web.ContextLoader.java

private static void create(ServletContext servletContext) throws MalformedURLException, URISyntaxException {
    String configLocation = servletContext.getInitParameter(CONFIG_FILE_PARAM);
    String contextPath = getContextPath(servletContext);
    QafeConfigurationManager contextInitialiser = new QafeConfigurationManager(contextPath);
    ApplicationContext springContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    contextInitialiser.setSpringContext(springContext);
    qafeContext.putInstance(QafeConfigurationManager.class.getName(), contextInitialiser);

    StopWatch watch = new StopWatch();
    watch.start();//from  ww  w.  j  a  v  a  2 s . c o m
    ApplicationContextLoader.unload();

    // The default way: works on JBoss/Tomcat/Jetty
    String configFileLocation = servletContext.getRealPath("/WEB-INF/");
    if (configFileLocation != null) {
        configFileLocation += File.separator + configLocation;
        logger.log(Level.INFO, "URL to config file on disk :" + configFileLocation + ")");
        ApplicationContextLoader.load(configFileLocation, true);
    } else {
        // This is how a weblogic explicitly wants the fetching of resources.
        URL url = servletContext.getResource("/WEB-INF/" + configLocation);
        logger.log(Level.INFO, "Fallback scenario" + url.toString());
        if (url != null) {
            logger.log(Level.INFO, "URL to config file " + url.toString());
            ApplicationContextLoader.load(url.toURI(), true);
        } else {
            throw new RuntimeException(
                    "Strange Error: /WEB-INF/ cannot be found. Check the appserver or installation directory.");
        }
    }

    watch.stop();
    logger.log(Level.INFO,
            "Root WebApplicationContext: initialization completed in " + watch.getTime() + " ms");
}