- java.lang.Object
-
- org.snmp4j.transport.AbstractTransportMapping<A>
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,TransportMapping<A>
- Direct Known Subclasses:
DummyTransport,DummyTransport.DummyTransportResponder,TcpTransportMapping,UdpTransportMapping
public abstract class AbstractTransportMapping<A extends Address> extends java.lang.Object implements TransportMapping<A>
TheAbstractTransportMappingprovides an abstract implementation for the message dispatcher list and the maximum inbound message size.- Version:
- 3.0
- Author:
- Frank Fock
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanasyncMsgProcessingSupportedprotected intmaxInboundMessageSizeprotected java.util.List<TransportListener>transportListener
-
Constructor Summary
Constructors Constructor Description AbstractTransportMapping()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddTransportListener(TransportListener l)Adds a transport listener to the transport.abstract voidclose()Closes the transport an releases all bound resources synchronously.protected voidfireProcessMessage(A address, java.nio.ByteBuffer buf, TransportStateReference tmStateReference)intgetMaxInboundMessageSize()Gets the maximum length of an incoming message that can be successfully processed by this transport mapping implementation.abstract java.lang.Class<? extends Address>getSupportedAddressClass()Gets the primaryAddressclass that is supported by this transport mapping.booleanisAsyncMsgProcessingSupported()Returnstrueif asynchronous (multi-threaded) message processing may be implemented.abstract voidlisten()Listen for incoming messages.voidremoveTransportListener(TransportListener l)Removes a transport listener.abstract voidsendMessage(A address, byte[] message, TransportStateReference tmStateReference, long timeoutMillis, int maxRetries)Sends a message to the supplied address using this transport.voidsetAsyncMsgProcessingSupported(boolean asyncMsgProcessingSupported)Specifies whether this transport mapping has to support asynchronous messages processing or not.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.snmp4j.TransportMapping
getListenAddress, getSupportedAddressClasses, getSupportedTransportType, isAddressSupported, isAddressSupported, isListening
-
-
-
-
Field Detail
-
transportListener
protected java.util.List<TransportListener> transportListener
-
maxInboundMessageSize
protected int maxInboundMessageSize
-
asyncMsgProcessingSupported
protected boolean asyncMsgProcessingSupported
-
-
Method Detail
-
getSupportedAddressClass
public abstract java.lang.Class<? extends Address> getSupportedAddressClass()
Description copied from interface:TransportMappingGets the primaryAddressclass that is supported by this transport mapping.- Specified by:
getSupportedAddressClassin interfaceTransportMapping<A extends Address>- Returns:
- a subclass of
Address.
-
sendMessage
public abstract void sendMessage(A address, byte[] message, TransportStateReference tmStateReference, long timeoutMillis, int maxRetries) throws java.io.IOException
Description copied from interface:TransportMappingSends a message to the supplied address using this transport.- Specified by:
sendMessagein interfaceTransportMapping<A extends Address>- Parameters:
address- anAddressinstance 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.timeoutMillis- maximum number of milli seconds the connection creation might take (if connection based).maxRetries- maximum retries during connection creation.- Throws:
java.io.IOException- if any underlying IO operation fails.
-
addTransportListener
public void addTransportListener(TransportListener l)
Description copied from interface:TransportMappingAdds a transport listener to the transport. Normally, at least one transport listener needs to be added to process incoming messages.- Specified by:
addTransportListenerin interfaceTransportMapping<A extends Address>- Parameters:
l- aTransportListenerinstance.
-
removeTransportListener
public void removeTransportListener(TransportListener l)
Description copied from interface:TransportMappingRemoves a transport listener. Incoming messages will no longer be propagated to the suppliedTransportListener.- Specified by:
removeTransportListenerin interfaceTransportMapping<A extends Address>- Parameters:
l- aTransportListenerinstance.
-
fireProcessMessage
protected void fireProcessMessage(A address, java.nio.ByteBuffer buf, TransportStateReference tmStateReference)
-
close
public abstract void close() throws java.io.IOExceptionDescription copied from interface:TransportMappingCloses the transport an releases all bound resources synchronously.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceTransportMapping<A extends Address>- Throws:
java.io.IOException- if any IO operation for the close fails.
-
listen
public abstract void listen() throws java.io.IOExceptionDescription copied from interface:TransportMappingListen for incoming messages. For connection oriented transports, this method needs to be called beforeTransportMapping.sendMessage(A, byte[], org.snmp4j.TransportStateReference, long, int)is called for the first time.- Specified by:
listenin interfaceTransportMapping<A extends Address>- Throws:
java.io.IOException- if an IO operation exception occurs while starting the listener.
-
getMaxInboundMessageSize
public int getMaxInboundMessageSize()
Description copied from interface:TransportMappingGets the maximum length of an incoming message that can be successfully processed by this transport mapping implementation.- Specified by:
getMaxInboundMessageSizein interfaceTransportMapping<A extends Address>- Returns:
- an integer > 484.
-
isAsyncMsgProcessingSupported
public boolean isAsyncMsgProcessingSupported()
Returnstrueif asynchronous (multi-threaded) message processing may be implemented. The default istrue.- Returns:
- if
falseis returned theMessageDispatcher.processMessage(org.snmp4j.TransportMapping, org.snmp4j.smi.Address, java.nio.ByteBuffer, org.snmp4j.TransportStateReference)method must not return before the message has been entirely processed.
-
setAsyncMsgProcessingSupported
public void setAsyncMsgProcessingSupported(boolean asyncMsgProcessingSupported)
Specifies whether this transport mapping has to support asynchronous messages processing or not.- Parameters:
asyncMsgProcessingSupported- iffalsetheMessageDispatcher.processMessage(org.snmp4j.TransportMapping, org.snmp4j.smi.Address, java.nio.ByteBuffer, org.snmp4j.TransportStateReference)method must not return before the message has been entirely processed, because the incoming message buffer is not copied before the message is being processed. Iftruethe message buffer is copied for each call, so that the message processing can be implemented asynchronously.
-
-