Package com.nt.udc.oi.transport
Class UdpOITransport
java.lang.Object
com.nt.udc.ndk.node.OITransport
com.nt.udc.oi.transport.UdpOITransport
- All Implemented Interfaces:
DataReceiverIfc
,DCTransport
,FileDataReceiverIfc
,Runnable
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.
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.
-
Field Summary
Fields inherited from class com.nt.udc.ndk.node.OITransport
dataProvider, filedataProvider, node, pollingInterval
-
Constructor Summary
ConstructorsConstructorDescriptionUdpOITransport
(OINode oinode, Factory factory) Construct a new UdpOITransport to be used within the specified OINode.UdpOITransport
(OINode oinode, Factory factory, int prt) Construct a new UdpOITransport to be used within the specified OINode. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
close()
Disconnect and close the socket.protected void
connect()
Create the socket and attempt to establish a connection.void
This method allows the transport's DataProvider to tell the transport that data is waiting to be 'picked up'.Retrieve the Factory object used to create the DatagramPacketsRetrieve the DatagramSocket object used to send/receive DatagramPacketsboolean
Indicates whether this UdpOITransport is connected to the socketboolean
Indicates whether data is available from the transport's DataProviderboolean
Indicates whether this UdpOITransport is currently processing databoolean
Indicates whether this UdpOITransport is runningboolean
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.void
processData
(DCFieldContainer record) Accept anOIRecord
object to be transmitted via UDP.void
processData
(DCFieldContainer[] records) Accept someOIRecord
objects to be transmitted via UDP.protected void
Attempt to re-establish the connection.void
run()
This method is used when the OITransport runs within its own thread.void
setFactory
(Factory factory) Set the Factory object used to create the DatagramPacketsprotected void
setProcessingData
(boolean value) Sets the boolean indicating whether the transport is currently processing data.protected void
setRunning
(boolean run) Sets the boolean which indicates whether the transport is runningvoid
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.void
shutdown()
Stop the transport.Methods inherited from class com.nt.udc.ndk.node.OITransport
fileDataIsAvailable, getDataProvider, getFileDataProvider, getNode, getPollingInterval, getRealNarsOut, incrementOut, isHealthy, processEndOfFileData, processFileData, processFileData, processRejectFile, processStartOfFileData, setDataProvider, setFileDataProvider, setNode, setPollingInterval, setTransactionID
-
Constructor Details
-
UdpOITransport
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 transportfactory
- The Factory object used to create DatagramPackets from the incoming OIRecords.- Throws:
NodeStartException
-
UdpOITransport
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 transportfactory
- 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'sgetData()
method and process it via the receiver'sprocessData()
method.- Specified by:
dataIsAvailable
in interfaceDataReceiverIfc
- Specified by:
dataIsAvailable
in classOITransport
-
processData
Accept anOIRecord
object to be transmitted via UDP.- Specified by:
processData
in interfaceDataReceiverIfc
- Specified by:
processData
in classOITransport
- Parameters:
record
-OIRecord
containing the data.- Throws:
NodeProcessingException
-
processData
Accept someOIRecord
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 ofOIRecord
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 interfaceRunnable
- Specified by:
run
in classOITransport
-
shutdown
public void shutdown()Stop the transport. Do not shutdown until all queued data has been processed.- Specified by:
shutdown
in interfaceDCTransport
- Specified by:
shutdown
in classOITransport
-
setFactory
Set the Factory object used to create the DatagramPackets- Parameters:
factory
- The Factory used to create the DatagramPackets
-
getFactory
Retrieve the Factory object used to create the DatagramPackets- Returns:
- The Factory used to create the DatagramPackets
-
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
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.
-