org.appng.api.messaging

## Class Messaging

- java.lang.Object
- - org.appng.api.messaging.Messaging

-     public class Messaging
      extends Object

  A utility class offering static helper methods to create and retrieve a `Sender` and to shutdown `Sender`s and `Receiver`s.
  Author:
    Matthias Müller
  See Also:
    `Sender`, `Receiver`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `APPNG_NODE_ID` Name of a system property used to identify the node

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Messaging()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Sender` | `createMessageSender(Environment env, ExecutorService executor)` Creates and returns a new `Sender` and a corresponding `Receiver`.
    `static Sender` | `createMessageSender(Environment env, ExecutorService executor, String nodeId, EventHandler<? extends Event> defaultHandler, Iterable<EventHandler<? extends Event>> handlers)` Creates and returns a new `Sender` and a corresponding `Receiver`.
    `static Sender` | `getMessageSender(Environment env)` Retrieves the previously created `Sender` from the `Environment`.
    `static String` | `getNodeId()` Returns the ID of this cluster node
    `static String` | `getNodeId(Environment env)` Deprecated. use `getNodeId()` instead
    `protected static Properties` | `getPlatformConfig(Environment env)`
    `static String` | `init()` Determines and returns the node id for this node.
    `static boolean` | `isEnabled(Environment env)`
    `static void` | `shutdown(Environment env)` Shuts down the messaging system, i.e.

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

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

- - ### Field Detail

    - #### APPNG_NODE_ID

          public static final String APPNG_NODE_ID

      Name of a system property used to identify the node
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Messaging

          public Messaging()

  - ### Method Detail

    - #### getMessageSender

          public static Sender getMessageSender(Environment env)

      Retrieves the previously created `Sender` from the `Environment`.
      Parameters:
        `env` - the `Environment` to use
      Returns:
        the `Sender`, if available
      See Also:
        `createMessageSender(Environment, ExecutorService)`, `createMessageSender(Environment, ExecutorService, String, EventHandler, Iterable)`

    - #### createMessageSender

          public static Sender createMessageSender(Environment env,
                                                   ExecutorService executor)

      Creates and returns a new `Sender` and a corresponding `Receiver`. The class name for the receiver is taken from the platform property "messagingReceiver". Uses the system property "appng.node.id" to retrieve the node id for the `Serializer`. If this property is absent, the local host name is used and the property is set.
      Parameters:
        `env` - the `Environment` to use
        `executor` - the `ExecutorService` to run the `Receiver` with
      Returns:
        - the `Sender` (if the platform property "messagingEnabled" is `true`
        - `null` if messaging is disabled or an error occurred while creating the sender

    - #### init

          public static String init()

      Determines and returns the node id for this node. If the system property "appng.node.id" is set, this value is used. Otherwise, the local host name is used (from `java.net.InetAddress.getLocalHost().getHostName()`}).
      Returns:
        the ID of this cluster node

    - #### getNodeId

          @Deprecated
          public static String getNodeId(Environment env)

      Deprecated. use `getNodeId()` instead
      Returns the ID of this cluster node
      Parameters:
        `env` - do not use
      Returns:
        the ID of this cluster node

    - #### getNodeId

          public static String getNodeId()

      Returns the ID of this cluster node
      Returns:
        the ID of this cluster node

    - #### getPlatformConfig

          protected static Properties getPlatformConfig(Environment env)

    - #### createMessageSender

          public static Sender createMessageSender(Environment env,
                                                   ExecutorService executor,
                                                   String nodeId,
                                                   EventHandler<? extends Event> defaultHandler,
                                                   Iterable<EventHandler<? extends Event>> handlers)

      Creates and returns a new `Sender` and a corresponding `Receiver`. The class name for the receiver is taken from the platform property "messagingReceiver".
      Parameters:
        `env` - the `Environment` to use
        `executor` - the `ExecutorService` to run the `Receiver` with
        `nodeId` - the node id for the `Serializer`
        `defaultHandler` - the default `EventHandler` for the `Receiver` (may be `null`)
        `handlers` - a list of `EventHandler`s to be registered at the `Receiver`
      Returns:
        - the `Sender` (if the platform property "messagingEnabled" is `true`
        - `null` if messaging is disabled or an error occurred while creating the sender

    - #### isEnabled

          public static boolean isEnabled(Environment env)

    - #### shutdown

          public static void shutdown(Environment env)

      Shuts down the messaging system, i.e. calls `Closeable.close()` for the `Sender` and the `Receiver` (in case the latter do implement `Closeable`)
      Parameters:
        `env` - then `Environment` to use

Copyright © 2011–2023 aiticon GmbH. All rights reserved.