com.twitter.hbc.core.Hosts Java Examples
The following examples show how to use
com.twitter.hbc.core.Hosts.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TwitterDataSource.java From kafka-streams with Apache License 2.0 | 6 votes |
private Client getTwitterClient(Properties props, BlockingQueue<String> messageQueue) { String clientName = props.getProperty("clientName"); String consumerKey = props.getProperty("consumerKey"); String consumerSecret = props.getProperty("consumerSecret"); String token = props.getProperty("token"); String tokenSecret = props.getProperty("tokenSecret"); List<String> searchTerms = Arrays.asList(props.getProperty("searchTerms").split(",")); Authentication authentication = new OAuth1(consumerKey,consumerSecret,token,tokenSecret); Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST); StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint(); hosebirdEndpoint.trackTerms(searchTerms); ClientBuilder clientBuilder = new ClientBuilder(); clientBuilder.name(clientName) .hosts(hosebirdHosts) .authentication(authentication) .endpoint(hosebirdEndpoint) .processor(new StringDelimitedProcessor(messageQueue)); return clientBuilder.build(); }
Example #2
Source File: BasicClient.java From hbc with Apache License 2.0 | 6 votes |
public BasicClient(String name, Hosts hosts, StreamingEndpoint endpoint, Authentication auth, boolean enableGZip, HosebirdMessageProcessor processor, ReconnectionManager reconnectionManager, RateTracker rateTracker, ExecutorService executorService, @Nullable BlockingQueue<Event> eventsQueue, HttpParams params, SchemeRegistry schemeRegistry) { Preconditions.checkNotNull(auth); HttpClient client; if (enableGZip) { client = new RestartableHttpClient(auth, enableGZip, params, schemeRegistry); } else { DefaultHttpClient defaultClient = new DefaultHttpClient(new PoolingClientConnectionManager(schemeRegistry), params); /** Set auth **/ auth.setupConnection(defaultClient); client = defaultClient; } this.canRun = new AtomicBoolean(true); this.executorService = executorService; this.clientBase = new ClientBase(name, client, hosts, endpoint, auth, processor, reconnectionManager, rateTracker, eventsQueue); }
Example #3
Source File: ClientBase.java From hbc with Apache License 2.0 | 6 votes |
ClientBase(String name, HttpClient client, Hosts hosts, StreamingEndpoint endpoint, Authentication auth, HosebirdMessageProcessor processor, ReconnectionManager manager, RateTracker rateTracker, @Nullable BlockingQueue<Event> eventsQueue) { this.client = Preconditions.checkNotNull(client); this.name = Preconditions.checkNotNull(name); this.endpoint = Preconditions.checkNotNull(endpoint); this.hosts = Preconditions.checkNotNull(hosts); this.auth = Preconditions.checkNotNull(auth); this.processor = Preconditions.checkNotNull(processor); this.reconnectionManager = Preconditions.checkNotNull(manager); this.rateTracker = Preconditions.checkNotNull(rateTracker); this.eventsQueue = eventsQueue; this.exitEvent = new AtomicReference<Event>(); this.isRunning = new CountDownLatch(1); this.statsReporter = new StatsReporter(); this.connectionEstablished = new AtomicBoolean(false); this.reconnect = new AtomicBoolean(false); }
Example #4
Source File: TwitterStream.java From AIBlueprints with MIT License | 5 votes |
public TwitterStream(SentimentDetector sentimentDetector, Gson gson, Properties props) { this.sentimentDetector = sentimentDetector; this.gson = gson; msgQueue = new LinkedBlockingQueue<String>(100000); Hosts hosts = new HttpHosts(Constants.STREAM_HOST); StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); List<String> terms = Lists.newArrayList( props.getProperty("twitter_terms") .split("\\s*,\\s*")); endpoint.trackTerms(terms); Authentication auth = new OAuth1( props.getProperty("twitter_consumer_key"), props.getProperty("twitter_consumer_secret"), props.getProperty("twitter_token"), props.getProperty("twitter_token_secret")); ClientBuilder builder = new ClientBuilder() .name("SmartCode-Client-01") .hosts(hosts) .authentication(auth) .endpoint(endpoint) .processor(new StringDelimitedProcessor(msgQueue)); client = builder.build(); client.connect(); }
Example #5
Source File: TwitterStream.java From AIBlueprints with MIT License | 5 votes |
public TwitterStream(Gson gson, Properties props, BlockingQueue<Map<String,Object>> imageQueue) { this.gson = gson; this.imageQueue = imageQueue; msgQueue = new LinkedBlockingQueue<String>(100000); Hosts hosts = new HttpHosts(Constants.STREAM_HOST); StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); List<String> terms = Lists.newArrayList( props.getProperty("twitter_terms") .split("\\s*,\\s*")); endpoint.trackTerms(terms); Authentication auth = new OAuth1( props.getProperty("twitter_consumer_key"), props.getProperty("twitter_consumer_secret"), props.getProperty("twitter_token"), props.getProperty("twitter_token_secret")); ClientBuilder builder = new ClientBuilder() .name("SmartCode-Client-01") .hosts(hosts) .authentication(auth) .endpoint(endpoint) .processor(new StringDelimitedProcessor(msgQueue)); client = builder.build(); client.connect(); }
Example #6
Source File: ClientBase.java From hbc with Apache License 2.0 | 4 votes |
ClientBase(String name, HttpClient client, Hosts hosts, StreamingEndpoint endpoint, Authentication auth, HosebirdMessageProcessor processor, ReconnectionManager manager, RateTracker rateTracker) { this(name, client, hosts, endpoint, auth, processor, manager, rateTracker, null); }
Example #7
Source File: SitestreamController.java From hbc with Apache License 2.0 | 4 votes |
/** * Construct a sitestream controller. */ public SitestreamController(HttpClient client, Hosts hosts, Authentication auth) { this.client = Preconditions.checkNotNull(client); this.hosts = Preconditions.checkNotNull(hosts); this.auth = Preconditions.checkNotNull(auth); }
Example #8
Source File: SitestreamController.java From hbc with Apache License 2.0 | 4 votes |
/** * Construct a sitestream controller using a DefaultHttpClient */ public SitestreamController(Hosts hosts, Authentication auth) { this.client = new DefaultHttpClient(new PoolingClientConnectionManager()); this.hosts = Preconditions.checkNotNull(hosts); this.auth = Preconditions.checkNotNull(auth); }
Example #9
Source File: HoseBirdTester.java From kafka-streams with Apache License 2.0 | 3 votes |
public static void main(String[] args) throws InterruptedException { BlockingQueue<String> msgQueue = new LinkedBlockingDeque<>(); Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST); StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint(); List<String> terms = Lists.newArrayList("superman vs batman","#supermanvsbatman"); hosebirdEndpoint.trackTerms(terms); Authentication hosebirdAuth = new OAuth1("18qydWMuiUohwCtQpp1MOFCFr", "YrYhYd09LKZLbhsKT1o4XcEPl6HiAoNykiOxYBq0dAB8t0vRCo", "16972669-KSvyDEMc7dussPfW6a9Ru65L4eWGj637ciHLHZLyn", "ky53NE6cbBvtNLopto7o9gVyHDejSB2kPsRhHGKEd1MrS"); ClientBuilder clientBuilder = new ClientBuilder(); clientBuilder.name("bbejeck-hosebird") .hosts(hosebirdHosts) .authentication(hosebirdAuth) .endpoint(hosebirdEndpoint) .processor(new StringDelimitedProcessor(msgQueue)); Client hosebirdClient = clientBuilder.build(); hosebirdClient.connect(); for (int msgRead = 0; msgRead < 100; msgRead++) { String msg = msgQueue.take(); System.out.println(msg); } hosebirdClient.stop(); }