Class ReplicatedTree

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Log log  
      static java.lang.String SEPARATOR  
    • Constructor Summary

      Constructors 
      Constructor Description
      ReplicatedTree()  
      ReplicatedTree​(java.lang.String groupname, java.lang.String props, long state_fetch_timeout)
      Creates a channel with the given properties.
      ReplicatedTree​(java.lang.String groupname, java.lang.String props, long state_fetch_timeout, boolean jmx)  
      ReplicatedTree​(JChannel channel)
      Expects an already connected channel.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void _put​(java.lang.String fqn, java.lang.String key, java.lang.Object value)  
      void _put​(java.lang.String fqn, java.util.HashMap data)  
      void _remove​(java.lang.String fqn)  
      void _remove​(java.lang.String fqn, java.lang.String key)  
      void _removeData​(java.lang.String fqn)  
      void addReplicatedTreeListener​(ReplicatedTree.ReplicatedTreeListener listener)  
      boolean exists​(java.lang.String fqn)
      Checks whether a given node exists in the tree
      void fetchState​(long timeout)
      Fetch the group state from the current coordinator.
      java.lang.Object get​(java.lang.String fqn, java.lang.String key)
      Finds a node given its name and returns the value associated with a given key in its data map.
      JChannel getChannel()
      Returns the Channel the DistributedTree is connected to
      java.util.Set getChildrenNames​(java.lang.String fqn)
      Returns all children of a given node
      int getGroupMembersNumber()
      Returns the number of current members joined to the group
      java.lang.String getGroupName()
      Returns the name of the group that the DistributedTree is connected to
      java.util.Set getKeys​(java.lang.String fqn)
      Gets the keys of the data map.
      Address getLocalAddress()  
      java.util.List<Address> getMembers()  
      void getState​(java.io.OutputStream ostream)
      Allows an application to write a state through a provided OutputStream.
      static void main​(java.lang.String[] args)  
      java.lang.String print​(java.lang.String fqn)
      Prints a representation of the node defined by fqn.
      void put​(java.lang.String fqn, java.lang.String key, java.lang.Object value)
      Adds a key and value to a given node.
      void put​(java.lang.String fqn, java.util.HashMap data)
      Adds a new node to the tree and sets its data.
      void receive​(Message msg)
      Callback.
      void remove​(java.lang.String fqn)
      Removes the node from the tree.
      void remove​(java.lang.String fqn, java.lang.String key)
      Removes key from the node's hashmap
      void removeReplicatedTreeListener​(ReplicatedTree.ReplicatedTreeListener listener)  
      void setRemoteCalls​(boolean flag)  
      void setRootNode​(ReplicatedTree.Node n)  
      void setState​(java.io.InputStream istream)
      Allows an application to read a state through a provided InputStream.
      void start()  
      void stop()  
      java.lang.String toString()  
      void viewAccepted​(View new_view)
      Called when a change in membership has occurred.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ReplicatedTree

        public ReplicatedTree​(java.lang.String groupname,
                              java.lang.String props,
                              long state_fetch_timeout)
                       throws java.lang.Exception
        Creates a channel with the given properties. Connects to the channel, then creates a PullPushAdapter and starts it
        Throws:
        java.lang.Exception
      • ReplicatedTree

        public ReplicatedTree​(java.lang.String groupname,
                              java.lang.String props,
                              long state_fetch_timeout,
                              boolean jmx)
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • ReplicatedTree

        public ReplicatedTree()
      • ReplicatedTree

        public ReplicatedTree​(JChannel channel)
                       throws java.lang.Exception
        Expects an already connected channel. Creates a PullPushAdapter and starts it
        Throws:
        java.lang.Exception
    • Method Detail

      • setRemoteCalls

        public void setRemoteCalls​(boolean flag)
      • getLocalAddress

        public Address getLocalAddress()
      • getMembers

        public java.util.List<Address> getMembers()
      • fetchState

        public void fetchState​(long timeout)
                        throws java.lang.Exception
        Fetch the group state from the current coordinator. If successful, this will trigger setState().
        Throws:
        java.lang.Exception
      • start

        public final void start()
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • stop

        public void stop()
      • put

        public void put​(java.lang.String fqn,
                        java.util.HashMap data)
        Adds a new node to the tree and sets its data. If the node doesn not yet exist, it will be created. Also, parent nodes will be created if not existent. If the node already has data, then the new data will override the old one. If the node already existed, a nodeModified() notification will be generated. Otherwise a nodeCreated() motification will be emitted.
        Parameters:
        fqn - The fully qualified name of the new node
        data - The new data. May be null if no data should be set in the node.
      • put

        public void put​(java.lang.String fqn,
                        java.lang.String key,
                        java.lang.Object value)
        Adds a key and value to a given node. If the node doesn't exist, it will be created. If the node already existed, a nodeModified() notification will be generated. Otherwise a nodeCreated() motification will be emitted.
        Parameters:
        fqn - The fully qualified name of the node
        key - The key
        value - The value
      • remove

        public void remove​(java.lang.String fqn)
        Removes the node from the tree.
        Parameters:
        fqn - The fully qualified name of the node.
      • remove

        public void remove​(java.lang.String fqn,
                           java.lang.String key)
        Removes key from the node's hashmap
        Parameters:
        fqn - The fullly qualified name of the node
        key - The key to be removed
      • exists

        public boolean exists​(java.lang.String fqn)
        Checks whether a given node exists in the tree
        Parameters:
        fqn - The fully qualified name of the node
        Returns:
        boolean Whether or not the node exists
      • getKeys

        public java.util.Set getKeys​(java.lang.String fqn)
        Gets the keys of the data map. Returns all keys as Strings. Returns null if node does not exist.
        Parameters:
        fqn - The fully qualified name of the node
        Returns:
        Set A set of keys (as Strings)
      • get

        public java.lang.Object get​(java.lang.String fqn,
                                    java.lang.String key)
        Finds a node given its name and returns the value associated with a given key in its data map. Returns null if the node was not found in the tree or the key was not found in the hashmap.
        Parameters:
        fqn - The fully qualified name of the node.
        key - The key.
      • print

        public java.lang.String print​(java.lang.String fqn)
        Prints a representation of the node defined by fqn. Output includes name, fqn and data.
      • getChildrenNames

        public java.util.Set getChildrenNames​(java.lang.String fqn)
        Returns all children of a given node
        Parameters:
        fqn - The fully qualified name of the node
        Returns:
        Set A list of child names (as Strings)
      • toString

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

        public java.lang.String getGroupName()
        Returns the name of the group that the DistributedTree is connected to
        Returns:
        String
      • getChannel

        public JChannel getChannel()
        Returns the Channel the DistributedTree is connected to
        Returns:
        Channel
      • getGroupMembersNumber

        public int getGroupMembersNumber()
        Returns the number of current members joined to the group
        Returns:
        int
      • _put

        public void _put​(java.lang.String fqn,
                         java.util.HashMap data)
      • _put

        public void _put​(java.lang.String fqn,
                         java.lang.String key,
                         java.lang.Object value)
      • _remove

        public void _remove​(java.lang.String fqn)
      • _remove

        public void _remove​(java.lang.String fqn,
                            java.lang.String key)
      • _removeData

        public void _removeData​(java.lang.String fqn)
      • getState

        public void getState​(java.io.OutputStream ostream)
                      throws java.lang.Exception
        Description copied from interface: StateListener
        Allows an application to write a state through a provided OutputStream. After the state has been written the OutputStream doesn't need to be closed as stream closing is automatically done when a calling thread returns from this callback.
        Specified by:
        getState in interface StateListener
        Overrides:
        getState in class ReceiverAdapter
        Parameters:
        ostream - the OutputStream
        Throws:
        java.lang.Exception - if the streaming fails, any exceptions should be thrown so that the state requester can re-throw them and let the caller know what happened
        See Also:
        OutputStream.close()
      • setState

        public void setState​(java.io.InputStream istream)
                      throws java.lang.Exception
        Description copied from interface: StateListener
        Allows an application to read a state through a provided InputStream. After the state has been read the InputStream doesn't need to be closed as stream closing is automatically done when a calling thread returns from this callback.
        Specified by:
        setState in interface StateListener
        Overrides:
        setState in class ReceiverAdapter
        Parameters:
        istream - the InputStream
        Throws:
        java.lang.Exception - if the streaming fails, any exceptions should be thrown so that the state requester can catch them and thus know what happened
        See Also:
        InputStream.close()
      • viewAccepted

        public void viewAccepted​(View new_view)
        Description copied from interface: MembershipListener
        Called when a change in membership has occurred. No long running actions, sending of messages or anything that could block should be done in this callback. If some long running action needs to be performed, it should be done in a separate thread.

        Note that on reception of the first view (a new member just joined), the channel will not yet be in the connected state. This only happens when JChannel.connect(String) returns.

        Specified by:
        viewAccepted in interface MembershipListener
        Overrides:
        viewAccepted in class ReceiverAdapter
      • main

        public static void main​(java.lang.String[] args)