4 Replies Latest reply: Apr 5, 2013 6:37 AM by Jonathan.Knight RSS

    com.tangosol.net.AddressProvider Interface implementation

    385089
      Can somebody post a sample implementation of com.tangosol.net.AddressProvider interface? How do I implement accept() and call the same from my client? Please help.
        • 1. Re: com.tangosol.net.AddressProvider Interface implementation
          785230
          Hi,

          You do not necessarily need to put anything inside the accept() method; in our AddressProvider implementation this method is empty. You do not call anything on the AddressProvider, you just put it into the correct places in the configuration file(s) and Coherence will call it. I know the Java Docs say that methods are called by the "client" but that really means called by Coherence.

          The only method you really must implement is the getNextAddress() method so that it returns an InetSocketAddress whenever Coherence asks for one. In theory you could just keep returning the same address over and over again and everything would work (providing the address is valid).

          As the Java Docs say, the accept() method is called after Coherence has successfully used the address you gave it to connect. The reject() method is called if Coherence tried to use the address that it was given for something but the operation failed.

          JK
          • 2. Re: com.tangosol.net.AddressProvider Interface implementation
            385089
            Removed the content

            Edited by: Shiva K on Apr 4, 2013 2:45 PM
            • 3. Re: com.tangosol.net.AddressProvider Interface implementation
              385089
              Thanks JK.

              It works on client side in remote-cache-scheme definition.

              <remote-cache-scheme>
                   --
              <initiator-config>
              <tcp-initiator>
              <remote-addresses>
                   <address-provider>
                        <class-name>MyAddressProvider</class-name>
                   </address-provider>
              </remote-addresses>

              </tcp-initiator>
              </initiator-config>
              </remote-cache-scheme>

              Not on the cluster/server side. cache-server.cmd/DefaultCacheServer hangs. As soon as I hardcode the addresses ( <socket-address>), it comes up without any issue.

                   <unicast-listener>
                        --
                        <well-known-addresses>
                             <address-provider>
                                  <class-name>MyAddressProvider</class-name>
                             </address-provider>
                        </well-known-addresses>
                   </unicast-listener>

              What do you think I am missing..

              Edited by: Shiva K on Apr 4, 2013 2:46 PM
              • 4. Re: com.tangosol.net.AddressProvider Interface implementation
                Jonathan.Knight
                Hi,

                It depends what your AddressProvider is doing. If all it does in getNextAddress is keep returning the same address, and if that address is not reachable then Coherence will get stuck in a loop calling your provider, trying to connect to the socket, failing to connect, then calling your provider again and so on.

                If you are going to use an AddressProvider for WKA then you need to implement the reject method so that you know not to return failed addresses next time the provider is asked for one. If you have used up all the addresses, i.e. they all failed, then you return null from getNextAddress.

                JK