List of usage examples for java.util.concurrent TimeUnit NANOSECONDS
TimeUnit NANOSECONDS
To view the source code for java.util.concurrent TimeUnit NANOSECONDS.
Click Source Link
From source file:at.alladin.rmbt.util.tools.InformationCollectorTool.java
public void start(final ExecutorService executor) { final long startTimeNs = System.nanoTime(); if (!this.running.get()) { running.set(true);// w ww. j a v a 2 s. co m executor.submit(new Runnable() { public void run() { try { while (InformationCollectorTool.this.running.get()) { update(); Thread.sleep(PAUSE_BETWEEN_AUTO_EXECUTION_IN_MS); final long executingTimeNs = System.nanoTime() - startTimeNs; if (executingTimeNs >= TimeUnit.NANOSECONDS.convert(timeout.get(), deltaTimeUnit)) { System.out.println("Timeout reached. Stopping InformationCollectorTool"); InformationCollectorTool.this.running.set(false); } } } catch (InterruptedException e) { e.printStackTrace(); } running.set(false); } }); } }
From source file:org.osiam.tests.performance.tools.TestDataCreation.java
public static void createTestUserAndGroups() { logger.info("Start creation of tests user and groups"); long start = System.nanoTime(); for (int userIndex = 1; userIndex <= NUMBER_USER; userIndex++) { User user = getNewUser(userIndex); user = OSIAM_CONNECTOR.createUser(user, ACCESS_TOKEN); users.add(user);//from www. j av a 2 s. com logger.info("Created User " + userIndex + "/" + NUMBER_USER); } for (int groupIndex = 1; groupIndex <= NUMBER_GROUPS; groupIndex++) { Group.Builder groupBuilder = new Group.Builder("group" + groupIndex); groupBuilder.setExternalId("GrExternalId" + groupIndex); groupBuilder.setMembers(getMembers(groupIndex)); OSIAM_CONNECTOR.createGroup(groupBuilder.build(), ACCESS_TOKEN); logger.info("Created Group " + groupIndex + "/" + NUMBER_GROUPS); } final Group group = OSIAM_CONNECTOR.getGroup(PerformanceTestContext.VALID_GROUP_ID, ACCESS_TOKEN); Group.Builder groupBuilder = new Group.Builder(group).setMembers(getMembers(1)); OSIAM_CONNECTOR.replaceGroup(PerformanceTestContext.VALID_GROUP_ID, groupBuilder.build(), ACCESS_TOKEN); long time = TimeUnit.SECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); logger.info("Finished creation of tests user and groups. {} seconds needed.", time); }
From source file:com.netflix.spinnaker.kork.web.interceptors.MetricsInterceptor.java
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { if (handler instanceof HandlerMethod) { HandlerMethod handlerMethod = (HandlerMethod) handler; String controller = handlerMethod.getMethod().getDeclaringClass().getSimpleName(); if (controllersToExclude.contains(controller)) { return; }//from ww w . j a v a 2s. co m Integer status = response.getStatus(); if (ex != null) { // propagated exceptions should get tracked as '500' regardless of response status status = 500; } Id id = registry.createId(metricName).withTag("controller", controller) .withTag("method", handlerMethod.getMethod().getName()) .withTag("status", status.toString().charAt(0) + "xx").withTag("statusCode", status.toString()); Map variables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); for (String pathVariable : pathVariablesToTag) { if (variables.containsKey(pathVariable)) { id = id.withTag(pathVariable, variables.get(pathVariable).toString()); } } if (ex != null) { id = id.withTag("success", "false").withTag("cause", ex.getClass().getSimpleName()); } else { id = id.withTag("success", "true"); } registry.timer(id).record(getNanoTime() - ((Long) request.getAttribute(TIMER_ATTRIBUTE)), TimeUnit.NANOSECONDS); } }
From source file:com.netflix.spinnaker.clouddriver.aws.security.sdkclient.AmazonClientInvocationHandler.java
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { final Id id = registry.createId("awsClientProxy.invoke", metricTags).withTag("method", method.getName()); final long startTime = System.nanoTime(); boolean wasDelegated = false; try {/*from w ww . j a v a 2 s.c om*/ Method thisMethod = this.getClass().getMethod(method.getName(), args != null && args.length > 0 ? getClassArgs(args) : new Class[0]); return thisMethod.invoke(this, args); } catch (NoSuchMethodException e) { wasDelegated = true; return method.invoke(delegate, args); } finally { registry.timer(id.withTag("requestMode", wasDelegated ? "sdkClient" : "edda")) .record(System.nanoTime() - startTime, TimeUnit.NANOSECONDS); } }
From source file:com.netflix.genie.core.jobs.workflow.impl.InitialSetupTask.java
/** * {@inheritDoc}/*from w w w . jav a 2 s . co m*/ */ @Override public void executeTask(@NotNull final Map<String, Object> context) throws GenieException, IOException { final long start = System.nanoTime(); final Map<String, String> tags = MetricsUtils.newSuccessTagsMap(); try { final JobExecutionEnvironment jobExecEnv = (JobExecutionEnvironment) context .get(JobConstants.JOB_EXECUTION_ENV_KEY); final String jobWorkingDirectory = jobExecEnv.getJobWorkingDir().getCanonicalPath(); final Writer writer = (Writer) context.get(JobConstants.WRITER_KEY); final String jobId = jobExecEnv.getJobRequest().getId() .orElseThrow(() -> new GeniePreconditionException("No job id found. Unable to continue")); log.info("Starting Initial Setup Task for job {}", jobId); this.createJobDirStructure(jobWorkingDirectory); // set the env variables in the launcher script this.createJobDirEnvironmentVariables(writer, jobWorkingDirectory); this.createApplicationEnvironmentVariables(writer); // create environment variables for the command final Command command = jobExecEnv.getCommand(); this.createCommandEnvironmentVariables(writer, command); // create environment variables for the cluster final Cluster cluster = jobExecEnv.getCluster(); this.createClusterEnvironmentVariables(writer, cluster); // create environment variable for the job itself this.createJobEnvironmentVariables(writer, jobId, jobExecEnv.getJobRequest().getName(), jobExecEnv.getMemory()); //Export the Genie Version writer.write(GENIE_VERSION_EXPORT); writer.write(LINE_SEPARATOR); writer.write(LINE_SEPARATOR); log.info("Finished Initial Setup Task for job {}", jobId); } catch (Throwable t) { MetricsUtils.addFailureTagsWithException(tags, t); throw t; } finally { this.getRegistry().timer(timerId.withTags(tags)).record(System.nanoTime() - start, TimeUnit.NANOSECONDS); } }
From source file:com.netflix.genie.core.jobs.workflow.impl.CommandTask.java
/** * {@inheritDoc}/*from ww w .ja va2 s. c om*/ */ @Override public void executeTask(@NotNull final Map<String, Object> context) throws GenieException, IOException { final long start = System.nanoTime(); try { final JobExecutionEnvironment jobExecEnv = (JobExecutionEnvironment) context .get(JobConstants.JOB_EXECUTION_ENV_KEY); final String jobWorkingDirectory = jobExecEnv.getJobWorkingDir().getCanonicalPath(); final String genieDir = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + JobConstants.GENIE_PATH_VAR; final Writer writer = (Writer) context.get(JobConstants.WRITER_KEY); log.info("Starting Command Task for job {}", jobExecEnv.getJobRequest().getId()); final String commandId = jobExecEnv.getCommand().getId() .orElseThrow(() -> new GeniePreconditionException("No command id found")); // Create the directory for this command under command dir in the cwd createEntityInstanceDirectory(genieDir, commandId, AdminResources.COMMAND); // Create the config directory for this id createEntityInstanceConfigDirectory(genieDir, commandId, AdminResources.COMMAND); // Get the setup file if specified and add it as source command in launcher script final Optional<String> setupFile = jobExecEnv.getCommand().getSetupFile(); if (setupFile.isPresent()) { final String commandSetupFile = setupFile.get(); if (StringUtils.isNotBlank(commandSetupFile)) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, commandId, commandSetupFile, FileType.SETUP, AdminResources.COMMAND); fts.getFile(commandSetupFile, localPath); super.generateSetupFileSourceSnippet(commandId, "Command:", localPath, writer, jobWorkingDirectory); } } // Iterate over and get all configuration files for (final String configFile : jobExecEnv.getCommand().getConfigs()) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, commandId, configFile, FileType.CONFIG, AdminResources.COMMAND); fts.getFile(configFile, localPath); } log.info("Finished Command Task for job {}", jobExecEnv.getJobRequest().getId()); } finally { final long finish = System.nanoTime(); this.timer.record(finish - start, TimeUnit.NANOSECONDS); } }
From source file:com.netflix.genie.core.jobs.workflow.impl.ClusterTask.java
/** * {@inheritDoc}/*from w w w . java2 s. c o m*/ */ @Override public void executeTask(@NotNull final Map<String, Object> context) throws GenieException, IOException { final long start = System.nanoTime(); try { final JobExecutionEnvironment jobExecEnv = (JobExecutionEnvironment) context .get(JobConstants.JOB_EXECUTION_ENV_KEY); final String jobWorkingDirectory = jobExecEnv.getJobWorkingDir().getCanonicalPath(); final String genieDir = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + JobConstants.GENIE_PATH_VAR; final Writer writer = (Writer) context.get(JobConstants.WRITER_KEY); log.info("Starting Cluster Task for job {}", jobExecEnv.getJobRequest().getId()); final String clusterId = jobExecEnv.getCluster().getId() .orElseThrow(() -> new GeniePreconditionException("No cluster id found")); // Create the directory for this application under applications in the cwd createEntityInstanceDirectory(genieDir, clusterId, AdminResources.CLUSTER); // Create the config directory for this id createEntityInstanceConfigDirectory(genieDir, clusterId, AdminResources.CLUSTER); // Get the set up file for cluster and add it to source in launcher script final Optional<String> setupFile = jobExecEnv.getCluster().getSetupFile(); if (setupFile.isPresent()) { final String clusterSetupFile = setupFile.get(); if (StringUtils.isNotBlank(clusterSetupFile)) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, clusterId, clusterSetupFile, FileType.SETUP, AdminResources.CLUSTER); fts.getFile(clusterSetupFile, localPath); super.generateSetupFileSourceSnippet(clusterId, "Cluster:", localPath, writer, jobWorkingDirectory); } } // Iterate over and get all configuration files for (final String configFile : jobExecEnv.getCluster().getConfigs()) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, clusterId, configFile, FileType.CONFIG, AdminResources.CLUSTER); fts.getFile(configFile, localPath); } log.info("Finished Cluster Task for job {}", jobExecEnv.getJobRequest().getId()); } finally { final long finish = System.nanoTime(); this.timer.record(finish - start, TimeUnit.NANOSECONDS); } }
From source file:fr.xebia.monitoring.demo.payment.CreditCardServiceMonitoringImpl.java
@ManagedAttribute public long getPurchaseInvocationDurationInMillis() { return TimeUnit.MILLISECONDS.convert(getPurchaseInvocationDurationInNanos(), TimeUnit.NANOSECONDS); }
From source file:com.netflix.genie.web.security.saml.SAMLUserDetailsServiceImpl.java
/** * {@inheritDoc}/*from w ww. j a v a 2s . c o m*/ */ @Override public Object loadUserBySAML(final SAMLCredential credential) throws UsernameNotFoundException { final long start = System.nanoTime(); try { if (credential == null) { throw new UsernameNotFoundException("No credential entered. Unable to get username."); } final String userAttributeName = this.samlProperties.getAttributes().getUser().getName(); final String userId = credential.getAttributeAsString(userAttributeName); if (StringUtils.isBlank(userId)) { throw new UsernameNotFoundException("No user id found using attribute: " + userAttributeName); } // User exists. Give them at least USER role final List<GrantedAuthority> authorities = Lists.newArrayList(USER); // See if we can get any other roles final String groupAttributeName = this.samlProperties.getAttributes().getGroups().getName(); final String adminGroup = this.samlProperties.getAttributes().getGroups().getAdmin(); final String[] groups = credential.getAttributeAsStringArray(groupAttributeName); if (groups == null) { log.warn("No groups found. User will only get ROLE_USER by default."); } else if (Arrays.asList(groups).contains(adminGroup)) { authorities.add(ADMIN); } // For debugging what's available in the credential from the IDP if (log.isDebugEnabled()) { log.debug("Attributes:"); credential.getAttributes().forEach(attribute -> { log.debug("Attribute: {}", attribute.getName()); log.debug("Values: {}", StringUtils.join(credential.getAttributeAsStringArray(attribute.getName()), ',')); }); } log.info("{} is logged in with authorities {}", userId, authorities); return new User(userId, "DUMMY", authorities); } finally { final long finished = System.nanoTime(); this.loadTimer.record(finished - start, TimeUnit.NANOSECONDS); } }
From source file:org.agatom.springatom.cmp.wizards.core.CreateObjectWizardProcessor.java
@Override public WizardResult onWizardInit(final Locale locale) throws Exception { LOGGER.debug(String.format("initialize(locale=%s)", locale)); final long startTime = System.nanoTime(); final WizardResult result = new WizardResult(); try {/*from w w w .j a v a 2s. c o m*/ final WizardDescriptor descriptor = this.initializeWizard(locale); final long endTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime); result.addWizardData(DESCRIPTOR_KEY, descriptor); result.addFeedbackMessage(FeedbackMessage.newInfo() .setMessage(this.messageSource.getMessage(WIZ_INITIALIZED_MSG, locale))); result.addDebugData(WizardDebugDataKeys.COMPILE_TIME, endTime) .addDebugData(WizardDebugDataKeys.PROCESSOR, ClassUtils.getShortName(this.getClass())) .addDebugData(WizardDebugDataKeys.LOCALE, locale); } catch (Exception exp) { LOGGER.error("Failed to build descriptor for wizard", exp); throw new Exception(exp.getMessage(), exp); } return result; }