Spring, Infinispan and JGroups - configuration programmatically

Konrad

I am using Spring 4.3, Infinispan 9.11 and JGroups 4.0.6. For JGroups I am using xml configuration, in which I have:

<TCPPING async_discovery="true"
         initial_hosts="${jgroups.tcpping.initial_hosts: HOSTS}"
(...)

Let's say I want to keep configuration in xml, however, I need to apply a list of hosts from another (yml) configuration file. A way to go might be to read yml properties from Java (I have that part) and set them somehow to the JGroups configuration.

This is what I've tried so far:

EmbeddedCacheManager cacheManager = new DefaultCacheManager(
            GlobalConfigurationBuilder.defaultClusteredBuilder()
                    .transport()
                    .nodeName(nodeName)
                    .addProperty(JGroupsTransport.CONFIGURATION_FILE, "tcp.xml")
                    .addProperty(JGroupsTransport.CONFIGURATION_STRING, "jgroups.tcpping.initial_hosts: HOSTS")
                    .build(),
            new ConfigurationBuilder()
                    ...
                    .build()
    );

However, configuration string doesn't do the job.

UPDATE. Another attempt:

JGroupsTransport transport = (JGroupsTransport)(cacheManager.getCacheManagerConfiguration().transport().transport());
    TCPPING ping = transport.getChannel().getProtocolStack().findProtocol(TCPPING.class);
    ping.setPortRange(1);
    ping.setInitialHosts(Arrays.asList(new IpAddress("HOST1:PORT1"), new IpAddress("HOST2:PORT2")));

That doesn't seem to be working neither.

Konrad

As Bela Ban and Altanis indicated, the problem is that Infinispan is calling JChannel.connect() before I am able to modify the transport properties. I've found a workaround though:

public class JGroupsChannelLookupImpl implements JGroupsChannelLookup {

    @Override
    public JChannel getJGroupsChannel(Properties p) {
        JChannel channel = null;
        try {
            channel = new JChannel("tcp.xml");
            TCPPING ping = channel.getProtocolStack().findProtocol(TCPPING.class);
            ping.setInitialHosts(Arrays.asList(HOST1, HOST2, HOST3, ...));
        }
        catch (Exception ex) {
            // do sth with the ex
        }
        Objects.requireNonNull(channel);
        return channel;
    }

(...)

}

Then when creating DefaultCacheManager, instead of loading the config directly from xml, just load channel lookup:

new DefaultCacheManager(
            GlobalConfigurationBuilder.defaultClusteredBuilder()
                    .transport()
                    .nodeName(nodeName)
                    .addProperty(JGroupsTransport.CHANNEL_LOOKUP, JGroupsChannelLookupImpl.class.getName())
                    .build(),
           (...)

Works as expected!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Infinispan not using specified JGroups configuration file and throwing Exception

From Dev

Hibernate Search, Infinispan, jgroups, Wildfly cluster integration configuration

From Dev

Infinispan server ignores jgroups bind_addr

From Dev

Infinispan server ignores jgroups bind_addr

From Dev

Infinispan Interceptor Configuration?

From Dev

Spring Transaction configuration programmatically with Spring 4.3.4 version

From Dev

Infinispan + WildFly + Spring

From Dev

How to initialize the JGroups AUTH protocol programmatically

From Dev

Best JGroups stack configuration for leader/follower relationship

From Dev

JGroups ec2 cluster fails to connect (times out) with Hibernate Search / Infinispan setup

From Dev

Programmatically check the build configuration

From Dev

Programmatically check the build configuration

From Dev

Spring @Cacheable double-checked locking (infinispan backend)

From Dev

TestNG Programmatically use xml configuration

From Dev

Programmatically getting Jenkins configuration for a plugin

From Dev

TestNG Programmatically use xml configuration

From Dev

How to set ImageResizer configuration programmatically?

From Dev

Load spring config programmatically

From Dev

Launch spring WebSocket programmatically

From Dev

Alternatives to JGroups

From Dev

In CXF, is there a way to program the configuration of a client programmatically?

From Dev

Retrieving fluent configuration programmatically without instantiating DbContext

From Dev

How to add programmatically dependencies to Gradle configuration?

From Dev

iOS: How to install a configuration profile programmatically

From Dev

Set web.xml configuration programmatically

From Dev

Is it possible to set display configuration programmatically on login time?

From Dev

Spring - Programmatically generate a set of beans

From Java

Configure DataSource programmatically in Spring Boot

From Dev

Spring authentication REST service programmatically

Related Related

  1. 1

    Infinispan not using specified JGroups configuration file and throwing Exception

  2. 2

    Hibernate Search, Infinispan, jgroups, Wildfly cluster integration configuration

  3. 3

    Infinispan server ignores jgroups bind_addr

  4. 4

    Infinispan server ignores jgroups bind_addr

  5. 5

    Infinispan Interceptor Configuration?

  6. 6

    Spring Transaction configuration programmatically with Spring 4.3.4 version

  7. 7

    Infinispan + WildFly + Spring

  8. 8

    How to initialize the JGroups AUTH protocol programmatically

  9. 9

    Best JGroups stack configuration for leader/follower relationship

  10. 10

    JGroups ec2 cluster fails to connect (times out) with Hibernate Search / Infinispan setup

  11. 11

    Programmatically check the build configuration

  12. 12

    Programmatically check the build configuration

  13. 13

    Spring @Cacheable double-checked locking (infinispan backend)

  14. 14

    TestNG Programmatically use xml configuration

  15. 15

    Programmatically getting Jenkins configuration for a plugin

  16. 16

    TestNG Programmatically use xml configuration

  17. 17

    How to set ImageResizer configuration programmatically?

  18. 18

    Load spring config programmatically

  19. 19

    Launch spring WebSocket programmatically

  20. 20

    Alternatives to JGroups

  21. 21

    In CXF, is there a way to program the configuration of a client programmatically?

  22. 22

    Retrieving fluent configuration programmatically without instantiating DbContext

  23. 23

    How to add programmatically dependencies to Gradle configuration?

  24. 24

    iOS: How to install a configuration profile programmatically

  25. 25

    Set web.xml configuration programmatically

  26. 26

    Is it possible to set display configuration programmatically on login time?

  27. 27

    Spring - Programmatically generate a set of beans

  28. 28

    Configure DataSource programmatically in Spring Boot

  29. 29

    Spring authentication REST service programmatically

HotTag

Archive