Class LWRMulticast

  • All Implemented Interfaces:
    MessageListener, java.util.EventListener

    public class LWRMulticast
    extends java.lang.Object
    implements MessageListener
    The LWRMulticast class is useful for sending and receiving JXTA multicast messages. A LWRMulticast is a (UDP) DatagramSocket, with additional capabilities for joining "groups" of other multicast hosts on the internet. A multicast group is specified within the context of PeerGroup and a propagate pipe advertisement. One would join a multicast group by first creating a MulticastSocket with the desired peer group and pipe advertisement.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ACKTAG
      Ack message element name
      protected MessageListener msgListener
      The application message listener
      static java.lang.String SEQTAG
      seq number message element name
      static java.lang.String SRCIDTAG
      source node id message element name
    • Constructor Summary

      Constructors 
      Constructor Description
      LWRMulticast​(ClusterManager manager, MessageListener msgListener)
      Create a multicast channel bind it to a specific pipe within specified peer group
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes this LWRMulticast.
      java.util.Set<PeerID> getAckList()
      Returns a list of ack's received from nodes identified by PeerID's
      static long getSequenceID​(Message msg)
      returns the source peer id of a message
      long getSoTimeout()
      Gets the Timeout attribute of the LWRMulticast
      static PeerID getSource​(Message msg)
      returns the source peer id of a message
      int getType()
      Returns the message type which Message is supporting i.g.
      boolean isBound()
      Returns the binding state of the LWRMulticast.
      boolean isClosed()
      Returns the closed state of the LWRMulticast.
      void joinGroup​(ClusterManager manager, MessageListener msgListener)
      joins MutlicastSocket to specified pipe within the context of group
      void receiveMessageEvent​(MessageEvent event)
      Processing a MessageEvent
      boolean send​(PeerID pid, Message msg)
      Send a message.
      void send​(Message msg, int threshold)
      Send a message to the predefined set of nodes, and expect a minimum of specified acks.
      boolean send​(java.util.Set<PeerID> ids, Message msg)
      Send a message to a set of peers
      void setSoTimeout​(long timeout)
      Sets the Timeout attribute of the LWRMulticast a timeout of 0 blocks forever, by default this channel's timeout is set to 0
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ACKTAG

        public static final java.lang.String ACKTAG
        Ack message element name
        See Also:
        Constant Field Values
      • SEQTAG

        public static final java.lang.String SEQTAG
        seq number message element name
        See Also:
        Constant Field Values
      • SRCIDTAG

        public static final java.lang.String SRCIDTAG
        source node id message element name
        See Also:
        Constant Field Values
      • msgListener

        protected transient MessageListener msgListener
        The application message listener
    • Constructor Detail

      • LWRMulticast

        public LWRMulticast​(ClusterManager manager,
                            MessageListener msgListener)
                     throws java.io.IOException
        Create a multicast channel bind it to a specific pipe within specified peer group
        Parameters:
        manager - the ClusterManger
        msgListener - the application listener
        Throws:
        java.io.IOException - if an io error occurs
    • Method Detail

      • joinGroup

        public void joinGroup​(ClusterManager manager,
                              MessageListener msgListener)
                       throws java.io.IOException
        joins MutlicastSocket to specified pipe within the context of group
        Parameters:
        manager - the ClusterManger
        msgListener - The application message listener
        Throws:
        java.io.IOException - if an io error occurs
      • isBound

        public boolean isBound()
        Returns the binding state of the LWRMulticast.
        Returns:
        true if the LWRMulticast successfully bound to an address
      • close

        public void close()
        Closes this LWRMulticast.
      • getAckList

        public java.util.Set<PeerID> getAckList()
        Returns a list of ack's received from nodes identified by PeerID's
        Returns:
        a List of PeerID's
      • getSoTimeout

        public long getSoTimeout()
        Gets the Timeout attribute of the LWRMulticast
        Returns:
        The soTimeout value
      • setSoTimeout

        public void setSoTimeout​(long timeout)
                          throws java.io.IOException
        Sets the Timeout attribute of the LWRMulticast a timeout of 0 blocks forever, by default this channel's timeout is set to 0
        Parameters:
        timeout - The new soTimeout value
        Throws:
        java.io.IOException - if an I/O error occurs
      • isClosed

        public boolean isClosed()
        Returns the closed state of the LWRMulticast.
        Returns:
        true if the channel has been closed
      • getSequenceID

        public static long getSequenceID​(Message msg)
        returns the source peer id of a message
        Parameters:
        msg - message
        Returns:
        The source value
      • getSource

        public static PeerID getSource​(Message msg)
        returns the source peer id of a message
        Parameters:
        msg - message
        Returns:
        The source value
      • send

        public void send​(Message msg,
                         int threshold)
                  throws java.io.IOException
        Send a message to the predefined set of nodes, and expect a minimum of specified acks.

        This method blocks until ack's upto to the specified threshold have been received or the timeout has been reached. A call to getAckList() returns a list of ack source peer ID's

        Parameters:
        msg - the message to send
        threshold - the minimun of ack expected, 0 indicates none are expected
        Throws:
        java.io.IOException - if an i/o error occurs, or SocketTimeoutException if the threshold is not met within timeout
      • send

        public boolean send​(PeerID pid,
                            Message msg)
                     throws java.io.IOException
        Send a message.
        Parameters:
        pid - destination PeerID
        msg - the message to send
        Returns:
        boolean true if the message has been sent otherwise false. false. is commonly returned for non-error related congestion, meaning that you should be able to send the message after waiting some amount of time.
        Throws:
        java.io.IOException - if an i/o error occurs
      • send

        public boolean send​(java.util.Set<PeerID> ids,
                            Message msg)
                     throws java.io.IOException
        Send a message to a set of peers
        Parameters:
        ids - destination PeerIDs
        msg - the message to send
        Returns:
        boolean true if the message has been sent otherwise false. false. is commonly returned for non-error related congestion, meaning that you should be able to send the message after waiting some amount of time.
        Throws:
        java.io.IOException - if an i/o error occurs