本文整理汇总了Java中com.twitter.hbc.core.Constants类的典型用法代码示例。如果您正苦于以下问题:Java Constants类的具体用法?Java Constants怎么用?Java Constants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Constants类属于com.twitter.hbc.core包,在下文中一共展示了Constants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureStreamClient
import com.twitter.hbc.core.Constants; //导入依赖的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();
}
示例2: getTwitterClient
import com.twitter.hbc.core.Constants; //导入依赖的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();
}
示例3: initialize
import com.twitter.hbc.core.Constants; //导入依赖的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();
}
示例4: setupHosebirdClient
import com.twitter.hbc.core.Constants; //导入依赖的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();
}
示例5: start
import com.twitter.hbc.core.Constants; //导入依赖的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();
}
示例6: streamTwitter
import com.twitter.hbc.core.Constants; //导入依赖的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
示例7: setup
import com.twitter.hbc.core.Constants; //导入依赖的package包/类
@Before
public void setup() {
this.client = mock(BasicClient.class);
this.cb = mock(ClientBuilder.class);
when(cb.name("Twitter Api Reader")).thenReturn(cb);
when(cb.hosts(Constants.STREAM_HOST)).thenReturn(cb);
when(cb.endpoint(any(StreamingEndpoint.class))).thenReturn(cb);
when(cb.authentication(any(Authentication.class))).thenReturn(cb);
when(cb.processor(any(HosebirdMessageProcessor.class))).thenReturn(cb);
when(cb.retries(10)).thenReturn(cb);
when(cb.build()).thenReturn(client);
this.logger = mock(Logger.class);
this.clientReadAndSendPredicate = new ReadAndSendPredicate() {
@Override
public boolean process() {
return !client.isDone();
}
};
this.config = new TwitterApiReaderConfig();
this.config.hosebird = new HosebirdConfig();
this.config.twitterapi = new TwitterApiConfig();
this.config.twitterapi.consumerKey = "aaaaa";
this.config.twitterapi.consumerSecret = "bbbbb";
this.config.twitterapi.accessToken = "ccccc";
this.config.twitterapi.accessSecret = "ddddd";
this.config.hosebird.retries = 10;
this.config.hosebird.bufferSize = 10000;
this.config.kafka = new KafkaConfig();
this.config.kafka.topic = "Data";
this.config.metrics = new MetricsConfig();
this.config.metrics.host = "G_HOST";
this.config.metrics.port = 1111;
this.config.metrics.prefix = "G_PREFIX";
this.config.metrics.reportingTime = 2;
}
示例8: getHosebirdCient_should_create_client_correctly
import com.twitter.hbc.core.Constants; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void getHosebirdCient_should_create_client_correctly() {
Producer<String, String> producer = mock(Producer.class);
TwitterApiReader tr = mock(TwitterApiReader.class);
reset(this.logger);
tr.setLogger(this.logger);
when(tr.getMetrics(any(StatsReporter.StatsTracker.class))).thenCallRealMethod();
when(tr.getHosebirdClient(any(LinkedBlockingQueue.class), any(Config.class))).thenCallRealMethod();
when(tr.getKafkaProducer(any(KafkaConfig.class))).thenReturn(producer);
when(tr.getClientBuilder()).thenReturn(this.cb);
when(tr.parseConfigFile(anyString())).thenReturn(config);
when(tr.getRetry()).thenReturn(true).thenReturn(false);
when(client.isDone()).thenReturn(true);
LinkedBlockingQueue<String> lbq = new LinkedBlockingQueue<>(10);
tr.getHosebirdClient(lbq, config);
verify(cb).name("Twitter Api Reader");
verify(cb).hosts(Constants.STREAM_HOST);
ArgumentCaptor<StreamingEndpoint> se = ArgumentCaptor.forClass(StreamingEndpoint.class);
verify(cb).endpoint(se.capture());
assertEquals("/1.1/statuses/filter.json?delimited=length&stall_warnings=true", se.getValue().getURI());
// Unfortunately there's not a good way of asserting that the Authentication and Processor have
// been created with the correct parameters.
verify(cb).retries(10);
}
示例9: setup
import com.twitter.hbc.core.Constants; //导入依赖的package包/类
@Before
public void setup() {
this.client = mock(BasicClient.class);
this.cb = mock(ClientBuilder.class);
when(cb.name("Gnip Reader")).thenReturn(cb);
when(cb.hosts(Constants.ENTERPRISE_STREAM_HOST)).thenReturn(cb);
when(cb.endpoint(any(StreamingEndpoint.class))).thenReturn(cb);
when(cb.authentication(any(Authentication.class))).thenReturn(cb);
when(cb.processor(any(HosebirdMessageProcessor.class))).thenReturn(cb);
when(cb.retries(10)).thenReturn(cb);
when(cb.build()).thenReturn(client);
this.logger = mock(Logger.class);
this.clientReadAndSendPredicate = new ReadAndSendPredicate() {
@Override
public boolean process() {
return !client.isDone();
}
};
this.config = new ConcreteHosebirdConfig();
this.config.hosebird = new HosebirdConfig();
this.config.hosebird.retries = 10;
this.config.hosebird.bufferSize = 10000;
this.config.kafka = new KafkaConfig();
this.config.kafka.topic = "Data";
this.config.metrics = new MetricsConfig();
this.config.metrics.host = "G_HOST";
this.config.metrics.port = 1111;
this.config.metrics.prefix = "G_PREFIX";
this.config.metrics.reportingTime = 2;
}
示例10: setup
import com.twitter.hbc.core.Constants; //导入依赖的package包/类
@Before
public void setup() {
this.client = mock(BasicClient.class);
this.cb = mock(ClientBuilder.class);
when(cb.name("Gnip Reader")).thenReturn(cb);
when(cb.hosts(Constants.ENTERPRISE_STREAM_HOST_v2)).thenReturn(cb);
when(cb.endpoint(any(StreamingEndpoint.class))).thenReturn(cb);
when(cb.authentication(any(Authentication.class))).thenReturn(cb);
when(cb.processor(any(HosebirdMessageProcessor.class))).thenReturn(cb);
when(cb.retries(10)).thenReturn(cb);
when(cb.build()).thenReturn(client);
this.logger = mock(Logger.class);
this.clientReadAndSendPredicate = new ReadAndSendPredicate() {
@Override
public boolean process() {
return !client.isDone();
}
};
this.config = new GnipReaderConfig();
this.config.gnip = new GnipConfig();
this.config.hosebird = new HosebirdConfig();
this.config.gnip.account = "ACCOUNT";
this.config.gnip.product = "PRODUCT";
this.config.gnip.label = "LABEL";
this.config.gnip.username = "USERNAME";
this.config.gnip.password = "PASSWORD";
this.config.hosebird.retries = 10;
this.config.hosebird.bufferSize = 10000;
this.config.kafka = new KafkaConfig();
this.config.kafka.topic = "Data";
this.config.metrics = new MetricsConfig();
this.config.metrics.host = "G_HOST";
this.config.metrics.port = 1111;
this.config.metrics.prefix = "G_PREFIX";
this.config.metrics.reportingTime = 2;
}
示例11: getHosebirdCient_should_create_client_correctly
import com.twitter.hbc.core.Constants; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void getHosebirdCient_should_create_client_correctly() {
Producer<String, String> producer = mock(Producer.class);
GnipReader tr = mock(GnipReader.class);
reset(this.logger);
tr.setLogger(this.logger);
when(tr.getMetrics(any(StatsReporter.StatsTracker.class))).thenCallRealMethod();
when(tr.getHosebirdClient(any(LinkedBlockingQueue.class), any(Config.class))).thenCallRealMethod();
when(tr.getKafkaProducer(any(KafkaConfig.class))).thenReturn(producer);
when(tr.getClientBuilder()).thenReturn(this.cb);
when(tr.parseConfigFile(anyString())).thenReturn(config);
when(tr.getRetry()).thenReturn(true).thenReturn(false);
when(client.isDone()).thenReturn(true);
LinkedBlockingQueue<String> lbq = new LinkedBlockingQueue<>(10);
tr.getHosebirdClient(lbq, config);
verify(cb).name("Gnip Reader");
verify(cb).hosts(Constants.ENTERPRISE_STREAM_HOST_v2);
ArgumentCaptor<StreamingEndpoint> se = ArgumentCaptor.forClass(StreamingEndpoint.class);
verify(cb).endpoint(se.capture());
assertEquals("/stream/PRODUCT/accounts/ACCOUNT/publishers/twitter/LABEL.json", se.getValue().getURI());
// Unfortunately there's not a good way of asserting that the Authentication and Processor have
// been created with the correct parameters.
ArgumentCaptor<Authentication> a = ArgumentCaptor.forClass(Authentication.class);
verify(cb).authentication(a.capture());
BasicAuth expectedAuth = new BasicAuth("USERNAME", "PASSWORD");
// assertEquals(expectedAuth, a.getValue());
ArgumentCaptor<HosebirdMessageProcessor> hbmp = ArgumentCaptor.forClass(HosebirdMessageProcessor.class);
verify(cb).processor(hbmp.capture());
LineStringProcessor expectedProcessor = new LineStringProcessor(lbq);
//assertEquals(expectedProcessor, hbmp.getValue());
verify(cb).retries(10);
}
示例12: startFiltering
import com.twitter.hbc.core.Constants; //导入依赖的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();
}
}
示例13: start
import com.twitter.hbc.core.Constants; //导入依赖的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;
}
示例14: subscribe
import com.twitter.hbc.core.Constants; //导入依赖的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
}
示例15: start
import com.twitter.hbc.core.Constants; //导入依赖的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);
}