Package spread

Class SpreadConnection

    • Field Detail

      • DEFAULT_AUTH_NAME

        private static final java.lang.String DEFAULT_AUTH_NAME
        See Also:
        Constant Field Values
      • DEFAULT_AUTHCLASS_NAME

        private static final java.lang.String DEFAULT_AUTHCLASS_NAME
        See Also:
        Constant Field Values
      • connected

        private boolean connected
      • rsynchro

        private java.lang.Boolean rsynchro
      • wsynchro

        private java.lang.Boolean wsynchro
      • listenersynchro

        private java.lang.Boolean listenersynchro
      • callingListeners

        private boolean callingListeners
      • basicListeners

        protected java.util.Vector basicListeners
      • advancedListeners

        protected java.util.Vector advancedListeners
      • address

        private java.net.InetAddress address
      • port

        private int port
      • priority

        private boolean priority
      • groupMembership

        private boolean groupMembership
      • authName

        private java.lang.String authName
      • authClassName

        private java.lang.String authClassName
      • authObj

        private java.lang.Object authObj
      • authMethodAuthenticate

        private java.lang.reflect.Method authMethodAuthenticate
      • socket

        private java.net.Socket socket
      • socketInput

        private java.io.InputStream socketInput
      • socketOutput

        private java.io.OutputStream socketOutput
      • listenerBuffer

        private java.util.Vector listenerBuffer
      • BUFFER_DISCONNECT

        private static final java.lang.Object BUFFER_DISCONNECT
      • BUFFER_ADD_BASIC

        private static final java.lang.Object BUFFER_ADD_BASIC
      • BUFFER_ADD_ADVANCED

        private static final java.lang.Object BUFFER_ADD_ADVANCED
      • BUFFER_REMOVE_BASIC

        private static final java.lang.Object BUFFER_REMOVE_BASIC
      • BUFFER_REMOVE_ADVANCED

        private static final java.lang.Object BUFFER_REMOVE_ADVANCED
    • Method Detail

      • sameEndian

        private static boolean sameEndian​(int i)
      • clearEndian

        private static int clearEndian​(int i)
      • flip

        protected static int flip​(int i)
      • flip

        private static short flip​(short s)
      • toBytes

        private static void toBytes​(SpreadGroup group,
                                    byte[] buffer,
                                    int bufferIndex)
      • toBytes

        private static void toBytes​(int i,
                                    byte[] buffer,
                                    int bufferIndex)
      • toInt

        protected static int toInt​(byte[] buffer,
                                   int bufferIndex)
      • readBytesFromSocket

        private void readBytesFromSocket​(byte[] buffer,
                                         java.lang.String bufferTypeString)
                                  throws SpreadException
        Throws:
        SpreadException
      • toGroup

        protected SpreadGroup toGroup​(byte[] buffer,
                                      int bufferIndex)
      • registerAuthentication

        public void registerAuthentication​(java.lang.String authName,
                                           java.lang.String authClassName)
                                    throws SpreadException
        Sets the authentication name and class string for the client side authentication method. An authentication method can only be registered before connect is called. The authentication method registered will then be used whenever connect(InetAddress, int, String, boolean, boolean) is called.
        Parameters:
        authName - the short official "name" of the method begin registered.
        authClassName - the complete class name for the method (including package)
        Throws:
        SpreadException - if the connection is already established
      • connect

        public void connect​(java.net.InetAddress address,
                            int port,
                            java.lang.String privateName,
                            boolean priority,
                            boolean groupMembership)
                     throws SpreadException
        Establishes a connection to a spread daemon. Groups can be joined, and messages can be sent or received once the connection has been established.
        Parameters:
        address - the daemon's address, or null to connect to the localhost
        port - the daemon's port, or 0 for the default port (4803)
        privateName - the private name to use for this connection
        priority - if true, this is a priority connection
        groupMembership - if true, membership messages will be received on this connection
        Throws:
        SpreadException - if the connection cannot be established
        See Also:
        disconnect()
      • getPrivateGroup

        public SpreadGroup getPrivateGroup()
        Gets the private group for this connection.
        Returns:
        the SpreadGroup representing this connection's private group, or null if there is no connection
      • receive

        public SpreadMessage receive()
                              throws SpreadException,
                                     java.io.InterruptedIOException
        Receives the next message waiting on this connection. If there are no messages waiting, the call will block until a message is ready to be received.
        Returns:
        the message that has just been received
        Throws:
        SpreadException - if there is no connection or there is any error reading a new message
        java.io.InterruptedIOException
      • receive

        public SpreadMessage[] receive​(int numMessages)
                                throws SpreadException,
                                       java.io.InterruptedIOException
        Receives numMessages messages on the connection and returns them in an array. If there are not numMessages messages waiting, the call will block until there are enough messages available.
        Parameters:
        numMessages - the number of messages to receive
        Returns:
        an array of messages
        Throws:
        SpreadException - if there is no connection or if there is any error reading the messages
        java.io.InterruptedIOException
      • poll

        public boolean poll()
                     throws SpreadException
        Returns true if there are any messages waiting on this connection.
        Returns:
        true if there is at least one message that can be received
        Throws:
        SpreadException - if there is no connection or if there is an error checking for messages
      • startListener

        private void startListener()
      • stopListener

        private void stopListener()
      • remove

        public void remove​(BasicMessageListener listener)
        Removes the BasicMessageListener from this connection. If this is the only listener on this connection, the listener thread will be stopped.
        Parameters:
        listener - the listener to remove
        See Also:
        add(BasicMessageListener)
      • remove

        public void remove​(AdvancedMessageListener listener)
        Removes the AdvancedMessageListener from this connection. If this is the only listener on this connection, the listener thread will be stopped.
        Parameters:
        listener - the listener to remove
        See Also:
        add(AdvancedMessageListener)
      • multicast

        public void multicast​(SpreadMessage message)
                       throws SpreadException
        Multicasts a message. The message will be sent to all the groups specified in the message.
        Parameters:
        message - the message to multicast
        Throws:
        SpreadException - if there is no connection or if there is any error sending the message
      • multicast

        public void multicast​(SpreadMessage[] messages)
                       throws SpreadException
        Multicasts an array of messages. Each message will be sent to all the groups specified in the message.
        Parameters:
        messages - the messages to multicast
        Throws:
        SpreadException - if there is no connection or if there is any error sending the messages