@Override public void start() throws CacheLoaderException { final Marshaller marshaller; if (configuration.marshaller() != null) { marshaller = Util.getInstance( configuration.marshaller(), ctx.getCache().getCacheConfiguration().classLoader()); } else if (configuration.hotRodWrapping()) { marshaller = new HotRodEntryMarshaller(ctx.getByteBufferFactory()); } else if (configuration.rawValues()) { marshaller = new GenericJBossMarshaller(); } else { marshaller = ctx.getMarshaller(); } ConfigurationBuilder builder = buildRemoteConfiguration(configuration, marshaller); remoteCacheManager = new RemoteCacheManager(builder.build()); if (configuration.remoteCacheName().equals(BasicCacheContainer.DEFAULT_CACHE_NAME)) remoteCache = remoteCacheManager.getCache(); else remoteCache = remoteCacheManager.getCache(configuration.remoteCacheName()); if (configuration.rawValues() && iceFactory == null) { iceFactory = ctx.getCache() .getAdvancedCache() .getComponentRegistry() .getComponent(InternalEntryFactory.class); } }
@Override protected RemoteCacheManager getRemoteCacheManager() { org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder(); clientBuilder.addServer().host("127.0.0.1").port(hotrodServer.getPort()); clientBuilder.marshaller(new ProtoStreamMarshaller()); return new RemoteCacheManager(clientBuilder.build()); }
protected Configuration getRemoteCacheManagerConfig(String login, String password) { ConfigurationBuilder config = getDefaultConfigBuilder(); config .security() .authentication() .callbackHandler(new LoginHandler(login, password, TEST_REALM)); return config.build(); }
private Configuration createRemoteCacheManagerConfiguration() { ConfigurationBuilder config = new ConfigurationBuilder(); config .addServer() .host(server1.getHotrodEndpoint().getInetAddress().getHostName()) .port(server1.getHotrodEndpoint().getPort()); return config.build(); }
protected Configuration getRemoteCacheManagerConfig(Subject subj) { ConfigurationBuilder config = getDefaultConfigBuilder(); config .security() .authentication() .clientSubject(subj) .callbackHandler( new LoginHandler("", "")); // callback handle is required by ISPN config validation return config.build(); }
protected Configuration getRemoteCacheManagerOverSslConfig(String login, String password) { ConfigurationBuilder config = getDefaultConfigBuilder(); config .security() .authentication() .callbackHandler(new LoginHandler(login, password, TEST_REALM)); config .security() .ssl() .enable() .keyStoreFileName(KEYSTORE_PATH) .keyStorePassword(KEYSTORE_PASSWORD.toCharArray()) .trustStoreFileName(TRUSTSTORE_PATH) .trustStorePassword(TRUSTSTORE_PASSWORD.toCharArray()); return config.build(); }
@Override protected void createCacheManagers() throws Throwable { final int numServers = numberOfHotRodServers(); hotrodServers = new HotRodServer[numServers]; createCluster(hotRodCacheConfiguration(clusterConfig()), numberOfHotRodServers()); for (int i = 0; i < numServers; i++) { EmbeddedCacheManager cm = cacheManagers.get(i); hotrodServers[i] = HotRodClientTestingUtil.startHotRodServer(cm); } String servers = HotRodClientTestingUtil.getServersString(hotrodServers); org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder(); clientBuilder.addServers(servers); remoteCacheManager = new RemoteCacheManager(clientBuilder.build()); remoteCache = remoteCacheManager.getCache(); }
private Configuration createRemoteCacheManagerConfiguration() { ConfigurationBuilder config = new ConfigurationBuilder(); for (RemoteInfinispanServer server : getServers()) { config .addServer() .host(server.getHotrodEndpoint().getInetAddress().getHostName()) .port(server.getHotrodEndpoint().getPort()); } config .balancingStrategy( "org.infinispan.server.test.client.hotrod.HotRodTestRequestBalancingStrategy") // load balancing .balancingStrategy( "org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy") // list of HotRod servers available to connect to // .addServers(hotRodServerList) .forceReturnValues(false) // TCP stuff .tcpNoDelay(true) .pingOnStartup(true) .transportFactory("org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory") // marshalling .marshaller("org.infinispan.commons.marshall.jboss.GenericJBossMarshaller") // executors .asyncExecutorFactory() .factoryClass("org.infinispan.client.hotrod.impl.async.DefaultAsyncExecutorFactory") .addExecutorProperty("infinispan.client.hotrod.default_executor_factory.pool_size", "10") .addExecutorProperty( "infinispan.client.hotrod.default_executor_factory.queue_size", "100000") // hashing .keySizeEstimate(64) .valueSizeEstimate(512); if (isDistributedMode()) { config.consistentHashImpl( 1, "org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1"); } else { config.consistentHashImpl( 2, "org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV2"); } return config.build(); }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { cacheManager = TestCacheManagerFactory.createCacheManager(hotRodCacheConfiguration()); cache = cacheManager.getCache(); hotRodServer = HotRodClientTestingUtil.startHotRodServer(cacheManager); ConfigurationBuilder clientBuilder = new ConfigurationBuilder(); clientBuilder.addServer().host("127.0.0.1").port(hotRodServer.getPort()); clientBuilder.marshaller(new ProtoStreamMarshaller()); remoteCacheManager = new RemoteCacheManager(clientBuilder.build()); remoteCache = remoteCacheManager.getCache(); // initialize client-side serialization context MarshallerRegistration.registerMarshallers( ProtoStreamMarshaller.getSerializationContext(remoteCacheManager)); return cacheManager; }
public static void main(String[] args) throws InterruptedException { // Create a configuration for a locally-running server ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT); // Connect to the server RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build()); // Obtain the remote cache RemoteCache<String, String> cache = cacheManager.getCache(); // Register a listener MyListener listener = new MyListener(); cache.addClientListener(listener); // Store some values cache.put("key1", "value1"); cache.put("key2", "value2"); cache.put("key1", "newValue"); // Remote events are asynchronous, so wait a bit Thread.sleep(1000); // Remove listener cache.removeClientListener(listener); // Stop the cache manager and release all resources cacheManager.stop(); }
@Override protected void createCacheManagers() throws Throwable { defaultBuilder = defaultCacheConfigurationBuilder(); distOneBuilder = hotRodCacheConfiguration(getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC)); distOneBuilder .clustering() .hash() .numOwners(1) .numSegments(1) .consistentHashFactory(new ControlledConsistentHashFactory(0)); distTwoBuilder = hotRodCacheConfiguration(getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC)); distTwoBuilder .clustering() .hash() .numOwners(1) .numSegments(1) .consistentHashFactory(new ControlledConsistentHashFactory(1)); server1 = addHotRodServer(); server2 = addHotRodServer(); blockUntilViewReceived(manager(0).getCache(), 2); blockUntilCacheStatusAchieved(manager(0).getCache(), ComponentStatus.RUNNING, 10000); blockUntilCacheStatusAchieved(manager(1).getCache(), ComponentStatus.RUNNING, 10000); org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder(); clientBuilder .addServer() .host(server1.getHost()) .port(server1.getPort()) .addServer() .host(server2.getHost()) .port(server2.getPort()); rcm = new RemoteCacheManager(clientBuilder.build()); }
@Test public void testHotRodRollingUpgradesDiffVersions() throws Exception { // Target node final int managementPortServer1 = 9990; MBeanServerConnectionProvider provider1; // Source node int managementPortServer2 = 10099; // jboss-as mgmt port MBeanServerConnectionProvider provider2; try { if (!Boolean.parseBoolean(System.getProperty("start.jboss.as.manually"))) { // start it by Arquillian controller.start("hotrod-rolling-upgrade-2-old"); managementPortServer2 = 10090; } ConfigurationBuilder builder = new ConfigurationBuilder(); builder .addServer() .host("127.0.0.1") .port(11322) .protocolVersion(ConfigurationProperties.PROTOCOL_VERSION_12); RemoteCacheManager rcm = new RemoteCacheManager(builder.build()); final RemoteCache<String, String> c2 = rcm.getCache("default"); c2.put("key1", "value1"); assertEquals("value1", c2.get("key1")); for (int i = 0; i < 50; i++) { c2.put("keyLoad" + i, "valueLoad" + i); } controller.start("hotrod-rolling-upgrade-1"); RemoteInfinispanMBeans s1 = createRemotes("hotrod-rolling-upgrade-1", "local", DEFAULT_CACHE_NAME); // hotrod.protocol.version, if explictily defined, is set in createRemotes() method final RemoteCache<Object, Object> c1 = createCache(s1); assertEquals( "Can't access etries stored in source node (target's RemoteCacheStore).", "value1", c1.get("key1")); provider2 = new MBeanServerConnectionProvider("127.0.0.1", managementPortServer2); final ObjectName rollMan = new ObjectName( "jboss." + InfinispanSubsystem.SUBSYSTEM_NAME + ":type=Cache," + "name=\"default(local)\"," + "manager=\"local\"," + "component=RollingUpgradeManager"); invokeOperation( provider2, rollMan.toString(), "recordKnownGlobalKeyset", new Object[] {}, new String[] {}); provider1 = new MBeanServerConnectionProvider( s1.server.getHotrodEndpoint().getInetAddress().getHostName(), managementPortServer1); invokeOperation( provider1, rollMan.toString(), "synchronizeData", new Object[] {"hotrod"}, new String[] {"java.lang.String"}); invokeOperation( provider1, rollMan.toString(), "disconnectSource", new Object[] {"hotrod"}, new String[] {"java.lang.String"}); // is source (RemoteCacheStore) really disconnected? c2.put("disconnected", "source"); assertEquals( "Can't obtain value from cache2 (source node).", "source", c2.get("disconnected")); assertNull( "Source node entries should NOT be accessible from target node (after RCS disconnection)", c1.get("disconnected")); // all entries migrated? assertEquals("Entry was not successfully migrated.", "value1", c1.get("key1")); for (int i = 0; i < 50; i++) { assertEquals( "Entry was not successfully migrated.", "valueLoad" + i, c1.get("keyLoad" + i)); } } finally { if (controller.isStarted("hotrod-rolling-upgrade-1")) { controller.stop("hotrod-rolling-upgrade-1"); } if (controller.isStarted("hotrod-rolling-upgrade-2-old")) { controller.stop("hotrod-rolling-upgrade-2-old"); } } }
protected RemoteCacheManager getRemoteCacheManager() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addServer().host("127.0.0.1").port(hotrodServer.getPort()); return new RemoteCacheManager(builder.build()); }
public static RemoteCacheManager getRemoteCacheManager(HotRodServer server) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addServer().host(server.getHost()).port(server.getPort()); return new InternalRemoteCacheManager(builder.build()); }