Re: [jgroups-users] problem with custom address

Questions/problems related to using JGroups <[email protected]> Tue, 19 Jun 2018 10:46:22 +0200
Newsgroups gmane.comp.java.javagroups.general
Message-ID <mailman.12433.1529397997.997.javagroups-users@lists.sourceforge.net>
I finally got around to take a look; sorry for the delay!

The problem was that your TestAddress did not generate a valid UUID. As 
a matter of fact, all bits in each TestAddress were 0! This means that 
you always generated *exactly the same address*! Of course, this won't 
work for multiple members :-)

The correct impl is below. The only important change is how you 
implement the AddressGenerator:
  jChannel.addAddressGenerator(() -> new 
TestAddress(UUID.generateRandomBytes()));


=========================================
public class bla implements RequestHandler, MembershipListener {
     protected JChannel          jChannel;
     protected MessageDispatcher dispatcher;

     static {
         ClassConfigurator.add((short) 5309, TestAddress.class);
     }

     protected void start(String name) throws Exception {
         jChannel = new JChannel("/home/bela/fast.xml").name(name);
         jChannel.addAddressGenerator(() -> new 
TestAddress(UUID.generateRandomBytes()));
         dispatcher = new MessageDispatcher(jChannel, this);
         dispatcher.setMembershipListener(this);
         jChannel.connect("demo");
     }

     public static void main(String[] args) throws Exception {
         new bla().start(args[0]);
     }

     public Object handle(Message msg) throws Exception {
         return new Date();
     }

     public void viewAccepted(View new_view) {
         System.out.printf("** view is %s\n", new_view);
     }



     public static class TestAddress extends UUID {

         String ipOrHost = new Date().toString(); // simple way to test 
info getting from node to node

         public TestAddress() {
         }

         public TestAddress(byte[] bytes) {
             super(bytes);
         }


         @Override
         public String toString() {
             return super.toString() + "(" + ipOrHost + ")";
         }
         @Override
         public Supplier<? extends TestAddress> create() {
             return TestAddress::new;
         }
         @Override
         public void writeTo(DataOutput out) throws Exception {
             super.writeTo(out);
             out.writeUTF(ipOrHost);
         }
         @Override
         public void readFrom(DataInput in) throws Exception {
             super.readFrom(in);
             ipOrHost = in.readUTF();
         }
     }

}


On 01/06/18 17:47, Questions/problems related to using JGroups wrote:
> On Fri, Jun 1, 2018 at 9:54 AM, Questions/problems related to using 
> JGroups <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>     The problem is that you cannot override equals(), take a look at my
>     sample program below:
> 
> 
> Ok, I've pulled that. Thanks. Still not working, but I have more info. 
> When I start each node, viewAccepted is called at startup, but never is 
> again. I added a loop that outputs jc.getView().getMembers() every few 
> seconds. On each node, I see that the members are *replaced* with 
> whoever joined last. The viewAccepted method is never called, and each 
> node ends up with a view containing 1 address, the address of the last 
> node to start.
> 
> On first node, with others started several seconds apart (duplicate 
> addresses removed):
> 
> 6/1/18 11:44:18 AM com.enterprisedb.efm.nodes.EfmNode lambda$doStartup$0 
> WARNING: [hostone-40171(Fri Jun 01 11:43:50 EDT 2018)]
> 6/1/18 11:44:33 AM com.enterprisedb.efm.nodes.EfmNode lambda$doStartup$0 
> WARNING: [localhost-9003(Fri Jun 01 11:43:50 EDT 2018)]
> 6/1/18 11:44:53 AM com.enterprisedb.efm.nodes.EfmNode lambda$doStartup$0 
> WARNING: [localhost-64497(Fri Jun 01 11:43:50 EDT 2018)]
> 6/1/18 11:45:08 AM com.enterprisedb.efm.nodes.EfmNode lambda$doStartup$0 
> WARNING: [localhost-48894(Fri Jun 01 11:43:50 EDT 2018)]
> 
> One difference from my code to yours in that we use a message 
> dispatcher. When we moved from 3.x to 4.x we had to change to dispatcher 
> to handle everything (I can find that thread if needed). So am doing 
> this, where 'this' in code extends ReceiverAdapter and implements 
> RequestHandler:
> 
>          jChannel = env.createJChannel(this);
>          jChannel.addAddressGenerator(TestAddress::new);
>          dispatcher = new MessageDispatcher(jChannel, this);
>          dispatcher.setMembershipListener(this);
>          dispatcher.setStateListener(this);
>          jChannel.connect(env.getClusterName(), null, 10 * 1000);
>          final JChannel jc = jChannel;
>          Thread t = new Thread(() -> {
>              while (true) {
>                  try {
>                      Thread.sleep(5000);
>                  } catch (InterruptedException e) {}
>                  LOGGER.log(Level.WARNING, 
> jc.getView().getMembers().toString());
>              }
>          });
>          t.setDaemon(true);
>          t.start();
> 
> If I comment out " jChannel.addAddressGenerator(TestAddress::new);" 
> everything is fine, but otherwise I'm seeing the issue of viewAccepted() 
> not called and the view being improperly replaced. Any thoughts on that?
> 
> Also, the extra text in toString is always specific to the node 
> outputting it, not to the node that the Address represents. Current code:
> 
> public class TestAddress extends UUID {
>      static {
>          ClassConfigurator.add((short) 5309, TestAddress.class);
>      }
>      String ipOrHost = new Date().toString(); // simple way to test info 
> getting from node to node
>      @Override
>      public String toString() {
>          return super.toString() + "(" + ipOrHost + ")";
>      }
>      @Override
>      public Supplier<? extends TestAddress> create() {
>          return TestAddress::new;
>      }
>      @Override
>      public void writeTo(DataOutput out) throws Exception {
>          super.writeTo(out);
>          out.writeUTF(ipOrHost);
>      }
>      @Override
>      public void readFrom(DataInput in) throws Exception {
>          super.readFrom(in);
>          ipOrHost = in.readUTF();
>      }
> }
> 
> Tried without the writeTo/readFrom and have same issue with the view.
> 
> Thanks,
> Bobby
> 
> 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> 
> 
> 
> _______________________________________________
> javagroups-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/javagroups-users
> 

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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
javagroups-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/javagroups-users