| /* |
| * Copyright (c) 2013 DataTorrent, Inc. ALL Rights Reserved. |
| * |
| * Licensed 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 com.datatorrent.contrib.rabbitmq; |
| |
| import com.datatorrent.api.DefaultOutputPort; |
| |
| /** |
| * This is the base implementation of a single port RabbitMQ input operator. |
| * Subclasses should implement the methods which convert RabbitMQ messages to tuples. |
| * <p> |
| * <br> |
| * Ports:<br> |
| * <b>Input</b>: No input port<br> |
| * <b>Output</b>: Can have one output port<br> |
| * <br> |
| * Properties:<br> |
| * None<br> |
| * <br> |
| * Compile time checks:<br> |
| * Class derived from this has to implement the abstract method getTuple() <br> |
| * <br> |
| * Run time checks:<br> |
| * None<br> |
| * <br> |
| * <b>Benchmarks</b>: Blast as many tuples as possible in inline mode<br> |
| * <table border="1" cellspacing=1 cellpadding=1 summary="Benchmark table for AbstractSinglePortRabbitMQInputOperator<K,V extends Number> operator template"> |
| * <tr><th>In-Bound</th><th>Out-bound</th><th>Comments</th></tr> |
| * <tr><td><b>10 thousand K,V pairs/s</td><td>One tuple per key per window per port</td><td>In-bound rate is the main determinant of performance. Operator can emit about 10 thousand unique (k,v immutable pairs) tuples/sec as RabbitMQ DAG. Tuples are assumed to be |
| * immutable. If you use mutable tuples and have lots of keys, the benchmarks may differ</td></tr> |
| * </table><br> |
| * <br> |
| * </p> |
| * @displayName Abstract Single Port RabbitMQ Input |
| * @category Messaging |
| * @tags input operator |
| * |
| * @since 0.3.2 |
| */ |
| public abstract class AbstractSinglePortRabbitMQInputOperator<T> extends AbstractRabbitMQInputOperator |
| { |
| /** |
| * This is the output port on which tuples extracted from RabbitMQ messages are emitted. |
| */ |
| final public transient DefaultOutputPort<T> outputPort = new DefaultOutputPort<T>(); |
| |
| /** |
| * Any concrete class derived from AbstractSinglePortRabbitMQInputOperator has to implement this method |
| * so that it knows what type of message it is going to send to Malhar. |
| * It converts a byte message into a Tuple. A Tuple can be of any type (derived from Java Object) that |
| * operator user intends to. |
| * |
| * @param message |
| */ |
| public abstract T getTuple(byte[] message); |
| |
| @Override |
| public void emitTuple(byte[] message) { |
| outputPort.emit(getTuple(message)); |
| } |
| } |