List of usage examples for com.google.common.collect Lists newArrayList
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayList()
From source file:org.apache.curator.example.LeaderSelectorExample.java
public static void main(String[] args) throws Exception { // all of the useful sample code is in ExampleClient.java System.out.println("Create " + CLIENT_QTY + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur."); System.out.println(/* ww w . j a v a2 s . c o m*/ "Notice that leader election is fair: all clients will become leader and will do so the same number of times."); List<CuratorFramework> clients = Lists.newArrayList(); List<ExampleClient> examples = Lists.newArrayList(); TestingServer server = new TestingServer(); String connect = "192.168.3.197"; try { for (int i = 0; i < CLIENT_QTY; ++i) { CuratorFramework client = CuratorFrameworkFactory.newClient(connect, new ExponentialBackoffRetry(1000, 3)); clients.add(client); ExampleClient example = new ExampleClient(client, PATH, "Client #" + i); examples.add(example); client.start(); example.start(); } System.out.println("Press enter/return to quit\n"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } finally { System.out.println("Shutting down..."); for (ExampleClient exampleClient : examples) { CloseableUtils.closeQuietly(exampleClient); } for (CuratorFramework client : clients) { CloseableUtils.closeQuietly(client); } CloseableUtils.closeQuietly(server); } }
From source file:me.huding.curator.cluster.LeaderSelectorExample.java
public static void main(String[] args) throws Exception { // all of the useful sample code is in ExampleClient.java System.out.println("Create " + CLIENT_QTY + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur."); System.out.println(//from w w w . j a va2s .c o m "Notice that leader election is fair: all clients will become leader and will do so the same number of times."); List<CuratorFramework> clients = Lists.newArrayList(); List<ExampleClient> examples = Lists.newArrayList(); try { for (int i = 0; i < CLIENT_QTY; ++i) { CuratorFramework client = CuratorFrameworkFactory.newClient(connectString, new ExponentialBackoffRetry(1000, 3)); clients.add(client); ExampleClient example = new ExampleClient(client, PATH, "Client #" + i); examples.add(example); client.start(); example.start(); } System.out.println("Press enter/return to quit\n"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } finally { System.out.println("Shutting down..."); for (ExampleClient exampleClient : examples) { CloseableUtils.closeQuietly(exampleClient); } for (CuratorFramework client : clients) { CloseableUtils.closeQuietly(client); } } }
From source file:com.example.zookeeper.example2_curator._official.leader.LeaderSelectorExample.java
public static void main(String[] args) throws Exception { // all of the useful sample code is in ExampleClient.java System.out.println("Create " + CLIENT_QTY + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur."); System.out.println(//www. j a va 2 s .c o m "Notice that leader election is fair: all clients will become leader and will do so the same number of times."); List<CuratorFramework> clients = Lists.newArrayList(); // List<ExampleClient> examples = Lists.newArrayList(); TestingServer server = new TestingServer(); try { for (int i = 0; i < CLIENT_QTY; ++i) { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); clients.add(client); ExampleClient example = new ExampleClient(client, PATH, "Client #" + i); examples.add(example); client.start(); example.start(); } System.out.println("Press enter/return to quit\n"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } finally { System.out.println("Shutting down..."); for (ExampleClient exampleClient : examples) { CloseableUtils.closeQuietly(exampleClient); } for (CuratorFramework client : clients) { CloseableUtils.closeQuietly(client); } CloseableUtils.closeQuietly(server); } }
From source file:org.deeplearning4j.streaming.embedded.JavaQueueStream.java
public static void main(String[] args) throws Exception { SparkConf sparkConf = new SparkConf().setMaster("local[*]"); // Create the context JavaStreamingContext ssc = new JavaStreamingContext(sparkConf, new Duration(1000)); // Create the queue through which RDDs can be pushed to // a QueueInputDStream Queue<JavaRDD<Integer>> rddQueue = new LinkedList<>(); // Create and push some RDDs into the queue List<Integer> list = Lists.newArrayList(); for (int i = 0; i < 1000; i++) { list.add(i);// w w w . ja v a 2 s. co m } for (int i = 0; i < 30; i++) { rddQueue.add(ssc.sparkContext().parallelize(list)); } // Create the QueueInputDStream and use it do some processing JavaDStream<Integer> inputStream = ssc.queueStream(rddQueue); JavaPairDStream<Integer, Integer> mappedStream = inputStream .mapToPair(new PairFunction<Integer, Integer, Integer>() { @Override public Tuple2<Integer, Integer> call(Integer i) { return new Tuple2<>(i % 10, 1); } }); JavaPairDStream<Integer, Integer> reducedStream = mappedStream .reduceByKey(new Function2<Integer, Integer, Integer>() { @Override public Integer call(Integer i1, Integer i2) { return i1 + i2; } }); reducedStream.print(); ssc.start(); ssc.awaitTermination(); }
From source file:org.lendingclub.mercator.demo.Main.java
public static void main(String[] args) { SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install();/*from ww w.j a v a 2 s. com*/ Projector projector = new Projector.Builder().build(); Runnable awsTask = new Runnable() { public void run() { try { List<String> regionList = Splitter.on(",").omitEmptyStrings().trimResults() .splitToList(Strings.nullToEmpty(System.getenv("AWS_REGIONS"))); if (regionList == null || regionList.isEmpty()) { regionList = Lists.newArrayList(); regionList.add("us-west-2"); regionList.add("us-east-1"); } LoggerFactory.getLogger(Main.class).info("scanning regions: {}", regionList); regionList.forEach(it -> { try { org.slf4j.LoggerFactory.getLogger(Main.class).info("scanning region: {}", it); Regions region = Regions.fromName(it); projector.createBuilder(AWSScannerBuilder.class).withRegion(region) .build(AllEntityScanner.class).scan(); } catch (Exception e) { LoggerFactory.getLogger(Main.class).warn("problem scanning " + it, e); } }); } catch (Exception e) { LoggerFactory.getLogger(Main.class).warn("problem", e); } } }; Runnable dockerTask = new Runnable() { public void run() { projector.createBuilder(DockerScannerBuilder.class).withLocalDockerDaemon().build().scan(); } }; ScheduledExecutorService exec = Executors.newScheduledThreadPool(5); exec.scheduleWithFixedDelay(awsTask, 0, 1, TimeUnit.MINUTES); exec.scheduleWithFixedDelay(dockerTask, 0, 10, TimeUnit.SECONDS); while (true == true) { try { Thread.sleep(1000); } catch (Exception e) { } } }
From source file:demo.leader.LeaderSelectorExample.java
public static void main(String[] args) throws Exception { // all of the useful sample code is in ExampleClient.java System.out.println("Create " + CLIENT_QTY + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur."); System.out.println(/* ww w .j a v a 2s . c o m*/ "Notice that leader election is fair: all clients will become leader and will do so the same number of times."); List<CuratorFramework> clients = Lists.newArrayList(); List<ExampleClient> examples = Lists.newArrayList(); TestingServer server = new TestingServer(); try { // for (int i = 0; i < CLIENT_QTY; ++i) { CuratorFramework client = CuratorFrameworkFactory.newClient(host, new ExponentialBackoffRetry(1000, 3)); clients.add(client); ExampleClient example = new ExampleClient(client, PATH, "Client#"); // ExampleClient example = new ExampleClient(client, PATH, "Client#" + i); examples.add(example); client.start(); example.start(); // } System.out.println("Press enter/return to quit\n"); String sleepSec = new BufferedReader(new InputStreamReader(System.in)).readLine(); } finally { System.out.println("Shutting down..."); for (ExampleClient exampleClient : examples) { CloseableUtils.closeQuietly(exampleClient); } for (CuratorFramework client : clients) { CloseableUtils.closeQuietly(client); } CloseableUtils.closeQuietly(server); } }
From source file:hellogroovy.ExampleCreateIssuesAsynchronous.java
public static void main(String[] args) throws IOException { final AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory(); final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "kalaliu", "Miahero0302"); try {/*from w w w . ja v a2 s . c o m*/ final List<Promise<BasicIssue>> promises = Lists.newArrayList(); final IssueRestClient issueClient = restClient.getIssueClient(); System.out.println("Sending issue creation requests..."); for (int i = 0; i < 1; i++) { final String summary = "this is a test for kala #" + i; // This is a test case // IssueInputBuilder builder = new IssueInputBuilder("ACP", 10000L, summary); //bug IssueInputBuilder builder = new IssueInputBuilder("ACP", 3L, summary); builder.setFieldValue("timetracking", new TimeTracking(1, null, null)); // builder.setFieldValue("customfield_10013", 1); final IssueInput newIssue = builder.build(); System.out.println("\tCreating: " + summary); promises.add(issueClient.createIssue(newIssue)); } System.out.println("Collecting responses..."); final Iterable<BasicIssue> createdIssues = transform(promises, new Function<Promise<BasicIssue>, BasicIssue>() { @Override public BasicIssue apply(Promise<BasicIssue> promise) { return promise.claim(); } }); System.out.println("Created issues:\n" + Joiner.on("\n").join(createdIssues)); } finally { restClient.close(); } }
From source file:com.weibangong.spark.streaming.JavaQueueStream.java
public static void main(String[] args) throws Exception { SparkConf sparkConf = new SparkConf().setAppName("JavaQueueStream"); // Create the context JavaStreamingContext ssc = new JavaStreamingContext(sparkConf, new Duration(1000)); // Create the queue through which RDDs can be pushed to // a QueueInputDStream Queue<JavaRDD<Integer>> rddQueue = new LinkedList<JavaRDD<Integer>>(); // Create and push some RDDs into the queue List<Integer> list = Lists.newArrayList(); for (int i = 0; i < 1000; i++) { list.add(i);// w w w. j a va2 s . c o m } for (int i = 0; i < 30; i++) { rddQueue.add(ssc.sparkContext().parallelize(list)); } // Create the QueueInputDStream and use it do some processing JavaDStream<Integer> inputStream = ssc.queueStream(rddQueue); JavaPairDStream<Integer, Integer> mappedStream = inputStream .mapToPair(new PairFunction<Integer, Integer, Integer>() { @Override public Tuple2<Integer, Integer> call(Integer i) { return new Tuple2<Integer, Integer>(i % 10, 1); } }); JavaPairDStream<Integer, Integer> reducedStream = mappedStream .reduceByKey(new Function2<Integer, Integer, Integer>() { @Override public Integer call(Integer i1, Integer i2) { return i1 + i2; } }); reducedStream.print(); ssc.start(); ssc.awaitTermination(); }
From source file:me.huding.curator.leader.LeaderSelectorExample.java
public static void main(String[] args) throws Exception { // all of the useful sample code is in ExampleClient.java System.out.println("Create " + CLIENT_QTY + " clients, have each negotiate for leadership and then wait a random number of seconds before letting another leader election occur."); System.out.println(//from w w w. ja va 2s . c om "Notice that leader election is fair: all clients will become leader and will do so the same number of times."); List<CuratorFramework> clients = Lists.newArrayList(); List<ExampleClient> examples = Lists.newArrayList(); try { for (int i = 0; i < CLIENT_QTY; ++i) { CuratorFramework client = CuratorFrameworkFactory.newClient(connectString, new ExponentialBackoffRetry(1000, 3)); clients.add(client); ExampleClient example = new ExampleClient(client, LEADER_PATH, "Client #" + i); examples.add(example); client.start(); example.start(); } System.out.println("Press enter/return to quit\n"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } finally { System.out.println("Shutting down..."); for (ExampleClient exampleClient : examples) { CloseableUtils.closeQuietly(exampleClient); } for (CuratorFramework client : clients) { CloseableUtils.closeQuietly(client); } } }
From source file:org.zookeepersample.curator.SharedCounterSample.java
public static void main(String[] args) throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient("myservice..myservice.com:2188", new ExponentialBackoffRetry(1000, 3)); client.start();//from www . ja v a 2s. c om SharedCount sharedCount = new SharedCount(client, PATH, 0); sharedCount.addListener(new SharedCountListener() { @Override public void stateChanged(CuratorFramework client, ConnectionState newState) { System.out.println(newState.toString()); } @Override public void countHasChanged(SharedCountReader sharedCount, int newCount) throws Exception { System.out.println(newCount); } }); sharedCount.start(); ExecutorService service = Executors.newFixedThreadPool(10); List<SharedCount> list = Lists.newArrayList(); for (int i = 0; i < 10; i++) { final SharedCount count = new SharedCount(client, PATH, 0); count.addListener(new SharedCountListener() { @Override public void stateChanged(CuratorFramework client, ConnectionState newState) { System.out.println(newState.toString()); } @Override public void countHasChanged(SharedCountReader sharedCount, int newCount) throws Exception { System.out.println(newCount); } }); list.add(count); Callable<Void> task = new Callable<Void>() { @Override public Void call() throws Exception { count.start(); //Thread.sleep(500); while (!count.trySetCount(count.getVersionedValue(), count.getCount() + 1)) { Thread.sleep(100); } return null; } }; service.submit(task); } service.shutdown(); service.awaitTermination(10, TimeUnit.MINUTES); for (SharedCount count : list) { count.close(); } sharedCount.close(); }