Class MemberImpl

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable, Member
    Direct Known Subclasses:
    StaticMember

    public class MemberImpl
    extends java.lang.Object
    implements Member, java.io.Externalizable
    A membership implementation using simple multicast. This is the representation of a multicast member. Carries the host, and port of the this or other cluster nodes.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] command
      Command, so that the custom payload doesn't have to be used This is for internal tribes use, such as SHUTDOWN_COMMAND
      protected byte[] dataPkg
      To avoid serialization over and over again, once the local dataPkg has been set, we use that to transmit data
      protected byte[] domain
      Domain if we want to filter based on domain.
      protected byte[] host
      The listen host for this member.
      protected java.lang.String hostname
      The hostname string representation.
      protected boolean local
      The flag indicating that this member is a local member.
      protected long memberAliveTime
      The number of milliseconds since this member was created, is kept track of using the start time
      protected java.util.concurrent.atomic.AtomicInteger msgCount
      Counter for how many broadcast messages have been sent from this member
      protected byte[] payload
      Custom payload that an app framework can broadcast Also used to transport stop command.
      protected int port
      The tcp listen port for this member
      protected int securePort
      The tcp/SSL listen port for this member
      protected long serviceStartTime
      For the local member only
      protected static StringManager sm
      The string manager for this class.
      static byte[] TRIBES_MBR_BEGIN
      The start marker for tribes member data.
      static byte[] TRIBES_MBR_END
      The end marker for tribes member data.
      protected int udpPort
      The udp listen port for this member
      protected byte[] uniqueId
      Unique session Id for this member
    • Constructor Summary

      Constructors 
      Constructor Description
      MemberImpl()
      Empty constructor for serialization
      MemberImpl​(java.lang.String host, int port, long aliveTime)
      Construct a new member object.
      MemberImpl​(java.lang.String host, int port, long aliveTime, byte[] payload)
      Construct a new member object with payload.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String bToS​(byte[] data)
      Convert byte array to string.
      static java.lang.String bToS​(byte[] data, int max)
      Convert byte array to string with max length.
      boolean equals​(java.lang.Object o)
      Returns true if the param o is a McastMember with the same name
      byte[] getCommand()
      Return the command associated with this member.
      byte[] getData()
      Create a data package to send over the wire representing this member.
      byte[] getData​(boolean getalive)
      Highly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not modify this data
      byte[] getData​(boolean getalive, boolean reset)
      Highly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not modify this data
      int getDataLength()
      Length of a message obtained by Member.getData(boolean) or Member.getData(boolean, boolean).
      byte[] getDomain()
      Return the domain for this cluster.
      byte[] getHost()
      Returns the listen host for the ChannelReceiver implementation
      java.lang.String getHostname()
      Get the hostname.
      static Member getMember​(byte[] data)
      Deserializes a member from data sent over the wire.
      static Member getMember​(byte[] data, int offset, int length)
      Deserializes a member from data sent over the wire.
      static Member getMember​(byte[] data, int offset, int length, MemberImpl member)
      Deserializes a member from data sent over the wire.
      static Member getMember​(byte[] data, MemberImpl member)
      Deserializes a member from data sent over the wire.
      long getMemberAliveTime()
      Contains information on how long this member has been online.
      int getMsgCount()
      Get the message count.
      java.lang.String getName()
      Return the name of this node, should be unique within the group.
      byte[] getPayload()
      Return the payload associated with this member.
      int getPort()
      Returns the listen port for the ChannelReceiver implementation
      int getSecurePort()
      Returns the secure listen port for the ChannelReceiver implementation.
      long getServiceStartTime()
      Get the service start time.
      int getUdpPort()
      Returns the UDP port that this member is listening to for UDP messages.
      byte[] getUniqueId()
      returns a UUID unique for this member over all sessions.
      int hashCode()  
      protected void inc()
      Increment the message count.
      boolean isFailing()
      Check if the member has been confirmed to malfunction.
      boolean isLocal()
      Check if the member is the local member.
      boolean isReady()
      The current state of the member.
      boolean isSuspect()
      The current state of the member.
      void readExternal​(java.io.ObjectInput in)  
      void setCommand​(byte[] command)
      Set the command associated with this member.
      void setDomain​(byte[] domain)
      Set the domain.
      void setHost​(byte[] host)
      Set the host.
      void setHostname​(java.lang.String host)
      Set the hostname.
      void setLocal​(boolean local)
      Set if the member is local.
      void setMemberAliveTime​(long time)
      Set the alive time in ms.
      void setMsgCount​(int msgCount)
      Set the message count.
      void setPayload​(byte[] payload)
      Set the payload associated with this member.
      void setPort​(int port)
      Set the port.
      void setSecurePort​(int securePort)
      Set the secure port.
      void setServiceStartTime​(long serviceStartTime)
      Set the service start time.
      void setUdpPort​(int port)
      Set the UDP port.
      void setUniqueId​(byte[] uniqueId)
      Set the unique ID.
      java.lang.String toString()  
      void writeExternal​(java.io.ObjectOutput out)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • TRIBES_MBR_BEGIN

        public static final byte[] TRIBES_MBR_BEGIN
        The start marker for tribes member data.
      • TRIBES_MBR_END

        public static final byte[] TRIBES_MBR_END
        The end marker for tribes member data.
      • sm

        protected static final StringManager sm
        The string manager for this class.
      • host

        protected volatile byte[] host
        The listen host for this member.
      • hostname

        protected transient volatile java.lang.String hostname
        The hostname string representation.
      • port

        protected volatile int port
        The tcp listen port for this member
      • udpPort

        protected volatile int udpPort
        The udp listen port for this member
      • securePort

        protected volatile int securePort
        The tcp/SSL listen port for this member
      • msgCount

        protected java.util.concurrent.atomic.AtomicInteger msgCount
        Counter for how many broadcast messages have been sent from this member
      • memberAliveTime

        protected volatile long memberAliveTime
        The number of milliseconds since this member was created, is kept track of using the start time
      • serviceStartTime

        protected transient long serviceStartTime
        For the local member only
      • dataPkg

        protected transient byte[] dataPkg
        To avoid serialization over and over again, once the local dataPkg has been set, we use that to transmit data
      • uniqueId

        protected volatile byte[] uniqueId
        Unique session Id for this member
      • payload

        protected volatile byte[] payload
        Custom payload that an app framework can broadcast Also used to transport stop command.
      • command

        protected volatile byte[] command
        Command, so that the custom payload doesn't have to be used This is for internal tribes use, such as SHUTDOWN_COMMAND
      • domain

        protected volatile byte[] domain
        Domain if we want to filter based on domain.
      • local

        protected volatile boolean local
        The flag indicating that this member is a local member.
    • Constructor Detail

      • MemberImpl

        public MemberImpl()
        Empty constructor for serialization
      • MemberImpl

        public MemberImpl​(java.lang.String host,
                          int port,
                          long aliveTime)
                   throws java.io.IOException
        Construct a new member object.
        Parameters:
        host - - the tcp listen host
        port - - the tcp listen port
        aliveTime - - the number of milliseconds since this member was created
        Throws:
        java.io.IOException - If there is an error converting the host name to an IP address
      • MemberImpl

        public MemberImpl​(java.lang.String host,
                          int port,
                          long aliveTime,
                          byte[] payload)
                   throws java.io.IOException
        Construct a new member object with payload.
        Parameters:
        host - the tcp listen host
        port - the tcp listen port
        aliveTime - the number of milliseconds since this member was created
        payload - the payload
        Throws:
        java.io.IOException - if there is an error converting the host name to an IP address
    • Method Detail

      • isReady

        public boolean isReady()
        Description copied from interface: Member
        The current state of the member.
        Specified by:
        isReady in interface Member
        Returns:
        true if the member is functioning correctly
      • isSuspect

        public boolean isSuspect()
        Description copied from interface: Member
        The current state of the member.
        Specified by:
        isSuspect in interface Member
        Returns:
        true if the member is suspect, but the crash has not been confirmed
      • isFailing

        public boolean isFailing()
        Description copied from interface: Member
        Check if the member has been confirmed to malfunction.
        Specified by:
        isFailing in interface Member
        Returns:
        true if the member has been confirmed to malfunction
      • inc

        protected void inc()
        Increment the message count.
      • getData

        public byte[] getData()
        Create a data package to send over the wire representing this member. This is faster than serialization.
        Returns:
        - the bytes for this member deserialized
      • getData

        public byte[] getData​(boolean getalive)
        Description copied from interface: Member
        Highly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not modify this data
        Specified by:
        getData in interface Member
        Parameters:
        getalive - calculate memberAlive time
        Returns:
        the data as a byte array
      • getData

        public byte[] getData​(boolean getalive,
                              boolean reset)
        Description copied from interface: Member
        Highly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not modify this data
        Specified by:
        getData in interface Member
        Parameters:
        getalive - calculate memberAlive time
        reset - reset the cached data package, and create a new one
        Returns:
        the data as a byte array
      • getMember

        public static Member getMember​(byte[] data,
                                       MemberImpl member)
        Deserializes a member from data sent over the wire.
        Parameters:
        data - The bytes received
        member - The member object to populate
        Returns:
        The populated member object.
      • getMember

        public static Member getMember​(byte[] data,
                                       int offset,
                                       int length,
                                       MemberImpl member)
        Deserializes a member from data sent over the wire.
        Parameters:
        data - The bytes received
        offset - The offset
        length - The length
        member - The member object to populate
        Returns:
        The populated member object
      • getMember

        public static Member getMember​(byte[] data)
        Deserializes a member from data sent over the wire.
        Parameters:
        data - the bytes received
        Returns:
        the member
      • getMember

        public static Member getMember​(byte[] data,
                                       int offset,
                                       int length)
        Deserializes a member from data sent over the wire.
        Parameters:
        data - the bytes received
        offset - the offset
        length - the length
        Returns:
        the member
      • getName

        public java.lang.String getName()
        Description copied from interface: Member
        Return the name of this node, should be unique within the group.
        Specified by:
        getName in interface Member
        Returns:
        the name of this node
      • getPort

        public int getPort()
        Description copied from interface: Member
        Returns the listen port for the ChannelReceiver implementation
        Specified by:
        getPort in interface Member
        Returns:
        the listen port for this member, -1 if it's not listening on an insecure port
        See Also:
        ChannelReceiver
      • getHost

        public byte[] getHost()
        Description copied from interface: Member
        Returns the listen host for the ChannelReceiver implementation
        Specified by:
        getHost in interface Member
        Returns:
        IPv4 or IPv6 representation of the host address this member listens to incoming data
        See Also:
        ChannelReceiver
      • getHostname

        public java.lang.String getHostname()
        Get the hostname.
        Returns:
        the hostname
      • getMsgCount

        public int getMsgCount()
        Get the message count.
        Returns:
        the message count
      • getMemberAliveTime

        public long getMemberAliveTime()
        Description copied from interface: Member
        Contains information on how long this member has been online. The result is the number of milliseconds this member has been broadcasting its membership to the group.
        Specified by:
        getMemberAliveTime in interface Member
        Returns:
        nr of milliseconds since this member started.
      • getServiceStartTime

        public long getServiceStartTime()
        Get the service start time.
        Returns:
        the service start time
      • getUniqueId

        public byte[] getUniqueId()
        Description copied from interface: Member
        returns a UUID unique for this member over all sessions. If the member crashes and restarts, the uniqueId will be different.
        Specified by:
        getUniqueId in interface Member
        Returns:
        byte[]
      • getPayload

        public byte[] getPayload()
        Description copied from interface: Member
        Return the payload associated with this member.
        Specified by:
        getPayload in interface Member
        Returns:
        the payload associated with this member
      • getCommand

        public byte[] getCommand()
        Description copied from interface: Member
        Return the command associated with this member.
        Specified by:
        getCommand in interface Member
        Returns:
        the command associated with this member
      • getDomain

        public byte[] getDomain()
        Description copied from interface: Member
        Return the domain for this cluster.
        Specified by:
        getDomain in interface Member
        Returns:
        the domain for this cluster
      • getSecurePort

        public int getSecurePort()
        Description copied from interface: Member
        Returns the secure listen port for the ChannelReceiver implementation. Returns -1 if it's not listening to a secure port.
        Specified by:
        getSecurePort in interface Member
        Returns:
        the listen port for this member, -1 if it's not listening on a secure port
        See Also:
        ChannelReceiver
      • getUdpPort

        public int getUdpPort()
        Description copied from interface: Member
        Returns the UDP port that this member is listening to for UDP messages.
        Specified by:
        getUdpPort in interface Member
        Returns:
        the listen UDP port for this member, -1 if it's not listening on a UDP port
      • setMemberAliveTime

        public void setMemberAliveTime​(long time)
        Description copied from interface: Member
        Set the alive time in ms.
        Specified by:
        setMemberAliveTime in interface Member
        Parameters:
        time - the value to set
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • bToS

        public static java.lang.String bToS​(byte[] data)
        Convert byte array to string.
        Parameters:
        data - the data
        Returns:
        the string
      • bToS

        public static java.lang.String bToS​(byte[] data,
                                            int max)
        Convert byte array to string with max length.
        Parameters:
        data - the data
        max - the max length
        Returns:
        the string
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Returns true if the param o is a McastMember with the same name
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - The object to test for equality
      • setHost

        public void setHost​(byte[] host)
        Set the host.
        Parameters:
        host - the host
      • setHostname

        public void setHostname​(java.lang.String host)
                         throws java.io.IOException
        Set the hostname.
        Parameters:
        host - the hostname
        Throws:
        java.io.IOException - if there is an error converting the host name to an IP address
      • setMsgCount

        public void setMsgCount​(int msgCount)
        Set the message count.
        Parameters:
        msgCount - the message count
      • setPort

        public void setPort​(int port)
        Set the port.
        Parameters:
        port - the port
      • setServiceStartTime

        public void setServiceStartTime​(long serviceStartTime)
        Set the service start time.
        Parameters:
        serviceStartTime - the service start time
      • setUniqueId

        public void setUniqueId​(byte[] uniqueId)
        Set the unique ID.
        Parameters:
        uniqueId - the unique ID
      • setPayload

        public void setPayload​(byte[] payload)
        Description copied from interface: Member
        Set the payload associated with this member.
        Specified by:
        setPayload in interface Member
        Parameters:
        payload - the payload
      • setCommand

        public void setCommand​(byte[] command)
        Description copied from interface: Member
        Set the command associated with this member.
        Specified by:
        setCommand in interface Member
        Parameters:
        command - the command
      • setDomain

        public void setDomain​(byte[] domain)
        Set the domain.
        Parameters:
        domain - the domain
      • setSecurePort

        public void setSecurePort​(int securePort)
        Set the secure port.
        Parameters:
        securePort - the secure port
      • setUdpPort

        public void setUdpPort​(int port)
        Set the UDP port.
        Parameters:
        port - the UDP port
      • isLocal

        public boolean isLocal()
        Description copied from interface: Member
        Check if the member is the local member.
        Specified by:
        isLocal in interface Member
        Returns:
        true if the member is local member
      • setLocal

        public void setLocal​(boolean local)
        Description copied from interface: Member
        Set if the member is local.
        Specified by:
        setLocal in interface Member
        Parameters:
        local - set to true if this is the local member
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException