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


Java StatusesSampleEndpoint类代码示例

本文整理汇总了Java中com.twitter.hbc.core.endpoint.StatusesSampleEndpoint的典型用法代码示例。如果您正苦于以下问题:Java StatusesSampleEndpoint类的具体用法?Java StatusesSampleEndpoint怎么用?Java StatusesSampleEndpoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StatusesSampleEndpoint类属于com.twitter.hbc.core.endpoint包,在下文中一共展示了StatusesSampleEndpoint类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入依赖的package包/类
@Override
public void start() {
    OAuth1 auth = new OAuth1(
        config.getProperty("oauth.consumer.key"),
        config.getProperty("oauth.consumer.secret"),
        config.getProperty("oauth.token"),
        config.getProperty("oauth.secret"));

    System.out.println(config.getProperty("oauth.consumer.key"));

    client = new ClientBuilder()
            .name("bask-twitter-feed")
            .hosts(Constants.STREAM_HOST)
            .endpoint(new StatusesSampleEndpoint())
            .authentication(auth)
            .processor(new StringDelimitedProcessor(queue))
            .build();

    client.connect();
    pollTweets();
}
 
开发者ID:Team-Whitespace,项目名称:BASK,代码行数:22,代码来源:TwitterFeed.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: initializeClient

import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入依赖的package包/类
private void initializeClient(StatusesSampleEndpoint endpoint, Authentication auth) {

		client = new ClientBuilder().name("twitterSourceClient").hosts(Constants.STREAM_HOST)
				.endpoint(endpoint).authentication(auth)
				.processor(new StringDelimitedProcessor(queue)).build();

		client.connect();
	}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:9,代码来源:TwitterSource.java

示例7: testBuilderSuccess

import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入依赖的package包/类
@Test
public void testBuilderSuccess() {
  new ClientBuilder()
          .hosts(new HttpHosts(Constants.STREAM_HOST))
          .endpoint(new StatusesSampleEndpoint())
          .processor(new NullProcessor())
          .authentication(new BasicAuth("username", "password"))
          .build();

}
 
开发者ID:twitter,项目名称:hbc,代码行数:11,代码来源:ClientBuilderTest.java

示例8: testInvalidHttpMethod

import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入依赖的package包/类
@Test
public void testInvalidHttpMethod() {
  try {
    new ClientBuilder()
            .hosts(new HttpHosts(Constants.STREAM_HOST))
            .endpoint(StatusesSampleEndpoint.PATH, "FAIL!")
            .processor(new NullProcessor())
            .authentication(new BasicAuth("username", "password"))
            .build();
    fail();
  } catch (Exception e) {
    // expected
  }
}
 
开发者ID:twitter,项目名称:hbc,代码行数:15,代码来源:ClientBuilderTest.java

示例9: testValidHttpMethod

import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入依赖的package包/类
@Test
public void testValidHttpMethod() {
  new ClientBuilder()
          .hosts(new HttpHosts(Constants.STREAM_HOST))
          .endpoint(StatusesSampleEndpoint.PATH, "gEt")
          .processor(new NullProcessor())
          .authentication(new BasicAuth("username", "password"))
          .build();

}
 
开发者ID:twitter,项目名称:hbc,代码行数:11,代码来源:ClientBuilderTest.java

示例10: oauth

import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入依赖的package包/类
public void oauth(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();

  Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret);
  // Authentication auth = new BasicAuth(username, password);

  // Create a new BasicClient. By default gzip is enabled.
  BasicClient client = new ClientBuilder()
    .hosts(Constants.STREAM_HOST)
    .endpoint(endpoint)
    .authentication(auth)
    .processor(new StringDelimitedProcessor(queue))
    .build();

  // Create an executor service which will spawn threads to do the actual work of parsing the incoming messages and
  // calling the listeners on each message
  int numProcessingThreads = 4;
  ExecutorService service = Executors.newFixedThreadPool(numProcessingThreads);

  // Wrap our BasicClient with the twitter4j client
  Twitter4jStatusClient t4jClient = new Twitter4jStatusClient(
    client, queue, Lists.newArrayList(listener1, listener2), service);

  // Establish a connection
  t4jClient.connect();
  for (int threads = 0; threads < numProcessingThreads; threads++) {
    // This must be called once per processing thread
    t4jClient.process();
  }

  Thread.sleep(5000);

  client.stop();
}
 
开发者ID:twitter,项目名称:hbc,代码行数:40,代码来源:Twitter4jSampleStreamExample.java

示例11: TwitterClient

import com.twitter.hbc.core.endpoint.StatusesSampleEndpoint; //导入依赖的package包/类
public TwitterClient() {
	/** Set up your blocking queues: Be sure to size these properly based on expected TPS of your stream */
	BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(100000);
	BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>(1000);

	/** Declare the host you want to connect to, the endpoint, and authentication (basic auth or oauth) */
	Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
	StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();
	// Optional: set up some followings and track terms
	List<Long> followings = Lists.newArrayList(1234L, 566788L);
	List<String> terms = Lists.newArrayList("twitter", "api");
	hosebirdEndpoint.followings(followings);
	hosebirdEndpoint.trackTerms(terms);

	// These secrets should be read from a config file
	Authentication hosebirdAuth = new OAuth1("consumerKey", "consumerSecret", "token", "secret");

	ClientBuilder builder = new ClientBuilder()
	  .name("Hosebird-Client-01")                              // optional: mainly for the logs
	  .hosts(hosebirdHosts)
	  .authentication(hosebirdAuth)
	  .endpoint(new StatusesSampleEndpoint())
	  .processor(new StringDelimitedProcessor(msgQueue))
	  .eventMessageQueue(eventQueue);                          // optional: use this if you want to process client events

	Client hosebirdClient = builder.build();
	// Attempts to establish a connection.
	hosebirdClient.connect();
}
 
开发者ID:flaxsearch,项目名称:hackday,代码行数:30,代码来源:TwitterClient.java

示例12: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。