public static <T> Object toCachedObject(T t) { if (t instanceof ServerID) { return new InfinispanServerID((ServerID) t); } if (t instanceof ClusterNodeInfo) { return new InfinispanClusterNodeInfo((ClusterNodeInfo) t); } if (t instanceof ClusterSerializable) { return new InfinispanClusterSerializable((ClusterSerializable) t); } return t; }
/** * Creates a new Vert.x compatible serializer. */ private Serializer createSerializer() { return Serializer.using(KryoNamespace.builder() .setRegistrationRequired(false) .register(KryoNamespaces.BASIC) .register(ServerID.class) .register(new ClusterSerializableSerializer<>(), ClusterSerializable.class) .build()); }
public static <V> V convertServerID(V val) { if (val.getClass() == ServerID.class) { ServerID sid = (ServerID)val; HazelcastServerID hsid = new HazelcastServerID(sid); return (V)hsid; } else { return val; } }
@Test public void shouldNotAddToMapCacheIfKeyDoesntAlreadyExist() throws Exception { String nonexistentKey = "non-existent-key." + UUID.randomUUID(); map.get(nonexistentKey, ar -> { if (ar.succeeded()) { try { ChoosableIterable<ServerID> s = ar.result(); Map<String, ChoosableIterable<ServerID>> cache = getCacheFromMap(); // System.err.println("CACHE CONTENTS: " + cache); // check result assertNotNull(s); assertTrue(s.isEmpty()); // check cache assertNotNull(cache); assertFalse( "Map cache should not contain key " + nonexistentKey, cache.containsKey(nonexistentKey)); } catch (Exception e) { fail(e.toString()); } finally { testComplete(); } } else { fail(ar.cause().toString()); } }); await(); }
@Override public InfinispanClusterNodeInfo readObject(ObjectInput input) throws IOException, ClassNotFoundException { ClusterNodeInfo clusterNodeInfo = new ClusterNodeInfo(input.readUTF(), new ServerID(input.readInt(), input.readUTF())); return new InfinispanClusterNodeInfo(clusterNodeInfo); }
public InfinispanServerID(ServerID serverID) { Objects.requireNonNull(serverID); this.serverID = serverID; }
public ServerID getServerID() { return serverID; }
@Override public InfinispanServerID readObject(ObjectInput input) throws IOException, ClassNotFoundException { ServerID serverID = new ServerID(input.readInt(), input.readUTF()); return new InfinispanServerID(serverID); }
public HazelcastServerID(ServerID serverID) { super(serverID.port, serverID.host); }
@Override public void readData(ObjectDataInput dataInput) throws IOException { nodeId = dataInput.readUTF(); serverID = new ServerID(dataInput.readInt(), dataInput.readUTF()); }
@SuppressWarnings("unchecked") private Map<String, ChoosableIterable<ServerID>> getCacheFromMap() throws Exception { Field field = map.getClass().getDeclaredField("cache"); field.setAccessible(true); return (Map<String, ChoosableIterable<ServerID>>) field.get(map); }