Re: [jgroups-users] problem with custom address

Questions/problems related to using JGroups <[email protected]> Fri, 1 Jun 2018 15:54:31 +0200
Newsgroups gmane.comp.java.javagroups.general
Message-ID <mailman.23792.1527861289.27734.javagroups-users@lists.sourceforge.net>
The problem is that you cannot override equals(), take a look at my 
sample program below:
public class bla {
     protected JChannel ch;

     protected void start(String name) throws Exception {
         ch=new JChannel().name(name);

         ch.addAddressGenerator(TestAddress::new);

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

         ch.connect("demo");
         System.out.printf("channel's address: %s, type: %s\n", 
ch.getAddress(), ch.getAddress().getClass().getSimpleName());

         Util.keyPress("<enter> to leave");
         Util.close(ch);

     }

     public static class TestAddress extends UUID {
         static {
             ClassConfigurator.add((short) 5309, TestAddress.class);
         }
         final String extraInfo = "test"; // would be bind address or 
host name in real case
         @Override
         public String toString() {
             return super.toString() + extraInfo;
         }
         // to make findbugs happy. not changing per 
http://www.jgroups.org/manual4/index.html#CustomAddresses
         //@Override
         //public boolean equals(Object o) {
           //  return super.equals(o);
        // }
         // because otherwise: java.lang.IllegalStateException: 
TestAddress.create() returned the wrong class: UUID
         @Override
         public Supplier<? extends TestAddress> create() {
             return TestAddress::new;
         }
     }

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


On 31/05/18 18:23, Questions/problems related to using JGroups wrote:
> Hi all,
> 
> JGroups 4.0.8.Final (maven): am trying a custom address so that we can 
> output the binding ip address or hostname of an Address whenever it's 
> logged. Really, just want to override toString with some more information.
> 
> Adding with this after creating the JChannel and before connecting:
> 
>          jChannel = <helper method>
>          jChannel.addAddressGenerator(new AddressGenerator() {
>              @Override
>              public Address generateAddress() {
>                  return new TestAddress();
>              }
>          });
> 
> My whole TestAddress, sans extra whitespace, is below. When I use this, 
> every node starts ok, but none of them connect to anyone else, so each 
> node is its own cluster. On the 2nd node started, for instance, there 
> are no errors in the logs coming from jgroups -- just nothing happens 
> after discovery request is sent to the coordinator's address. I don't 
> know if it matters, but am using a TCP-based stack that I can send out.
> 
> Address class:
> 
> public class TestAddress extends UUID {
>      static {
>          ClassConfigurator.add((short) 5309, TestAddress.class);
>      }
>      final String extraInfo = "test"; // would be bind address or host 
> name in real case
>      @Override
>      public String toString() {
>          return super.toString() + extraInfo;
>      }
>      // to make findbugs happy. not changing per 
> http://www.jgroups.org/manual4/index.html#CustomAddresses
>      @Override
>      public boolean equals(Object o) {
>          return super.equals(o);
>      }
>      // because otherwise: java.lang.IllegalStateException: 
> TestAddress.create() returned the wrong class: UUID
>      @Override
>      public Supplier<? extends TestAddress> create() {
>          return TestAddress::new;
>      }
> }
> 
> Any ideas on what I'm missing here that should be added/fixed?
> 
> 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