List of usage examples for org.springframework.util StopWatch stop
public void stop() throws IllegalStateException
From source file:org.dd4t.core.filters.impl.DefaultLinkResolverFilter.java
protected void resolvePage(GenericPage page) { StopWatch stopWatch = null; if (logger.isDebugEnabled()) { stopWatch = new StopWatch(); stopWatch.start();/*from w w w . ja v a 2 s . com*/ } List<ComponentPresentation> cpList = page.getComponentPresentations(); if (cpList != null) { for (ComponentPresentation cp : cpList) { resolveComponent((GenericComponent) cp.getComponent(), page); } } resolveMap(page.getMetadata()); if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug( "ResolvePage for " + page.getId() + " finished in " + stopWatch.getTotalTimeMillis() + " ms"); } }
From source file:org.jason.mapmaker.repository.impl.HibernateGenericRepository.java
public void save(Collection<T> objects) { StopWatch stopWatch = new StopWatch(); stopWatch.start();// www . j ava 2s.co m Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); int i = 1; for (T obj : objects) { session.save(obj); //sessionFactory.getCurrentSession().save(obj); i++; if (i % 100 == 0) { session.flush(); session.clear(); //sessionFactory.getCurrentSession().flush(); } } tx.commit(); session.close(); stopWatch.stop(); log.debug("Persisted " + i + " objects in " + stopWatch.getTotalTimeSeconds() + " seconds"); }
From source file:org.dd4t.core.factories.impl.SimplePageFactory.java
private Page findSimplePageByUrl(String url, int publicationId, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException { if (context == null && securityFilterPresent()) { throw new RuntimeException("use of findPageByUrl is not allowed when a SecurityFilter is set"); }//from w w w . jav a 2 s . co m StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter findSimplePageByUrl url: " + url + " and publicationId: " + publicationId); stopWatch = new StopWatch("findSimplePageByUrl"); stopWatch.start(); } PageMeta pageMeta = null; Page page = null; try { pageMeta = brokerPageProvider.getPageMetaByURL(url, publicationId); if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Got pageMeta in " + stopWatch.getTotalTimeMillis() + " ms"); stopWatch.start(); } page = (Page) getPageFromMeta(pageMeta); if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Got Page in " + stopWatch.getTotalTimeMillis() + " ms"); stopWatch.start(); } try { // run all filters regardless if they are allowed to be cached // or not doFilters(page, context, BaseFilter.RunPhase.Both); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Ran filters in " + stopWatch.getTotalTimeMillis() + " ms"); stopWatch.start(); } } catch (StorageException e) { logger.error("Storage exception when searching for page: " + url, e); throw new RuntimeException(e); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit findSimplePageByUrl (" + stopWatch.getTotalTimeMillis() + " ms)"); } return page; }
From source file:com.persistent.cloudninja.scheduler.TenantBlobSizeGenerator.java
@Override public boolean execute() { boolean retVal = true; StopWatch watch = new StopWatch(); try {/*from w w w. java 2 s. co m*/ watch.start(); LOGGER.debug("In generator"); TenantBlobSizeQueue queue = (TenantBlobSizeQueue) getWorkQueue(); //get all tenantIds List<TenantIdMasterEntity> listTenant = tenantIdMasterDao.getAllTenants(); for (Iterator<TenantIdMasterEntity> iterator = listTenant.iterator(); iterator.hasNext();) { TenantIdMasterEntity tenant = (TenantIdMasterEntity) iterator.next(); String tenantId = tenant.getTenantId(); //put each tenant Id in queue queue.enqueue(tenantId); LOGGER.info("Generator : msg added is " + tenantId); } watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "GenerateMeterBlobSizeWork", "Measure blob size for " + listTenant.size() + " tenants"); } catch (StorageException e) { retVal = false; LOGGER.error(e.getMessage(), e); } return retVal; }
From source file:org.impalaframework.extension.mvc.flash.FlashStateEnabledAnnotationHandlerAdapter.java
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { RequestModelHelper.maybeDebugRequest(logger, request); StopWatch watch = null; final boolean debugEnabled; if (logger.isDebugEnabled()) { debugEnabled = true;//from ww w . j a v a 2 s .co m } else { debugEnabled = false; } try { if (debugEnabled) { watch = new StopWatch(); watch.start(); logger.debug(MemoryUtils.getMemoryInfo().toString()); } beforeHandle(request); ModelAndView modelAndView = super.handle(request, response, handler); if (modelAndView != null) { afterHandle(request, modelAndView); return modelAndView; } } finally { if (debugEnabled) { watch.stop(); logger.debug("Request executed in " + watch.getTotalTimeMillis() + " milliseconds"); } } return null; }
From source file:org.dd4t.core.factories.impl.GenericPageFactory.java
/** * Transform source into a page.// ww w .j av a 2s . c om * * @param source * @return */ public GenericPage getPageFromSource(String source) { StopWatch stopWatch = null; try { if (logger.isDebugEnabled()) { stopWatch = new StopWatch(); stopWatch.start("getPageFromSource"); } return (GenericPage) this.getSerializer().deserialize(source, GenericPage.class); } catch (Exception e) { logger.error("Exception when deserializing page: ", e); throw new RuntimeException(e); } finally { if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Deserialization of page took: " + stopWatch.getLastTaskTimeMillis() + " ms"); } } }
From source file:com.persistent.cloudninja.scheduler.TenantDBSizeGenerator.java
/** * Adds message to tenantdbsizequeue which is shared between processor * and generator./*w w w .jav a 2 s. co m*/ */ @Override public boolean execute() { StopWatch watch = new StopWatch(); boolean retVal = true; int tenantIds = 0; try { watch.start(); LOGGER.debug("In generator"); TenantDBSizeQueue queue = (TenantDBSizeQueue) getWorkQueue(); List<TenantIdMasterEntity> listTenant = tenantIdMasterDao.getAllTenants(); tenantIds = listTenant.size(); for (Iterator<TenantIdMasterEntity> iterator = listTenant.iterator(); iterator.hasNext();) { TenantIdMasterEntity tenant = (TenantIdMasterEntity) iterator.next(); String tenantId = tenant.getTenantId(); queue.enqueue(tenantId); LOGGER.info("Generator : msg added is " + tenantId); } watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "GenerateMeterTenantDBSizeWork", "Measure database size for " + tenantIds + " tenants"); } catch (StorageException e) { retVal = false; LOGGER.error(e.getMessage(), e); } return retVal; }
From source file:com.persistent.cloudninja.scheduler.TenantStorageBWProcessor.java
/** * Calculates storage bandwidth of tenant. */// w w w . j av a 2 s . c o m @Override public boolean execute() { StopWatch watch = new StopWatch(); boolean retVal = true; List<StorageBandwidthBatchEntity> batchesToProcess = null; try { LOGGER.debug("In TenantStorageBWProcessor"); TenantStorageBWQueue queue = (TenantStorageBWQueue) getWorkQueue(); batchesToProcess = queue.dequeue(); if (batchesToProcess == null) { retVal = false; } else { watch.start(); processBatches(batchesToProcess); watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "GenerateStorageBandwidth", "Batch Size = " + batchesToProcess.size()); } } catch (Exception e) { retVal = false; LOGGER.error(e.getMessage(), e); } return retVal; }
From source file:com.ascend.campaign.configs.SwaggerConfig.java
@Bean public Docket swaggerSpringfoxDocket() { StopWatch watch = new StopWatch(); watch.start();// w ww . j a v a 2s.c o m Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()) .genericModelSubstitutes(ResponseEntity.class).forCodeGeneration(true) .genericModelSubstitutes(ResponseEntity.class) .directModelSubstitute(org.joda.time.LocalDate.class, String.class) .directModelSubstitute(org.joda.time.LocalDateTime.class, Date.class) .directModelSubstitute(org.joda.time.DateTime.class, Date.class) .directModelSubstitute(java.time.LocalDate.class, String.class) .directModelSubstitute(java.time.ZonedDateTime.class, Date.class) .directModelSubstitute(java.time.LocalDateTime.class, Date.class).select() .paths(regex(DEFAULT_INCLUDE_PATTERN)).build(); watch.stop(); return docket; }
From source file:org.openmrs.module.diabetesmanagement.web.controller.SimulationFormController.java
/** * The onSubmit method receives the form/command object that was modified by the input form and * saves it to the database./* ww w . j a v a2 s . c om*/ * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) * @param request Current servlet request. * @param response Current servlet response. * @param command Form object with request parameters bound onto it. * @param errors Holder without errors. * @return The prepared model and view, or null. * @throws Exception In case of errors. */ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { Context.addProxyPrivilege(OpenmrsConstants.PRIV_VIEW_USERS); Context.addProxyPrivilege(OpenmrsConstants.PRIV_VIEW_PATIENTS); try { if (Context.isAuthenticated()) { StopWatch stopwatch = new StopWatch(); ObjectOutputStream out = null; File f = null; File root = OpenmrsUtil.getDirectoryInApplicationDataDirectory("diabetesmanagement/simulation"); String sessionId = request.getSession().getId() + "_"; // Benchmarking the simulation model run Simulation sim = (Simulation) command; stopwatch.start(); sim.runSimulation(); stopwatch.stop(); sim.setExecutionTime(stopwatch.getTotalTimeSeconds()); // Serializing current results, if available if (sim.getResultsAvailableCurrent()) { // Current plasma glucose f = new File(root.getAbsolutePath(), sessionId + FILENAME_PLASMA_GLUCOSE_CURRENT); f.delete(); out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(sim.getResultGlucoseCurrent()); out.close(); // Current plasma insulin f = new File(root.getAbsolutePath(), sessionId + FILENAME_PLASMA_INSULIN_CURRENT); f.delete(); out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(sim.getResultInsulinCurrent()); out.close(); // Current meals if (sim.getMealsCurrent() != null) { f = new File(root.getAbsolutePath(), sessionId + FILENAME_MEALS_CURRENT); f.delete(); out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(sim.getMealsCurrent()); out.close(); } // Current insulin injections (1) if (sim.getInsulinInjections1() != null) { f = new File(root.getAbsolutePath(), sessionId + FILENAME_INJECTIONS_1); f.delete(); out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(sim.getInsulinInjections1()); out.close(); } // Current insulin injections (2) if (sim.getInsulinInjections2() != null) { f = new File(root.getAbsolutePath(), sessionId + FILENAME_INJECTIONS_2); f.delete(); out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(sim.getInsulinInjections2()); out.close(); } } // Serializing previous results, if available if (sim.getResultsAvailablePrevious()) { // Previous plasma glucose f = new File(root.getAbsolutePath(), sessionId + FILENAME_PLASMA_GLUCOSE_PREVIOUS); f.delete(); out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(sim.getResultGlucosePrevious()); out.close(); // Previous plasma insulin f = new File(root.getAbsolutePath(), sessionId + FILENAME_PLASMA_INSULIN_PREVIOUS); f.delete(); out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(sim.getResultInsulinPrevious()); out.close(); // Previous meals if (sim.getMealsPrevious() != null) { f = new File(root.getAbsolutePath(), sessionId + FILENAME_MEALS_PREVIOUS); f.delete(); out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(sim.getMealsCurrent()); out.close(); } } } } finally { Context.removeProxyPrivilege(OpenmrsConstants.PRIV_VIEW_USERS); Context.removeProxyPrivilege(OpenmrsConstants.PRIV_VIEW_PATIENTS); } return showForm(request, response, errors); }