List of usage examples for com.google.common.base Stopwatch stop
public Stopwatch stop()
From source file:org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor.java
/** * Executes a task inside a task context. * * @param taskContext Task context to execute. * @param output Standard output sink. * @param error Error sink./*from w ww . j av a2 s .c om*/ * @return Returns the task result. */ @Override public TaskResultImpl execute(TaskContext taskContext, PrintStream output, PrintStream error) { ScriptHandler scriptHandler = ScriptLoader.createLocalHandler(); String nodesFile = null; SchedulerNodeClient schedulerNodeClient = null; RemoteSpace userSpaceClient = null; RemoteSpace globalSpaceClient = null; try { nodesFile = writeNodesFile(taskContext); VariablesMap variables = new VariablesMap(); variables.setInheritedMap(taskContextVariableExtractor.extractVariables(taskContext, nodesFile, false)); variables.setScopeMap(taskContextVariableExtractor.extractScopeVariables(taskContext)); Map<String, String> resultMetadata = new HashMap<>(); Map<String, String> thirdPartyCredentials = forkedTaskVariablesManager .extractThirdPartyCredentials(taskContext); schedulerNodeClient = forkedTaskVariablesManager.createSchedulerNodeClient(taskContext); userSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.USER); globalSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.GLOBAL); forkedTaskVariablesManager.addBindingsToScriptHandler(scriptHandler, taskContext, variables, thirdPartyCredentials, schedulerNodeClient, userSpaceClient, globalSpaceClient, resultMetadata); Stopwatch stopwatch = Stopwatch.createUnstarted(); TaskResultImpl taskResult; try { stopwatch.start(); Serializable result = execute(taskContext, output, error, scriptHandler, thirdPartyCredentials, variables); stopwatch.stop(); taskResult = new TaskResultImpl(taskContext.getTaskId(), result, null, stopwatch.elapsed(TimeUnit.MILLISECONDS)); } catch (Throwable e) { stopwatch.stop(); e.printStackTrace(error); taskResult = new TaskResultImpl(taskContext.getTaskId(), e, null, stopwatch.elapsed(TimeUnit.MILLISECONDS)); } executeFlowScript(taskContext.getControlFlowScript(), scriptHandler, output, error, taskResult); taskResult.setPropagatedVariables( SerializationUtil.serializeVariableMap(variables.getPropagatedVariables())); taskResult.setMetadata(resultMetadata); return taskResult; } catch (Throwable e) { e.printStackTrace(error); return new TaskResultImpl(taskContext.getTaskId(), e); } finally { if (nodesFile != null && !nodesFile.isEmpty()) { FileUtils.deleteQuietly(new File(nodesFile)); } } }
From source file:com.google.api.ads.adwords.jaxws.extensions.downloader.MultipleClientReportDownloader.java
/** * Downloads the specified report for all specified CIDs. Prints out list of failed CIDs. Returns * List<File> for all successful downloads. * * @param reportDefinition Report to download. * @param cids CIDs to download the report for. * @return Collection of File objects reports have been downloaded to. * @throws InterruptedException error trying to stop downloader thread. *//* ww w . j a va 2s .co m*/ public Collection<File> downloadReports(final AdWordsSession.Builder builder, final ReportDefinition reportDefinition, final Set<Long> cids) throws InterruptedException { AdWordsSessionBuilderSynchronizer sessionBuilder = new AdWordsSessionBuilderSynchronizer(builder); final Collection<Long> failed = new ConcurrentSkipListSet<Long>(); final Collection<File> results = new ConcurrentSkipListSet<File>(); // We use a Latch so the main thread knows when all the worker threads are complete. final CountDownLatch latch = new CountDownLatch(cids.size()); Stopwatch stopwatch = Stopwatch.createStarted(); for (final Long cid : cids) { RunnableDownloader downloader = new RunnableDownloader(this.retriesCount, this.backoffInterval, this.bufferSize, cid, reportDefinition, sessionBuilder, results); downloader.setFailed(failed); executeRunnableDownloader(downloader, latch); } latch.await(); stopwatch.stop(); return this.printResultsAndReturn(results, stopwatch.elapsed(TimeUnit.MILLISECONDS), failed, cids); }
From source file:org.graylog2.shared.initializers.InputSetupService.java
@Override protected void shutDown() throws Exception { LOG.debug("Stopping InputSetupService"); eventBus.unregister(this); for (IOState<MessageInput> state : inputRegistry.getRunningInputs()) { MessageInput input = state.getStoppable(); LOG.info("Attempting to close input <{}> [{}].", input.getUniqueReadableId(), input.getName()); Stopwatch s = Stopwatch.createStarted(); try {/*from w ww . ja v a 2 s.c om*/ input.stop(); LOG.info("Input <{}> closed. Took [{}ms]", input.getUniqueReadableId(), s.elapsed(TimeUnit.MILLISECONDS)); } catch (Exception e) { LOG.error("Unable to stop input <{}> [{}]: " + e.getMessage(), input.getUniqueReadableId(), input.getName()); } finally { s.stop(); } } LOG.debug("Stopped InputSetupService"); }
From source file:uk.ac.open.kmi.iserve.discovery.disco.impl.SparqlLogicConceptMatcher.java
private MatchResult queryForMatchResult(URI origin, URI destination, String queryStr) { MatchType type = LogicConceptMatchType.Fail; // Query the engine Query query = QueryFactory.create(queryStr); QueryExecution qe = QueryExecutionFactory.sparqlService(this.sparqlEndpoint.toASCIIString(), query); MonitoredQueryExecution qexec = new MonitoredQueryExecution(qe); try {//from w w w . j av a2 s .c om Stopwatch stopwatch = new Stopwatch().start(); ResultSet qResults = qexec.execSelect(); stopwatch.stop(); log.debug("Time taken for querying the registry: {}", stopwatch); // Obtain matches if any and figure out the type if (qResults.hasNext()) { QuerySolution soln = qResults.nextSolution(); type = getMatchType(soln); } log.debug("Concept {} was matched to {} with type {}", origin, destination, type); } finally { qexec.close(); } return new AtomicMatchResult(origin, destination, type, this); }
From source file:org.eclipse.viatra.modelobfuscator.application.common.ModelObfuscatorHeadless.java
/** * @param obfuscatorBuilder//w w w . j a v a2s . co m */ private void performObfuscation(EMFModelObfuscatorBuilder obfuscatorBuilder) { SimpleEMFModelObfuscator obfuscator = obfuscatorBuilder.build(); System.out.println("Obfuscating EMF resource set"); Stopwatch stopwatch = Stopwatch.createStarted(); obfuscator.obfuscate(); stopwatch.stop(); String elapsedTime = stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms (" + stopwatch.elapsed(TimeUnit.NANOSECONDS) + " ns)"; System.out.println("Obfuscation finished in: " + elapsedTime); }
From source file:ch.ge.ve.protopoc.service.protocol.DefaultAuthority.java
@Override public void startPartialDecryption() { log.info("Authority " + j + " starting decryption"); ShufflesAndProofs shufflesAndProofs = bulletinBoardService.getShufflesAndProofs(); List<Encryption> encryptions = mixingAuthorityAlgorithms.getEncryptions(ballotEntries, confirmationEntries); List<ShuffleProof> shuffleProofs = shufflesAndProofs.getShuffleProofs(); List<List<Encryption>> shuffles = shufflesAndProofs.getShuffles(); Stopwatch checkShuffleWatch = Stopwatch.createStarted(); if (!decryptionAuthorityAlgorithms.checkShuffleProofs(shuffleProofs, encryptions, shuffles, systemPublicKey, j)) {/* w ww . jav a 2 s .co m*/ throw new InvalidShuffleProofRuntimeException("At least one shuffle proof was invalid"); } checkShuffleWatch.stop(); perfLog.info(String.format("Authority %d : checked shuffle proof in %dms", j, checkShuffleWatch.elapsed(TimeUnit.MILLISECONDS))); BigInteger secretKey = myPrivateKey.getPrivateKey(); List<Encryption> finalShuffle = shuffles.get(publicParameters.getS() - 1); Stopwatch decryptionWatch = Stopwatch.createStarted(); List<BigInteger> partialDecryptions = decryptionAuthorityAlgorithms.getPartialDecryptions(finalShuffle, secretKey); decryptionWatch.stop(); perfLog.info(String.format("Authority %d : decrypted in %dms", j, decryptionWatch.elapsed(TimeUnit.MILLISECONDS))); BigInteger publicKey = myPublicKey.getPublicKey(); Stopwatch decryptionProofWatch = Stopwatch.createStarted(); DecryptionProof decryptionProof = decryptionAuthorityAlgorithms.genDecryptionProof(secretKey, publicKey, finalShuffle, partialDecryptions); decryptionProofWatch.stop(); perfLog.info(String.format("Authority %d : decryption proof in %dms", j, decryptionProofWatch.elapsed(TimeUnit.MILLISECONDS))); bulletinBoardService.publishPartialDecryptionAndProof(j, partialDecryptions, decryptionProof); }
From source file:de.metas.ui.web.dashboard.KPIDataLoader.java
public KPIDataResult retrieveData() { final Stopwatch duration = Stopwatch.createStarted(); logger.trace("Retrieving data for {}, range={}", kpi, mainTimeRange); final KPIDataResult.Builder data = KPIDataResult.builder().setRange(mainTimeRange); timeRanges.forEach(timeRange -> loadData(data, timeRange)); return data.setTook(duration.stop()).build(); }
From source file:com.example.appengine.spanner.SpannerTasks.java
static void runTask(Task task, PrintWriter pw) { Stopwatch stopwatch = Stopwatch.createStarted(); switch (task) { case createDatabase: createDatabase(pw);/* www.jav a 2 s . co m*/ break; case writeExampleData: writeExampleData(pw); break; case query: query(pw); break; case read: read(pw); break; case addMarketingBudget: addMarketingBudgetColumnToAlbums(pw); break; case updateMarketingBudget: updateMarketingBudgetData(); break; case queryMarketingBudget: queryMarketingBudget(pw); break; case addIndex: addIndex(); break; case readUsingIndex: readUsingIndex(pw); break; case queryUsingIndex: queryUsingIndex(pw); break; case addStoringIndex: addStoringIndex(); break; case readStoringIndex: readStoringIndex(pw); break; case readOnlyTransaction: readOnlyTransaction(pw); break; case writeTransaction: writeWithTransaction(); break; default: break; } stopwatch.stop(); pw.println(task + " in milliseconds : " + stopwatch.elapsed(TimeUnit.MILLISECONDS)); pw.println("===================================================================="); }
From source file:blue.lapis.pore.event.PoreEventRegistry.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void register() throws IOException { Stopwatch watch = Stopwatch.createStarted(); InputStream in = PoreEventRegistry.class.getResourceAsStream("events.txt"); if (in == null) { Pore.getLogger().warn("No registered events found, Bukkit events will not be called."); return;/*from ww w . j ava 2 s. c o m*/ } try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.isEmpty() || line.charAt(0) == '#') { continue; } String owner = line; String method = null; int pos = line.lastIndexOf(':'); if (pos >= 0) { owner = line.substring(0, pos); method = line.substring(pos + 1); } try { // Pff Class poreEvent = Class.forName(owner); if (method != null) { poreEvent.getMethod(method).invoke(null); } else { register(poreEvent, null); } } catch (Exception e) { Pore.getLogger().warn("Failed to register class {} as an event", line, e); } } } Pore.getLogger().debug("Registered events in {}", watch.stop()); }
From source file:com.google.api.ads.adwords.jaxws.extensions.processors.onfile.ReportProcessorOnFile.java
/** * Process the local files delegating the call to the concrete implementation. * * @param reportType the report type.//from w ww . j av a 2 s . co m * @param localFiles the local files. * @param dateStart the start date. * @param dateEnd the end date. * @param dateRangeType the date range type. */ private <R extends Report> void processLocalFiles(String userId, String mccAccountId, ReportDefinitionReportType reportType, Collection<File> localFiles, String dateStart, String dateEnd, ReportDefinitionDateRangeType dateRangeType) { Stopwatch stopwatch = Stopwatch.createStarted(); @SuppressWarnings("unchecked") Class<R> reportBeanClass = (Class<R>) this.csvReportEntitiesMapping.getReportBeanClass(reportType); this.processFiles(userId, mccAccountId, reportBeanClass, localFiles, dateRangeType, dateStart, dateEnd); stopwatch.stop(); LOGGER.info( "\n* DB Process finished in " + (stopwatch.elapsed(TimeUnit.MILLISECONDS) / 1000) + " seconds ***"); }