当前位置: 首页>>代码示例>>Java>>正文


Java StatusesSampleEndpoint.stallWarnings方法代码示例

本文整理汇总了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");
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:23,代码来源:TwitterSource.java

示例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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:9,代码来源:TwitterSource.java

示例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);

}
 
开发者ID:redhat-italy,项目名称:jdg-quickstarts,代码行数:29,代码来源:TwitterService.java

示例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());
}
 
开发者ID:twitter,项目名称:hbc,代码行数:45,代码来源:SampleStreamExample.java


注:本文中的com.twitter.hbc.core.endpoint.StatusesSampleEndpoint.stallWarnings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。