com.h3c.util.net

## Class DefaultDatagramEngine

- java.lang.Object
- - com.h3c.util.net.DefaultDatagramEngine

- All Implemented Interfaces:
    DatagramEngine

      public class DefaultDatagramEngine
      extends Object
      implements DatagramEngine

  Datagram engine implementation.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.h3c.util.net.DatagramEngine

      `DatagramEngine.Listener`

  - ### Field Summary

    - ### Fields inherited from interface com.h3c.util.net.DatagramEngine

      `MAX_REQUEST_SIZE, MAX_RESPONSE_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultDatagramEngine(org.slf4j.Logger log, ExecutorService es, int localPort)` Constructor that creates a single socket handler.
    `DefaultDatagramEngine(org.slf4j.Logger log, ExecutorService es, int localPort, int numSocketHandlers)` Constructor that creates a 1 or more socket handlers.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int[]` | `getLocalPortBindings()`
    `boolean` | `isStarted()`
    `void` | `send(byte[] payload, InetSocketAddress address)` Main entry point to write the payload in a new datagram.
    `void` | `setListener(DatagramEngine.Listener listener)` Allows the setting of the engine listener.
    `void` | `start()` Starts the engine.
    `void` | `stop()` Stops the engine.

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

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

- - ### Constructor Detail

    - #### DefaultDatagramEngine

          public DefaultDatagramEngine(org.slf4j.Logger log,
                               ExecutorService es,
                               int localPort,
                               int numSocketHandlers)
                                throws SocketException

      Constructor that creates a 1 or more socket handlers.
      Parameters:
        `log` - logger
        `es` - executor service
        `localPort` - local port to bind socket (0 for dynamic port allocation)
        `numSocketHandlers` - number of socket handlers when allocating dynamic socket ports (localPort is 0);
      Throws:
        `SocketException` - if there is a problem creating the socket

    - #### DefaultDatagramEngine

          public DefaultDatagramEngine(org.slf4j.Logger log,
                               ExecutorService es,
                               int localPort)
                                throws SocketException

      Constructor that creates a single socket handler.
      Parameters:
        `log` - logger
        `es` - executor service
        `localPort` - local port to bind socket (0 for dynamic port allocation)
      Throws:
        `SocketException` - if there is a problem creating the socket

  - ### Method Detail

    - #### setListener

          public void setListener(DatagramEngine.Listener listener)

      Description copied from interface: `DatagramEngine`
      Allows the setting of the engine listener. All engine implementations need to save the listener.
      Specified by:
        `setListener` in interface `DatagramEngine`
      Parameters:
        `listener` - engine listener

    - #### start

          public void start()

      Description copied from interface: `DatagramEngine`
      Starts the engine.
      Specified by:
        `start` in interface `DatagramEngine`

    - #### stop

          public void stop()

      Description copied from interface: `DatagramEngine`
      Stops the engine. Engine implementations should shutdown all resources, worker threads, etc.
      Specified by:
        `stop` in interface `DatagramEngine`

    - #### send

          public void send(byte[] payload,
                  InetSocketAddress address)

      Description copied from interface: `DatagramEngine`
      Main entry point to write the payload in a new datagram.
      Specified by:
        `send` in interface `DatagramEngine`
      Parameters:
        `payload` - datagram payload
        `address` - socket address to send payload

    - #### isStarted

          public boolean isStarted()

    - #### getLocalPortBindings

          public int[] getLocalPortBindings()

Copyright © 2014. All Rights Reserved.