List of usage examples for com.google.common.collect Lists newArrayList
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayList()
From source file:com.x.app.test.HelloWorld.java
public static void main(String[] args) { if (args.length < 1) { System.err.println("Arguments format: <host:port of zookeeper server>"); System.exit(1);/*from w w w. ja va 2 s.c om*/ } String zkStr = args[0]; YarnConfiguration yarnConfiguration = new YarnConfiguration(); yarnConfiguration.setSocketAddr("yarn.resourcemanager.address", new InetSocketAddress("192.168.80.103", 8032)); final TwillRunnerService twillRunner = new YarnTwillRunnerService(yarnConfiguration, zkStr); twillRunner.start(); String yarnClasspath = yarnConfiguration.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH, Joiner.on(",").join(YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)); List<String> applicationClassPaths = Lists.newArrayList(); Iterables.addAll(applicationClassPaths, Splitter.on(",").split(yarnClasspath)); final TwillController controller = twillRunner.prepare(new HelloWorldRunnable()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationClassPaths(applicationClassPaths) .withBundlerClassAcceptor(new HadoopClassExcluder()).start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { Futures.getUnchecked(controller.terminate()); } finally { twillRunner.stop(); } } }); try { controller.awaitTerminated(); } catch (ExecutionException e) { e.printStackTrace(); } }
From source file:com.google.logicoin.examples.PrintPeers.java
public static void main(String[] args) throws Exception { BriefLogFormatter.init();//from w ww .jav a2s . com System.out.println("=== DNS ==="); printDNS(); System.out.println("=== Version/chain heights ==="); ArrayList<InetAddress> addrs = new ArrayList<InetAddress>(); for (InetSocketAddress peer : dnsPeers) addrs.add(peer.getAddress()); System.out.println("Scanning " + addrs.size() + " peers:"); final NetworkParameters params = MainNetParams.get(); final Object lock = new Object(); final long[] bestHeight = new long[1]; List<ListenableFuture<TCPNetworkConnection>> futures = Lists.newArrayList(); for (final InetAddress addr : addrs) { final ListenableFuture<TCPNetworkConnection> future = TCPNetworkConnection.connectTo(params, new InetSocketAddress(addr, params.getPort()), 1000 /* timeout */, null); futures.add(future); // Once the connection has completed version handshaking ... Futures.addCallback(future, new FutureCallback<TCPNetworkConnection>() { public void onSuccess(TCPNetworkConnection conn) { // Check the chain height it claims to have. VersionMessage ver = conn.getVersionMessage(); long nodeHeight = ver.bestHeight; synchronized (lock) { long diff = bestHeight[0] - nodeHeight; if (diff > 0) { System.out.println("Node is behind by " + diff + " blocks: " + addr); } else if (diff == 0) { System.out.println("Node " + addr + " has " + nodeHeight + " blocks"); bestHeight[0] = nodeHeight; } else if (diff < 0) { System.out.println("Node is ahead by " + Math.abs(diff) + " blocks: " + addr); bestHeight[0] = nodeHeight; } } conn.close(); } public void onFailure(Throwable throwable) { System.out.println("Failed to talk to " + addr + ": " + throwable.getMessage()); } }); } // Wait for every tried connection to finish. Futures.successfulAsList(futures).get(); }
From source file:tachyon.Format.java
/** * Formats the Tachyon file system via {@code java -cp %s tachyon.Format <MASTER/WORKER>}. * * @param args either {@code MASTER} or {@code WORKER} * @throws IOException if a non-Tachyon related exception occurs *//*w w w .j a v a 2 s .c o m*/ public static void main(String[] args) throws IOException { if (args.length != 1) { LOG.info(USAGE); System.exit(-1); } TachyonConf tachyonConf = new TachyonConf(); if ("MASTER".equals(args[0].toUpperCase())) { String masterJournal = tachyonConf.get(Constants.MASTER_JOURNAL_FOLDER); if (!formatFolder("JOURNAL_FOLDER", masterJournal, tachyonConf)) { System.exit(-1); } List<String> masterServiceNames = Lists.newArrayList(); masterServiceNames.add(Constants.BLOCK_MASTER_NAME); masterServiceNames.add(Constants.FILE_SYSTEM_MASTER_NAME); masterServiceNames.add(Constants.LINEAGE_MASTER_NAME); if (tachyonConf.getBoolean(Constants.KEY_VALUE_ENABLED)) { masterServiceNames.add(Constants.KEY_VALUE_MASTER_NAME); } for (String masterServiceName : masterServiceNames) { if (!formatFolder(masterServiceName + "_JOURNAL_FOLDER", PathUtils.concatPath(masterJournal, masterServiceName), tachyonConf)) { System.exit(-1); } } // A journal folder is thought to be formatted only when a file with the specific name is // present under the folder. UnderFileSystemUtils.touch( PathUtils.concatPath(masterJournal, Constants.FORMAT_FILE_PREFIX + System.currentTimeMillis()), tachyonConf); } else if ("WORKER".equals(args[0].toUpperCase())) { String workerDataFolder = tachyonConf.get(Constants.WORKER_DATA_FOLDER); int storageLevels = tachyonConf.getInt(Constants.WORKER_TIERED_STORE_LEVELS); for (int level = 0; level < storageLevels; level++) { String tierLevelDirPath = String.format(Constants.WORKER_TIERED_STORE_LEVEL_DIRS_PATH_FORMAT, level); String[] dirPaths = tachyonConf.get(tierLevelDirPath).split(","); String name = "TIER_" + level + "_DIR_PATH"; for (String dirPath : dirPaths) { String dirWorkerDataFolder = PathUtils.concatPath(dirPath.trim(), workerDataFolder); UnderFileSystem ufs = UnderFileSystem.get(dirWorkerDataFolder, tachyonConf); if (ufs.exists(dirWorkerDataFolder)) { if (!formatFolder(name, dirWorkerDataFolder, tachyonConf)) { System.exit(-1); } } } } } else { LOG.info(USAGE); System.exit(-1); } }
From source file:org.graylog2.radio.Main.java
public static void main(String[] args) { LOG.info("Starting up."); final CommandLineArguments cli = new CommandLineArguments(); final JCommander jCommander = new JCommander(cli, args); jCommander.setProgramName("graylog2-radio"); // Show help and exit. if (cli.isHelp()) { jCommander.usage();/*www . ja v a 2 s.co m*/ System.exit(0); } ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory .getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); if (cli.isDebug()) { root.setLevel(Level.ALL); } else { root.setLevel(Level.INFO); } savePidFile(cli.getPidFile()); LOG.info("Loading configuration: " + cli.getConfigFile()); Configuration configuration = new Configuration(); JadConfig jadConfig = new JadConfig(new PropertiesRepository(cli.getConfigFile()), configuration); // Parse configuration. try { jadConfig.process(); } catch (RepositoryException e) { LOG.error("Couldn't load configuration file " + cli.getConfigFile(), e); System.exit(1); } catch (ValidationException e) { LOG.error("Invalid configuration", e); System.exit(1); } // Parse input configuration; List<InputConfiguration> inputs = Lists.newArrayList(); try { String inputDefinition = Tools.readFile(configuration.getInputsFile()); inputs = InputConfigurationParser.fromString(inputDefinition); LOG.info("Read {} initial inputs from {}", inputs.size(), configuration.getInputsFile()); } catch (Exception e) { LOG.error("Could not read initial set of inputs. Terminating.", e); System.exit(1); } Radio radio = new Radio(); radio.setConfiguration(configuration); try { radio.initialize(inputs); } catch (IOException e) { LOG.error("IOException on startup.", e); System.exit(1); } }
From source file:org.apache.ctakes.relationextractor.eval.ModifierExtractorEvaluation.java
public static void main(String[] args) throws Exception { // parse the options, validate them, and generate XMI if necessary final EvaluationOptions options = CliFactory.parseArguments(EvaluationOptions.class, args); SHARPXMI.validate(options);//from w ww.java 2 s.c om SHARPXMI.generateXMI(options); // determine the grid of parameters to search through // for the full set of LibLinear parameters, see: // https://github.com/bwaldvogel/liblinear-java/blob/master/src/main/java/de/bwaldvogel/liblinear/Train.java List<ParameterSettings> gridOfSettings = Lists.newArrayList(); for (int solver : new int[] { 0 /* logistic regression */, 1 /* SVM */ }) { for (double svmCost : new double[] { 0.01, 0.05, 0.1, 0.5, 1, 5, 10, 50, 100 }) { gridOfSettings.add(new ParameterSettings(LibLinearStringOutcomeDataWriter.class, new String[] { "-s", String.valueOf(solver), "-c", String.valueOf(svmCost) })); } } // run the evaluation SHARPXMI.evaluate(options, BEST_PARAMETERS, gridOfSettings, new Function<ParameterSettings, ModifierExtractorEvaluation>() { @Override public ModifierExtractorEvaluation apply(@Nullable ParameterSettings params) { return new ModifierExtractorEvaluation(new File("target/models/modifier"), params); } }); }
From source file:com.google.bitcoin.examples.PrintPeers.java
public static void main(String[] args) throws Exception { BriefLogFormatter.init();//from ww w. j a v a 2 s. co m System.out.println("=== DNS ==="); printDNS(); System.out.println("=== Version/chain heights ==="); ArrayList<InetAddress> addrs = new ArrayList<InetAddress>(); for (InetSocketAddress peer : dnsPeers) addrs.add(peer.getAddress()); System.out.println("Scanning " + addrs.size() + " peers:"); final NetworkParameters params = MainNetParams.get(); final Object lock = new Object(); final long[] bestHeight = new long[1]; List<ListenableFuture<Void>> futures = Lists.newArrayList(); NioClientManager clientManager = new NioClientManager(); for (final InetAddress addr : addrs) { InetSocketAddress address = new InetSocketAddress(addr, params.getPort()); final Peer peer = new Peer(params, new VersionMessage(params, 0), null, new PeerAddress(address)); final SettableFuture future = SettableFuture.create(); // Once the connection has completed version handshaking ... peer.addEventListener(new AbstractPeerEventListener() { public void onPeerConnected(Peer p, int peerCount) { // Check the chain height it claims to have. VersionMessage ver = peer.getPeerVersionMessage(); long nodeHeight = ver.bestHeight; synchronized (lock) { long diff = bestHeight[0] - nodeHeight; if (diff > 0) { System.out.println("Node is behind by " + diff + " blocks: " + addr); } else if (diff == 0) { System.out.println("Node " + addr + " has " + nodeHeight + " blocks"); bestHeight[0] = nodeHeight; } else if (diff < 0) { System.out.println("Node is ahead by " + Math.abs(diff) + " blocks: " + addr); bestHeight[0] = nodeHeight; } } // Now finish the future and close the connection future.set(null); peer.close(); } public void onPeerDisconnected(Peer p, int peerCount) { if (!future.isDone()) System.out.println("Failed to talk to " + addr); future.set(null); } }); clientManager.openConnection(address, peer); futures.add(future); } // Wait for every tried connection to finish. Futures.successfulAsList(futures).get(); }
From source file:org.guldenj.examples.PrintPeers.java
public static void main(String[] args) throws Exception { BriefLogFormatter.init();//w w w . ja v a 2s . c o m System.out.println("=== DNS ==="); printDNS(); System.out.println("=== Version/chain heights ==="); ArrayList<InetAddress> addrs = new ArrayList<InetAddress>(); for (InetSocketAddress peer : dnsPeers) addrs.add(peer.getAddress()); System.out.println("Scanning " + addrs.size() + " peers:"); final NetworkParameters params = MainNetParams.get(); final Object lock = new Object(); final long[] bestHeight = new long[1]; List<ListenableFuture<Void>> futures = Lists.newArrayList(); NioClientManager clientManager = new NioClientManager(); for (final InetAddress addr : addrs) { InetSocketAddress address = new InetSocketAddress(addr, params.getPort()); final Peer peer = new Peer(params, new VersionMessage(params, 0), null, new PeerAddress(address)); final SettableFuture<Void> future = SettableFuture.create(); // Once the connection has completed version handshaking ... peer.addConnectedEventListener(new PeerConnectedEventListener() { @Override public void onPeerConnected(Peer p, int peerCount) { // Check the chain height it claims to have. VersionMessage ver = peer.getPeerVersionMessage(); long nodeHeight = ver.bestHeight; synchronized (lock) { long diff = bestHeight[0] - nodeHeight; if (diff > 0) { System.out.println("Node is behind by " + diff + " blocks: " + addr); } else if (diff == 0) { System.out.println("Node " + addr + " has " + nodeHeight + " blocks"); bestHeight[0] = nodeHeight; } else if (diff < 0) { System.out.println("Node is ahead by " + Math.abs(diff) + " blocks: " + addr); bestHeight[0] = nodeHeight; } } // Now finish the future and close the connection future.set(null); peer.close(); } }); peer.addDisconnectedEventListener(new PeerDisconnectedEventListener() { @Override public void onPeerDisconnected(Peer p, int peerCount) { if (!future.isDone()) System.out.println("Failed to talk to " + addr); future.set(null); } }); clientManager.openConnection(address, peer); futures.add(future); } // Wait for every tried connection to finish. Futures.successfulAsList(futures).get(); }
From source file:org.bitcoinj.examples.PrintPeers.java
public static void main(String[] args) throws Exception { BriefLogFormatter.init();/*from w w w . ja v a 2 s. co m*/ System.out.println("=== DNS ==="); printDNS(); System.out.println("=== Version/chain heights ==="); ArrayList<InetAddress> addrs = new ArrayList<InetAddress>(); for (InetSocketAddress peer : dnsPeers) addrs.add(peer.getAddress()); System.out.println("Scanning " + addrs.size() + " peers:"); final NetworkParameters params = MainNetParams.get(); final Object lock = new Object(); final long[] bestHeight = new long[1]; List<ListenableFuture<Void>> futures = Lists.newArrayList(); NioClientManager clientManager = new NioClientManager(); for (final InetAddress addr : addrs) { InetSocketAddress address = new InetSocketAddress(addr, params.getPort()); final Peer peer = new Peer(params, new VersionMessage(params, 0), null, new PeerAddress(params, address)); final SettableFuture<Void> future = SettableFuture.create(); // Once the connection has completed version handshaking ... peer.addConnectedEventListener(new PeerConnectedEventListener() { @Override public void onPeerConnected(Peer p, int peerCount) { // Check the chain height it claims to have. VersionMessage ver = peer.getPeerVersionMessage(); long nodeHeight = ver.bestHeight; synchronized (lock) { long diff = bestHeight[0] - nodeHeight; if (diff > 0) { System.out.println("Node is behind by " + diff + " blocks: " + addr); } else if (diff == 0) { System.out.println("Node " + addr + " has " + nodeHeight + " blocks"); bestHeight[0] = nodeHeight; } else if (diff < 0) { System.out.println("Node is ahead by " + Math.abs(diff) + " blocks: " + addr); bestHeight[0] = nodeHeight; } } // Now finish the future and close the connection future.set(null); peer.close(); } }); peer.addDisconnectedEventListener(new PeerDisconnectedEventListener() { @Override public void onPeerDisconnected(Peer p, int peerCount) { if (!future.isDone()) System.out.println("Failed to talk to " + addr); future.set(null); } }); clientManager.openConnection(address, peer); futures.add(future); } // Wait for every tried connection to finish. Futures.successfulAsList(futures).get(); }
From source file:com.dogecoin.dogecoinj.examples.PrintPeers.java
public static void main(String[] args) throws Exception { BriefLogFormatter.init();/*from w w w. j a va2s. c om*/ System.out.println("=== DNS ==="); printDNS(); System.out.println("=== Version/chain heights ==="); ArrayList<InetAddress> addrs = new ArrayList<InetAddress>(); for (InetSocketAddress peer : dnsPeers) addrs.add(peer.getAddress()); System.out.println("Scanning " + addrs.size() + " peers:"); final NetworkParameters params = MainNetParams.get(); final Object lock = new Object(); final long[] bestHeight = new long[1]; List<ListenableFuture<Void>> futures = Lists.newArrayList(); NioClientManager clientManager = new NioClientManager(); for (final InetAddress addr : addrs) { InetSocketAddress address = new InetSocketAddress(addr, params.getPort()); final Peer peer = new Peer(params, new VersionMessage(params, 0), null, new PeerAddress(address)); final SettableFuture<Void> future = SettableFuture.create(); // Once the connection has completed version handshaking ... peer.addEventListener(new AbstractPeerEventListener() { @Override public void onPeerConnected(Peer p, int peerCount) { // Check the chain height it claims to have. VersionMessage ver = peer.getPeerVersionMessage(); long nodeHeight = ver.bestHeight; synchronized (lock) { long diff = bestHeight[0] - nodeHeight; if (diff > 0) { System.out.println("Node is behind by " + diff + " blocks: " + addr); } else if (diff == 0) { System.out.println("Node " + addr + " has " + nodeHeight + " blocks"); bestHeight[0] = nodeHeight; } else if (diff < 0) { System.out.println("Node is ahead by " + Math.abs(diff) + " blocks: " + addr); bestHeight[0] = nodeHeight; } } // Now finish the future and close the connection future.set(null); peer.close(); } @Override public void onPeerDisconnected(Peer p, int peerCount) { if (!future.isDone()) System.out.println("Failed to talk to " + addr); future.set(null); } }); clientManager.openConnection(address, peer); futures.add(future); } // Wait for every tried connection to finish. Futures.successfulAsList(futures).get(); }
From source file:com.google.worldcoin.examples.PrintPeers.java
public static void main(String[] args) throws Exception { BriefLogFormatter.init();/* w w w. j a v a 2s . c o m*/ System.out.println("=== DNS ==="); printDNS(); System.out.println("=== Version/chain heights ==="); ArrayList<InetAddress> addrs = new ArrayList<InetAddress>(); for (InetSocketAddress peer : dnsPeers) addrs.add(peer.getAddress()); //addrs.add(convertAddress()); System.out.println("Scanning " + addrs.size() + " peers:"); final NetworkParameters params = MainNetParams.get(); final Object lock = new Object(); final long[] bestHeight = new long[1]; List<ListenableFuture<Void>> futures = Lists.newArrayList(); NioClientManager clientManager = new NioClientManager(); for (final InetAddress addr : addrs) { InetSocketAddress address = new InetSocketAddress(addr, params.getPort()); final Peer peer = new Peer(params, new VersionMessage(params, 0), null, new PeerAddress(address)); final SettableFuture future = SettableFuture.create(); // Once the connection has completed version handshaking ... peer.addEventListener(new AbstractPeerEventListener() { public void onPeerConnected(Peer p, int peerCount) { // Check the chain height it claims to have. VersionMessage ver = peer.getPeerVersionMessage(); long nodeHeight = ver.bestHeight; synchronized (lock) { long diff = bestHeight[0] - nodeHeight; if (diff > 0) { System.out.println("Node is behind by " + diff + " blocks: " + addr); } else if (diff == 0) { System.out.println("Node " + addr + " has " + nodeHeight + " blocks"); bestHeight[0] = nodeHeight; } else if (diff < 0) { System.out.println("Node is ahead by " + Math.abs(diff) + " blocks: " + addr); bestHeight[0] = nodeHeight; } } // Now finish the future and close the connection future.set(null); peer.close(); } public void onPeerDisconnected(Peer p, int peerCount) { if (!future.isDone()) System.out.println("Failed to talk to " + addr); future.set(null); } }); clientManager.start(); clientManager.openConnection(address, peer); futures.add(future); } // Wait for every tried connection to finish. Futures.successfulAsList(futures).get(); }