List of usage examples for org.springframework.util StopWatch start
public void start() throws IllegalStateException
From source file:io.curly.commons.logging.MethodExecutionAspectInterceptor.java
@SuppressWarnings("ArgNamesErrorsInspection") @Around(value = "execution(* *(..)) && @annotation(loggable)) ", argNames = "joinPoint, loggable") public Object invoke(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable { if (executionEnabled) { StopWatch watch = new StopWatch(joinPoint.toShortString()); watch.start(); try {//from w ww. j a va2s. c o m return joinPoint.proceed(); } finally { watch.stop(); synchronized (this) { if (actuatorEnabled && (gaugeService != null)) { String gagueName = "gauge.execution." + joinPoint.getTarget() + "." + joinPoint.getSignature().getName(); gaugeService.submit(gagueName, watch.getLastTaskTimeMillis()); } log(loggable.value(), joinPoint.getTarget().getClass(), "Executed method {} in {} ms", joinPoint.getSignature().getName(), watch.getLastTaskTimeMillis()); } } } return joinPoint.proceed(); }
From source file:org.springintegration.PayloadAwareTimingInterceptor.java
@Override public Message<?> preSend(Message<?> message, MessageChannel channel) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); this.stopWatchHolder.set(new StopWatchHolder(stopWatch, message.getPayload().getClass())); return super.preSend(message, channel); }
From source file:com.persistent.cloudninja.scheduler.TenantCreationTask.java
@Override public boolean execute() { boolean retval = true; try {//from w w w .ja va 2s.c o m TenantCreationQueue tntCreationQueue = (TenantCreationQueue) getWorkQueue(); String message = tntCreationQueue.dequeue(SchedulerSettings.MessageVisibilityTimeout); if (message == null) { LOGGER.debug("Msg is null"); retval = false; } else { StopWatch watch = new StopWatch(); watch.start(); ProvisioningTenantDTO provisioningTenantDTO = createDTOfromMessage(message); boolean tenantCreationSuccess = provisioningService.provisionTenant(provisioningTenantDTO); if (tenantCreationSuccess) { LOGGER.debug("tenant created :" + provisioningTenantDTO.getTenantId()); } else { LOGGER.debug( "tenant creation for tenant ID :" + provisioningTenantDTO.getTenantId() + " failed."); } watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "ProvisionTenantWork", "Tenant " + provisioningTenantDTO.getTenantId() + " is created."); } } catch (StorageException e) { retval = false; LOGGER.error(e.getMessage(), e); } return retval; }
From source file:com.api.foobar.config.apidoc.SwaggerConfiguration.java
/** * Swagger Springfox configuration.//from w ww .j av a 2 s. c o m * * @param swaggerProperties the properties of the application * @return the Swagger Springfox configuration */ @Bean public Docket swaggerSpringfoxDocket(SwaggerProperties swaggerProperties) { log.debug("Starting Swagger"); StopWatch watch = new StopWatch(); watch.start(); Contact contact = getContact(swaggerProperties); ApiInfo apiInfo = getApiInfo(swaggerProperties, contact); Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo).forCodeGeneration(true) // .genericModelSubstitutes(ResponseEntity.class) // .ignoredParameterTypes(Pageable.class) // .ignoredParameterTypes(java.sql.Date.class) // .directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class) // .directModelSubstitute(java.time.ZonedDateTime.class, Date.class) // .directModelSubstitute(java.time.LocalDateTime.class, Date.class) .select().apis(RequestHandlerSelectors.any()).paths(apiPaths()).build().pathMapping("/") .directModelSubstitute(DateTime.class, String.class).genericModelSubstitutes(ResponseEntity.class) .alternateTypeRules(newRule( typeResolver.resolve(DeferredResult.class, typeResolver.resolve(ResponseEntity.class, WildcardType.class)), typeResolver.resolve(WildcardType.class))) .globalOperationParameters(globalOperationParameters()).useDefaultResponseMessages(true) //Flag to indicate if default http response codes need to be used or not .securitySchemes(newArrayList(apiKey())).securityContexts(newArrayList(securityContext())) .enableUrlTemplating(false); //if true, use 'from style query' for generated paths watch.stop(); log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis()); return docket; }
From source file:com.quartzdesk.executor.core.job.AbstractJob.java
/** * The method invoked by the Quartz scheduler. * * @param context a {@link JobExecutionContext} instance. * @throws JobExecutionException if an error occurs while executing the job. *///from www . j av a 2s . com @Override public final void execute(JobExecutionContext context) throws JobExecutionException { String jobFullName = context.getJobDetail().getKey().toString(); StopWatch sw = new StopWatch(); sw.start(); ClassLoader origContextClassLoader = Thread.currentThread().getContextClassLoader(); try { if (log.isInfoEnabled()) log.info("Started scheduled job: {}", jobFullName); if (log.isDebugEnabled()) { StringBuilder jobDataMapDump = new StringBuilder(); // map that contains merged job data from the job detail data map and trigger data map JobDataMap jobDataMap = context.getMergedJobDataMap(); for (Iterator<String> keys = jobDataMap.keySet().iterator(); keys.hasNext();) { String key = keys.next(); String value = CommonUtils.safeToString(jobDataMap.get(key)); jobDataMapDump.append(key).append('=').append(value); if (keys.hasNext()) jobDataMapDump.append(CommonConst.NL); } log.debug("Job data map dump:{}{}", CommonConst.NL, jobDataMapDump.toString()); } // Set the context class loader to be the class loader of the job class. // This is a workaround/fix for the WebSpere Application Server where // WebSphere work manager threads are typically used to execute jobs. Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); executeJob(context); sw.stop(); if (log.isInfoEnabled()) log.info("Finished scheduled job: {}. Time taken: {}s.", jobFullName, sw.getTotalTimeSeconds()); } catch (JobExecutionException e) { if (log.isErrorEnabled()) log.error("Error executing scheduled job: " + jobFullName, e); throw e; } finally { // restore the original thread context class loader Thread.currentThread().setContextClassLoader(origContextClassLoader); } }
From source file:com.persistent.cloudninja.scheduler.TenantStorageBWGenerator.java
/** * Adds message to storagebandwidthqueue which is shared between processor * and generator./*from ww w . j av a 2 s. co m*/ */ @Override public boolean execute() { StopWatch watch = new StopWatch(); boolean retVal = true; try { watch.start(); LOGGER.debug("In generator"); TenantStorageBWQueue queue = (TenantStorageBWQueue) getWorkQueue(); List<StorageBandwidthBatchEntity> batchesToProcess = getLogsToProcess(); queue.enqueue(batchesToProcess); watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "GenerateStorageBandwidth", "BatchSize = " + batchesToProcess.size()); } catch (Exception e) { retVal = false; LOGGER.error(e.getMessage(), e); } return retVal; }
From source file:com.persistent.cloudninja.scheduler.TenantDBSizeGenerator.java
/** * Adds message to tenantdbsizequeue which is shared between processor * and generator./*from www. ja va2s . c om*/ */ @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.quartzdesk.test.quartz.v2.AbstractJob.java
/** * The method invoked by the Spring scheduler. This method simply delegates the * execution to the {@link #executeJob(JobExecutionContext)} method. * * @param context a {@link JobExecutionContext} instance. * @throws JobExecutionException if an error occurs while executing the * job./* www . jav a 2s .com*/ */ @Override public final void execute(JobExecutionContext context) throws JobExecutionException { String jobFullName = context.getJobDetail().getKey().toString(); String triggerFullName = context.getTrigger().getKey().toString(); StopWatch sw = new StopWatch(); sw.start(); ClassLoader origContextClassLoader = Thread.currentThread().getContextClassLoader(); try { if (log.isInfoEnabled()) log.info("Started scheduled job: {}, fired by trigger: {}", jobFullName, triggerFullName); if (log.isDebugEnabled()) { StringBuilder jobDataMapDump = new StringBuilder(); // map that contains merged job data from the job detail data map and trigger data map JobDataMap jobDataMap = context.getMergedJobDataMap(); for (Iterator<String> keys = jobDataMap.keySet().iterator(); keys.hasNext();) { String key = keys.next(); String value = CommonUtils.safeToString(jobDataMap.get(key)); jobDataMapDump.append(key).append('=').append(value); if (keys.hasNext()) jobDataMapDump.append(CommonConst.NL); } log.debug("Job data map dump:{}{}", CommonConst.NL, jobDataMapDump.toString()); } // Set the context class loader to be the class loader of the job class. // This is a workaround/fix for a problem with setting the thread's context // class loader through Quartz properties when WebSphere work manager threads // are used. Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); executeJob(context); sw.stop(); if (log.isInfoEnabled()) log.info("Finished scheduled job: {}. Time taken: {}s.", jobFullName, sw.getTotalTimeSeconds()); } catch (JobExecutionException e) { if (log.isErrorEnabled()) log.error("Error executing scheduled job: " + jobFullName, e); throw e; } finally { // restore the original thread context class loader Thread.currentThread().setContextClassLoader(origContextClassLoader); } }
From source file:my.adam.smo.client.Client.java
public BlockingRpcChannel blockingConnect(final InetSocketAddress sa) { return new BlockingRpcChannel() { private int countDownCallTimesToRelease = 1; private RpcChannel rpc = connect(sa); @Override//from w w w . ja v a 2s . co m public Message callBlockingMethod(Descriptors.MethodDescriptor method, RpcController controller, Message request, Message responsePrototype) throws ServiceException { StopWatch stopWatch = new StopWatch("callBlockingMethod"); stopWatch.start(); final CountDownLatch callbackLatch = new CountDownLatch(countDownCallTimesToRelease); final AtomicReference<Message> result = new AtomicReference<Message>(); RpcCallback<Message> done = new RpcCallback<Message>() { @Override public void run(Message parameter) { result.set(parameter); callbackLatch.countDown(); } }; rpc.callMethod(method, controller, request, responsePrototype, done); try { boolean succeededBeforeTimeout = callbackLatch.await(blocking_method_call_timeout, TimeUnit.SECONDS); if (!succeededBeforeTimeout) { throw new ServiceException( "blocking method timeout reached for method:" + method.getFullName()); } } catch (InterruptedException e) { getLogger().error("call failed", e); stopWatch.stop(); } stopWatch.stop(); getLogger().trace(stopWatch.shortSummary()); return result.get(); } }; }
From source file:com.quartzdesk.test.quartz.v1.AbstractJob.java
/** * The method invoked by the Spring scheduler. This method simply delegates the * execution to the {@link #executeJob(JobExecutionContext)} method. * * @param context a {@link JobExecutionContext} instance. * @throws JobExecutionException if an error occurs while executing the * job./*www . j av a 2 s . c o m*/ */ @SuppressWarnings("unchecked") @Override public final void execute(JobExecutionContext context) throws JobExecutionException { String jobFullName = context.getJobDetail().getFullName(); String triggerFullName = context.getTrigger().getFullName(); StopWatch sw = new StopWatch(); sw.start(); ClassLoader origContextClassLoader = Thread.currentThread().getContextClassLoader(); try { if (log.isInfoEnabled()) log.info("Started scheduled job: {}, fired by trigger: {}", jobFullName, triggerFullName); if (log.isDebugEnabled()) { StringBuilder jobDataMapDump = new StringBuilder(); // map that contains merged job data from the job detail data map and trigger data map JobDataMap jobDataMap = context.getMergedJobDataMap(); for (Iterator<String> keys = (Iterator<String>) jobDataMap.keySet().iterator(); keys.hasNext();) { String key = keys.next(); String value = CommonUtils.safeToString(jobDataMap.get(key)); jobDataMapDump.append(key).append('=').append(value); if (keys.hasNext()) jobDataMapDump.append(CommonConst.NL); } log.debug("Job data map dump:{}{}", CommonConst.NL, jobDataMapDump.toString()); } // Set the context class loader to be the class loader of the job class. // This is a workaround/fix for a problem with setting the thread's context // class loader through Quartz properties when WebSphere work manager threads // are used. Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); executeJob(context); sw.stop(); if (log.isInfoEnabled()) log.info("Finished scheduled job: {}. Time taken: {}s.", jobFullName, sw.getTotalTimeSeconds()); } catch (JobExecutionException e) { if (log.isErrorEnabled()) log.error("Error executing scheduled job: " + jobFullName, e); throw e; } finally { // restore the original thread context class loader Thread.currentThread().setContextClassLoader(origContextClassLoader); } }