List of usage examples for org.apache.commons.lang.time StopWatch StopWatch
public StopWatch()
Constructor.
From source file:edu.cornell.med.icb.util.ProcessEstimator.java
/** * Create a process estimator for a specified number of totalUnits. * This will start the timer immediately. * @param totalUnitsVal the number of totalUnits this will estimate completeion for *//*from w ww . j ava 2 s .c om*/ public ProcessEstimator(final int totalUnitsVal) { assert totalUnitsVal > 0; totalUnits = new AtomicInteger(totalUnitsVal); stopWatch = new StopWatch(); stopWatch.start(); unitsCompleted = new AtomicInteger(0); regressor = new LinearRegression(); }
From source file:io.cloudslang.engine.queue.services.ExecutionQueueServiceImpl.java
@Override @Transactional//from ww w. j a va 2 s .c o m public void enqueue(List<ExecutionMessage> messages) { if (CollectionUtils.isEmpty(messages)) return; if (logger.isDebugEnabled()) logger.debug("Enqueue " + messages.size() + " messages"); StopWatch stopWatch = new StopWatch(); stopWatch.start(); // assign worker for messages with pending status messages = executionAssignerService.assignWorkers(messages); if (logger.isDebugEnabled()) logger.debug("Messages were assigned successfully"); final List<ExecutionMessage> stateMessages = new ArrayList<>(messages.size()); // first fill the execution state id for new insert for (ExecutionMessage msg : messages) { if (msg.getExecStateId() == ExecutionMessage.EMPTY_EXEC_STATE_ID) { long execStateId = executionQueueRepository.generateExecStateId(); msg.setExecStateId(execStateId); stateMessages.add(msg); } else if (msg.getPayload() != null && msg.getStatus() == ExecStatus.IN_PROGRESS) { stateMessages.add(msg); } } if (CollectionUtils.isNotEmpty(listeners)) { stopWatch.split(); for (QueueListener listener : listeners) { listener.prePersist(messages); } if (logger.isDebugEnabled()) logger.debug("Listeners done in " + (stopWatch.getSplitTime()) + " ms"); } stopWatch.split(); if (stateMessages.size() > 0) executionQueueRepository.insertExecutionStates(stateMessages); long msgVersion = versionService.getCurrentVersion(VersionService.MSG_RECOVERY_VERSION_COUNTER_NAME); executionQueueRepository.insertExecutionQueue(messages, msgVersion); if (logger.isDebugEnabled()) logger.debug("Persistency done in " + (stopWatch.getSplitTime()) + " ms"); if (CollectionUtils.isNotEmpty(listeners)) { stopWatch.split(); List<ExecutionMessage> failedMessages = filter(messages, ExecStatus.FAILED); List<ExecutionMessage> terminatedMessages = filter(messages, ExecStatus.TERMINATED); for (QueueListener listener : listeners) { listener.onEnqueue(messages, messages.size()); if (failedMessages.size() > 0) listener.onFailed(failedMessages); if (terminatedMessages.size() > 0) listener.onTerminated(terminatedMessages); } if (logger.isDebugEnabled()) logger.debug("Listeners done in " + (stopWatch.getSplitTime()) + " ms"); } if (logger.isDebugEnabled()) logger.debug("Enqueue done in " + (stopWatch.getTime()) + " ms"); }
From source file:au.id.hazelwood.xmltvguidebuilder.config.ConfigFactory.java
public Config create(File file) throws InvalidConfigException { try {/*from w ww . j av a 2 s. c om*/ StopWatch stopWatch = new StopWatch(); stopWatch.start(); LOGGER.debug("Validating config file {}", file); schema.newValidator().validate(new StreamSource(file)); LOGGER.debug("Loading config file {}", file); HierarchicalConfiguration configuration = new XMLConfiguration(file); int offset = configuration.getInt("listing.offset"); int days = configuration.getInt("listing.days"); int synopsis = configuration.getInt("listing.synopsis"); String regionId = configuration.getString("listing.regionId"); Map<Integer, ChannelConfig> channelConfigById = loadChannelConfigs(configuration); Config config = new Config(offset, days, synopsis, regionId, new ArrayList<>(channelConfigById.values())); LOGGER.debug("Loaded {} from {} in {}", config, file, formatDurationWords(stopWatch.getTime())); return config; } catch (Throwable e) { throw new InvalidConfigException(e.getMessage(), e); } }
From source file:eagle.storage.jdbc.entity.impl.JdbcEntityUpdaterImpl.java
@Override public int update(List<E> entities) throws Exception { ConnectionManager cm = ConnectionManagerFactory.getInstance(); TorqueStatementPeerImpl<E> peer = cm.getStatementExecutor(this.jdbcEntityDefinition.getJdbcTableName()); Connection connection = cm.getConnection(); connection.setAutoCommit(false);//w w w . j a va2s . c o m StopWatch stopWatch = new StopWatch(); stopWatch.start(); int num = 0; try { for (E entity : entities) { String primaryKey = entity.getEncodedRowkey(); PrimaryKeyCriteriaBuilder pkBuilder = new PrimaryKeyCriteriaBuilder(Arrays.asList(primaryKey), this.jdbcEntityDefinition.getJdbcTableName()); Criteria selectCriteria = pkBuilder.build(); if (LOG.isDebugEnabled()) LOG.debug("Updating by query: " + SqlBuilder.buildQuery(selectCriteria).getDisplayString()); ColumnValues columnValues = JdbcEntitySerDeserHelper.buildColumnValues(entity, this.jdbcEntityDefinition); num += peer.delegate().doUpdate(selectCriteria, columnValues, connection); } if (LOG.isDebugEnabled()) LOG.debug("Committing updates"); connection.commit(); } catch (Exception ex) { LOG.error("Failed to update, rolling back", ex); connection.rollback(); throw ex; } finally { stopWatch.stop(); if (LOG.isDebugEnabled()) LOG.debug("Closing connection"); connection.close(); } LOG.info(String.format("Updated %s records in %s ms", num, stopWatch.getTime())); return num; }
From source file:com.liferay.portal.monitoring.internal.BaseDataSample.java
@Override public void prepare() { if (_stopWatch == null) { _stopWatch = new StopWatch(); } _stopWatch.start(); }
From source file:eagle.storage.jdbc.entity.impl.JdbcEntityWriterImpl.java
@Override public List<String> write(List<E> entities) throws Exception { List<String> keys = new ArrayList<String>(); if (LOG.isDebugEnabled()) LOG.debug("Writing " + entities.size() + " entities"); StopWatch stopWatch = new StopWatch(); stopWatch.start();// w w w . ja v a 2s . co m Connection connection = ConnectionManagerFactory.getInstance().getConnection(); // set auto commit false and commit by hands for 3x~5x better performance connection.setAutoCommit(false); try { TorqueStatementPeerImpl<E> peer = connectionManager .getStatementExecutor(this.jdbcEntityDefinition.getJdbcTableName()); for (E entity : entities) { entity.setEncodedRowkey(peer.getPrimaryKeyBuilder().build(entity)); ColumnValues columnValues = JdbcEntitySerDeserHelper.buildColumnValues(entity, this.jdbcEntityDefinition); // TODO: implement batch insert for better performance ObjectKey key = peer.delegate().doInsert(columnValues, connection); try { if (key != null) { keys.add((String) key.getValue()); } else { keys.add(entity.getEncodedRowkey()); } } catch (ClassCastException ex) { throw new RuntimeException( "Key is not in type of String (VARCHAR) , but JdbcType (java.sql.Types): " + key.getJdbcType() + ", value: " + key.getValue(), ex); } } // Why not commit in finally: give up all if any single entity throws exception to make sure consistency guarantee if (LOG.isDebugEnabled()) { LOG.debug("Committing writing"); } connection.commit(); } catch (Exception ex) { LOG.error("Failed to write records, rolling back", ex); connection.rollback(); throw ex; } finally { stopWatch.stop(); if (LOG.isDebugEnabled()) LOG.debug("Closing connection"); connection.close(); } LOG.info(String.format("Wrote %s records in %s ms (table: %s)", keys.size(), stopWatch.getTime(), this.jdbcEntityDefinition.getJdbcTableName())); return keys; }
From source file:net.nan21.dnet.core.web.controller.data.AbstractDsWriteController.java
/** * Default handler for insert action./*from w w w . ja va 2s .c om*/ * * @param resourceName * @param dataformat * @param dataString * @param paramString * @return * @throws Exception */ @RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "=" + Constants.DS_ACTION_INSERT) @ResponseBody public String insert(@PathVariable String resourceName, @PathVariable String dataFormat, @RequestParam(value = Constants.REQUEST_PARAM_DATA, required = false, defaultValue = "{}") String dataString, @RequestParam(value = Constants.REQUEST_PARAM_PARAMS, required = false, defaultValue = "{}") String paramString, HttpServletRequest request, HttpServletResponse response) throws Exception { try { StopWatch stopWatch = new StopWatch(); stopWatch.start(); if (logger.isInfoEnabled()) { logger.info("Processing request: {}.{} -> action = {} ", new String[] { resourceName, dataFormat, Constants.DS_ACTION_INSERT }); } if (logger.isDebugEnabled()) { logger.debug(" --> request-data: {} ", new String[] { dataString }); logger.debug(" --> request-params: {} ", new String[] { paramString }); } this.prepareRequest(request, response); this.authorizeDsAction(resourceName, Constants.DS_ACTION_INSERT, null); if (!dataString.startsWith("[")) { dataString = "[" + dataString + "]"; } IDsService<M, F, P> service = this.findDsService(resourceName); IDsMarshaller<M, F, P> marshaller = service.createMarshaller(IDsMarshaller.JSON); List<M> list = marshaller.readListFromString(dataString); P params = marshaller.readParamsFromString(paramString); service.insert(list, params); IActionResultSave result = this.packResultSave(list, params); stopWatch.stop(); result.setExecutionTime(stopWatch.getTime()); String out = null; if (dataFormat.equals(IDsMarshaller.XML)) { IDsMarshaller<M, F, P> resultMarshaller = service.createMarshaller(dataFormat); out = resultMarshaller.writeResultToString(result); response.setContentType("text/xml; charset=UTF-8"); } else { out = marshaller.writeResultToString(result); response.setContentType("text/plain; charset=UTF-8"); } return out; } catch (Exception e) { return this.handleException(e, response); } finally { this.finishRequest(); } }
From source file:com.liferay.portal.search.lucene.LuceneIndexer.java
protected void doReIndex(int delay) { if (SearchEngineUtil.isIndexReadOnly()) { return;/*from www. ja v a2 s. c o m*/ } if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene started"); } if (delay < 0) { delay = 0; } try { if (delay > 0) { Thread.sleep(Time.SECOND * delay); } } catch (InterruptedException ie) { } StopWatch stopWatch = null; if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } try { LuceneHelperUtil.delete(_companyId); List<Portlet> portlets = PortletLocalServiceUtil.getPortlets(_companyId); portlets = ListUtil.sort(portlets, new PortletLuceneComparator()); for (Portlet portlet : portlets) { if (!portlet.isActive()) { continue; } List<Indexer> indexers = portlet.getIndexerInstances(); if (indexers == null) { continue; } for (Indexer indexer : indexers) { reindex(indexer); } } if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene completed in " + (stopWatch.getTime() / Time.SECOND) + " seconds"); } } catch (Exception e) { _log.error("Error encountered while reindexing", e); if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene failed"); } } _finished = true; }
From source file:com.liferay.calendar.servlet.CalendarServletContextListener.java
@Override protected void doPortalInit() throws Exception { _messageListener = new HotDeployMessageListener(ClpSerializer.getServletContextName()) { @Override//ww w .j a v a2 s .c o m protected void onDeploy(Message message) throws Exception { if (!PortletPropsValues.CALENDAR_SYNC_CALEVENTS_ON_STARTUP) { return; } StopWatch stopWatch = null; if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } CalendarImporterLocalServiceUtil.importCalEvents(); if (_log.isInfoEnabled()) { StringBundler sb = new StringBundler(6); sb.append("Calendar events synchronization takes "); sb.append(stopWatch.getTime()); sb.append(" ms. Set the property "); sb.append("\"calendar.sync.calevents.on.startup\" "); sb.append("to \"false\" to disable calendar events "); sb.append("synchronization."); _log.info(sb.toString()); } } }; MessageBusUtil.registerMessageListener(DestinationNames.HOT_DEPLOY, _messageListener); }
From source file:com.liferay.portal.search.lucene33.LuceneIndexer.java
protected void doReIndex(int delay) { if (SearchEngineUtil.isIndexReadOnly()) { return;//from w w w.j a v a 2s.c o m } if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene started"); } if (delay < 0) { delay = 0; } try { if (delay > 0) { Thread.sleep(Time.SECOND * delay); } } catch (InterruptedException ie) { } StopWatch stopWatch1 = null; if (_log.isInfoEnabled()) { stopWatch1 = new StopWatch(); stopWatch1.start(); } try { LuceneHelperUtil.delete(_companyId); List<Portlet> portlets = PortletLocalServiceUtil.getPortlets(_companyId); portlets = ListUtil.sort(portlets, new PortletLuceneComparator()); for (Portlet portlet : portlets) { if (!portlet.isActive()) { continue; } Indexer indexer = portlet.getIndexerInstance(); if (indexer == null) { continue; } String indexerClass = portlet.getIndexerClass(); StopWatch stopWatch2 = null; if (_log.isInfoEnabled()) { stopWatch2 = new StopWatch(); stopWatch2.start(); } if (_log.isInfoEnabled()) { _log.info("Reindexing with " + indexerClass + " started"); } indexer.reindex(new String[] { String.valueOf(_companyId) }); if (_log.isInfoEnabled()) { _log.info("Reindexing with " + indexerClass + " completed in " + (stopWatch2.getTime() / Time.SECOND) + " seconds"); } } if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene completed in " + (stopWatch1.getTime() / Time.SECOND) + " seconds"); } } catch (Exception e) { _log.error("Error encountered while reindexing", e); if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene failed"); } } _finished = true; }