Package org.zeromq

Class ZAgent.SimpleAgent

  • All Implemented Interfaces:
    ZAgent
    Enclosing interface:
    ZAgent

    public static final class ZAgent.SimpleAgent
    extends java.lang.Object
    implements ZAgent
    Creates a very simple agent with an easy lock mechanism.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] lock  
      private boolean locked  
      private ZMQ.Socket pipe  
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleAgent​(ZMQ.Socket pipe, java.lang.String lock)
      Creates a new simple agent.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the pipe.
      ZMQ.Socket pipe()
      Returns the socket used for communication.
      ZMsg recv()
      Receives a control message sent from the Plateau in the Corbeille.
      ZMsg recv​(boolean wait)
      Receives a control message sent from the Plateau in the Corbeille.
      ZMsg recv​(int timeout)
      Receives a control message sent from the Plateau in the Corbeille.
      boolean send​(java.lang.String word)
      Sends a control message from the Corbeille to the Plateau side.
      boolean send​(java.lang.String word, boolean more)
      Sends a control message from the Corbeille to the Plateau side.
      boolean send​(ZMsg message)
      Sends a control message from the Corbeille to the Plateau.
      boolean send​(ZMsg msg, boolean destroy)
      Sends a control message from Corbeille side to the Plateau side.
      boolean sign()
      Gives a sign if the distant Star is here.
      • Methods inherited from class java.lang.Object

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

      • lock

        private final byte[] lock
      • locked

        private boolean locked
    • Constructor Detail

      • SimpleAgent

        public SimpleAgent​(ZMQ.Socket pipe,
                           java.lang.String lock)
        Creates a new simple agent.
        Parameters:
        pipe - the pipe used to send control messages to the distant IStar.
        lock - the lock to use. If null, the locking mechanism is omitted.
    • Method Detail

      • sign

        public boolean sign()
        Description copied from interface: ZAgent
        Gives a sign if the distant Star is here.
        Specified by:
        sign in interface ZAgent
        Returns:
        true if here, otherwise false
      • close

        public void close()
        Description copied from interface: ZAgent
        Closes the pipe.
        Specified by:
        close in interface ZAgent
      • recv

        public ZMsg recv()
        Description copied from interface: ZAgent
        Receives a control message sent from the Plateau in the Corbeille. The call is blocking.
        Specified by:
        recv in interface ZAgent
        Returns:
        the received message or null if the context was shut down.
      • recv

        public ZMsg recv​(int timeout)
        Description copied from interface: ZAgent
        Receives a control message sent from the Plateau in the Corbeille. The call times out if there is no message after the elapsed time.
        Specified by:
        recv in interface ZAgent
        Parameters:
        timeout - the timeout in milliseconds before returning null.
        Returns:
        the received message or null if the context was shut down or if no message after the timeout.
      • recv

        public ZMsg recv​(boolean wait)
        Description copied from interface: ZAgent
        Receives a control message sent from the Plateau in the Corbeille. The call is blocking depending on the parameter.
        Specified by:
        recv in interface ZAgent
        Parameters:
        wait - true to make a blocking call, false to not wait, and possibly return null
        Returns:
        the received message or null if the context was shut down or if there is no message when not blocking.
      • send

        public boolean send​(ZMsg message)
        Description copied from interface: ZAgent
        Sends a control message from the Corbeille to the Plateau.
        Specified by:
        send in interface ZAgent
        Parameters:
        message - the message to send
        Returns:
        true if the message was sent, otherwise false (if the distant Star is dead for example)
      • send

        public boolean send​(java.lang.String word)
        Description copied from interface: ZAgent
        Sends a control message from the Corbeille to the Plateau side.
        Specified by:
        send in interface ZAgent
        Parameters:
        word - the message to send
        Returns:
        true if the message was sent, otherwise false (if the distant Star is dead for example)
      • send

        public boolean send​(java.lang.String word,
                            boolean more)
        Description copied from interface: ZAgent
        Sends a control message from the Corbeille to the Plateau side.
        Specified by:
        send in interface ZAgent
        Parameters:
        word - the message to send
        more - true to send more strings in a single message
        Returns:
        true if the message was sent, otherwise false (if the distant Star is dead for example)
      • send

        public boolean send​(ZMsg msg,
                            boolean destroy)
        Description copied from interface: ZAgent
        Sends a control message from Corbeille side to the Plateau side.
        Specified by:
        send in interface ZAgent
        Parameters:
        msg - the message to send
        destroy - true to destroy the message after sending it.
        Returns:
        true if the message was sent, otherwise false (if the distant Star is dead for example)
      • pipe

        public ZMQ.Socket pipe()
        Description copied from interface: ZAgent
        Returns the socket used for communication. For advanced usage.
        Specified by:
        pipe in interface ZAgent
        Returns:
        the socket used to communicate with the distant Star.