use of org.infinispan.remoting.transport.jgroups.JGroupsTransport in project keycloak by keycloak.
the class DistributedCacheConcurrentWritesTest method printStats.
private static void printStats(BasicCache cache) {
if (cache instanceof Cache) {
Cache cache1 = (Cache) cache;
JChannel channel = ((JGroupsTransport) cache1.getAdvancedCache().getRpcManager().getTransport()).getChannel();
System.out.println("Sent MB: " + channel.getSentBytes() / 1000000 + ", sent messages: " + channel.getSentMessages() + ", received MB: " + channel.getReceivedBytes() / 1000000 + ", received messages: " + channel.getReceivedMessages());
} else {
Map<String, String> stats = ((RemoteCache) cache).stats().getStatsMap();
System.out.println("Stats: " + stats);
}
}
use of org.infinispan.remoting.transport.jgroups.JGroupsTransport in project wildfly by wildfly.
the class JGroupsTransportServiceConfigurator method get.
@Override
public TransportConfiguration get() {
ChannelFactory factory = this.factory.get();
Properties properties = new Properties();
properties.put(JGroupsTransport.CHANNEL_CONFIGURATOR, new ChannelConfigurator(factory, this.containerName));
ProtocolStackConfiguration stack = factory.getProtocolStackConfiguration();
org.wildfly.clustering.jgroups.spi.TransportConfiguration.Topology topology = stack.getTransport().getTopology();
TransportConfigurationBuilder builder = new GlobalConfigurationBuilder().transport().clusterName(this.cluster.get()).distributedSyncTimeout(this.lockTimeout).transport(new JGroupsTransport()).withProperties(properties);
if (topology != null) {
builder.siteId(topology.getSite()).rackId(topology.getRack()).machineId(topology.getMachine());
}
return builder.create();
}
use of org.infinispan.remoting.transport.jgroups.JGroupsTransport in project keycloak by keycloak.
the class InfinispanUtil method configureTransport.
public static void configureTransport(GlobalConfigurationBuilder gcb, String nodeName, String siteName, String jgroupsUdpMcastAddr, String jgroupsConfigPath) {
if (nodeName == null) {
gcb.transport().defaultTransport();
} else {
FileLookup fileLookup = FileLookupFactory.newInstance();
synchronized (CHANNEL_INIT_SYNCHRONIZER) {
String originalMcastAddr = System.getProperty(InfinispanConnectionProvider.JGROUPS_UDP_MCAST_ADDR);
if (jgroupsUdpMcastAddr == null) {
System.getProperties().remove(InfinispanConnectionProvider.JGROUPS_UDP_MCAST_ADDR);
} else {
System.setProperty(InfinispanConnectionProvider.JGROUPS_UDP_MCAST_ADDR, jgroupsUdpMcastAddr);
}
try {
JChannel channel = new JChannel(fileLookup.lookupFileLocation(jgroupsConfigPath, InfinispanUtil.class.getClassLoader()).openStream());
channel.setName(nodeName);
JGroupsTransport transport = new JGroupsTransport(channel);
TransportConfigurationBuilder transportBuilder = gcb.transport().nodeName(nodeName).siteId(siteName).transport(transport);
// Use the cluster corresponding to current site. This is needed as the nodes in different DCs should not share same cluster
if (siteName != null) {
transportBuilder.clusterName(siteName);
}
transportBuilder.jmx().domain(InfinispanConnectionProvider.JMX_DOMAIN + "-" + nodeName).enable();
logger.infof("Configured jgroups transport with the channel name: %s", nodeName);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (originalMcastAddr == null) {
System.getProperties().remove(InfinispanConnectionProvider.JGROUPS_UDP_MCAST_ADDR);
} else {
System.setProperty(InfinispanConnectionProvider.JGROUPS_UDP_MCAST_ADDR, originalMcastAddr);
}
}
}
}
}
use of org.infinispan.remoting.transport.jgroups.JGroupsTransport in project keycloak by keycloak.
the class TopologyInfo method getRouteName.
/**
* Get route to be used as the identifier for sticky session. Return null if I am not able to find the appropriate route (or in case of local mode)
*/
public String getRouteName(Cache cache, Object key) {
if (cache.getCacheConfiguration().clustering().cacheMode().isClustered() && isGeneratedNodeName) {
logger.warn("Clustered configuration used, but node name is not properly set. Make sure to start server with jboss.node.name property identifying cluster node");
}
if (isGeneratedNodeName) {
return null;
}
// Impl based on Wildfly sticky session algorithm for generating routes ( org.wildfly.clustering.web.infinispan.session.InfinispanRouteLocator )
Address address = getOwnerAddress(cache, key);
// Local mode
if (address == null || (address == LocalModeAddress.INSTANCE)) {
return myNodeName;
}
org.jgroups.Address jgroupsAddress = toJGroupsAddress(address);
String name = NameCache.get(jgroupsAddress);
// If no logical name exists, create one using physical address
if (name == null) {
Transport transport = cache.getCacheManager().getTransport();
JChannel jgroupsChannel = ((JGroupsTransport) transport).getChannel();
IpAddress ipAddress = (IpAddress) jgroupsChannel.down(new Event(Event.GET_PHYSICAL_ADDRESS, jgroupsAddress));
// Physical address might be null if node is no longer a member of the cluster
InetSocketAddress socketAddress = (ipAddress != null) ? new InetSocketAddress(ipAddress.getIpAddress(), ipAddress.getPort()) : new InetSocketAddress(0);
name = String.format("%s:%s", socketAddress.getHostString(), socketAddress.getPort());
logger.debugf("Address not found in NameCache. Fallback to %s", name);
}
return name;
}
Aggregations