Topolojideki değişikleri dinlememizi sağlar.
Örnek
Elimizde dinlemek istediğimiz şu liste olsun.
import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; import static org.apache.ignite.events.EventType.EVT_NODE_JOINED; import static org.apache.ignite.events.EventType.EVT_NODE_LEFT; import static org.apache.ignite.events.EventType.EVT_NODE_SEGMENTED; private static final int[] EVTS_DISCOVERY = new int[] { EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED, EVT_NODE_SEGMENTED };
Şöyle yaparız. Topolojideki değişikleri dinlememizi sağlar.
import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.managers.discovery.DiscoCache; private volatile List<ServiceInstance> instances; IgniteEx ignite = ...; ignite.context().event().addDiscoveryEventListener(this::topologyChanged, EVTS_DISCOVERY); updateInstances(ignite.cluster().nodes()); private void topologyChanged(DiscoveryEvent event, DiscoCache cache) { updateInstances(event.topologyNodes()); } private void updateInstances(Collection<ClusterNode> nodes) { instances = nodes.stream() .filter(node -> !node.isClient()) .map(this::toServiceInstance) .collect(Collectors.toList()); } private ServiceInstance toServiceInstance(ClusterNode node) { return new DefaultServiceInstance(node.consistentId().toString(), SERVICE_ID, node.attribute("load_balancing_host"), node.attribute("load_balancing_port"), false ); }
Hiç yorum yok:
Yorum Gönder