/** * Create tenant. * @param tenant tenant key */ public void createTenant(String tenant) { StopWatch stopWatch = StopWatch.createStarted(); log.info("START - SETUP:CreateTenant: tenantKey: {}", tenant); try { tenantListRepository.addTenant(tenant); databaseService.create(tenant); databaseService.migrate(tenant); addUaaSpecification(tenant); addLoginsSpecification(tenant); log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime()); } catch (Exception e) { log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Delete tenant. * @param tenant tenant key */ public void deleteTenant(String tenant) { StopWatch stopWatch = StopWatch.createStarted(); log.info("START - SETUP:DeleteTenant: tenantKey: {}", tenant); try { databaseService.drop(tenant); tenantListRepository.deleteTenant(tenant); tenantConfigRepository.deleteConfig(tenant.toUpperCase(), "/" + applicationProperties.getTenantPropertiesName()); tenantConfigRepository.deleteConfig(tenant.toUpperCase(), "/" + applicationProperties.getTenantLoginPropertiesName()); log.info("STOP - SETUP:DeleteTenant: tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime()); } catch (Exception e) { log.info("STOP - SETUP:DeleteTenant: tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Migrate database with liquibase. * @param tenantKey the tenant key */ @SneakyThrows public void migrate(String tenantKey) { final StopWatch stopWatch = createStarted(); try { log.info("START - SETUP:CreateTenant:liquibase tenantKey: {}", tenantKey); SpringLiquibase liquibase = new SpringLiquibase(); liquibase.setResourceLoader(resourceLoader); liquibase.setDataSource(dataSource); liquibase.setChangeLog(CHANGE_LOG_PATH); liquibase.setContexts(liquibaseProperties.getContexts()); liquibase.setDefaultSchema(tenantKey); liquibase.setDropFirst(liquibaseProperties.isDropFirst()); liquibase.setChangeLogParameters(DatabaseUtil.defaultParams(tenantKey)); liquibase.setShouldRun(true); liquibase.afterPropertiesSet(); log.info("STOP - SETUP:CreateTenant:liquibase tenantKey: {}, result: OK, time = {} ms", tenantKey, stopWatch.getTime()); } catch (Exception e) { log.info("STOP - SETUP:CreateTenant:liquibase tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenantKey, e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Drop database schema for tenant. * * @param tenantKey - the tenant key */ @SneakyThrows public void drop(String tenantKey) { StopWatch stopWatch = createStarted(); log.info("START - SETUP:DeleteTenant:schema tenantKey: {}", tenantKey); try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { statement.executeUpdate(String.format(schemaDropResolver.getSchemaDropCommand(), tenantKey)); log.info("STOP - SETUP:DeleteTenant:schema tenantKey: {}, result: OK, time = {} ms", tenantKey, stopWatch.getTime()); } catch (Exception e) { log.info("STOP - SETUP:DeleteTenant:schema tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenantKey, e.getMessage(), stopWatch.getTime()); throw e; } }
public void start() throws Exception { StopWatch stopWatch = new StopWatch(); stopWatch.start(); //游戏基础框架服务启动 frameworkInit(); //游戏业务初始化 gameLogicInit(); stopWatch.stop(); logger.error("游戏服务启动,耗时[{}]毫秒", stopWatch.getTime()); //mbean监控 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); GameMonitorMXBean controller = new GameMonitor(); mbs.registerMBean(controller, new ObjectName("GameMXBean:name=GameMonitor")); }
/** * Aspect for logging before service calls. * * @param joinPoint joinPoint * @return method result * @throws Throwable throwable */ @SneakyThrows @Around("servicePointcut() && !excluded()") public Object logBeforeService(ProceedingJoinPoint joinPoint) { StopWatch stopWatch = StopWatch.createStarted(); try { logStart(joinPoint); Object result = joinPoint.proceed(); logStop(joinPoint, result, stopWatch); return result; } catch (Exception e) { logError(joinPoint, e, stopWatch); throw e; } }
/** * Create tenant. * * @param tenant the tenant * @return the tenant */ public Tenant createTenant(Tenant tenant) { StopWatch stopWatch = createStarted(); log.info("START - SETUP:CreateTenant: tenantKey: {}", tenant.getTenantKey()); try { tenantDatabaseService.create(tenant); tenantDashboardService.create(tenant); log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: OK, time = {} ms", tenant.getTenantKey(), stopWatch.getTime()); return tenant; } catch (Exception e) { log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenant.getTenantKey(), e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Create default dashboard. * @param tenant - the tenant */ public void create(Tenant tenant) { final StopWatch stopWatch = StopWatch.createStarted(); final String tenantKey = tenant.getTenantKey(); TenantInfo info = TenantContext.getCurrent(); try { log.info("START - SETUP:CreateTenant:dashboard tenantKey: {}", tenantKey); TenantContext.setCurrentQuite(tenantKey); Dashboard dashboard = new Dashboard(); dashboard.setName(tenantKey.toLowerCase()); dashboard.setOwner(tenantKey.toLowerCase()); dashboard.setIsPublic(false); dashboardService.save(dashboard); log.info("STOP - SETUP:CreateTenant:dashboard tenantKey: {}, result: OK, time = {} ms", tenantKey, stopWatch.getTime()); } catch (Exception e) { log.info("STOP - SETUP:CreateTenant:dashboard tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenantKey, e.getMessage(), stopWatch.getTime()); throw e; } finally { TenantContext.setCurrentQuite(info); } }
public void addTenant(Tenant tenant) { StopWatch stopWatch = StopWatch.createStarted(); log.info("START - SETUP:CreateTenant: tenantKey: {}", tenant); try { String tenantName = tenant.getTenantKey().toUpperCase(); tenantListRepository.addTenant(tenantName); tenantDatabaseService.create(tenant); tenantElasticService.create(tenant); addEntitySpecification(tenantName); addWebAppSpecification(tenantName); log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime()); } catch (Exception e) { log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime()); throw e; } }
public void deleteTenant(String tenantKey) { StopWatch stopWatch = StopWatch.createStarted(); log.info("START - SETUP:DeleteTenant: tenantKey: {}", tenantKey); try { tenantDatabaseService.drop(tenantKey); tenantElasticService.delete(tenantKey); tenantListRepository.deleteTenant(tenantKey.toLowerCase()); String specificationName = applicationProperties.getSpecificationName(); tenantConfigRepository.deleteConfig(tenantKey.toUpperCase(), "/" + specificationName); String webappSpecificationName = applicationProperties.getSpecificationWebappName(); webappTenantConfigRepository.deleteConfig(tenantKey.toUpperCase(), "/" + webappSpecificationName); log.info("STOP - SETUP:DeleteTenant: tenantKey: {}, result: OK, time = {} ms", tenantKey, stopWatch.getTime()); } catch (Exception e) { log.info("STOP - SETUP:DeleteTenant: tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenantKey, e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Create database schema for tenant. * * @param tenant - the tenant */ public void create(Tenant tenant) { StopWatch stopWatch = createStarted(); log.info("START - SETUP:CreateTenant:schema tenantKey={}", tenant.getTenantKey()); DatabaseUtil.createSchema(dataSource, tenant.getTenantKey()); log.info("STOP - SETUP:CreateTenant:schema tenantKey={}, time={}ms", tenant.getTenantKey(), stopWatch.getTime()); try { stopWatch.reset(); stopWatch.start(); log.info("START - SETUP:CreateTenant:liquibase tenantKey={}", tenant.getTenantKey()); SpringLiquibase liquibase = new SpringLiquibase(); liquibase.setResourceLoader(resourceLoader); liquibase.setDataSource(dataSource); liquibase.setChangeLog(CHANGE_LOG_PATH); liquibase.setContexts(liquibaseProperties.getContexts()); liquibase.setDefaultSchema(tenant.getTenantKey()); liquibase.setDropFirst(liquibaseProperties.isDropFirst()); liquibase.setShouldRun(true); liquibase.afterPropertiesSet(); log.info("STOP - SETUP:CreateTenant:liquibase tenantKey={}, time={}ms", tenant.getTenantKey(), stopWatch.getTime()); } catch (LiquibaseException e) { throw new RuntimeException("Can not migrate database for creation tenant " + tenant.getTenantKey(), e); } }
/** * Create new tenant. * @param tenant the new tenant name */ public void createTenant(String tenant) { StopWatch stopWatch = StopWatch.createStarted(); log.info("START - SETUP:CreateTenant: tenantKey: {}", tenant); try { tenantListRepository.addTenant(tenant.toLowerCase()); cassandraService.createCassandraKeyspace(tenant); cassandraService.migrateCassandra(tenant); kafkaService.createKafkaTopic(tenant); kafkaService.sendCommand(tenant, Constants.CREATE_COMMAND); addTimelineSpecification(tenant.toUpperCase()); log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime()); } catch (Exception e) { log.info("STOP - SETUP:CreateTenant: tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Delete tenant. * @param tenant the tenant name */ public void deleteTenant(String tenant) { StopWatch stopWatch = StopWatch.createStarted(); log.info("START - SETUP:DeleteTenant: tenantKey: {}", tenant); try { cassandraService.dropCassandraKeyspace(tenant); kafkaService.deleteKafkaTopic(tenant); kafkaService.sendCommand(tenant, Constants.DELETE_COMMAND); tenantListRepository.deleteTenant(tenant.toLowerCase()); String specificationName = applicationProperties.getTenantPropertiesName(); tenantConfigRepository.deleteConfig(tenant.toUpperCase(), "/" + specificationName); log.info("STOP - SETUP:DeleteTenant: tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime()); } catch (Exception e) { log.info("STOP - SETUP:DeleteTenant: tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Create topic consumer. * @param tenant the kafka topic */ public void createKafkaConsumer(String tenant) { StopWatch stopWatch = StopWatch.createStarted(); try { log.info("START - SETUP:CreateTenant:kafka consumer tenantKey: {}", tenant); ConcurrentMessageListenerContainer<String, String> container = consumers.get(tenant); if (container != null) { if (!container.isRunning()) { container.start(); } } else { ContainerProperties containerProps = new ContainerProperties(tenant); container = new ConcurrentMessageListenerContainer<>(consumerFactory, containerProps); container.setupMessageListener((MessageListener<String, String>) consumer::consumeEvent); container.setBeanName(tenant); container.start(); consumers.put(tenant, container); } log.info("STOP - SETUP:CreateTenant:kafka consumer tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime()); } catch (Exception e) { log.error("STOP - SETUP:CreateTenant:kafka consumer tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime(), e); } }
/** * Delete topic consumer. * @param tenant the kafka topic */ public void deleteKafkaConsumer(String tenant) { StopWatch stopWatch = StopWatch.createStarted(); try { log.info("START - SETUP:DeleteTenant:kafka consumer tenantKey: {}", tenant); if (consumers.get(tenant) != null) { consumers.get(tenant).stop(); consumers.remove(tenant); } log.info("STOP - SETUP:DeleteTenant:kafka consumer tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime()); } catch (Exception e) { log.error("STOP - SETUP:DeleteTenant:kafka consumer tenantKey: {}, result: FAIL, error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime(), e); } }
/** * Send 'tenant management' command to system topic. * @param tenant the tenant to manage * @param command the command (e.g. CREATE, DELETE, ...) */ public void sendCommand(String tenant, String command) { StopWatch stopWatch = StopWatch.createStarted(); try { log.info("START - SETUP:ManageTenant:kafka send command tenantKey: {}, command: {}", tenant, command); template.send(properties.getKafkaSystemTopic(), tenant, createSystemEvent(tenant, command)); log.info("STOP - SETUP:ManageTenant:kafka send command tenantKey: {}, command: {}," + " result: OK, time = {} ms", tenant, command, stopWatch.getTime()); } catch (Exception e) { log.error("STOP - SETUP:ManageTenant:kafka send command tenantKey: {}, command: {}," + " result: FAIL, error: {}, time = {} ms", tenant, command, e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Create cassandra keyspace. * @param tenant the keyspace name */ public void createCassandraKeyspace(String tenant) { StopWatch stopWatch = StopWatch.createStarted(); try { log.info("START - SETUP:CreateTenant:cassandra keyspace tenantKey: {}", tenant); Cluster.builder().addContactPoints(cassandraProperties.getContactPoints()) .build().connect().execute(String.format(properties.getCassandra().getKeyspaceCreateCql(), tenant)); log.info("STOP - SETUP:CreateTenant:cassandra keyspace tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime()); } catch (Exception e) { log.error("STOP - SETUP:CreateTenant:cassandra keyspace tenantKey: {}, result: FAIL," + " error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Migrate cassandra keyspace. * @param tenant the keyspace name */ public void migrateCassandra(String tenant) { StopWatch stopWatch = StopWatch.createStarted(); try { log.info("START - SETUP:CreateTenant:cassandra migration tenantKey: {}", tenant); ClusterConfiguration clusterConfiguration = new ClusterConfiguration(); clusterConfiguration.setContactpoints(new String[]{cassandraProperties.getContactPoints()}); KeyspaceConfiguration keyspaceConfiguration = new KeyspaceConfiguration(); keyspaceConfiguration.setName(tenant.toLowerCase()); keyspaceConfiguration.setClusterConfig(clusterConfiguration); CassandraMigration cm = new CassandraMigration(); cm.setLocations(new String[]{properties.getCassandra().getMigrationFolder()}); cm.setKeyspaceConfig(keyspaceConfiguration); cm.migrate(); log.info("STOP - SETUP:CreateTenant:cassandra migration tenantKey: {}, result: OK, time = {} ms", tenant, stopWatch.getTime()); } catch (Exception e) { log.error("STOP - SETUP:CreateTenant:cassandra migration tenantKey: {}," + " result: FAIL, error: {}, time = {} ms", tenant, e.getMessage(), stopWatch.getTime()); throw e; } }
/** * Monitor the elapsed time of method on controller layer, in * order to detect performance problems as soon as possible. * If elapsed time > 1 s, log it as an error. Otherwise, log it * as an info. */ @Around("controllerLayer()") public Object monitorElapsedTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { // Timing the method in controller layer StopWatch stopWatch = new StopWatch(); stopWatch.start(); Object result = proceedingJoinPoint.proceed(); stopWatch.stop(); // Log the elapsed time double elapsedTime = stopWatch.getTime() / 1000.0; Signature signature = proceedingJoinPoint.getSignature(); String infoString = "[" + signature.toShortString() + "][Elapsed time: " + elapsedTime + " s]"; if (elapsedTime > 1) { log.error(infoString + "[Note that it's time consuming!]"); } else { log.info(infoString); } // Return the result return result; }
/** * Opens TaskHistory, processes the task, then closes TaskHistory. * <p/> * Exceptions thrown here propagate up and cause the job to end with an error. */ TaskStatus openProcessCloseTask(TaskRun taskRun) { TaskStatus taskStatus = null; TaskHistory taskHistory = openTaskHistory(taskRun); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); taskStatus = taskRun.getTask().process(taskRun.isNoop()); } finally { LOGGER.debug("Task " + taskRun.getTask().getName() + " done ... time elapsed: " + stopWatch.toString()); if (taskStatus == null) { taskStatus = TaskStatus.ERROR; } closeTaskHistory(taskRun.isNoop(), taskHistory, taskStatus); } return taskStatus; }
/** * Waits (blocking) til the progressChecker says we are done, or until an uncaught error occurs, or until timeout. * * @return The result object when the progressChecker determines that we have reached a conclusion. */ public T waitTilDone() { StopWatch stopWatch = new StopWatch(); stopWatch.start(); int waitNum = 0; while (waitNum < waiterParameters.getMaxNumWaits() + 1) //Not counting "waitNum#0" since first one doesn't call sleep() { if (waitNum == 0) { progressChecker.initialCheck(); } else { progressChecker.followupCheck(waitNum); } if (progressChecker.isDone()) { LOGGER.info("Done: " + progressChecker.getDescription() + " ... time elapsed: " + stopWatch.toString()); return progressChecker.getResult(); } ++waitNum; sleep(waitNum, stopWatch); } return progressChecker.timeout(); }
/** * Sleeps for the wait delay, and catches interrupt exceptions. */ private void sleep(int waitNum, StopWatch stopWatch) { if (0 < waitNum && waitNum < waiterParameters.getMaxNumWaits() + 1) { if (waitNum % waiterParameters.getWaitReportInterval() == 0) { LOGGER.info("Wait #" + waitNum + " (max " + waiterParameters.getMaxNumWaits() + ") for " + progressChecker.getDescription() + " ... time elapsed: " + stopWatch.toString()); } final long delay = waitNum == 1 ? waiterParameters.getInitialWaitDelayMilliseconds() : waiterParameters.getFollowupWaitDelayMilliseconds(); if (delay >= LONG_SLEEP_THRESHOLD) { LOGGER.debug("Going to sleep for " + delay + " milliseconds"); } try { threadSleeper.sleep(delay); } catch (InterruptedException e) //NOSONAR { LOGGER.warn("Sleep was interrupted"); } } }
/** * Creates an RDS instance snapshot using the specified snapshot id. * <p/> * Caller must wait for status=available afterwards. */ public DBSnapshot createSnapshot(String snapshotId, String instanceName) { LOGGER.debug("createDBSnapshot(snapshotId: " + snapshotId + ", instanceName: " + instanceName + ")"); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); CreateDBSnapshotRequest request = new CreateDBSnapshotRequest(snapshotId, instanceName); return awsRdsClient.createDBSnapshot(request); } finally { stopWatch.stop(); LOGGER.debug("createDBSnapshot time elapsed: " + stopWatch); } }
/** * Copies an RDS parameter group. */ public DBParameterGroup copyParameterGroup(String sourceParamGroupName, String destParamGroupName) { LOGGER.debug("copyDBParameterGroup(sourceParamGroupName: " + sourceParamGroupName + ", destParamGroupName: " + destParamGroupName + ")"); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); CopyDBParameterGroupRequest request = new CopyDBParameterGroupRequest(); request.setSourceDBParameterGroupIdentifier(sourceParamGroupName); request.setTargetDBParameterGroupIdentifier(destParamGroupName); request.setTargetDBParameterGroupDescription(PARAM_GROUP_DESCRIPTION); return awsRdsClient.copyDBParameterGroup(request); } finally { stopWatch.stop(); LOGGER.debug("copyDBParameterGroup time elapsed: " + stopWatch); } }
/** * Restores a snapshot to a brand new instance. * <p/> * New instance gets the default security group, otherwise should be same as snapshot. * <p/> * Caller must wait for status=available afterwards. */ public DBInstance restoreInstanceFromSnapshot(String instanceName, String snapshotId, String subnetGroupName) { LOGGER.debug("restoreDBInstanceFromDBSnapshot(instanceName: " + instanceName + ", snapshotId: " + snapshotId + ", subnetGroupName: " + subnetGroupName + ")"); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); RestoreDBInstanceFromDBSnapshotRequest request = new RestoreDBInstanceFromDBSnapshotRequest( instanceName, snapshotId); request.setDBSubnetGroupName(subnetGroupName); return awsRdsClient.restoreDBInstanceFromDBSnapshot(request); } finally { stopWatch.stop(); LOGGER.debug("restoreDBInstanceFromDBSnapshot time elapsed: " + stopWatch); } }
/** * Modifies the instance by applying new security groups and new parameter group. * <p/> * Caller must wait for status=available afterwards. */ public DBInstance modifyInstanceWithSecgrpParamgrp(String instanceName, Collection<String> vpcSecurityGroupIds, String paramGroupName) { LOGGER.debug("modifyDBInstance(instanceName: " + instanceName + ", vpcSecurityGroupIds: (" + StringUtils.join(vpcSecurityGroupIds, ", ") + "), paramGroupName: " + paramGroupName + ")"); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); ModifyDBInstanceRequest request = new ModifyDBInstanceRequest(instanceName); request.setVpcSecurityGroupIds(vpcSecurityGroupIds); request.setDBParameterGroupName(paramGroupName); return awsRdsClient.modifyDBInstance(request); } finally { stopWatch.stop(); LOGGER.debug("modifyDBInstance time elapsed: " + stopWatch); } }
/** * Requests deletion of the instance, without creating a final snapshot or deleting any other related * snapshots. * <p/> * Caller must wait for status=deleted or DBInstanceNotFoundException afterwards. */ public DBInstance deleteInstance(String instanceName) { LOGGER.debug("deleteDBInstance(instanceName: " + instanceName + ")"); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); DeleteDBInstanceRequest request = new DeleteDBInstanceRequest(instanceName); request.setSkipFinalSnapshot(true); return awsRdsClient.deleteDBInstance(request); } finally { stopWatch.stop(); LOGGER.debug("deleteDBInstance time elapsed: " + stopWatch); } }
/** * Requests a reboot of the instance. * <p/> * Caller must wait for status=available afterwards. */ public DBInstance rebootInstance(String instanceId) { LOGGER.debug("rebootDBInstance(instanceName: " + instanceId + ")"); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); RebootDBInstanceRequest request = new RebootDBInstanceRequest(instanceId); return awsRdsClient.rebootDBInstance(request); } finally { stopWatch.stop(); LOGGER.debug("rebootDBInstance time elapsed: " + stopWatch); } }
/** * Deletes the parameter group. (Assuming it is not in use by any database instance.) */ public void deleteParameterGroup(String paramGroupName) { LOGGER.debug("deleteDBParameterGroup(paramGroupName: " + paramGroupName + ")"); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); DeleteDBParameterGroupRequest request = new DeleteDBParameterGroupRequest(paramGroupName); awsRdsClient.deleteDBParameterGroup(request); } finally { stopWatch.stop(); LOGGER.debug("deleteDBParameterGroup time elapsed: " + stopWatch); } }
/** * Deletes the snapshot. (Assuming it was in available state.) * <p/> * Caller must wait for status=deleted afterwards. */ public DBSnapshot deleteSnapshot(String snapshotId) { LOGGER.debug("deleteDBSnapshot(snapshotId: " + snapshotId + ")"); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); DeleteDBSnapshotRequest request = new DeleteDBSnapshotRequest(snapshotId); return awsRdsClient.deleteDBSnapshot(request); } finally { stopWatch.stop(); LOGGER.debug("deleteDBSnapshot time elapsed: " + stopWatch); } }
/** * Requests registration of the ec2 instance with the ELB. * <p/> * After calling here, you need to call DescribeLoadBalancers or DescribeInstanceHealth to see if registration is * complete. */ public void registerInstance(String elbName, String ec2InstanceId) { LOGGER.debug("registerInstancesWithLoadBalancer(elbName: " + elbName + ", ec2InstanceId: " + ec2InstanceId + ")"); assertNonBlankArgs(elbName, ec2InstanceId); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); RegisterInstancesWithLoadBalancerRequest request = new RegisterInstancesWithLoadBalancerRequest(); request.setLoadBalancerName(elbName); request.setInstances(Arrays.asList(new Instance(ec2InstanceId))); awsElbClient.registerInstancesWithLoadBalancer(request); //Currently not doing anything with the RegisterInstancesWithLoadBalancerResult } finally { stopWatch.stop(); LOGGER.debug("registerInstancesWithLoadBalancer time elapsed " + stopWatch); } }
/** * Requests deregistration of the ec2 instance from the ELB. * <p/> * After calling here, you need to call DescribeLoadBalancers to see if registration is complete. */ public void deregisterInstance(String elbName, String ec2InstanceId) { LOGGER.debug("deregisterInstancesFromLoadBalancer(elbName: " + elbName + ", ec2InstanceId: " + ec2InstanceId + ")"); assertNonBlankArgs(elbName, ec2InstanceId); StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); DeregisterInstancesFromLoadBalancerRequest request = new DeregisterInstancesFromLoadBalancerRequest(); request.setLoadBalancerName(elbName); request.setInstances(Arrays.asList(new Instance(ec2InstanceId))); awsElbClient.deregisterInstancesFromLoadBalancer(request); //Currently not doing anything with the DeregisterInstancesFromLoadBalancerResult } finally { stopWatch.stop(); LOGGER.debug("deregisterInstancesFromLoadBalancer time elapsed " + stopWatch); } }
public ObservableList<Link> findAllLinksInLinkMappingWithoutParent() { final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final ObservableList<LinkMapping> allLinkMappingsWithoutParent = LinkMappingSqlService.getDefault().findAllLinksInLinkMappingWithoutParent(); final ObservableList<Link> links = FXCollections.observableArrayList(); allLinkMappingsWithoutParent.stream() .forEach(linkMapping -> { final Optional<Link> optional = this.findById(Link.class, linkMapping.getChildId()); if (optional.isPresent()) { links.add(optional.get()); } }); stopWatch.split(); this.printToLog(stopWatch.toSplitString(), allLinkMappingsWithoutParent.size(), "findAllLinksInLinkMappingWithoutParent()"); // NOI18N stopWatch.stop(); return links; }
public ObservableList<Link> findAllLinksInLinkMappingWithParent(final long parentId, final LinkMappingType parentType) { final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final ObservableList<LinkMapping> allLinkMappingsWithParent = LinkMappingSqlService.getDefault().findAllLinksInLinkMappingWithParent(parentId, parentType); final ObservableList<Link> links = FXCollections.observableArrayList(); allLinkMappingsWithParent.stream() .forEach(linkMapping -> { final Optional<Link> optional = this.findById(Link.class, linkMapping.getChildId()); if (optional.isPresent()) { links.add(optional.get()); } }); stopWatch.split(); this.printToLog(stopWatch.toSplitString(), allLinkMappingsWithParent.size(), "findAllLinksInLinkMappingWithPrimary(long, LinkMappingType)"); // NOI18N stopWatch.stop(); return links; }
void deleteAllExerciseTermsWithExerciseId(long exerciseId) { final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final ObservableList<ExerciseTerm> exerciseTerms = SqlProvider.getDefault().findAllExerciseTermsWithExerciseId(exerciseId); DatabaseFacade.getDefault().getCrudService().beginTransaction(); exerciseTerms.stream() .forEach(exerciseTerm -> { DatabaseFacade.getDefault().getCrudService().getEntityManager().remove(exerciseTerm); }); DatabaseFacade.getDefault().getCrudService().commitTransaction(); stopWatch.split(); LoggerFacade.getDefault().debug(this.getClass(), " + Need " + stopWatch.toSplitString() + " for executing [deleteAllExerciseTermsWithExerciseId(long)]"); // NOI18N this.printToLog(stopWatch.toSplitString(), exerciseTerms.size(), "deleteAllExerciseTermsWithExerciseId(long exerciseId)"); // NOI18N stopWatch.stop(); }
/** * Executes the specified runnable in a timed block, and prints the measured * time to the specified logger, with the specified prefix. * * @param log * the logger to print the result to * @param prefix * the prefix in the printed message * @param f * the runnable to time */ public static void timed( Logger log, String prefix, Runnable f ) { StopWatch sw = new StopWatch(); sw.start(); f.run(); sw.stop(); log.trace( String.format( "%s: %sms (%sns)", prefix, sw.getTime(), sw.getNanoTime() ) ); }
/** * @throws Exception * @see MethodInterceptor#invoke(MethodInvocation) */ public Object invoke(MethodInvocation invocation) throws Throwable { //用 commons-lang 提供的 StopWatch 计时,Spring 也提供了一个 StopWatch StopWatch clock = new StopWatch(); clock.start(); //计时开始 //监控的类名 String className = invocation.getMethod().getDeclaringClass().getSimpleName(); //监控的方法名 String methodName = className + "." + invocation.getMethod().getName(); //监控的参数 Object[] objs = invocation.getArguments(); Object result = null; try{ //这个是我们监控的bean的执行并返回结果 result = invocation.proceed(); }catch(Throwable e){ logger.error("["+methodName+"] = >> Transaction Rollback 参数 = >> " + getString(objs)); logger.error("=================== Service层异常 已经回滚事务 = >> "+methodName+" ===================="); throw new RuntimeException(); } clock.stop(); //计时结束 if (logger.isInfoEnabled()) { logger.debug("执行时间:" + clock.getTime() + " ms [" + methodName + "]"); } return result; }
private void applyProducers(List<Mutant<A>> mutants) { for (MutantProducer<A> producer : producers) { // Time the application of each producer StopWatch timer = new StopWatch(); timer.start(); List<Mutant<A>> producerMutants = producer.mutate(); timer.stop(); producerTimings.put(producer.getClass(), timer); // Record how many mutants were added by the operator int newMutants = producerMutants.size(); Class producerClass = producer.getClass(); // Following 2 lines are for compatibility with higher-order mutation int producerCount = producerCounts.containsKey(producerClass) ? producerCounts.get(producerClass) : 0; producerCounts.put(producerClass, producerCount + newMutants); // Store the name of the operator as the simple description String simpleDescription = producer.getClass().getSimpleName(); for (Mutant<A> mutant : producerMutants) { mutant.setSimpleDescription(simpleDescription); } mutants.addAll(producerMutants); } }