Class UdpMessenger
java.lang.Object
java.lang.Thread
org.metricshub.ipmi.core.transport.UdpMessenger
Handles the UDP connection.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionUdpMessenger(int port) Initiates UdpMessenger, binds it to the specified port and starts listening.UdpMessenger(int port, InetAddress address) Initiates UdpMessenger, binds it to the specified port and IP address and starts listening. -
Method Summary
Modifier and TypeMethodDescriptionvoidCloses the socket and releases port.intintgetPort()static intReturns number of packets sent since last creation of the instance ofUdpMessenger.voidregister(UdpListener listener) Registers listener in the UdpMessenger so it will be notified viaUdpListener.notifyMessage(UdpMessage)when new message arrives.voidrun()voidsend(UdpMessage message) SendsUdpMessage.voidsetBufferSize(int bufferSize) Sets message data buffer size to bufferSize.voidunregister(UdpListener listener) Unregisters listener from UdpMessenger so it no longer will be notified.Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
Constructor Details
-
UdpMessenger
Initiates UdpMessenger, binds it to the specified port and starts listening. Wildcard IP address will be used.- Parameters:
port- - port to bind socket to.- Throws:
SocketException- if the socket could not be opened, or the socket could not bind to the specified local port.UnknownHostException
-
UdpMessenger
Initiates UdpMessenger, binds it to the specified port and IP address and starts listening.- Parameters:
port- - port to bind socket to.address- - IP address to bind socket to.- Throws:
SocketException- if the socket could not be opened, or the socket could not bind to the specified local port.
-
-
Method Details
-
getPort
public int getPort() -
setBufferSize
public void setBufferSize(int bufferSize) Sets message data buffer size to bufferSize. -
getBufferSize
public int getBufferSize()- Returns:
- Size of the message data buffer
-
run
public void run() -
closeConnection
public void closeConnection()Closes the socket and releases port.- Specified by:
closeConnectionin interfaceMessenger
-
register
Registers listener in the UdpMessenger so it will be notified viaUdpListener.notifyMessage(UdpMessage)when new message arrives.- Specified by:
registerin interfaceMessenger- Parameters:
listener- -UdpListenerto register.
-
unregister
Unregisters listener from UdpMessenger so it no longer will be notified.- Specified by:
unregisterin interfaceMessenger- Parameters:
listener- -UdpListenerto unregister
-
getSentPackets
public static int getSentPackets()Returns number of packets sent since last creation of the instance ofUdpMessenger. For debug/testing purposes only. -
send
SendsUdpMessage.- Specified by:
sendin interfaceMessenger- Parameters:
message- -UdpMessageto send.- Throws:
IOException- when sending of the message fails
-