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


Java StringDelimitedProcessor类代码示例

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


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

示例1: configureStreamClient

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
private static BasicClient configureStreamClient(BlockingQueue<String> msgQueue, String twitterKeys, List<Long> userIds, List<String> terms) {
    Hosts hosts = new HttpHosts(Constants.STREAM_HOST);
    StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint()
            .followings(userIds)
            .trackTerms(terms);
    endpoint.stallWarnings(false);

    String[] keys = twitterKeys.split(":");
    Authentication auth = new OAuth1(keys[0], keys[1], keys[2], keys[3]);

    ClientBuilder builder = new ClientBuilder()
            .name("Neo4j-Twitter-Stream")
            .hosts(hosts)
            .authentication(auth)
            .endpoint(endpoint)
            .processor(new StringDelimitedProcessor(msgQueue));

    return builder.build();
}
 
开发者ID:neo4j-examples,项目名称:neo4j-twitter-stream,代码行数:20,代码来源:TwitterStreamProcessor.java

示例2: getTwitterClient

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
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();

    }
 
开发者ID:bbejeck,项目名称:kafka-streams,代码行数:26,代码来源:TwitterDataSource.java

示例3: initialize

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
@Override
protected void initialize() throws InitializationException {
	// Initialize endpoint
	this.endpoint = new StatusesFilterEndpoint();
			
	// Initialize queues
	this.queue = new LinkedBlockingQueue<String>(10000);
			
	// Set keywords
	this.endpoint.trackTerms(terms);
		    
    // Create a new BasicClient. By default gzip is enabled.
    this.client = new ClientBuilder()
      .hosts(Constants.STREAM_HOST)
      .endpoint(endpoint)
      .authentication(auth)
      .processor(new StringDelimitedProcessor(queue))
      .build();
}
 
开发者ID:DaniUPC,项目名称:near-image-replica-detection,代码行数:20,代码来源:TwitterProvider.java

示例4: setupHosebirdClient

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
public static void setupHosebirdClient() {
       /** Declare the host you want to connect to, the endpoint, and authentication (basic auth or oauth) */
	Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
	StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();

       // Optional: set up some followings and track terms
	List<Long> followings = Lists.newArrayList(1234L, 566788L);
	List<String> terms = Lists.newArrayList("twitter", "api");
	endpoint.followings(followings);
	endpoint.trackTerms(terms);

	Authentication hosebirdAuth = new OAuth1(
       		Helper.properties().getProperty("consumerKey"),
       		Helper.properties().getProperty("consumerSecret"),
       		Helper.properties().getProperty("token"),
       		Helper.properties().getProperty("secret"));

       ClientBuilder builder = new ClientBuilder()
        .name("Hosebird-Client-01")		// optional: mainly for the logs
        .hosts(hosebirdHosts)
        .authentication(hosebirdAuth)
        .endpoint(endpoint)
        .processor(new StringDelimitedProcessor(msgQueue));

	hosebirdClient = builder.build();
}
 
开发者ID:twitterdev,项目名称:twttr-kinesis,代码行数:27,代码来源:TweetCollector.java

示例5: start

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的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

示例6: testIdleProbe

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
@Test
public void testIdleProbe() throws Exception {
  SimpleStreamProvider simpleStream = new SimpleStreamProvider(messages, true, true);
  int count = 0;
  try {
    InputStream stream = simpleStream.createInputStream();
    BlockingQueue<String> queue = new ArrayBlockingQueue<String>(10);
    HosebirdMessageProcessor processor = new StringDelimitedProcessor(queue);
    processor.setup(stream);
    // read until we hit the IOException
    while (count < messages.length * 2) {
      processor.process();
      // trimming to get rid of the CRLF
      assertTrue(messages[count].equals(queue.take().trim()));
      count++;
    }
    fail();
  } catch (IOException e) {
    // expected
  }
  assertEquals(messages.length, count);
}
 
开发者ID:twitter,项目名称:hbc,代码行数:23,代码来源:LineDelimitedStreamProcessorTest.java

示例7: streamTwitter

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的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

示例8: startFiltering

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
public void startFiltering() {

		List<Job> jobs = jobRepository.findAll();
		log.info("There are " + jobs.size() + " jobs in the database.");

		if (jobs.size() == 0) {
			log.error("No jobs found at the database. Please define some jobs first.");
			return;
		}

		BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000);

		StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
		List<String> keywords = new ArrayList<>();
		for (Job j : jobs) {
			keywords.addAll(j.getKeywords());
		}
		endpoint.trackTerms(keywords);

		Authentication auth = new OAuth1(consumerKey, consumerSecret, accessToken, accessSecret);

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

		int numProcessingThreads = 4;
		ExecutorService service = Executors.newFixedThreadPool(numProcessingThreads);

		List<StatusListener> listeners = new ArrayList<>();
		listeners.add(statusStreamHandlerImpl.createListener());

		Twitter4jStatusClient t4jClient = new Twitter4jStatusClient(client, queue, listeners, service);

		t4jClient.connect();
		for (int threads = 0; threads < numProcessingThreads; threads++) {
			t4jClient.process();
		}

	}
 
开发者ID:PySualk,项目名称:TwitterPictureGatherer,代码行数:39,代码来源:CollectorService.java

示例9: start

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
@Override
public TwitterAggregator start(final String... keywords) {
    final BlockingQueue<String> queue = new LinkedBlockingQueue<>(10000);

    final Authentication auth = new OAuth1(
            consumerKey,
            consumerSecret,
            token,
            tokenSecret);

    // Create a new BasicClient. By default gzip is enabled.
    final ClientBuilder builder = new ClientBuilder()
            .hosts(Constants.STREAM_HOST)
            .endpoint(new StatusesFilterEndpoint().trackTerms(Lists.newArrayList(keywords)))
            .authentication(auth)
            .processor(new StringDelimitedProcessor(queue));

    // Wrap our BasicClient with the twitter4j client
    client = new Twitter4jStatusClient(
            builder.build(),
            queue,
            Collections.singletonList(new TwitterMessageListener()),
            C1Services.getInstance().getExecutorService());

    client.connect();
    client.process();

    return this;
}
 
开发者ID:martinjmares,项目名称:javaone2015-cloudone,代码行数:30,代码来源:TwitterAggregator.java

示例10: buildClient

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
/**
 * @param tweetQueue tweet Queue.
 * @param hosts Hostes.
 * @param endpoint Endpoint.
 * @return Client.
 */
protected Client buildClient(BlockingQueue<String> tweetQueue, HttpHosts hosts, StreamingEndpoint endpoint) {
    Authentication authentication = new OAuth1(oAuthSettings.getConsumerKey(), oAuthSettings.getConsumerSecret(),
        oAuthSettings.getAccessToken(), oAuthSettings.getAccessTokenSecret());

    ClientBuilder builder = new ClientBuilder()
        .name("Ignite-Twitter-Client")
        .hosts(hosts)
        .authentication(authentication)
        .endpoint(endpoint)
        .processor(new StringDelimitedProcessor(tweetQueue));

    return builder.build();
}
 
开发者ID:apache,项目名称:ignite,代码行数:20,代码来源:TwitterStreamer.java

示例11: subscribe

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
public void subscribe(final StatusStreamHandler listener, String... terms) {
	/**
	 * 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();
	hosebirdEndpoint.trackTerms(Lists.newArrayList(terms));

	Authentication hosebirdAuth = oAuth();

	ClientBuilder builder = new ClientBuilder().name("Hosebird-Client-01")
			// optional: mainly for the logs
			.hosts(hosebirdHosts).authentication(hosebirdAuth).endpoint(hosebirdEndpoint)
			.processor(new StringDelimitedProcessor(msgQueue)).eventMessageQueue(eventQueue);
	Client client = builder.build();

	final ExecutorService executorService = Executors.newFixedThreadPool(1);
	final Twitter4jStatusClient t4jClient = new Twitter4jStatusClient(client, msgQueue,
			Lists.newArrayList(listener), executorService);
	t4jClient.connect();

	// Call this once for every thread you want to spin off for processing
	// the raw messages.
	// This should be called at least once.
	t4jClient.process(); // required to start processing the messages
}
 
开发者ID:cyriux,项目名称:hexagonal-sentimental,代码行数:35,代码来源:TwitterStream.java

示例12: start

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的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

示例13: collect

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
public void collect() throws IOException {

        final BlockingQueue<String> queue = new LinkedBlockingQueue<>(QUEUE_SIZE);
        final StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();

        // Set location to collect on
        endpoint.locations(Lists.newArrayList(COLLECTION_LOCATION));

        // add some track terms with this code:
        // endpoint.trackTerms(Lists.newArrayList("twitterapi", "#yolo"));

        final Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret);

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

        // Establish a connection
        client.connect();

        while (!client.isDone()) {
            writeTweetsToFile(getFileToWrite(), queue);
        }

        client.stop();
        log.info("Client stopped, restart needed");
    }
 
开发者ID:geomesa,项目名称:geomesa-twitter,代码行数:32,代码来源:TwitterStreamCollector.java

示例14: activate

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的package包/类
public void activate()
{
    synchronized (_pauseSyncObject)
    {
        try
        {
            _tweetQueue = new LinkedBlockingQueue<String>(TWEETQUEUESIZE);

            StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
            endpoint.trackTerms(Lists.newArrayList(_trackTerm));

            Authentication authentication = new OAuth1(_consumerKey, _consumerSecret, _token, _tokenSecret);

            ClientBuilder twitterClientBuilder = new ClientBuilder();
            twitterClientBuilder.name("DataBrokerClient");
            twitterClientBuilder.hosts(Constants.STREAM_HOST);
            twitterClientBuilder.endpoint(endpoint);
            twitterClientBuilder.authentication(authentication);
            twitterClientBuilder.processor(new StringDelimitedProcessor(_tweetQueue));

            _twitterClient = twitterClientBuilder.build();
            _twitterClient.connect();
        }
        catch (Throwable throwable)
        {
            logger.log(Level.WARNING, "TwitterDataSource: Configuring problem \"" + _name + "\"", throwable);
            _twitterClient = null;
            _tweetQueue    = null;
        }

        _fetch = true;
        _pauseSyncObject.notify();
    }
}
 
开发者ID:arjuna-technologies,项目名称:Twitter_DataBroker_PlugIn,代码行数:35,代码来源:TwitterDataSource.java

示例15: initializeClient

import com.twitter.hbc.core.processor.StringDelimitedProcessor; //导入依赖的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


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