List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression)
From source file:org.apache.streams.twitter.provider.TwitterFollowingProvider.java
/** * To use from command line://from w w w. j a v a 2s . c o m * * <p/> * Supply (at least) the following required configuration in application.conf: * * <p/> * twitter.oauth.consumerKey * twitter.oauth.consumerSecret * twitter.oauth.accessToken * twitter.oauth.accessTokenSecret * twitter.info * * <p/> * Launch using: * * <p/> * mvn exec:java -Dexec.mainClass=org.apache.streams.twitter.provider.TwitterFollowingProvider -Dexec.args="application.conf tweets.json" * * @param args args * @throws Exception Exception */ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length >= 2); String configfile = args[0]; String outfile = args[1]; Config reference = ConfigFactory.load(); File file = new File(configfile); assert (file.exists()); Config testResourceConfig = ConfigFactory.parseFileAnySyntax(file, ConfigParseOptions.defaults().setAllowMissing(false)); Config typesafe = testResourceConfig.withFallback(reference).resolve(); StreamsConfiguration streamsConfiguration = StreamsConfigurator.detectConfiguration(typesafe); TwitterFollowingConfiguration config = new ComponentConfigurator<>(TwitterFollowingConfiguration.class) .detectConfiguration(typesafe, "twitter"); TwitterFollowingProvider provider = new TwitterFollowingProvider(config); ObjectMapper mapper = new StreamsJacksonMapper( Collections.singletonList(TwitterDateTimeFormat.TWITTER_FORMAT)); PrintStream outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); provider.prepare(config); provider.startStream(); do { Thread.sleep(streamsConfiguration.getBatchFrequencyMs()); for (StreamsDatum datum : provider.readCurrent()) { String json; try { json = mapper.writeValueAsString(datum.getDocument()); outStream.println(json); } catch (JsonProcessingException ex) { System.err.println(ex.getMessage()); } } } while (provider.isRunning()); provider.cleanUp(); outStream.flush(); }
From source file:org.apache.streams.facebook.provider.page.FacebookPageProvider.java
/** * Run FacebookPageProvider from command line. * @param args configfile outfile//from www . jav a 2 s . c o m * @throws Exception Exception */ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length >= 2); String configfile = args[0]; String outfile = args[1]; Config reference = ConfigFactory.load(); File confFile = new File(configfile); assert (confFile.exists()); Config conf = ConfigFactory.parseFileAnySyntax(confFile, ConfigParseOptions.defaults().setAllowMissing(false)); Config typesafe = conf.withFallback(reference).resolve(); StreamsConfiguration streamsConfiguration = StreamsConfigurator.detectConfiguration(typesafe); FacebookConfiguration config = new ComponentConfigurator<>(FacebookConfiguration.class) .detectConfiguration(typesafe, "facebook"); FacebookPageProvider provider = new FacebookPageProvider(config); PrintStream outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); provider.prepare(config); provider.startStream(); do { Uninterruptibles.sleepUninterruptibly(streamsConfiguration.getBatchFrequencyMs(), TimeUnit.MILLISECONDS); for (StreamsDatum datum : provider.readCurrent()) { String json; try { json = MAPPER.writeValueAsString(datum.getDocument()); outStream.println(json); } catch (JsonProcessingException ex) { System.err.println(ex.getMessage()); } } } while (provider.isRunning()); provider.cleanUp(); outStream.flush(); }
From source file:com.cloudera.nav.sdk.examples.lineage3.LineageExport.java
/** * @param args 1. config file path/* w w w .ja v a 2 s . c o m*/ * 2. query to fetch entities for which lineage * would be downloaded. * 3. direction * 4. length * 5. lineage options * @throws Exception */ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length == 5); Preconditions.checkArgument( "downstream".equals(args[2].toLowerCase()) || "upstream".equals(args[2].toLowerCase())); Preconditions.checkArgument(Integer.parseInt(args[3]) > 0); Preconditions.checkArgument(Integer.parseInt(args[4]) >= -1); (new LineageExport(args[0], args[1], args[2].toUpperCase(), args[3], args[4])).run(); }
From source file:nerds.antelax.commons.net.pubsub.Megaphone.java
public static void main(final String... args) throws Throwable { Preconditions.checkArgument(args.length > 1); final Collection<InetSocketAddress> servers = hostPortPairsFromString(args[0], PubSubServer.DEFAULT_ADDRESS.getPort()); final Collection<String> topics = new LinkedList<String>(); for (int pos = 1; pos < args.length; ++pos) topics.add(args[pos]);// w ww .j a va2 s . c o m new Megaphone(servers, topics).repl(); }
From source file:org.apache.fluo.core.worker.FluoWorkerImpl.java
public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: FluoWorkerImpl <fluoPropsPath>"); System.exit(-1);/* ww w. j a v a2s .c o m*/ } String propsPath = args[0]; Objects.requireNonNull(propsPath); File propsFile = new File(propsPath); if (!propsFile.exists()) { System.err.println("ERROR - Fluo properties file does not exist: " + propsPath); System.exit(-1); } Preconditions.checkArgument(propsFile.exists()); try { FluoConfiguration config = new FluoConfiguration(propsFile); FluoWorkerImpl worker = new FluoWorkerImpl(config); worker.start(); while (true) { UtilWaitThread.sleep(10000); } } catch (Exception e) { log.error("Exception running FluoWorker: ", e); } }
From source file:org.apache.fluo.core.oracle.FluoOracleImpl.java
public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: FluoOracleImpl <fluoPropsPath>"); System.exit(-1);//from w w w . j av a2s. c om } String propsPath = args[0]; Objects.requireNonNull(propsPath); File propsFile = new File(propsPath); if (!propsFile.exists()) { System.err.println("ERROR - Fluo properties file does not exist: " + propsPath); System.exit(-1); } Preconditions.checkArgument(propsFile.exists()); try { FluoConfiguration config = new FluoConfiguration(propsFile); FluoOracleImpl oracle = new FluoOracleImpl(config); oracle.start(); while (true) { UtilWaitThread.sleep(10000); } } catch (Exception e) { log.error("Exception running FluoOracle: ", e); } }
From source file:org.apache.streams.twitter.provider.TwitterStreamProvider.java
/** * To use from command line://from w ww. j a v a2 s . co m * * <p/> * Supply (at least) the following required configuration in application.conf: * * <p/> * twitter.oauth.consumerKey * twitter.oauth.consumerSecret * twitter.oauth.accessToken * twitter.oauth.accessTokenSecret * * <p/> * Launch using: * * <p/> * mvn exec:java -Dexec.mainClass=org.apache.streams.twitter.provider.TwitterStreamProvider -Dexec.args="application.conf tweets.json" * * @param args */ public static void main(String[] args) { Preconditions.checkArgument(args.length >= 2); String configfile = args[0]; String outfile = args[1]; Config reference = ConfigFactory.load(); File file = new File(configfile); assert (file.exists()); Config testResourceConfig = ConfigFactory.parseFileAnySyntax(file, ConfigParseOptions.defaults().setAllowMissing(false)); Config typesafe = testResourceConfig.withFallback(reference).resolve(); StreamsConfiguration streamsConfiguration = StreamsConfigurator.detectConfiguration(typesafe); TwitterStreamConfiguration config = new ComponentConfigurator<>(TwitterStreamConfiguration.class) .detectConfiguration(typesafe, "twitter"); TwitterStreamProvider provider = new TwitterStreamProvider(config); ObjectMapper mapper = StreamsJacksonMapper .getInstance(Collections.singletonList(TwitterDateTimeFormat.TWITTER_FORMAT)); PrintStream outStream; try { outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); } catch (FileNotFoundException ex) { LOGGER.error("FileNotFoundException", ex); return; } provider.prepare(config); provider.startStream(); do { Uninterruptibles.sleepUninterruptibly(streamsConfiguration.getBatchFrequencyMs(), TimeUnit.MILLISECONDS); for (StreamsDatum datum : provider.readCurrent()) { String json; try { json = mapper.writeValueAsString(datum.getDocument()); outStream.println(json); } catch (JsonProcessingException ex) { System.err.println(ex.getMessage()); } } } while (provider.isRunning()); provider.cleanUp(); outStream.flush(); }
From source file:org.apache.streams.twitter.provider.TwitterUserInformationProvider.java
/** * To use from command line:/*w w w . ja v a2 s. com*/ * * <p/> * Supply (at least) the following required configuration in application.conf: * * <p/> * twitter.oauth.consumerKey * twitter.oauth.consumerSecret * twitter.oauth.accessToken * twitter.oauth.accessTokenSecret * twitter.info * * <p/> * Launch using: * * <p/> * mvn exec:java -Dexec.mainClass=org.apache.streams.twitter.provider.TwitterUserInformationProvider -Dexec.args="application.conf tweets.json" * * @param args args * @throws Exception Exception */ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length >= 2); String configfile = args[0]; String outfile = args[1]; Config reference = ConfigFactory.load(); File file = new File(configfile); assert (file.exists()); Config testResourceConfig = ConfigFactory.parseFileAnySyntax(file, ConfigParseOptions.defaults().setAllowMissing(false)); Config typesafe = testResourceConfig.withFallback(reference).resolve(); StreamsConfiguration streamsConfiguration = StreamsConfigurator.detectConfiguration(typesafe); TwitterUserInformationConfiguration config = new ComponentConfigurator<>( TwitterUserInformationConfiguration.class).detectConfiguration(typesafe, "twitter"); TwitterUserInformationProvider provider = new TwitterUserInformationProvider(config); PrintStream outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); provider.prepare(config); provider.startStream(); do { Uninterruptibles.sleepUninterruptibly(streamsConfiguration.getBatchFrequencyMs(), TimeUnit.MILLISECONDS); for (StreamsDatum datum : provider.readCurrent()) { String json; try { json = MAPPER.writeValueAsString(datum.getDocument()); outStream.println(json); } catch (JsonProcessingException ex) { System.err.println(ex.getMessage()); } } } while (provider.isRunning()); provider.cleanUp(); outStream.flush(); }
From source file:org.apache.streams.moreover.MoreoverProvider.java
/** * To use from command line:// w w w . jav a 2 s. c o m * * <p/> * Supply configuration similar to src/test/resources/rss.conf * * <p/> * Launch using: * * <p/> * mvn exec:java -Dexec.mainClass=org.apache.streams.moreover.MoreoverProvider -Dexec.args="rss.conf articles.json" * * @param args args * @throws Exception Exception */ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length >= 2); String configfile = args[0]; String outfile = args[1]; Config reference = ConfigFactory.load(); File file = new File(configfile); assert (file.exists()); Config testResourceConfig = ConfigFactory.parseFileAnySyntax(file, ConfigParseOptions.defaults().setAllowMissing(false)); Config typesafe = testResourceConfig.withFallback(reference).resolve(); StreamsConfiguration streamsConfiguration = StreamsConfigurator.detectConfiguration(typesafe); MoreoverConfiguration config = new ComponentConfigurator<>(MoreoverConfiguration.class) .detectConfiguration(typesafe, "rss"); MoreoverProvider provider = new MoreoverProvider(config); ObjectMapper mapper = StreamsJacksonMapper.getInstance(); PrintStream outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); provider.prepare(config); provider.startStream(); do { Uninterruptibles.sleepUninterruptibly(streamsConfiguration.getBatchFrequencyMs(), TimeUnit.MILLISECONDS); for (StreamsDatum datum : provider.readCurrent()) { String json; try { json = mapper.writeValueAsString(datum.getDocument()); outStream.println(json); } catch (JsonProcessingException ex) { System.err.println(ex.getMessage()); } } } while (provider.isRunning()); provider.cleanUp(); outStream.flush(); }
From source file:org.apache.streams.twitter.provider.TwitterTimelineProvider.java
/** * To use from command line:// w w w . j a v a2 s . c o m * * <p/> * Supply (at least) the following required configuration in application.conf: * * <p/> * twitter.oauth.consumerKey * twitter.oauth.consumerSecret * twitter.oauth.accessToken * twitter.oauth.accessTokenSecret * twitter.info * * <p/> * Launch using: * * <p/> * mvn exec:java -Dexec.mainClass=org.apache.streams.twitter.provider.TwitterTimelineProvider -Dexec.args="application.conf tweets.json" * * @param args args * @throws Exception Exception */ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length >= 2); String configfile = args[0]; String outfile = args[1]; Config reference = ConfigFactory.load(); File file = new File(configfile); assert (file.exists()); Config testResourceConfig = ConfigFactory.parseFileAnySyntax(file, ConfigParseOptions.defaults().setAllowMissing(false)); Config typesafe = testResourceConfig.withFallback(reference).resolve(); StreamsConfiguration streamsConfiguration = StreamsConfigurator.detectConfiguration(typesafe); TwitterTimelineProviderConfiguration config = new ComponentConfigurator<>( TwitterTimelineProviderConfiguration.class).detectConfiguration(typesafe, "twitter"); TwitterTimelineProvider provider = new TwitterTimelineProvider(config); ObjectMapper mapper = new StreamsJacksonMapper( Stream.of(TwitterDateTimeFormat.TWITTER_FORMAT).collect(Collectors.toList())); PrintStream outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); provider.prepare(config); provider.startStream(); do { Uninterruptibles.sleepUninterruptibly(streamsConfiguration.getBatchFrequencyMs(), TimeUnit.MILLISECONDS); for (StreamsDatum datum : provider.readCurrent()) { String json; try { json = mapper.writeValueAsString(datum.getDocument()); outStream.println(json); } catch (JsonProcessingException ex) { System.err.println(ex.getMessage()); } } } while (provider.isRunning()); provider.cleanUp(); outStream.flush(); }