/** * Select a service with a particular qualifier */ public static ServiceHint withQualifier(String qualifier) { return new ServiceHint(QUALIFIER_HINT, qualifier); }
private ServiceInformation selectHintedService( final ConsistentHashRing ring, final ServiceHint... hints) { if (CollectionUtils.isEmpty(ring)) { return null; } String hashKey = null; for (ServiceHint hint : hints) { if (ServiceHint.CONSISTENTHASH_HINT.equals(hint.getName())) { hashKey = hint.getValue(); break; } } if (hashKey != null) { return ring.get(hashKey); } else { return ring.get(String.valueOf(random.nextInt())); } } }
/** Selects a service that serves the requested hash key. * * @param hashKey (example: user id, or another consistent identifier) * @return */ public static ServiceHint servesKey(String hashKey) { return new ServiceHint(CONSISTENTHASH_HINT, hashKey); } }
public static ServiceHint withVersion(int version) { return new ServiceHint(VERSION_HINT, String.valueOf(version)); }
hints.add(new ServiceHint(name.substring("X-Ness-SDHint-".length(), name.length()), header.getValue()));