public class DefaultUdpTransportMapping extends UdpTransportMapping
DefaultUdpTransportMapping
implements a UDP transport
mapping based on Java standard IO and using an internal thread for
listening on the inbound socket.Modifier and Type | Field and Description |
---|---|
protected WorkerTask |
listener |
protected org.snmp4j.transport.DefaultUdpTransportMapping.ListenThread |
listenerThread |
protected DatagramSocket |
socket |
udpAddress
asyncMsgProcessingSupported, maxInboundMessageSize, transportListener
Constructor and Description |
---|
DefaultUdpTransportMapping()
Creates a UDP transport with an arbitrary local port on all local
interfaces.
|
DefaultUdpTransportMapping(UdpAddress udpAddress)
Creates a UDP transport on the specified address.
|
DefaultUdpTransportMapping(UdpAddress udpAddress,
boolean reuseAddress)
Creates a UDP transport with optional reusing the address if is currently
in timeout state (TIME_WAIT) after the connection is closed.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the socket and stops the listener thread.
|
int |
getPriority()
Returns the priority of the internal listen thread.
|
int |
getReceiveBufferSize()
Gets the requested receive buffer size for the underlying UDP socket.
|
int |
getSocketTimeout()
Returns the socket timeout.
|
String |
getThreadName()
Returns the name of the listen thread.
|
boolean |
isListening()
Returns
true if the transport mapping is listening for
incoming messages. |
void |
listen()
Starts the listener thread that accepts incoming messages.
|
void |
sendMessage(UdpAddress targetAddress,
byte[] message,
TransportStateReference tmStateReference)
Sends a message to the supplied address using this transport.
|
void |
setMaxInboundMessageSize(int maxInboundMessageSize) |
void |
setPriority(int newPriority)
Changes the priority of the listen thread for this UDP transport mapping.
|
void |
setReceiveBufferSize(int receiveBufferSize)
Sets the receive buffer size, which should be > the maximum inbound message
size.
|
void |
setSocketTimeout(int socketTimeout)
Sets the socket timeout in milliseconds.
|
void |
setThreadName(String name)
Sets the name of the listen thread for this UDP transport mapping.
|
getAddress, getListenAddress, getSupportedAddressClass
addTransportListener, fireProcessMessage, getMaxInboundMessageSize, isAsyncMsgProcessingSupported, removeTransportListener, setAsyncMsgProcessingSupported
protected DatagramSocket socket
protected WorkerTask listener
protected org.snmp4j.transport.DefaultUdpTransportMapping.ListenThread listenerThread
public DefaultUdpTransportMapping() throws IOException
IOException
- if socket binding fails.public DefaultUdpTransportMapping(UdpAddress udpAddress, boolean reuseAddress) throws IOException
udpAddress
- the local address for sending and receiving of UDP messages.reuseAddress
- if true
addresses are reused which provides faster socket
binding if an application is restarted for instance.IOException
- if socket binding fails.public DefaultUdpTransportMapping(UdpAddress udpAddress) throws IOException
udpAddress
- the local address for sending and receiving of UDP messages.IOException
- if socket binding fails.public void sendMessage(UdpAddress targetAddress, byte[] message, TransportStateReference tmStateReference) throws IOException
TransportMapping
sendMessage
in interface TransportMapping<UdpAddress>
sendMessage
in class UdpTransportMapping
targetAddress
- an Address
instance denoting the target address.message
- the whole message as an array of bytes.tmStateReference
- the (optional) transport model state reference as defined by
RFC 5590 section 6.1.IOException
- if any underlying IO operation fails.public void close() throws IOException
close
in interface TransportMapping<UdpAddress>
close
in class UdpTransportMapping
IOException
public void listen() throws IOException
close()
method should be called to stop the
listen thread gracefully and free associated ressources.listen
in interface TransportMapping<UdpAddress>
listen
in class UdpTransportMapping
IOException
public void setPriority(int newPriority)
listen()
has been
called for this transport mapping.newPriority
- the new priority.Thread.setPriority(int)
public int getPriority()
Thread.MIN_PRIORITY
and
Thread.MAX_PRIORITY
.public void setThreadName(String name)
listen()
has been
called for this transport mapping.name
- the new thread name.public String getThreadName()
null
.public void setMaxInboundMessageSize(int maxInboundMessageSize)
public int getSocketTimeout()
public int getReceiveBufferSize()
public void setReceiveBufferSize(int receiveBufferSize)
listen()
to be
effective.receiveBufferSize
- an integer value >0 and > AbstractTransportMapping.getMaxInboundMessageSize()
.public void setSocketTimeout(int socketTimeout)
socketTimeout
- the socket timeout for incoming messages in milliseconds.
A timeout of zero is interpreted as an infinite timeout.public boolean isListening()
TransportMapping
true
if the transport mapping is listening for
incoming messages. For connection oriented transport mappings this
is a prerequisite to be able to send SNMP messages. For connectionless
transport mappings it is a prerequisite to be able to receive responses.true
if this transport mapping is listening for messages.Copyright © 2013 SNMP4J.org. All Rights Reserved.