本文整理汇总了Java中org.kitesdk.data.event.StandardEvent类的典型用法代码示例。如果您正苦于以下问题:Java StandardEvent类的具体用法?Java StandardEvent怎么用?Java StandardEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardEvent类属于org.kitesdk.data.event包,在下文中一共展示了StandardEvent类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.kitesdk.data.event.StandardEvent; //导入依赖的package包/类
public void run(@DataIn(name="source.events", type=StandardEvent.class) View<StandardEvent> input,
@DataOut(name="target.events", type=StandardEvent.class) View<StandardEvent> output) {
DatasetReader<StandardEvent> reader = input.newReader();
DatasetWriter<StandardEvent> writer = output.newWriter();
try {
while (reader.hasNext()) {
writer.write(reader.next());
}
} finally {
Closeables.closeQuietly(reader);
Closeables.closeQuietly(writer);
}
}
示例2: run
import org.kitesdk.data.event.StandardEvent; //导入依赖的package包/类
@Override
public int run(List<String> args) throws Exception {
Preconditions.checkState(!Datasets.exists(uri),
"events dataset already exists");
DatasetDescriptor descriptor = new DatasetDescriptor.Builder()
.schema(StandardEvent.class).build();
View<StandardEvent> events = Datasets.create(uri, descriptor, StandardEvent.class);
DatasetWriter<StandardEvent> writer = events.newWriter();
try {
while (System.currentTimeMillis() - baseTimestamp < 36000) {
writer.write(generateRandomEvent());
}
} finally {
writer.close();
}
System.out.println("Generated " + counter + " events");
return 0;
}
示例3: process
import org.kitesdk.data.event.StandardEvent; //导入依赖的package包/类
@Override
public void process(
Pair<String, Iterable<StandardEvent>> keyAndEvents,
Emitter<Session> emitter) {
final Iterator<StandardEvent> events = keyAndEvents.second().iterator();
if (!events.hasNext()) {
return;
}
// Initialize the values needed to create a session for this group
final StandardEvent firstEvent = events.next();
long startTime = firstEvent.getTimestamp();
long endTime = firstEvent.getTimestamp();
int numEvents = 1;
// Inspect each event and keep track of start time, end time, and count
while (events.hasNext()) {
final StandardEvent event = events.next();
startTime = Math.min(startTime, event.getTimestamp());
endTime = Math.max(endTime, event.getTimestamp());
numEvents += 1;
}
// Create a session. Use the first event for fields that do not change
emitter.emit(Session.newBuilder() // same on all events:
.setUserId(firstEvent.getUserId()) // the user id (grouped by)
.setSessionId(firstEvent.getSessionId()) // session id (grouped by)
.setIp(firstEvent.getIp()) // the source IP address
.setStartTimestamp(startTime)
.setDuration(endTime - startTime)
.setSessionEventCount(numEvents)
.build());
}
示例4: doGet
import org.kitesdk.data.event.StandardEvent; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<head><title>Kite Example</title></title>");
pw.println("<body>");
String userId = request.getParameter("user_id");
String message = request.getParameter("message");
if (message == null) {
pw.println("<p>No message specified.</p>");
} else {
pw.println("<p>Message: " + message + "</p>");
StandardEvent event = StandardEvent.newBuilder()
.setEventInitiator("server_user")
.setEventName("web:message")
.setUserId(Long.parseLong(userId))
.setSessionId(request.getSession(true).getId())
.setIp(request.getRemoteAddr())
.setTimestamp(System.currentTimeMillis())
.build();
logger.info(event);
}
pw.println("<p><a href=\"/demo-logging-webapp\">Home</a></p>");
pw.println("</body></html>");
}
示例5: generateRandomEvent
import org.kitesdk.data.event.StandardEvent; //导入依赖的package包/类
public StandardEvent generateRandomEvent() {
return StandardEvent.newBuilder()
.setEventInitiator(new Utf8("client_user"))
.setEventName(randomEventName())
.setUserId(randomUserId())
.setSessionId(randomSessionId())
.setIp(randomIp())
.setTimestamp(randomTimestamp())
.setEventDetails(randomEventDetails())
.build();
}
示例6: run
import org.kitesdk.data.event.StandardEvent; //导入依赖的package包/类
@Override
public int run(String[] args) throws Exception {
// Turn debug on while in development.
getPipeline().enableDebug();
getPipeline().getConfiguration().set("crunch.log.job.progress", "true");
Dataset<StandardEvent> eventsDataset = Datasets.load(
"dataset:hdfs:/tmp/data/default/events", StandardEvent.class);
View<StandardEvent> eventsToProcess;
if (args.length == 0 || (args.length == 1 && args[0].equals("LATEST"))) {
// get the current minute
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
long currentMinute = cal.getTimeInMillis();
// restrict events to before the current minute
// in the workflow, this also has a lower bound for the timestamp
eventsToProcess = eventsDataset.toBefore("timestamp", currentMinute);
} else if (isView(args[0])) {
eventsToProcess = Datasets.load(args[0], StandardEvent.class);
} else {
eventsToProcess = FileSystemDatasets.viewForPath(eventsDataset, new Path(args[0]));
}
if (eventsToProcess.isEmpty()) {
LOG.info("No records to process.");
return 0;
}
// Create a parallel collection from the working partition
PCollection<StandardEvent> events = read(
CrunchDatasets.asSource(eventsToProcess));
// Group events by user and cookie id, then create a session for each group
PCollection<Session> sessions = events
.by(new GetSessionKey(), Avros.strings())
.groupByKey()
.parallelDo(new MakeSession(), Avros.specifics(Session.class));
// Write the sessions to the "sessions" Dataset
getPipeline().write(sessions,
CrunchDatasets.asTarget("dataset:hive:/tmp/data/default/sessions"),
Target.WriteMode.APPEND);
return run().succeeded() ? 0 : 1;
}
示例7: map
import org.kitesdk.data.event.StandardEvent; //导入依赖的package包/类
@Override
public String map(StandardEvent event) {
// Create a key from the session id and user id
return event.getSessionId() + event.getUserId();
}
示例8: testGetSchemas
import org.kitesdk.data.event.StandardEvent; //导入依赖的package包/类
@Test
public void testGetSchemas() {
List<Schema> schemas = JobReflection.getSchemas(new StandardEventsJob());
Assert.assertEquals(1, schemas.size());
Assert.assertEquals(SpecificData.get().getSchema(StandardEvent.class), schemas.get(0));
}