Re: Determine current number of Server Nodes

2017-07-10 Thread Chris Berry
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] 
>  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 { 
> 
> @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, 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
>  
> 
> To unsubscribe from Determine current number of Server Nodes, click here 
> .
> 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.

Re: Determine current number of Server Nodes

2017-07-10 Thread dkarachentsev
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 {

@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, 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.