com.tibco.be.custom.channel

## Class BaseDestination

- java.lang.Object
- - com.tibco.be.custom.channel.BaseDestination

- All Implemented Interfaces:
    Destination

      public abstract class BaseDestination
      extends java.lang.Object
      implements Destination

  A `BaseDestination` represent the end-points that the transport can use.
  The execution sequence in a Destination's lifecycle is as follows :
  `init()` -> `connect()` -> `start()` -> `close()`

  Users must take care of this sequence while providing the Destination's implementation

  Since:
    5.4

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected BaseChannel` | `channel` Reference to the Channel that this Destination is part of.
    `protected java.lang.String` | `defaultEventUri` Stores the default Event's URI associated to this `Destination`
    `protected java.lang.String` | `destinationName` Stores the name of the destination
    `protected java.util.Properties` | `destinationProperties` Stores the destination properties
    `protected EventProcessor` | `eventProcessor` The instance of `EventProcessor`.This is used to process events received on the destination
    `protected Logger` | `logger` Stores the Logger instance associated
    `protected BaseEventSerializer` | `serializer` Stores the serializer used to serialize events into objects that the underlying transport can use, and deserialize those objects into events.
    `protected boolean` | `suspended` Flag denoting that the Destination is suspended or not
    `protected java.lang.String` | `uri` Stores the URI of the `Destination`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `bind(EventProcessor eventProcessor)` Initializes the listener(s) for the specified EventProcessor.
    `abstract void` | `close()` Closes the Destination and frees up all its resources.
    `abstract void` | `connect()` Connects the `Destination` to its underlying end-point.
    `BaseChannel` | `getChannel()` Gets the `Channel` instance associated with this destination
    `java.lang.String` | `getDefaultEventUri()` Gets the default Event URI associated with this `Destination`
    `java.lang.String` | `getDestinationName()` Gets the name of the `Destination`
    `java.util.Properties` | `getDestinationProperties()` Gets the Properties associated with the `Destination`
    `EventContext` | `getEventContext(Event event)` Gets the user `EventContext` You can override to provide custom implementation for `EventContext` If not defined the DefaultEventContext will be used.
    `EventProcessor` | `getEventProcessor()` Gets the instance of `EventProcessor`.This is used to process events received on the destination
    `BaseEventSerializer` | `getSerializer()` Gets the `BaseEventSerializer` instance associated with this destination
    `java.lang.String` | `getUri()` Gets the URI of this `Destination`
    `abstract void` | `init()` Initializes the `Destination` by allocating necessary resources, creating pools, etc.
    `boolean` | `isSuspended()` Returns the suspension state of Destination.
    `abstract Event` | `requestEvent(Event outevent, java.lang.String responseEventURI, BaseEventSerializer serializer, long timeout, java.util.Map userData)` Sends an event on the specified destination and waits for a response.
    `void` | `resume()` Sets the flag suspended to "false".
    `abstract void` | `send(EventWithId event, java.util.Map userData)` Sends an event on this `Destination`.
    `abstract void` | `start()` Starts the destination, so that it can receive data from the end-point.
    `void` | `suspend()` Sets the flag suspended to "true".

- - ### Field Detail

    - #### channel

          protected BaseChannel channel

      Reference to the Channel that this Destination is part of.
      Since:
        5.4

    - #### destinationName

          protected java.lang.String destinationName

      Stores the name of the destination
      Since:
        5.4

    - #### suspended

          protected boolean suspended

      Flag denoting that the Destination is suspended or not
      Since:
        5.4

    - #### uri

          protected java.lang.String uri

      Stores the URI of the `Destination`
      Since:
        5.4

    - #### defaultEventUri

          protected java.lang.String defaultEventUri

      Stores the default Event's URI associated to this `Destination`
      Since:
        5.4

    - #### serializer

          protected BaseEventSerializer serializer

      Stores the serializer used to serialize events into objects that the underlying transport can use, and deserialize those objects into events.
      Since:
        5.4

    - #### logger

          protected Logger logger

      Stores the Logger instance associated
      Since:
        5.4

    - #### destinationProperties

          protected java.util.Properties destinationProperties

      Stores the destination properties
      Since:
        5.4

    - #### eventProcessor

          protected EventProcessor eventProcessor

      The instance of `EventProcessor`.This is used to process events received on the destination

  - ### Method Detail

    - #### init

          public abstract void init()

      Initializes the `Destination` by allocating necessary resources, creating pools, etc. After this call, you will be able to `connect`, `start` or `close` this `Destination`.
      Throws:
        `java.lang.Exception` - when initialization failed
      Since:
        5.4
      See Also:
        `BaseDestination.connect()`, `BaseDestination.close()`

    - #### connect

          public abstract void connect()

      Connects the `Destination` to its underlying end-point.

      After this call, you will be able to `start` or `close` the `Destination`.

      Do not start sending or receiving data here.

      Specified by:
        `connect` in interface `Destination`
      Throws:
        `java.lang.Exception` - when the Destination could not be connected to the underlying endpoint.
      Since:
        5.4
      See Also:
        `BaseDestination.start()`, `BaseDestination.close()`

    - #### start

          public abstract void start()

      Starts the destination, so that it can receive data from the end-point.

      Only valid on a connected `Destination` After this call, you will be able to `stop` and `close` the `Destination`.

      Specified by:
        `start` in interface `Destination`
      Throws:
        `java.lang.Exception` - when the Destination could not be started.
      Since:
        5.4
      See Also:
        `BaseDestination.connect()`, `BaseDestination.close()`

    - #### close

          public abstract void close()

      Closes the Destination and frees up all its resources.

      After this call, you will be able to `init` the `Destination`.

      Specified by:
        `close` in interface `Destination`
      Throws:
        `java.lang.Exception` - encountered exception
      Since:
        5.4

    - #### suspend

          public void suspend()

      Sets the flag suspended to "true". Users can override this method to provide their own implementation of suspend
      Since:
        5.4

    - #### isSuspended

          public boolean isSuspended()

      Returns the suspension state of Destination.
      Since:
        5.4.1

    - #### resume

          public void resume()

      Sets the flag suspended to "false". Users can override this method to provide their own implementation of resume
      Since:
        5.4

    - #### send

          public abstract void send(EventWithId event,
                                    java.util.Map userData)

      Sends an event on this `Destination`. This method is invoked when the BE application code invokes `Event.send()`
      Parameters:
        `event` - the `Event` to send. The user's Destination implementation should use the Destination's serializer as configured in the project and send this data to its configured end-point
        `userData` - During runtime, the application code can optionally pass a map of key/value pairs using `Event.sendEvent`. The users destination may choose to make use of this additional data.
      Throws:
        `java.lang.Exception` - when the event could not be sent
      Since:
        5.4

    - #### bind

          public void bind(EventProcessor eventProcessor)

      Initializes the listener(s) for the specified EventProcessor. The framework can call this method multiple times, once for each agent where-in this destination is specified as input destination. Listener(s) must just be initialized here, actual polling should only start on `start`. The threading model is left to the programmer.
      Throws:
        `java.lang.Exception` - encountered exception
      Since:
        5.4.1

    - #### requestEvent

          public abstract Event requestEvent(Event outevent,
                                             java.lang.String responseEventURI,
                                             BaseEventSerializer serializer,
                                             long timeout,
                                             java.util.Map userData)

      Sends an event on the specified destination and waits for a response.
      Parameters:
        `outevent` - The outgoing `Event`
        `responseEventURI` - the URI of the response event
        `serializer` - the instance of serializer
        `timeout` - timeout
        `userData` - During runtime, the application code can optionally pass a map of key/value pairs using `Event.requestEvent`. The users destination may choose to make use of this additional data.
      Returns:
        Returns the an `Event` of type `responseEventURI`
      Throws:
        `java.lang.Exception` - Exception when request failed
      Since:
        5.4

    - #### getDestinationName

          public java.lang.String getDestinationName()

      Gets the name of the `Destination`
      Returns:
        the `Destination` name
      Since:
        5.4

    - #### getDestinationProperties

          public java.util.Properties getDestinationProperties()

      Gets the Properties associated with the `Destination`
      Returns:
        the `Destination` Properties
      Since:
        5.4

    - #### getUri

          public java.lang.String getUri()

      Gets the URI of this `Destination`
      Returns:
        URI of the Destination
      Since:
        5.4

    - #### getDefaultEventUri

          public java.lang.String getDefaultEventUri()

      Gets the default Event URI associated with this `Destination`
      Returns:
        default Event URI associated with this `Destination`
      Since:
        5.4

    - #### getChannel

          public BaseChannel getChannel()

      Gets the `Channel` instance associated with this destination
      Returns:
        the instance of the `Channel` associated with this destination
      Since:
        5.4

    - #### getSerializer

          public BaseEventSerializer getSerializer()

      Gets the `BaseEventSerializer` instance associated with this destination
      Returns:
        the `BaseEventSerializer` instance associated with this destination
      Since:
        5.4

    - #### getEventProcessor

          public EventProcessor getEventProcessor()

      Gets the instance of `EventProcessor`.This is used to process events received on the destination
      Returns:
        the `EventProcessorr`.
      Since:
        5.4

    - #### getEventContext

          public EventContext getEventContext(Event event)

      Gets the user `EventContext` You can override to provide custom implementation for `EventContext` If not defined the DefaultEventContext will be used.
      Parameters:
        `event` - the event for which `EventContext` is required.
      Returns:
        the `EventContext`.
      Since:
        5.4