Skip to content

@igrigorik /TweetEvent.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
wrapping esper with JRuby embrace
require 'rubygems'
require 'java'
require '../esper-4.2.0.jar'
require '../esper/lib/commons-logging-1.1.1.jar'
require '../esper/lib/antlr-runtime-3.2.jar'
require '../esper/lib/cglib-nodep-2.2.jar'
require '../esper/lib/log4j-1.2.16.jar'
include_class 'com.espertech.esper.client.EPRuntime'
include_class 'com.espertech.esper.client.EPServiceProviderManager'
include_class 'com.espertech.esper.client.EPServiceProvider'
include_class 'com.espertech.esper.client.EPStatement'
include_class 'com.espertech.esper.client.UpdateListener'
include_class 'com.espertech.esper.client.EventBean'
include_class 'org.apache.commons.logging.Log'
include_class 'org.apache.commons.logging.LogFactory'
require 'tweetstream'
java_import 'TweetEvent'
class TweetListener
include UpdateListener
def update(newEvents, oldEvents)
newEvents.each do |event|
puts "New event: #{event.getUnderlying.toString}"
end
end
end
epService = EPServiceProviderManager.getDefaultProvider
statement = epService.getEPAdministrator.createEPL("select * from TweetEvent")
statement.addListener(TweetListener.new)
TweetStream::Client.new('username','password').track('keyword') do |t|
event = TweetEvent.new(t.user.screen_name, t.text, t.user.time_zone, t.retweet_count)
epService.getEPRuntime.sendEvent(event);
end
// A simple Tweet POJO:
// $> javac TweetEvent.java
public class TweetEvent {
private String user;
private String text;
private String timezone;
private int retweets;
public TweetEvent(String user, String text, String timezone, int retweets) {
this.user = user;
this.text = text;
this.timezone = timezone;
this.retweets = retweets;
}
public int getRetweets() {
return retweets;
}
public String getText() {
return text;
}
public String getUser() {
return user;
}
public String getTimezone() {
return timezone;
}
public String toString() {
return user + ": " + text + " - (" + timezone + ")";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.