Class UdpOITransport

java.lang.Object
com.nt.udc.ndk.node.OITransport
com.nt.udc.oi.transport.UdpOITransport
All Implemented Interfaces:
DataReceiverIfc, DCTransport, FileDataReceiverIfc, Runnable

public class UdpOITransport extends OITransport
This class will create a socket on the given port for sending DatagramPacket() objects via UDP. The DatagramPacket() objects will be created by the Factory() object from the incoming OIRecord() objects.
The recommended use of this transport is for it to be run within its own thread so it can 'pull' the data from its DataProvider. This will allow the transport to control the flow of data it receives and stop that flow if a problem occurs.
The default behavior for this transport, when run within its own thread, is for the transport to request data from its DataProvider via the getBulkData() method. The DCFieldContainers received are then processed individually, and when the array has been fully processed, a request for more data is made.
  • Constructor Details

    • UdpOITransport

      public UdpOITransport(OINode oinode, Factory factory) throws NodeStartException
      Construct a new UdpOITransport to be used within the specified OINode. The transport will send the packets created by the Factory.
      Parameters:
      oinode - Reference to the OINode containing the transport
      factory - The Factory object used to create DatagramPackets from the incoming OIRecords.
      Throws:
      NodeStartException
    • UdpOITransport

      public UdpOITransport(OINode oinode, Factory factory, int prt) throws NodeStartException
      Construct a new UdpOITransport to be used within the specified OINode. The DatagramSocket will be bound to the given port.
      Parameters:
      oinode - Reference to the OINode containing the transport
      factory - The Factory object used to create DatagramPackets from the incoming OIRecords.
      prt - The port number on which to create the socket
      Throws:
      NodeStartException
  • Method Details

    • dataIsAvailable

      public void dataIsAvailable()
      This method allows the transport's DataProvider to tell the transport that data is waiting to be 'picked up'. It is then the responsibility of the transport to retrieve the data via the provider's getData() method and process it via the receiver's processData() method.
      Specified by:
      dataIsAvailable in interface DataReceiverIfc
      Specified by:
      dataIsAvailable in class OITransport
    • processData

      public void processData(DCFieldContainer record) throws NodeProcessingException
      Accept an OIRecord object to be transmitted via UDP.
      Specified by:
      processData in interface DataReceiverIfc
      Specified by:
      processData in class OITransport
      Parameters:
      record - OIRecord containing the data.
      Throws:
      NodeProcessingException
    • processData

      public void processData(DCFieldContainer[] records) throws NodeProcessingException
      Accept some OIRecord objects to be transmitted via UDP. This method will block until the data can be successfully transmitted, unless the transport is configured to drop records while the connection is lost.
      Parameters:
      records - An array of OIRecord objects.
      Throws:
      NodeProcessingException
    • run

      public void run()
      This method is used when the OITransport runs within its own thread. The method contains the logic to retrieve the data from the the transport's DataProvider and hand the OIRecord() objects to the processData() method.
      Specified by:
      run in interface Runnable
      Specified by:
      run in class OITransport
    • shutdown

      public void shutdown()
      Stop the transport. Do not shutdown until all queued data has been processed.
      Specified by:
      shutdown in interface DCTransport
      Specified by:
      shutdown in class OITransport
    • setFactory

      public void setFactory(Factory factory)
      Set the Factory object used to create the DatagramPackets
      Parameters:
      factory - The Factory used to create the DatagramPackets
    • getFactory

      public Factory getFactory()
      Retrieve the Factory object used to create the DatagramPackets
      Returns:
      The Factory used to create the DatagramPackets
    • getSocket

      public DatagramSocket getSocket()
      Retrieve the DatagramSocket object used to send/receive DatagramPackets
      Returns:
      The DatagramSocket used to send/receive DatagramPackets
    • setRunning

      protected void setRunning(boolean run)
      Sets the boolean which indicates whether the transport is running
    • isRunning

      public boolean isRunning()
      Indicates whether this UdpOITransport is running
    • isDataAvailable

      public boolean isDataAvailable()
      Indicates whether data is available from the transport's DataProvider
    • isProcessingData

      public boolean isProcessingData()
      Indicates whether this UdpOITransport is currently processing data
    • setProcessingData

      protected void setProcessingData(boolean value)
      Sets the boolean indicating whether the transport is currently processing data.
    • isWaitForReconnect

      public boolean isWaitForReconnect()
      Indicates whether this UdpOITransport is configured to, in the event of a lost connection, wait for the connection to be re-established before sending the data. The default is to wait.
      Returns:
      true, if transport will hold the current record until the connection has been re-established. Otherwise, the current record will be dropped and processing will continue with the next record.
    • setWaitForReconnect

      public void setWaitForReconnect(boolean value)
      Sets the boolean indicating whether the transport should, in the event of a lost connection, wait for the connection to be re-established before sending the current packet or drop the current packet and move on to processing the next record.
    • isConnected

      public boolean isConnected()
      Indicates whether this UdpOITransport is connected to the socket
    • connect

      protected void connect() throws IOException
      Create the socket and attempt to establish a connection.
      Throws:
      IOException
    • close

      protected void close()
      Disconnect and close the socket.
    • reconnect

      protected void reconnect()
      Attempt to re-establish the connection.