Java tutorial
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package analizadorTweet; import org.apache.s4.base.Event; import org.apache.s4.core.ProcessingElement; import org.apache.s4.core.Stream; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; import java.util.Calendar; import java.util.Date; import java.util.Random;; public class SavePE extends ProcessingElement { boolean seen = false; boolean ImprimerEventoLlegada = false; boolean ImprimirDelay = true; MongoConnection mongo; public void onEvent(Event event) { if (ImprimerEventoLlegada) { System.out.println("Pe: " + event.get("SaveId")); System.out.println("@" + event.get("User")); System.out.println(event.get("Text")); System.out.println("Location: " + event.get("Location")); System.out.println("Timestamp: " + event.get("Timestamp")); System.out.println("earthPos: " + event.get("earthPos")); System.out.println("earthNeg: " + event.get("earthNeg")); System.out.println("earthSub: " + event.get("earthSub")); System.out.println("earthNeu: " + event.get("earthNeu")); System.out.println("elhPos: " + event.get("elhPos")); System.out.println("elhNeg: " + event.get("elhNeg")); System.out.println("subScore: " + event.get("subScore")); System.out.println("earthSub: " + event.get("earthSub")); System.out.println("label: " + event.get("label")); System.out.println("-------------------------------------------"); } if (ImprimirDelay) { java.util.Date date = new java.util.Date(); Long Tfinal = Calendar.getInstance().getTimeInMillis(); Long Tinicio = Long.parseLong(event.get("Location")); System.out.println("PE: " + event.get("SaveId") + " delay: " + (Tfinal - Tinicio)); } java.util.Date date = new java.util.Date(); Long Tfinal = Calendar.getInstance().getTimeInMillis(); Long Tinicio = Long.parseLong(event.get("Location")); //Aca hago el Save en mongo DBObject tweet = new BasicDBObject(); tweet.put("Content", event.get("Text")); tweet.put("Delay", Tfinal - Tinicio); mongo.setupMongo(); mongo.insert(tweet); seen = true; } @Override protected void onCreate() { mongo = new MongoConnection(); mongo.setupMongo(); } @Override protected void onRemove() { } }