org.apache.storm.assignments

## Class InMemoryAssignmentBackend

- java.lang.Object
- - org.apache.storm.assignments.InMemoryAssignmentBackend

- All Implemented Interfaces:
    AutoCloseable, ILocalAssignmentsBackend

      public class InMemoryAssignmentBackend
      extends Object
      implements ILocalAssignmentsBackend

  An assignment backend which will keep all assignments and id-info in memory. Only used if no backend is specified internal.

  About thread safe: idToAssignment,idToName,nameToId are all memory cache in nimbus local, for

  - idToAssignment: nimbus will modify it and supervisors will sync it at fixed interval, so the assignments would come to eventual consistency.
  - idToName: storm submitting/killing is guarded by the same lock, a `ConcurrentHashMap` is ok.
  - nameToId: same as idToName.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `InMemoryAssignmentBackend()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<String>` | `assignments()` List all the storm runtime ids of local assignments.
    `Map<String,Assignment>` | `assignmentsInfo()` Get all the local assignments of local state.
    `void` | `clearStateForStorm(String stormId)` Clear all the state for a storm.
    `void` | `close()` Function to release resource.
    `void` | `deleteStormId(String stormName)` Delete a local cache of stormId which is mapped to a specific storm name.
    `Assignment` | `getAssignment(String stormId)` Get assignment as `Assignment` for a storm.
    `String` | `getStormId(String stormName)` Get storm runtime id from local.
    `boolean` | `isSynchronized()` Decide if the assignments is synchronized from remote state-store.
    `void` | `keepOrUpdateAssignment(String stormId, Assignment assignment)` Keep a storm assignment to local state or update old assignment.
    `void` | `keepStormId(String stormName, String stormId)` Keep a mapping storm-name -> storm-id to local state.
    `void` | `prepare(Map conf)` Initial function for creating backend.
    `void` | `removeAssignment(String stormId)`
    `void` | `setSynchronized()` Mark this backend as synchronized when sync work is done.
    `void` | `syncRemoteAssignments(Map<String,byte[]> remote)` Sync remote assignments to local, if remote is null, we will sync it from zk.
    `void` | `syncRemoteIds(Map<String,String> remote)` Sync remote storm ids to local, will just used for nimbus.

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

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

- - ### Constructor Detail

    - #### InMemoryAssignmentBackend

          public InMemoryAssignmentBackend()

  - ### Method Detail

    - #### isSynchronized

          public boolean isSynchronized()

      Description copied from interface: `ILocalAssignmentsBackend`

      Decide if the assignments is synchronized from remote state-store.

      Specified by:
        `isSynchronized` in interface `ILocalAssignmentsBackend`

    - #### setSynchronized

          public void setSynchronized()

      Description copied from interface: `ILocalAssignmentsBackend`

      Mark this backend as synchronized when sync work is done.

      Specified by:
        `setSynchronized` in interface `ILocalAssignmentsBackend`

    - #### prepare

          public void prepare(Map conf)

      Description copied from interface: `ILocalAssignmentsBackend`

      Initial function for creating backend.

      Specified by:
        `prepare` in interface `ILocalAssignmentsBackend`
      Parameters:
        `conf` - config

    - #### keepOrUpdateAssignment

          public void keepOrUpdateAssignment(String stormId,
                                             Assignment assignment)

      Description copied from interface: `ILocalAssignmentsBackend`

      Keep a storm assignment to local state or update old assignment.

      Specified by:
        `keepOrUpdateAssignment` in interface `ILocalAssignmentsBackend`
      Parameters:
        `stormId` - storm runtime id
        `assignment` - assignment as thrift

    - #### getAssignment

          public Assignment getAssignment(String stormId)

      Description copied from interface: `ILocalAssignmentsBackend`

      Get assignment as `Assignment` for a storm.

      Specified by:
        `getAssignment` in interface `ILocalAssignmentsBackend`
      Parameters:
        `stormId` - storm runtime id
      Returns:
        assignment

    - #### removeAssignment

          public void removeAssignment(String stormId)

      Specified by:
        `removeAssignment` in interface `ILocalAssignmentsBackend`

    - #### assignments

          public List<String> assignments()

      Description copied from interface: `ILocalAssignmentsBackend`

      List all the storm runtime ids of local assignments.

      Specified by:
        `assignments` in interface `ILocalAssignmentsBackend`
      Returns:
        a list of storm ids

    - #### assignmentsInfo

          public Map<String,Assignment> assignmentsInfo()

      Description copied from interface: `ILocalAssignmentsBackend`

      Get all the local assignments of local state.

      Specified by:
        `assignmentsInfo` in interface `ILocalAssignmentsBackend`
      Returns:
        mapping of storm-id -> assignment

    - #### syncRemoteAssignments

          public void syncRemoteAssignments(Map<String,byte[]> remote)

      Description copied from interface: `ILocalAssignmentsBackend`

      Sync remote assignments to local, if remote is null, we will sync it from zk.

      Specified by:
        `syncRemoteAssignments` in interface `ILocalAssignmentsBackend`
      Parameters:
        `remote` - specific remote assignments, if it is null, it will sync from zookeeper[only used for nimbus]

    - #### keepStormId

          public void keepStormId(String stormName,
                                  String stormId)

      Description copied from interface: `ILocalAssignmentsBackend`

      Keep a mapping storm-name -> storm-id to local state.

      Specified by:
        `keepStormId` in interface `ILocalAssignmentsBackend`
      Parameters:
        `stormName` - storm name
        `stormId` - storm runtime id

    - #### getStormId

          public String getStormId(String stormName)

      Description copied from interface: `ILocalAssignmentsBackend`

      Get storm runtime id from local.

      Specified by:
        `getStormId` in interface `ILocalAssignmentsBackend`
      Parameters:
        `stormName` - name of a storm
      Returns:
        runtime storm id

    - #### syncRemoteIds

          public void syncRemoteIds(Map<String,String> remote)

      Description copied from interface: `ILocalAssignmentsBackend`

      Sync remote storm ids to local, will just used for nimbus.

      Specified by:
        `syncRemoteIds` in interface `ILocalAssignmentsBackend`
      Parameters:
        `remote` - remote ids from state store

    - #### deleteStormId

          public void deleteStormId(String stormName)

      Description copied from interface: `ILocalAssignmentsBackend`

      Delete a local cache of stormId which is mapped to a specific storm name.

      Specified by:
        `deleteStormId` in interface `ILocalAssignmentsBackend`
      Parameters:
        `stormName` - storm name

    - #### clearStateForStorm

          public void clearStateForStorm(String stormId)

      Description copied from interface: `ILocalAssignmentsBackend`

      Clear all the state for a storm.

      Specified by:
        `clearStateForStorm` in interface `ILocalAssignmentsBackend`
      Parameters:
        `stormId` - storm id

    - #### close

          public void close()

      Description copied from interface: `ILocalAssignmentsBackend`

      Function to release resource.

      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `ILocalAssignmentsBackend`

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