backtype.storm.tuple
Class Tuple

java.lang.Object
  extended by AFn
      extended by backtype.storm.utils.IndifferentAccessMap
          extended by backtype.storm.tuple.Tuple
All Implemented Interfaces:
java.util.Map

public class Tuple
extends IndifferentAccessMap

The tuple is the main data structure in Storm. A tuple is a named list of values, where each value can be any type. Tuples are dynamically typed -- the types of the fields do not need to be declared. Tuples have helper methods like getInteger and getString to get field values without having to cast the result. Storm needs to know how to serialize all the values in a tuple. By default, Storm knows how to serialize the primitive types, strings, and byte arrays. If you want to use another type, you'll need to implement and register a serializer for that type. See http://github.com/nathanmarz/storm/wiki/Serialization for more info.


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class backtype.storm.utils.IndifferentAccessMap
_map
 
Constructor Summary
Tuple(TopologyContext context, java.util.List<java.lang.Object> values, int taskId, java.lang.String streamId)
           
Tuple(TopologyContext context, java.util.List<java.lang.Object> values, int taskId, java.lang.String streamId, MessageId id)
           
 
Method Summary
 int count()
           
 boolean equals(java.lang.Object other)
           
 int fieldIndex(java.lang.String field)
           
 byte[] getBinary(int i)
          Returns the byte array at position i in the tuple.
 byte[] getBinaryByField(java.lang.String field)
           
 java.lang.Boolean getBoolean(int i)
          Returns the Boolean at position i in the tuple.
 java.lang.Boolean getBooleanByField(java.lang.String field)
           
 java.lang.Byte getByte(int i)
          Returns the Byte at position i in the tuple.
 java.lang.Byte getByteByField(java.lang.String field)
           
 java.lang.Double getDouble(int i)
          Returns the Double at position i in the tuple.
 java.lang.Double getDoubleByField(java.lang.String field)
           
 Fields getFields()
          Gets the names of the fields in this tuple.
 java.lang.Float getFloat(int i)
          Returns the Float at position i in the tuple.
 java.lang.Float getFloatByField(java.lang.String field)
           
 java.lang.Integer getInteger(int i)
          Returns the Integer at position i in the tuple.
 java.lang.Integer getIntegerByField(java.lang.String field)
           
 java.lang.Long getLong(int i)
          Returns the Long at position i in the tuple.
 java.lang.Long getLongByField(java.lang.String field)
           
 IPersistentMap getMap()
           
 MessageId getMessageId()
           
 java.lang.Short getShort(int i)
          Returns the Short at position i in the tuple.
 java.lang.Short getShortByField(java.lang.String field)
           
 java.lang.String getSourceComponent()
          Gets the id of the component that created this tuple.
 GlobalStreamId getSourceGlobalStreamid()
          Returns the global stream id (component + stream) of this tuple.
 java.lang.String getSourceStreamId()
          Gets the id of the stream that this tuple was emitted to.
 int getSourceTask()
          Gets the id of the task that created this tuple.
 java.lang.String getString(int i)
          Returns the String at position i in the tuple.
 java.lang.String getStringByField(java.lang.String field)
           
 java.util.List<java.lang.Object> getTuple()
          Deprecated. 
 java.lang.Object getValue(int i)
          Gets the field at position i in the tuple.
 java.lang.Object getValueByField(java.lang.String field)
           
 java.util.List<java.lang.Object> getValues()
          Gets all the values in this tuple.
 int hashCode()
           
 IPersistentMap meta()
           
 java.lang.Object nth(int i)
           
 java.lang.Object nth(int i, java.lang.Object notfound)
           
 java.util.List<java.lang.Object> select(Fields selector)
          Returns a subset of the tuple based on the fields selector.
 ISeq seq()
           
 int size()
          Returns the number of fields in this tuple.
 java.lang.String toString()
           
 java.lang.Object valAt(java.lang.Object o)
           
 
Methods inherited from class backtype.storm.utils.IndifferentAccessMap
assoc, assocEx, clear, cons, containsKey, containsValue, empty, entryAt, entrySet, equiv, get, invoke, invoke, isEmpty, iterator, keySet, put, putAll, remove, setMap, valAt, values, without
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tuple

public Tuple(TopologyContext context,
             java.util.List<java.lang.Object> values,
             int taskId,
             java.lang.String streamId,
             MessageId id)

Tuple

public Tuple(TopologyContext context,
             java.util.List<java.lang.Object> values,
             int taskId,
             java.lang.String streamId)
Method Detail

size

public int size()
Returns the number of fields in this tuple.

Specified by:
size in interface java.util.Map
Overrides:
size in class IndifferentAccessMap

fieldIndex

public int fieldIndex(java.lang.String field)

getValue

public java.lang.Object getValue(int i)
Gets the field at position i in the tuple. Returns object since tuples are dynamically typed.


getString

public java.lang.String getString(int i)
Returns the String at position i in the tuple. If that field is not a String, you will get a runtime error.


getInteger

public java.lang.Integer getInteger(int i)
Returns the Integer at position i in the tuple. If that field is not an Integer, you will get a runtime error.


getLong

public java.lang.Long getLong(int i)
Returns the Long at position i in the tuple. If that field is not a Long, you will get a runtime error.


getBoolean

public java.lang.Boolean getBoolean(int i)
Returns the Boolean at position i in the tuple. If that field is not a Boolean, you will get a runtime error.


getShort

public java.lang.Short getShort(int i)
Returns the Short at position i in the tuple. If that field is not a Short, you will get a runtime error.


getByte

public java.lang.Byte getByte(int i)
Returns the Byte at position i in the tuple. If that field is not a Byte, you will get a runtime error.


getDouble

public java.lang.Double getDouble(int i)
Returns the Double at position i in the tuple. If that field is not a Double, you will get a runtime error.


getFloat

public java.lang.Float getFloat(int i)
Returns the Float at position i in the tuple. If that field is not a Float, you will get a runtime error.


getBinary

public byte[] getBinary(int i)
Returns the byte array at position i in the tuple. If that field is not a byte array, you will get a runtime error.


getValueByField

public java.lang.Object getValueByField(java.lang.String field)

getStringByField

public java.lang.String getStringByField(java.lang.String field)

getIntegerByField

public java.lang.Integer getIntegerByField(java.lang.String field)

getLongByField

public java.lang.Long getLongByField(java.lang.String field)

getBooleanByField

public java.lang.Boolean getBooleanByField(java.lang.String field)

getShortByField

public java.lang.Short getShortByField(java.lang.String field)

getByteByField

public java.lang.Byte getByteByField(java.lang.String field)

getDoubleByField

public java.lang.Double getDoubleByField(java.lang.String field)

getFloatByField

public java.lang.Float getFloatByField(java.lang.String field)

getBinaryByField

public byte[] getBinaryByField(java.lang.String field)

getTuple

@Deprecated
public java.util.List<java.lang.Object> getTuple()
Deprecated. 


getValues

public java.util.List<java.lang.Object> getValues()
Gets all the values in this tuple.


getFields

public Fields getFields()
Gets the names of the fields in this tuple.


select

public java.util.List<java.lang.Object> select(Fields selector)
Returns a subset of the tuple based on the fields selector.


getSourceGlobalStreamid

public GlobalStreamId getSourceGlobalStreamid()
Returns the global stream id (component + stream) of this tuple.


getSourceComponent

public java.lang.String getSourceComponent()
Gets the id of the component that created this tuple.


getSourceTask

public int getSourceTask()
Gets the id of the task that created this tuple.


getSourceStreamId

public java.lang.String getSourceStreamId()
Gets the id of the stream that this tuple was emitted to.


getMessageId

public MessageId getMessageId()

toString

public java.lang.String toString()

equals

public boolean equals(java.lang.Object other)

hashCode

public int hashCode()

valAt

public java.lang.Object valAt(java.lang.Object o)
Overrides:
valAt in class IndifferentAccessMap

seq

public ISeq seq()
Overrides:
seq in class IndifferentAccessMap

nth

public java.lang.Object nth(int i)

nth

public java.lang.Object nth(int i,
                            java.lang.Object notfound)

count

public int count()
Overrides:
count in class IndifferentAccessMap

meta

public IPersistentMap meta()

getMap

public IPersistentMap getMap()
Overrides:
getMap in class IndifferentAccessMap