本文整理汇总了Java中com.twitter.hbc.core.endpoint.StatusesSampleEndpoint.stallWarnings方法的典型用法代码示例。如果您正苦于以下问题:Java StatusesSampleEndpoint.stallWarnings方法的具体用法?Java StatusesSampleEndpoint.stallWarnings怎么用?Java StatusesSampleEndpoint.stallWarnings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.twitter.hbc.core.endpoint.StatusesSampleEndpoint
的用法示例。
在下文中一共展示了StatusesSampleEndpoint.stallWarnings方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeConnection
import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入方法依赖的package包/类
/**
* Initialize Hosebird Client to be able to consume Twitter's Streaming API
*/
private void initializeConnection() {
if (LOG.isInfoEnabled()) {
LOG.info("Initializing Twitter Streaming API connection");
}
queue = new LinkedBlockingQueue<String>(queueSize);
StatusesSampleEndpoint endpoint = new StatusesSampleEndpoint();
endpoint.stallWarnings(false);
Authentication auth = authenticate();
initializeClient(endpoint, auth);
if (LOG.isInfoEnabled()) {
LOG.info("Twitter Streaming API connection established successfully");
}
}
示例2: streamTwitter
import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入方法依赖的package包/类
public static void streamTwitter(String consumerKey, String consumerSecret, String accessToken, String accessSecret) throws InterruptedException {
BlockingQueue<String> statusQueue = new LinkedBlockingQueue<String>(10000);
StatusesSampleEndpoint ending = new StatusesSampleEndpoint();
ending.stallWarnings(false);
Authentication twitterAuth = new OAuth1(consumerKey, consumerSecret, accessToken, accessSecret);
BasicClient twitterClient = new ClientBuilder()
.name("Twitter client")
.hosts(Constants.STREAM_HOST)
.endpoint(ending)
.authentication(twitterAuth)
.processor(new StringDelimitedProcessor(statusQueue))
.build();
twitterClient.connect();
for (int msgRead = 0; msgRead < 1000; msgRead++) {
if (twitterClient.isDone()) {
System.out.println(twitterClient.getExitEvent().getMessage());
break;
}
String msg = statusQueue.poll(10, TimeUnit.SECONDS);
if (msg == null) {
System.out.println("Waited 10 seconds - no message received");
} else {
System.out.println(msg);
}
}
twitterClient.stop();
System.out.printf("%d messages processed!\n", twitterClient.getStatsTracker().getNumMessages());
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:40,代码来源:SampleStreamExample.java
示例3: createEndpoint
import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入方法依赖的package包/类
@Override
public StreamingEndpoint createEndpoint() {
// this default endpoint initializer returns the sample endpoint: Returning a sample from the firehose (all tweets)
StatusesSampleEndpoint endpoint = new StatusesSampleEndpoint();
endpoint.stallWarnings(false);
endpoint.delimited(false);
return endpoint;
}
示例4: start
import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入方法依赖的package包/类
public void start(String hashtag) {
BlockingQueue<String> queue = new LinkedBlockingQueue<>(10000);
StatusesSampleEndpoint endpoint = new StatusesSampleEndpoint();
endpoint.stallWarnings(false);
StatusesFilterEndpoint filterEndpoint = new StatusesFilterEndpoint();
List<String> terms = Lists.newArrayList(hashtag);
filterEndpoint.trackTerms(terms);
String consumerKey = System.getProperty("twitter.consumerKey", "");
String consumerSecret = System.getProperty("twitter.consumerSecret", "");
String token = System.getProperty("twitter.token", "");
String tokenSecret = System.getProperty("twitter.tokenSecret", "");
Authentication auth = new OAuth1(consumerKey,consumerSecret,token,tokenSecret);
client = new ClientBuilder()
.name("JDG #" + hashtag + " client")
.hosts(Constants.STREAM_HOST)
.endpoint(filterEndpoint)
.authentication(auth)
.processor(new StringDelimitedProcessor(queue))
.build();
TwitterReader reader = new TwitterReader(client, queue, cache, timeout);
executor = Executors.newSingleThreadExecutor();
executor.execute(reader);
}
示例5: run
import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入方法依赖的package包/类
public static void run(String consumerKey, String consumerSecret, String token, String secret) throws InterruptedException {
// Create an appropriately sized blocking queue
BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000);
// Define our endpoint: By default, delimited=length is set (we need this for our processor)
// and stall warnings are on.
StatusesSampleEndpoint endpoint = new StatusesSampleEndpoint();
endpoint.stallWarnings(false);
Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret);
//Authentication auth = new com.twitter.hbc.httpclient.auth.BasicAuth(username, password);
// Create a new BasicClient. By default gzip is enabled.
BasicClient client = new ClientBuilder()
.name("sampleExampleClient")
.hosts(Constants.STREAM_HOST)
.endpoint(endpoint)
.authentication(auth)
.processor(new StringDelimitedProcessor(queue))
.build();
// Establish a connection
client.connect();
// Do whatever needs to be done with messages
for (int msgRead = 0; msgRead < 1000; msgRead++) {
if (client.isDone()) {
System.out.println("Client connection closed unexpectedly: " + client.getExitEvent().getMessage());
break;
}
String msg = queue.poll(5, TimeUnit.SECONDS);
if (msg == null) {
System.out.println("Did not receive a message in 5 seconds");
} else {
System.out.println(msg);
}
}
client.stop();
// Print some stats
System.out.printf("The client read %d messages!\n", client.getStatsTracker().getNumMessages());
}