You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by dkarachentsev <dk...@gridgain.com> on 2017/07/10 07:55:53 UTC

Re: Determine current number of Server Nodes

Hi Chris,

You understand correctly that you need to subscribe for node joined event.
Here is possible example of how to write it:

    private static class Listener implements IgnitePredicate<Event> {

        @IgniteInstanceResource
        private Ignite ignite;

        @Override public boolean apply(Event evt) {
            int size = ignite.cluster().forServers().nodes().size(); //
check cluster size for servers only

            if (size == 10) {
                // Generate ready event only once
                if (ignite.cache("flags").putIfAbsent("gridReady", true))
                    System.out.println("Got expected size");

                // Unsubscribe
                return false;
            }

            return true;
        }
    }

And configuration:

        Map<IgnitePredicate&lt;? extends Event>, int[]> listeners = new
HashMap<>();

        listeners.put(new Listener(), new int[]{EventType.EVT_NODE_JOINED});

        cfg.setLocalEventListeners(listeners);

        cfg.setCacheConfiguration(new CacheConfiguration("flags"));

Thanks!
-Dmitry



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Determine-current-number-of-Server-Nodes-tp14542p14550.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Determine current number of Server Nodes

Posted by Chris Berry <ch...@gmail.com>.
Wow. Thanks for the quick response!!
I didn’t see the `forServers()` before. That is great.

And I like the idea of sharing the state directly in a “flags” cache.
Great idea.

In my case, I also want to continually monitor the “expected number of Servers”, so that I can send Alerts as Nodes inevitably come and go in AWS.
But I can use this same idea and provide another Listener that sends an Alert (or logs an ERROR, etc.)

Good stuff!
Thank you again,
— Chris 

> On Jul 10, 2017, at 2:55 AM, dkarachentsev [via Apache Ignite Users] <ml...@n6.nabble.com> wrote:
> 
> Hi Chris, 
> 
> You understand correctly that you need to subscribe for node joined event. Here is possible example of how to write it: 
> 
>     private static class Listener implements IgnitePredicate<Event> { 
> 
>         @IgniteInstanceResource 
>         private Ignite ignite; 
> 
>         @Override public boolean apply(Event evt) { 
>             int size = ignite.cluster().forServers().nodes().size(); // check cluster size for servers only 
> 
>             if (size == 10) { 
>                 // Generate ready event only once 
>                 if (ignite.cache("flags").putIfAbsent("gridReady", true)) 
>                     System.out.println("Got expected size"); 
> 
>                 // Unsubscribe 
>                 return false; 
>             } 
> 
>             return true; 
>         } 
>     } 
> 
> And configuration: 
> 
>         Map<IgnitePredicate<? extends Event>, int[]> listeners = new HashMap<>(); 
> 
>         listeners.put(new Listener(), new int[]{EventType.EVT_NODE_JOINED}); 
> 
>         cfg.setLocalEventListeners(listeners); 
> 
>         cfg.setCacheConfiguration(new CacheConfiguration("flags")); 
> 
> Thanks! 
> -Dmitry 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://apache-ignite-users.70518.x6.nabble.com/Determine-current-number-of-Server-Nodes-tp14542p14550.html <http://apache-ignite-users.70518.x6.nabble.com/Determine-current-number-of-Server-Nodes-tp14542p14550.html>
> To unsubscribe from Determine current number of Server Nodes, click here <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=14542&code=Y2hyaXN3YmVycnlAZ21haWwuY29tfDE0NTQyfC0xMzY1MjUwNjAz>.
> NAML <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Determine-current-number-of-Server-Nodes-tp14542p14552.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.