org.apache.storm.cassandra

## Class Murmur3StreamGrouping

- java.lang.Object
- - org.apache.storm.cassandra.Murmur3StreamGrouping

- All Implemented Interfaces:
    Serializable, CustomStreamGrouping

      public class Murmur3StreamGrouping
      extends Object
      implements CustomStreamGrouping

  Simple `CustomStreamGrouping` that uses Murmur3 algorithm to choose the target task of a tuple.

  This stream grouping may be used to optimise writes to Apache Cassandra.

  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Murmur3StreamGrouping(List<String> partitionKeyNames)` Creates a new `Murmur3StreamGrouping` instance.
    `Murmur3StreamGrouping(String... partitionKeyNames)` Creates a new `Murmur3StreamGrouping` instance.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<Integer>` | `chooseTasks(int taskId, List<Object> values)` This function implements a custom stream grouping.
    `static long` | `hashes(List<Object> values)` Computes the murmur3 hash for the specified values.
    `void` | `prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks)` Tells the stream grouping at runtime the tasks in the target bolt.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Murmur3StreamGrouping

          public Murmur3StreamGrouping(String... partitionKeyNames)

      Creates a new `Murmur3StreamGrouping` instance.

      Parameters:
        `partitionKeyNames` - `partitionKeyNames`.

    - #### Murmur3StreamGrouping

          public Murmur3StreamGrouping(List<String> partitionKeyNames)

      Creates a new `Murmur3StreamGrouping` instance.

      Parameters:
        `partitionKeyNames` - `partitionKeyNames`.

  - ### Method Detail

    - #### hashes

          public static long hashes(List<Object> values)
                             throws IOException

      Computes the murmur3 hash for the specified values. http://stackoverflow.com/questions/27212797/cassandra-hashing-algorithm-with-composite-keys https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/db/marshal/CompositeType.java

      Parameters:
        `values` - the fields which are part of the (compose) partition key
      Returns:
        the computed hash for input values
      Throws:
        `IOException`

    - #### prepare

          public void prepare(WorkerTopologyContext context,
                              GlobalStreamId stream,
                              List<Integer> targetTasks)

      Tells the stream grouping at runtime the tasks in the target bolt. This information should be used in chooseTasks to determine the target tasks.

      It also tells the grouping the metadata on the stream this grouping will be used on.

      Specified by:
        `prepare` in interface `CustomStreamGrouping`

    - #### chooseTasks

          public List<Integer> chooseTasks(int taskId,
                                           List<Object> values)

      This function implements a custom stream grouping. It takes in as input the number of tasks in the target bolt in prepare and returns the tasks to send the tuples to.

      Specified by:
        `chooseTasks` in interface `CustomStreamGrouping`
        `values` - the values to group on

Copyright © 2021 The Apache Software Foundation. All rights reserved.