List of usage examples for com.google.common.collect Lists newArrayList
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayList()
From source file:thread.DataAccessor.java
public static void main(String[] args) { List<String> requests = Lists.newArrayList(); for (int i = 0; i < 5; i++) { requests.add("request:" + i); }/* w w w .j a v a2s. c om*/ DataAccessor da = new DataAccessor(); List<ProcessedResponse> results = da.getDataFromService(requests); for (ProcessedResponse result : results) { System.out.println("Response: " + result); } executor.shutdown(); }
From source file:org.apache.kylin.engine.streaming.diagnose.StreamingLogAnalyzer.java
public static void main(String[] args) { int errorFileCount = 0; List<Long> ellapsedTimes = Lists.newArrayList(); String patternStr = "(\\d{2}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2})"; Pattern pattern = Pattern.compile(patternStr); SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("GMT")); // NOTE: this must be GMT to calculate epoch date correctly Preconditions.checkArgument(args.length == 1, "Usage: StreamingLogsAnalyser streaming_logs_folder"); for (File file : FileUtils.listFiles(new File(args[0]), new String[] { "log" }, false)) { System.out.println("Processing file " + file.toString()); long startTime = 0; long endTime = 0; try {//from w w w.j a v a 2s.co m List<String> contents = Files.readAllLines(file.toPath(), Charset.defaultCharset()); for (int i = 0; i < contents.size(); ++i) { Matcher m = pattern.matcher(contents.get(i)); if (m.find()) { startTime = format.parse("20" + m.group(1)).getTime(); break; } } for (int i = contents.size() - 1; i >= 0; --i) { Matcher m = pattern.matcher(contents.get(i)); if (m.find()) { endTime = format.parse("20" + m.group(1)).getTime(); break; } } if (startTime == 0 || endTime == 0) { throw new RuntimeException("start time or end time is not found"); } if (endTime - startTime < 60000) { System.out.println("Warning: this job took less than one minute!!!! " + file.toString()); } ellapsedTimes.add(endTime - startTime); } catch (Exception e) { System.out.println("Exception when processing log file " + file.toString()); System.out.println(e); errorFileCount++; } } System.out.println("Totally error files count " + errorFileCount); System.out.println("Totally normal files processed " + ellapsedTimes.size()); long sum = 0; for (Long x : ellapsedTimes) { sum += x; } System.out.println("Avg build time " + (sum / ellapsedTimes.size())); }
From source file:autobind.AutoBindExample.java
public static void main(String[] args) throws Exception { // This Governator feature tells the CLASSPATH scanner // to ignore listed classes. So, even though ExampleService // is annotated with @AutoBindSingleton it will not // get created in this example List<Class<?>> ignore = Lists.newArrayList(); ignore.add(ExampleService.class); // Always get the Guice injector from Governator Injector injector = LifecycleInjector.builder().usingBasePackages("autobind") .ignoringAutoBindClasses(ignore) // tell Governator's CLASSPATH scanner to ignore listed classes .withBootstrapModule(new BootstrapModule() { @Override/*from w w w. j a v a 2 s . c o m*/ public void configure(BootstrapBinder binder) { // bind an AutoBindProvider for @AutoBind annotated fields/arguments TypeLiteral<AutoBindProvider<AutoBind>> typeLiteral = new TypeLiteral<AutoBindProvider<AutoBind>>() { }; binder.bind(typeLiteral).to(ExampleAutoBindProvider.class).asEagerSingleton(); } }).createInjector(); LifecycleManager manager = injector.getInstance(LifecycleManager.class); // Always start the Lifecycle Manager manager.start(); System.out.println(injector.getInstance(ExampleObjectA.class).getValue()); System.out.println(injector.getInstance(ExampleObjectB.class).getValue()); System.out.println(injector.getInstance(ExampleObjectC.class).getValue()); /* Console will output: letter A - 1 letter B - 2 letter C - 3 */ // your app would execute here // Always close the Lifecycle Manager at app end manager.close(); }
From source file:AnalyzeBigramRelativeFrequencyTuple.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("usage: [input-path]"); System.exit(-1);/* w w w . j a va2 s . c o m*/ } System.out.println("input path: " + args[0]); List<PairOfWritables<Tuple, FloatWritable>> pairs = SequenceFileUtils.readDirectory(new Path(args[0])); List<PairOfWritables<Tuple, FloatWritable>> list1 = Lists.newArrayList(); List<PairOfWritables<Tuple, FloatWritable>> list2 = Lists.newArrayList(); for (PairOfWritables<Tuple, FloatWritable> p : pairs) { Tuple bigram = p.getLeftElement(); if (bigram.get(0).equals("light")) { list1.add(p); } if (bigram.get(0).equals("contain")) { list2.add(p); } } Collections.sort(list1, new Comparator<PairOfWritables<Tuple, FloatWritable>>() { @SuppressWarnings("unchecked") public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); int i = 0; for (PairOfWritables<Tuple, FloatWritable> p : list1) { Tuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); i++; if (i > 10) { break; } } Collections.sort(list2, new Comparator<PairOfWritables<Tuple, FloatWritable>>() { @SuppressWarnings("unchecked") public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); i = 0; for (PairOfWritables<Tuple, FloatWritable> p : list2) { Tuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); i++; if (i > 10) { break; } } }
From source file:AnalyzeBigramRelativeFrequency.java
public static void main(String[] args) { if (args.length != 1) { System.out.println("usage: [input-path]"); System.exit(-1);/*from www . ja v a 2 s .c o m*/ } System.out.println("input path: " + args[0]); List<PairOfWritables<PairOfStrings, FloatWritable>> pairs = SequenceFileUtils .readDirectory(new Path(args[0])); List<PairOfWritables<PairOfStrings, FloatWritable>> list1 = Lists.newArrayList(); List<PairOfWritables<PairOfStrings, FloatWritable>> list2 = Lists.newArrayList(); for (PairOfWritables<PairOfStrings, FloatWritable> p : pairs) { PairOfStrings bigram = p.getLeftElement(); if (bigram.getLeftElement().equals("light")) { list1.add(p); } if (bigram.getLeftElement().equals("contain")) { list2.add(p); } } Collections.sort(list1, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); int i = 0; for (PairOfWritables<PairOfStrings, FloatWritable> p : list1) { PairOfStrings bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); i++; if (i > 10) { break; } } Collections.sort(list2, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); i = 0; for (PairOfWritables<PairOfStrings, FloatWritable> p : list2) { PairOfStrings bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); i++; if (i > 10) { break; } } }
From source file:AnalyzeBigramRelativeFrequencyJson.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("usage: [input-path]"); System.exit(-1);/*from w ww . j av a 2 s .co m*/ } System.out.println("input path: " + args[0]); List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> pairs = SequenceFileUtils .readDirectory(new Path(args[0])); List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> list1 = Lists.newArrayList(); List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> list2 = Lists.newArrayList(); for (PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p : pairs) { BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement(); if (bigram.getJsonObject().get("Left").getAsString().equals("light")) { list1.add(p); } if (bigram.getJsonObject().get("Left").getAsString().equals("contain")) { list2.add(p); } } Collections.sort(list1, new Comparator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>>() { public int compare(PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e1, PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); int i = 0; for (PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p : list1) { BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); i++; if (i > 10) { break; } } Collections.sort(list2, new Comparator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>>() { public int compare(PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e1, PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); i = 0; for (PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p : list2) { BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); i++; if (i > 10) { break; } } }
From source file:com.spotify.folsom.LoadTestRunner.java
public static void main(final String[] args) throws Throwable { final BinaryMemcacheClient<String> client = new MemcacheClientBuilder<>(StringTranscoder.UTF8_INSTANCE) .withAddress("127.0.0.1").withMaxOutstandingRequests(100000).connectBinary(); final String[] keys = new String[10]; for (int i = 0; i < 10; i++) { keys[i] = "key" + i; }/*from w w w.ja v a 2s .co m*/ final List<ListenableFuture<Boolean>> futures = Lists.newArrayList(); for (int r = 0; r < 100; r++) { for (final String keyProto : keys) { final String key = keyProto + ":" + r; final ListenableFuture<MemcacheStatus> setFuture = client.set(key, "value" + key, 100000); final ListenableFuture<String> getFuture = Utils.transform(setFuture, new AsyncFunction<MemcacheStatus, String>() { @Override public ListenableFuture<String> apply(final MemcacheStatus input) throws Exception { return client.get(key); } }); final ListenableFuture<String> deleteFuture = Utils.transform(getFuture, new AsyncFunction<String, String>() { @Override public ListenableFuture<String> apply(final String value) throws Exception { return Utils.transform(client.delete(key), new Function<MemcacheStatus, String>() { @Override public String apply(final MemcacheStatus input) { return value; } }); } }); final ListenableFuture<Boolean> assertFuture = Utils.transform(deleteFuture, new Function<String, Boolean>() { @Override public Boolean apply(final String input) { return ("value" + key).equals(input); } }); futures.add(assertFuture); } } final List<Boolean> asserts = Futures.allAsList(futures).get(); int failed = 0; for (final boolean b : asserts) { if (!b) { failed++; } } System.out.println(failed + " failed of " + asserts.size()); client.shutdown(); }
From source file:com.chthhk.zk.curator.mastersel.LeaderSelectorCurator.java
public static void main(String[] args) throws Exception { // all of the useful sample code is in ExampleClient.java List<CuratorFramework> clients = Lists.newArrayList(); List<WorkServer> workServers = Lists.newArrayList(); try {// ww w . ja va 2 s.c om for (int i = 0; i < CLIENT_QTY; ++i) { CuratorFramework client = CuratorFrameworkFactory.newClient("192.168.1.105:2181", new ExponentialBackoffRetry(1000, 3)); clients.add(client); WorkServer workServer = new WorkServer(client, PATH, "Client #" + i); workServer.setListener(new RunningListener() { public void processStop(Object context) { System.out.println(context.toString() + "processStop..."); } public void processStart(Object context) { System.out.println(context.toString() + "processStart..."); } public void processActiveExit(Object context) { System.out.println(context.toString() + "processActiveExit..."); } public void processActiveEnter(Object context) { System.out.println(context.toString() + "processActiveEnter..."); } }); workServers.add(workServer); client.start(); workServer.start(); } System.out.println("Press enter/return to quit\n"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } finally { System.out.println("Shutting down..."); for (WorkServer workServer : workServers) { CloseableUtils.closeQuietly(workServer); } for (CuratorFramework client : clients) { CloseableUtils.closeQuietly(client); } } }
From source file:jflowmap.GeoClusteringOfCountries.java
public static void main(String[] args) throws IOException { StaxGraphMLReader reader = new StaxGraphMLReader(); Graph g = reader.readFromLocation("data/refugees/refugees-2008.xml.gz").iterator().next(); List<Country> countries = Lists.newArrayList(); for (int i = 0, numNodes = g.getNodeCount(); i < numNodes; i++) { Node node = g.getNode(i); countries.add(new Country(node.getString("name"), node.getString("code"), node.getDouble("x"), node.getDouble("y"))); }//from ww w .j a v a 2s. c o m DistanceMeasure<Country> dm = new DistanceMeasure<Country>() { @Override public double distance(Country t1, Country t2) { double dx = t1.getX() - t2.getX(); double dy = t1.getY() - t2.getY(); return Math.sqrt(dx * dx + dy * dy); } }; logger.info("Starting clustering nodes"); ClusterNode<Country> c = HierarchicalClusterer.<Country>createWith(dm, // Linkages.<Country>average() // Linkages.<Country>single() Linkages.<Country>complete()).build().clusterToRoot(countries, new ProgressTracker()); int[] ind = c.getItemIndices(); for (int i : ind) { System.out.println(countries.get(i).getName()); } }
From source file:com.yahoo.pulsar.client.tutorial.SampleAsyncProducer.java
public static void main(String[] args) throws PulsarClientException, InterruptedException, IOException { PulsarClient pulsarClient = PulsarClient.create("http://127.0.0.1:8080"); ProducerConfiguration conf = new ProducerConfiguration(); conf.setSendTimeout(3, TimeUnit.SECONDS); Producer producer = pulsarClient.createProducer("persistent://my-property/use/my-ns/my-topic", conf); List<CompletableFuture<MessageId>> futures = Lists.newArrayList(); for (int i = 0; i < 10; i++) { final String content = "my-message-" + i; CompletableFuture<MessageId> future = producer.sendAsync(content.getBytes()); future.handle((v, ex) -> {/*from w w w . j a v a 2s .c om*/ if (ex == null) { log.info("Message persisted: {}", content); } else { log.error("Error persisting message: {}", content, ex); } return null; }); futures.add(future); } log.info("Waiting for async ops to complete"); for (CompletableFuture<MessageId> future : futures) { future.join(); } log.info("All operations completed"); pulsarClient.close(); }