1

TwitterはJavaクライアントライブラリをリリースし、それを使用するための次のサンプルコードを含めました。

// Connect to the filter endpoint, tracking the term "twitterapi"
Hosts host = new BasicHost(Constants.STREAM_HOST);
StreamingEndpoint endpoint = new StatusesFilterEndpoint();
endpoint.trackTerms(Lists.newArrayList("twitterapi"));

// Drop in the oauth credentials for your app, available on dev.twitter.com
Authentication auth = new OAuth1("consumerKey", "consumerSecret", 
                             "token", "tokenSecret");

// Initialize a queue to collect messages from the stream
BlockingQueue<String> messages = new LinkedBlockingQueue<String>(100000);

// Build a client and read messages until the connection closes.
ClientBuilder builder = new ClientBuilder()
    .name("FooBarBaz-StreamingClient")
    .hosts(host)
    .authentication(auth)
    .endpoint(endpoint)
    .processor(new StringDelimitedProcessor(messages));
Client client = builder.build;
client.connect();

while (!client.isDone()) {
  String message = messages.take();
  // Do something with message
}

https://dev.twitter.com/blog/the-hosebird-client-streaming-libraryでのリリース発表

山かっこはどういう意味ですか?

4

2 に答える 2

3

のスーパーインターフェースの 1 つにBlockingQueue<String>Collection があります。つまり、 の機能を実装し、java.util.Collectionジェネリックを使用してコレクションをキャスト保存する可能性を提供します! ジェネリックで:

BlockingQueue<String>

BlockingQueue 内で String を操作する可能性しかありません。別の値を追加してみると、IDE によって不一致が通知されます。アプリケーションの実行中にチェックが行われないため、これは大きなメリットです。

于 2013-03-01T09:58:35.397 に答える
0

これmessagesは、 のインスタンスがLinkedBlockingQueuetype のオブジェクトで機能することを意味しますString。別の例については Java の HashMap を参照してください。Java のGenerics の簡単な紹介についてはwikipediaを参照してください。

于 2013-03-01T09:59:38.200 に答える