org.infinispan.remoting.transport.jgroups.JGroupsTransport Java Examples

The following examples show how to use org.infinispan.remoting.transport.jgroups.JGroupsTransport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TopologyInfo.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: DistributedCacheConcurrentWritesTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #3
Source File: DistributedCacheWriteSkewTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Cache<String, UserSessionEntity> cache1 = createManager("node1").getCache(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME);
    Cache<String, UserSessionEntity> cache2 = createManager("node2").getCache(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME);

    // Create initial item
    UserSessionEntity session = new UserSessionEntity();
    session.setId("123");
    session.setRealmId("foo");
    session.setBrokerSessionId("!23123123");
    session.setBrokerUserId(null);
    session.setUser("foo");
    session.setLoginUsername("foo");
    session.setIpAddress("123.44.143.178");
    session.setStarted(Time.currentTime());
    session.setLastSessionRefresh(Time.currentTime());

    AuthenticatedClientSessionEntity clientSession = new AuthenticatedClientSessionEntity(UUID.randomUUID());
    clientSession.setAuthMethod("saml");
    clientSession.setAction("something");
    clientSession.setTimestamp(1234);
    session.getAuthenticatedClientSessions().put(CLIENT_1_UUID.toString(), clientSession.getId());

    cache1.put("123", session);

    //cache1.replace("123", session);

    // Create 2 workers for concurrent write and start them
    Worker worker1 = new Worker(1, cache1);
    Worker worker2 = new Worker(2, cache2);

    long start = System.currentTimeMillis();

    System.out.println("Started clustering test");

    worker1.start();
    //worker1.join();
    worker2.start();

    worker1.join();
    worker2.join();

    long took = System.currentTimeMillis() - start;
    session = cache1.get("123");
    System.out.println("Took: " + took + " ms. Notes count: " + session.getNotes().size() + ", failedReplaceCounter: " + failedReplaceCounter.get());

    // JGroups statistics
    JChannel channel = (JChannel)((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());

    // Kill JVM
    cache1.stop();
    cache2.stop();
    cache1.getCacheManager().stop();
    cache2.getCacheManager().stop();

    System.out.println("Managers killed");
}