use of net.azisaba.kuvel.discovery.impl.RedisLoadBalancerDiscovery in project Kuvel by AzisabaNetwork.
the class Kuvel method onProxyInitialization.
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
kuvelConfig = new KuvelConfig(this);
try {
kuvelConfig.load();
} catch (Exception e) {
logger.severe("Failed to load config file. Plugin feature will be disabled.");
e.printStackTrace();
return;
}
kuvelServiceHandler = new KuvelServiceHandler(this, client);
if (kuvelConfig.isRedisEnabled()) {
Objects.requireNonNull(kuvelConfig.getRedisConnectionData());
Objects.requireNonNull(kuvelConfig.getProxyGroupName());
proxyIdProvider = new ProxyIdProvider(kuvelConfig.getRedisConnectionData().createJedisPool(), kuvelConfig.getProxyGroupName());
proxyIdProvider.runTask(proxy, this);
logger.info("This proxy's id is: " + proxyIdProvider.getId());
redisConnectionLeader = new RedisConnectionLeader(this, kuvelConfig.getRedisConnectionData().createJedisPool(), kuvelConfig.getProxyGroupName(), proxyIdProvider.getId());
redisConnectionLeader.trySwitch();
if (redisConnectionLeader.isLeader()) {
logger.info("This proxy is selected as leader.");
}
kuvelServiceHandler.setAndRunLoadBalancerDiscovery(new RedisLoadBalancerDiscovery(client, this, kuvelConfig.getRedisConnectionData().createJedisPool(), kuvelConfig.getProxyGroupName(), redisConnectionLeader, kuvelServiceHandler));
kuvelServiceHandler.setAndRunServerDiscovery(new RedisServerDiscovery(client, this, kuvelConfig.getRedisConnectionData().createJedisPool(), kuvelConfig.getProxyGroupName(), redisConnectionLeader, kuvelServiceHandler));
proxy.getScheduler().buildTask(this, () -> {
if (redisConnectionLeader.isLeader()) {
redisConnectionLeader.extendLeader();
} else {
redisConnectionLeader.trySwitch();
}
}).repeat(5, TimeUnit.MINUTES).schedule();
redisSubscriber = new RedisSubscriber(kuvelConfig.getRedisConnectionData().createJedisPool(), this, kuvelConfig.getProxyGroupName(), kuvelServiceHandler, redisConnectionLeader);
redisSubscriber.subscribe();
} else {
kuvelServiceHandler.setAndRunLoadBalancerDiscovery(new SimpleLoadBalancerDiscovery(client, this, kuvelServiceHandler));
kuvelServiceHandler.setAndRunServerDiscovery(new SimpleServerDiscovery(client, this, kuvelServiceHandler));
}
proxy.getEventManager().register(this, new LoadBalancerListener(this, kuvelServiceHandler));
}
use of net.azisaba.kuvel.discovery.impl.RedisLoadBalancerDiscovery in project Kuvel by AzisabaNetwork.
the class RedisConnectionLeader method runDiscoveryTask.
private void runDiscoveryTask() {
if (plugin.getKuvelConfig().getRedisConnectionData() == null) {
return;
}
plugin.getKuvelServiceHandler().setAndRunLoadBalancerDiscovery(new RedisLoadBalancerDiscovery(plugin.getClient(), plugin, plugin.getKuvelConfig().getRedisConnectionData().createJedisPool(), plugin.getKuvelConfig().getProxyGroupName(), this, plugin.getKuvelServiceHandler()));
plugin.getKuvelServiceHandler().setAndRunServerDiscovery(new RedisServerDiscovery(plugin.getClient(), plugin, plugin.getKuvelConfig().getRedisConnectionData().createJedisPool(), plugin.getKuvelConfig().getProxyGroupName(), this, plugin.getKuvelServiceHandler()));
}
Aggregations