Menu

Cannot use viewAccepted in RecieverAdapter while using ForkChannel to leverage exisiting Infinispan JGroups Channel

2019-03-25
2019-03-27
  • Jikku Joyce

    Jikku Joyce - 2019-03-25

    Hi,

    I am using fork channel api to fork my main channel. I have set it as a receiver using my implementation of reciever adapter. I can send and receive messages but cannot use the inherited method "viewAccepted" which should theoretically get invoked when there is a change in the jgroups view. But I do not get control to this method when I add a node or remove a node. However I still get control at my main channel's infinispan listerner class implementation annotated by @ViewChanged. This makes me confused.

    1. Is this the expected behavior?
    2. The fork channel does not send messages via the main channel. Is this understanding right?
    3. When a node in main channel goes down or a new node is added, the fork channel also behaves similar to main channel. Is this right?
    4. Is there a way to convert Infinispan Address to JGroups Address?
     
    • Bela Ban

      Bela Ban - 2019-03-26

      On 25.03.19 13:17, Jikku Joyce wrote:

      Hi,

      I am using fork channel api to fork my main channel. I have set it as a
      receiver using my implementation of reciever adapter. I can send and
      receive messages but cannot use the inherited method "viewAccepted"
      which should theoretically get invoked when there is a change in the
      jgroups view.

      Take a look at the program below. I set a ReceiverAdapter and implement
      viewAccepted(), which is called.

      But I do not get control to this method when I add a node
      or remove a node. However I still get control at my main channel's
      infinispan listerner class implementation annotated by @ViewChanged.
      This makes me confused.

      1. Is this the expected behavior?
      2. The fork channel does not send messages via the main channel. Is
        this understanding right?

      No. A ForkChannel is depending on the main channel, and its lifecycle is
      a subset of the main channel's lifecycle.

      1. When a node in main channel goes down or a new node is added, the
        fork channel also behaves similar to main channel. Is this right?

      Yes

      1. Is there a way to convert Infinispan Address to JGroups Address?

      I suggest look at how the InfinispanAddress is implemented. I assume
      this is possible; for example JGroupsAddress has a getJGroupsAddress()
      method.

      public class bla4 {
      protected JChannel ch;
      protected ForkChannel fc1, fc2;

       protected void start() throws Exception {
           ch=new JChannel("/home/bela/fork.xml");
           fc1=new ForkChannel(ch, "counter", "fc1");
           fc2=new ForkChannel(ch, "lock", "fc2");
      
           fc1.setReceiver(new ReceiverAdapter() {
               public void viewAccepted(View view) {
                   System.out.printf("%s: view is %s\n", fc1.getAddress(),
      

      view);
      }
      });
      fc2.setReceiver(new ReceiverAdapter() {
      public void viewAccepted(View view) {
      System.out.printf("%s: view is %s\n", fc2.getAddress(),
      view);
      }
      });

           ch.connect("demo");
           fc1.connect("bla");
           fc2.connect("foo");
       }
      
       public static void main(String[] args) throws Exception {
           new bla4().start();
       }
      

      }


      Cannot use viewAccepted in RecieverAdapter while using ForkChannel to
      leverage exisiting Infinispan JGroups Channel
      https://sourceforge.net/p/javagroups/discussion/18794/thread/9bccf3e2b2/?limit=25#9937


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/javagroups/discussion/18794/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

      --
      Bela Ban | http://www.jgroups.org

       
      • Jikku Joyce

        Jikku Joyce - 2019-03-26

        Hi Bela,

        Thanks for the reply.

        I created ForkedChannel as below:

        public ReceiverAdapterImpl() { //Constructor of my receiver adapter implementation
        jGroupsTransport = ispnCache.getAdvancedCache().getRpcManager().getTransport();
        jGroupsMainChannel = ((JGroupsTransport)jGroupsTransport).getChannel();
        jGroupsForkChannel = new ForkChannel(jGroupsMainChannel,
                            "stackId",
                            "channelId",
                            true, ProtocolStack.Position.ABOVE, TCP.class); jGroupsForkChannel.connect("comms");
        jGroupsForkChannel.setReceiver(this);
        }
        

        But when a new node was added to the cluster I did not get control to my viewAccepted() method in my ReceiverAdapter. I do not have control over infinispan channel creation, so I cannot call my mainChannel.connect() after I create forkChannel. Is this the problem?

        I get call back in my infinispan listener class to its @VIewChanged annotated method though.

         
        • Bela Ban

          Bela Ban - 2019-03-27

          You main mistake was to add FORK just above the transport (TCP).
          Instead, FORK needs to be placed at the top of the protocol stack:

          public class bla4 extends ReceiverAdapter {
          protected JChannel ch;

           protected void start() throws Exception {
               ch=new JChannel(); // uses udp.xml by default
               TP transport=ch.getProtocolStack().getTransport();
               transport.setBindAddress(Util.getLocalhost());
               ch.connect("demo");
               ForkChannel jGroupsForkChannel=new ForkChannel(ch,
                                                              "stackId",
                                                              "channelId",
                                                              true,
          

          ProtocolStack.Position.ABOVE, FRAG2.class);
          jGroupsForkChannel.setReceiver(this);
          jGroupsForkChannel.connect("comms");
          System.out.printf("-- %s started, waiting for messages\n",
          jGroupsForkChannel.getAddress());
          }

           public void viewAccepted(View view) {
               System.out.println("view = " + view);
           }
          
           public static void main(String[] args) throws Exception {
               new bla4().start();
           }
          

          }

          On 26.03.19 14:09, Jikku Joyce wrote:

          Hi Bela,

          Thanks for the reply.

          I created ForkedChannel as below:

          public ReceiverAdapterImpl() { //Constructor of my receiver adapter implementation
          jGroupsTransport = ispnCache.getAdvancedCache().getRpcManager().getTransport();
          jGroupsMainChannel = ((JGroupsTransport)jGroupsTransport).getChannel();
          jGroupsForkChannel = new ForkChannel(jGroupsMainChannel,
          "stackId",
          "channelId",
          true, ProtocolStack.Position.ABOVE, TCP.class); jGroupsForkChannel.connect("comms");
          jGroupsForkChannel.setReceiver(this);
          }

          But when a new node was added to the cluster I did not get control to my
          viewAccepted() method in my ReceiverAdapter. I do not have control over
          infinispan channel creation, so I cannot call my mainChannel.connect()
          after I create forkChannel. Is this the problem?

          I get call back in my infinispan listener class to its @VIewChanged
          annotated method though.


          Cannot use viewAccepted in RecieverAdapter while using ForkChannel to
          leverage exisiting Infinispan JGroups Channel
          https://sourceforge.net/p/javagroups/discussion/18794/thread/9bccf3e2b2/?limit=25#9937/598a/9dd3


          Sent from sourceforge.net because you indicated interest in
          https://sourceforge.net/p/javagroups/discussion/18794/

          To unsubscribe from further messages, please visit
          https://sourceforge.net/auth/subscriptions/

          --
          Bela Ban | http://www.jgroups.org

           
          • Jikku Joyce

            Jikku Joyce - 2019-03-27

            Hi Bela,

            I tried with FRAG2 initially. But I was not able to create fork channel and was getting a null pointer exception as below:

            java.lang.NullPointerException
                at org.jgroups.stack.ProtocolStack.insertProtocol(ProtocolStack.java:603)
                at org.jgroups.fork.ForkChannel.getFORK(ForkChannel.java:281)
                at org.jgroups.fork.ForkChannel.<init>(ForkChannel.java:75)
            

            Then only when I used TCP.class I was able to get it working. Any idea why this happens?

            When I analyse my main channel :
            my bottom protocol is TCP,
            down protocol is STATE_TRANSFER,
            top protocol is STATE_TRANSFER and
            up protocol is null.

            Can you share your JGroups configuration too?

             
  • Bela Ban

    Bela Ban - 2019-03-27

    Well, FRAG2 is not in your stack. Try STATE_TRANSFER instead.
    You cannot place FORK directly above the transport, it needs to be at the top of the stack!

     
    • Jikku Joyce

      Jikku Joyce - 2019-03-27

      That worked Bela !!! Thanks a lot for the help.

       

Log in to post a comment.