protected boolean calculateServiceUp() { Optional<Entity> upNode = Iterables.tryFind(getMembers(), EntityPredicates.attributeEqualTo(SERVICE_UP, Boolean.TRUE)); return upNode.isPresent(); }
private static Iterable<Entity> filterStartableManagedEntities(Iterable<Entity> contenders) { return Iterables.filter(contenders, Predicates.and(Predicates.instanceOf(Startable.class), EntityPredicates.managed())); }
@Override public void update() { synchronized (mutex) { for (CassandraCluster member : Iterables.filter(getMembers(), CassandraCluster.class)) { member.update(); } calculateServiceUp(); // Choose the first available location to set host and port (and compute one-up) Optional<Entity> upNode = Iterables.tryFind(getMembers(), EntityPredicates.attributeEqualTo(SERVICE_UP, Boolean.TRUE)); if (upNode.isPresent()) { setAttribute(HOSTNAME, upNode.get().getAttribute(Attributes.HOSTNAME)); setAttribute(THRIFT_PORT, upNode.get().getAttribute(CassandraNode.THRIFT_PORT)); } } } }
private static Iterable<Entity> filterStartableManagedEntities(Iterable<Entity> contenders) { return Iterables.filter(contenders, Predicates.and(Predicates.instanceOf(Startable.class), EntityPredicates.managed())); } }
@Override public void update() { synchronized (mutex) { // Update our seeds, as necessary seedTracker.refreshSeeds(); // Choose the first available cluster member to set host and port (and compute one-up) Optional<Entity> upNode = Iterables.tryFind(getMembers(), EntityPredicates.attributeEqualTo(SERVICE_UP, Boolean.TRUE)); setAttribute(SERVICE_UP, upNode.isPresent()); if (upNode.isPresent()) { setAttribute(HOSTNAME, upNode.get().getAttribute(Attributes.HOSTNAME)); setAttribute(THRIFT_PORT, upNode.get().getAttribute(CassandraNode.THRIFT_PORT)); } else { setAttribute(HOSTNAME, null); setAttribute(THRIFT_PORT, null); } } }
@Override public synchronized void recompute() { if (subscriptionHandle != null) getSubscriptionContext().unsubscribe(subscriptionHandle); if (subscriptionHandle2 != null) getSubscriptionContext().unsubscribe(subscriptionHandle2); Entity t = getTarget(); if (t != null) { subscriptionHandle = subscribeToChildren(t, Startable.SERVICE_UP, new SensorEventListener<Boolean>() { @Override public void onEvent(SensorEvent<Boolean> event) { boolean changed = (event.getValue()) ? addMember(event.getSource()) : removeMember(event.getSource()); if (changed) { recomputeAddresses(); } }}); subscriptionHandle2 = subscribe(t, Changeable.MEMBER_REMOVED, new SensorEventListener<Entity>() { @Override public void onEvent(SensorEvent<Entity> event) { boolean changed = removeMember(event.getValue()); if (changed) { recomputeAddresses(); } }}); setMembers(t.getChildren(), EntityPredicates.attributeEqualTo(Startable.SERVICE_UP, true)); } recomputeAddresses(); }