Java tutorial
package com.unisa.storm.bolt; /** * This file is part of UniSAHadoop. * * UniSAHadoop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * UniSAHadoop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with UniSAHadoop. If not, see <http://www.gnu.org/licenses/>. */ import org.apache.log4j.Logger; import java.io.IOException; import java.util.Map; import backtype.storm.topology.BasicOutputCollector; import backtype.storm.topology.OutputFieldsDeclarer; import backtype.storm.topology.base.BaseBasicBolt; import backtype.storm.tuple.Fields; import backtype.storm.tuple.Tuple; import backtype.storm.tuple.Values; import com.fasterxml.jackson.databind.MappingIterator; import com.fasterxml.jackson.dataformat.csv.*; import com.unisa.dataformat.*; public class ExchMsgParserBolt extends BaseBasicBolt { private static final long serialVersionUID = 42L; private static final Logger LOGGER = Logger.getLogger(ExchMsgParserBolt.class); private static final CsvMapper mapper = new CsvMapper(); private static final CsvSchema schema = mapper.schemaFor(ExchangeMsg.class); public void declareOutputFields(OutputFieldsDeclarer declarer) { declarer.declare(new Fields("dateTime", "clientIP", "clientHostname", "serverIP", "serverHostname", "sourceContext", "connectorId", "source", "eventId", "internalMessageId", "messageId", "networkMessageId", "recipientAddress", "recipientStatus", "totalBytes", "recipientCount", "relatedRecipientAddress", "reference", "messageSubject", "senderAddress", "returnPath", "messageInfo", "directionality", "tenantId", "originalClientIP", "originalServerIP", "customData")); } public void execute(Tuple input, BasicOutputCollector collector) { LOGGER.debug("Parsing incomming Exchange Message:"); String msg = input.getString(0); try { MappingIterator<Map<?, ?>> it = mapper.reader(schema).withType(Map.class).readValues(msg); Map<?, ?> result = it.nextValue(); ExchangeMsg exchMsg = new ExchangeMsg(result.get("dateTime").toString(), result.get("clientIP").toString(), result.get("clientHostname").toString(), result.get("serverIP").toString(), result.get("serverHostname").toString(), result.get("sourceContext").toString(), result.get("connectorId").toString(), result.get("source").toString(), result.get("eventId").toString(), result.get("internalMessageId").toString(), result.get("messageId").toString(), result.get("networkMessageId").toString(), result.get("recipientAddress").toString(), result.get("recipientStatus").toString(), result.get("totalBytes").toString(), result.get("recipientCount").toString(), result.get("relatedRecipientAddress").toString(), result.get("reference").toString(), result.get("messageSubject").toString(), result.get("senderAddress").toString(), result.get("returnPath").toString(), result.get("messageInfo").toString(), result.get("directionality").toString(), result.get("tenantId").toString(), result.get("originalClientIP").toString(), result.get("originalServerIP").toString(), result.get("customData").toString()); //Debug LOGGER.debug(exchMsg.toString()); //System.out.println(exchMsg.toString()); it.close(); collector.emit(new Values(exchMsg.getDateTime(), exchMsg.getClientIP(), exchMsg.getClientHostname(), exchMsg.getServerIP(), exchMsg.getServerHostname(), exchMsg.getSourceContext(), exchMsg.getConnectorId(), exchMsg.getSource(), exchMsg.getEventId(), exchMsg.getInternalMessageId(), exchMsg.getMessageId(), exchMsg.getNetworkMessageId(), exchMsg.getRecipientAddress(), exchMsg.getRecipientStatus(), exchMsg.getTotalBytes(), exchMsg.getRecipientCount(), exchMsg.getRelatedRecipientAddress(), exchMsg.getReference(), exchMsg.getMessageSubject(), exchMsg.getSenderAddress(), exchMsg.getReturnPath(), exchMsg.getMessageInfo(), exchMsg.getDirectionality(), exchMsg.getTenantId(), exchMsg.getOriginalClientIP(), exchMsg.getOriginalServerIP(), exchMsg.getCustomData())); } catch (IOException ex) { LOGGER.error("IO error while reading source", ex); LOGGER.trace(null, ex); } } public Map<String, Object> getComponenetConfiguration() { return null; } }