@Override public boolean isClusterSafe() { final Node node = getNode(); final Collection<Member> memberList = node.clusterService.getMembers(); if (memberList == null || memberList.isEmpty() || memberList.size() < 2) { return true; } final Collection<Future> futures = new ArrayList<Future>(memberList.size()); for (Member member : memberList) { final Address target = member.getAddress(); final Operation operation = new SafeStateCheckOperation(); final InternalCompletableFuture future = node.getNodeEngine() .getOperationService() .invokeOnTarget(InternalPartitionService.SERVICE_NAME, operation, target); futures.add(future); } // todo this max wait is appropriate? final int maxWaitTime = getMaxWaitTime(node); for (Future future : futures) { try { final Object result = future.get(maxWaitTime, TimeUnit.SECONDS); final boolean safe = (Boolean) result; if (!safe) { return false; } } catch (Exception e) { logger.warning("Error while querying cluster's safe state", e); return false; } } return true; }
public static OperationService getOperationService(HazelcastInstance hz) { Node node = getNode(hz); if (node == null) { throw new NullPointerException("node is null in Hazelcast instance " + hz); } NodeEngineImpl nodeEngine = node.getNodeEngine(); try { return nodeEngine.getOperationService(); } catch (NoSuchMethodError e) { // fallback for a binary incompatible change (see commit http://git.io/vtfKU) return getOperationServiceViaReflection(nodeEngine); } }
protected NodeEngine getNodeEngine(HazelcastInstance instance) { Node node = TestUtil.getNode(instance); return node.getNodeEngine(); }
protected ICacheService getCacheService(HazelcastInstance instance) { Node node = TestUtil.getNode(instance); return node.getNodeEngine().getService(ICacheService.SERVICE_NAME); }