Class MyReceiver<T>

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, Receiver

    public class MyReceiver<T>
    extends java.lang.Object
    implements Receiver, java.io.Closeable
    Generic receiver for a JChannel
    Since:
    3.3
    Author:
    Bela Ban
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<T> list  
      protected java.lang.String name  
      protected boolean raw_msgs  
      protected java.util.Map<java.lang.String,​java.lang.String> state  
      protected boolean verbose  
    • Constructor Summary

      Constructors 
      Constructor Description
      MyReceiver()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void getState​(java.io.OutputStream out)
      Allows an application to write the state to an OutputStream.
      java.util.List<T> list()  
      java.util.List<java.lang.String> list​(java.util.function.Function<T,​java.lang.String> f)  
      java.lang.String name()  
      MyReceiver<T> name​(java.lang.String name)  
      MyReceiver<T> rawMsgs​(boolean flag)  
      void receive​(Message msg)
      Called when a message is received.
      MyReceiver<T> reset()  
      void setState​(java.io.InputStream input)
      Allows an application to read the state from an InputStream.
      int size()  
      java.util.Map<java.lang.String,​java.lang.String> state()  
      java.lang.String toString()  
      MyReceiver<T> verbose​(boolean flag)  
      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
    • Field Detail

      • list

        protected final java.util.List<T> list
      • name

        protected java.lang.String name
      • verbose

        protected boolean verbose
      • raw_msgs

        protected boolean raw_msgs
      • state

        protected final java.util.Map<java.lang.String,​java.lang.String> state
    • Constructor Detail

      • MyReceiver

        public MyReceiver()
    • Method Detail

      • receive

        public void receive​(Message msg)
        Description copied from interface: Receiver
        Called when a message is received.
        Specified by:
        receive in interface Receiver
        Parameters:
        msg - The message
      • viewAccepted

        public void viewAccepted​(View new_view)
        Description copied from interface: Receiver
        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 Receiver
      • getState

        public void getState​(java.io.OutputStream out)
                      throws java.lang.Exception
        Description copied from interface: Receiver
        Allows an application to write the state to an 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 Receiver
        Parameters:
        out - 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
      • setState

        public void setState​(java.io.InputStream input)
                      throws java.lang.Exception
        Description copied from interface: Receiver
        Allows an application to read the state from an 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 Receiver
        Parameters:
        input - 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
      • rawMsgs

        public MyReceiver<T> rawMsgs​(boolean flag)
      • list

        public java.util.List<T> list()
      • list

        public java.util.List<java.lang.String> list​(java.util.function.Function<T,​java.lang.String> f)
      • state

        public java.util.Map<java.lang.String,​java.lang.String> state()
      • verbose

        public MyReceiver<T> verbose​(boolean flag)
      • name

        public java.lang.String name()
      • name

        public MyReceiver<T> name​(java.lang.String name)
      • size

        public int size()
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • toString

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