Module org.snmp4j

Class DefaultTcpTransportMapping

    • Constructor Detail

      • DefaultTcpTransportMapping

        public DefaultTcpTransportMapping()
                                   throws java.io.IOException
        Creates a default TCP transport mapping with the server for incoming messages disabled.
        Throws:
        java.io.IOException - on failure of binding a local port.
      • DefaultTcpTransportMapping

        public DefaultTcpTransportMapping​(TcpAddress serverAddress)
                                   throws java.io.IOException
        Creates a default TCP transport mapping that binds to the given address (interface) on the local host.
        Parameters:
        serverAddress - the TcpAddress instance that describes the server address to listen on incoming connection requests.
        Throws:
        java.io.IOException - if the given address cannot be bound.
    • Method Detail

      • listen

        public void listen()
                    throws java.io.IOException
        Listen for incoming and outgoing requests. If the serverEnabled member is false the server for incoming requests is not started. This starts the internal server thread that processes messages.
        Specified by:
        listen in interface TransportMapping<TcpAddress>
        Specified by:
        listen in class TcpTransportMapping<DefaultTcpTransportMapping.SocketEntry>
        Throws:
        java.net.SocketException - when the transport is already listening for incoming/outgoing messages.
        java.io.IOException - if the listen port could not be bound to the server thread.
      • setPriority

        public void setPriority​(int newPriority)
        Changes the priority of the server thread for this TCP transport mapping. This method has no effect, if called before listen() has been called for this transport mapping or if SNMP4J is configured to use a non-default thread factory.
        Parameters:
        newPriority - the new priority.
        Since:
        1.2.2
        See Also:
        Thread.setPriority(int)
      • getPriority

        public int getPriority()
        Returns the priority of the internal listen thread.
        Returns:
        a value between Thread.MIN_PRIORITY and Thread.MAX_PRIORITY.
        Since:
        1.2.2
      • setThreadName

        public void setThreadName​(java.lang.String name)
        Sets the name of the listen thread for this UDP transport mapping. This method has no effect, if called before listen() has been called for this transport mapping.
        Parameters:
        name - the new thread name.
        Since:
        1.6
      • getThreadName

        public java.lang.String getThreadName()
        Returns the name of the listen thread.
        Returns:
        the thread name if in listening mode, otherwise null.
        Since:
        1.6
      • sendMessage

        public void sendMessage​(TcpAddress address,
                                byte[] message,
                                TransportStateReference tmStateReference,
                                long timeoutMillis,
                                int maxRetries)
                         throws java.io.IOException
        Sends a SNMP message to the supplied address.
        Specified by:
        sendMessage in interface TransportMapping<TcpAddress>
        Specified by:
        sendMessage in class TcpTransportMapping<DefaultTcpTransportMapping.SocketEntry>
        Parameters:
        address - an TcpAddress. A ClassCastException is thrown if address is not a TcpAddress instance.
        message - byte[] the message to sent.
        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 an IO exception occurs while trying to send the message.
      • isServerEnabled

        public boolean isServerEnabled()
        Checks whether a server for incoming requests is enabled.
        Returns:
        boolean
      • setServerEnabled

        public void setServerEnabled​(boolean serverEnabled)
        Sets whether a server for incoming requests should be created when the transport is set into listen state. Setting this value has no effect until the listen() method is called (if the transport is already listening, close() has to be called before).
        Parameters:
        serverEnabled - if true if the transport will listens for incoming requests after listen() has been called.
      • getSocketCleaner

        public CommonTimer getSocketCleaner()
        Gets the CommonTimer that controls socket cleanup operations.
        Returns:
        a socket cleaner timer.
        Since:
        3.0
      • setMaxInboundMessageSize

        public void setMaxInboundMessageSize​(int maxInboundMessageSize)
        Sets the maximum buffer size for incoming requests. When SNMP packets are received that are longer than this maximum size, the messages will be silently dropped and the connection will be closed.
        Parameters:
        maxInboundMessageSize - the length of the inbound buffer in bytes.
      • isListening

        public boolean isListening()
        Description copied from interface: TransportMapping
        Returns 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.
        Returns:
        true if this transport mapping is listening for messages.
      • getMaxBusyLoops

        protected int getMaxBusyLoops()
      • setMaxBusyLoops

        protected void setMaxBusyLoops​(int maxBusyLoops)
      • socketClosedRemotely

        protected void socketClosedRemotely​(java.nio.channels.SelectionKey sk,
                                            java.nio.channels.SocketChannel readChannel,
                                            TcpAddress incomingAddress)
                                     throws java.io.IOException
        Throws:
        java.io.IOException