Search in sources :

Example 1 with JGroupsTransport

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);
    }
}
Also used : JChannel(org.jgroups.JChannel) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache) BasicCache(org.infinispan.commons.api.BasicCache)

Example 2 with JGroupsTransport

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();
}
Also used : ChannelConfigurator(org.jboss.as.clustering.infinispan.ChannelConfigurator) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) TransportConfigurationBuilder(org.infinispan.configuration.global.TransportConfigurationBuilder) ProtocolStackConfiguration(org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration) TransportConfiguration(org.infinispan.configuration.global.TransportConfiguration) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory) Properties(java.util.Properties)

Example 3 with JGroupsTransport

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);
                }
            }
        }
    }
}
Also used : JChannel(org.jgroups.JChannel) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) TransportConfigurationBuilder(org.infinispan.configuration.global.TransportConfigurationBuilder) FileLookup(org.infinispan.commons.util.FileLookup)

Example 4 with JGroupsTransport

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;
}
Also used : JChannel(org.jgroups.JChannel) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) LocalModeAddress(org.infinispan.remoting.transport.LocalModeAddress) Address(org.infinispan.remoting.transport.Address) InetSocketAddress(java.net.InetSocketAddress) Event(org.jgroups.Event) IpAddress(org.jgroups.stack.IpAddress) Transport(org.infinispan.remoting.transport.Transport) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport)

Aggregations

JGroupsTransport (org.infinispan.remoting.transport.jgroups.JGroupsTransport)4 JChannel (org.jgroups.JChannel)3 TransportConfigurationBuilder (org.infinispan.configuration.global.TransportConfigurationBuilder)2 InetSocketAddress (java.net.InetSocketAddress)1 Properties (java.util.Properties)1 Cache (org.infinispan.Cache)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 BasicCache (org.infinispan.commons.api.BasicCache)1 FileLookup (org.infinispan.commons.util.FileLookup)1 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)1 TransportConfiguration (org.infinispan.configuration.global.TransportConfiguration)1 Address (org.infinispan.remoting.transport.Address)1 LocalModeAddress (org.infinispan.remoting.transport.LocalModeAddress)1 Transport (org.infinispan.remoting.transport.Transport)1 JGroupsAddress (org.infinispan.remoting.transport.jgroups.JGroupsAddress)1 ChannelConfigurator (org.jboss.as.clustering.infinispan.ChannelConfigurator)1 Event (org.jgroups.Event)1 IpAddress (org.jgroups.stack.IpAddress)1 ChannelFactory (org.wildfly.clustering.jgroups.spi.ChannelFactory)1 ProtocolStackConfiguration (org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration)1