public static byte[] getKeyForServer(HotRodServer primaryOwner, String cacheName) { GenericJBossMarshaller marshaller = new GenericJBossMarshaller(); Cache<?, ?> cache = cacheName != null ? primaryOwner.getCacheManager().getCache(cacheName) : primaryOwner.getCacheManager().getCache(); Random r = new Random(); byte[] dummy = new byte[8]; int attemptsLeft = 1000; try { do { r.nextBytes(dummy); attemptsLeft--; } while (!isFirstOwner(cache, marshaller.objectToByteBuffer(dummy)) && attemptsLeft >= 0); } catch (IOException e) { throw new AssertionError(e); } catch (InterruptedException e) { throw new AssertionError(e); } if (attemptsLeft < 0) throw new IllegalStateException("Could not find any key owned by " + primaryOwner); log.infof( "Binary key %s hashes to [cluster=%s,hotrod=%s]", Util.printArray(dummy, false), primaryOwner.getCacheManager().getAddress(), primaryOwner.getAddress()); return dummy; }
/** * Get a split-personality key, whose POJO version hashes to the primary owner passed in, but it's * binary version does not. */ public static Integer getSplitIntKeyForServer( HotRodServer primaryOwner, HotRodServer binaryOwner, String cacheName) { Cache<?, ?> cache = cacheName != null ? primaryOwner.getCacheManager().getCache(cacheName) : primaryOwner.getCacheManager().getCache(); Cache<?, ?> binaryOwnerCache = cacheName != null ? binaryOwner.getCacheManager().getCache(cacheName) : binaryOwner.getCacheManager().getCache(); Random r = new Random(); byte[] dummy; Integer dummyInt; int attemptsLeft = 1000; boolean primaryOwnerFound = false; boolean binaryOwnerFound = false; do { dummyInt = r.nextInt(); dummy = toBytes(dummyInt); attemptsLeft--; primaryOwnerFound = isFirstOwner(cache, dummyInt); binaryOwnerFound = isFirstOwner(binaryOwnerCache, dummy); } while (!(primaryOwnerFound && binaryOwnerFound) && attemptsLeft >= 0); if (attemptsLeft < 0) throw new IllegalStateException("Could not find any key owned by " + primaryOwner); log.infof( "Integer key [pojo=%s,bytes=%s] hashes to [cluster=%s,hotrod=%s], but the binary version's owner is [cluster=%s,hotrod=%s]", Util.toHexString(dummy), dummyInt, primaryOwner.getCacheManager().getAddress(), primaryOwner.getAddress(), binaryOwner.getCacheManager().getAddress(), binaryOwner.getAddress()); return dummyInt; }
byte[] getKeyForServer(HotRodServer primaryOwner, String cacheName) { Cache<?, ?> cache = primaryOwner.getCacheManager().getCache(cacheName); Random r = new Random(); byte[] dummy = new byte[8]; int attemptsLeft = 1000; do { r.nextBytes(dummy); } while (!isFirstOwner(cache, dummy) && attemptsLeft >= 0); if (attemptsLeft < 0) throw new IllegalStateException("Could not find any key owned by " + primaryOwner); log.infof( "Binary key %s hashes to [cluster=%s,hotrod=%s]", Util.printArray(dummy, false), primaryOwner.getCacheManager().getAddress(), primaryOwner.getAddress()); return dummy; }
public static Integer getIntKeyForServer(HotRodServer primaryOwner, String cacheName) { Cache<?, ?> cache = cacheName != null ? primaryOwner.getCacheManager().getCache(cacheName) : primaryOwner.getCacheManager().getCache(); Random r = new Random(); byte[] dummy; Integer dummyInt; int attemptsLeft = 1000; do { dummyInt = r.nextInt(); dummy = toBytes(dummyInt); attemptsLeft--; } while (!isFirstOwner(cache, dummy) && attemptsLeft >= 0); if (attemptsLeft < 0) throw new IllegalStateException("Could not find any key owned by " + primaryOwner); log.infof( "Integer key %s hashes to [cluster=%s,hotrod=%s]", dummyInt, primaryOwner.getCacheManager().getAddress(), primaryOwner.getAddress()); return dummyInt; }