public static <T extends FailoverRequestBalancingStrategy> T getLoadBalancer( RemoteCacheManager client) { TcpTransportFactory transportFactory = null; if (client instanceof InternalRemoteCacheManager) { transportFactory = (TcpTransportFactory) ((InternalRemoteCacheManager) client).getTransportFactory(); } else { transportFactory = TestingUtil.extractField(client, "transportFactory"); } return (T) transportFactory.getBalancer(HotRodConstants.DEFAULT_CACHE_NAME_BYTES); }
private Object generateKeyAndShutdownServer() throws IOException, ClassNotFoundException, InterruptedException { resetStats(); Cache<Object, Object> cache = manager(1).getCache(); ExecutorService ex = Executors.newSingleThreadExecutor(getTestThreadFactory("KeyGenerator")); KeyAffinityService kaf = KeyAffinityServiceFactory.newKeyAffinityService(cache, ex, new ByteKeyGenerator(), 2, true); Address address = cache.getAdvancedCache().getRpcManager().getTransport().getAddress(); byte[] keyBytes = (byte[]) kaf.getKeyForAddress(address); String key = ByteKeyGenerator.getStringObject(keyBytes); ex.shutdownNow(); kaf.stop(); remoteCache.put(key, "v"); assertOnlyServerHit(getAddress(hotRodServer2)); TcpTransportFactory tcpTp = (TcpTransportFactory) ((InternalRemoteCacheManager) remoteCacheManager).getTransportFactory(); Marshaller sm = new JBossMarshaller(); TcpTransport transport = (TcpTransport) tcpTp.getTransport( sm.objectToByteBuffer(key, 64), null, RemoteCacheManager.cacheNameBytes()); try { assertEquals( transport.getServerAddress(), new InetSocketAddress("localhost", hotRodServer2.getPort())); } finally { tcpTp.releaseTransport(transport); } log.info("About to stop Hot Rod server 2"); hotRodServer2.stop(); return key; }