简体   繁体   中英

Develop programmatically a Jgroup Channel for Infinispan in a Cluster

I'm working with infinispan 8.1.0 Final and Wildfly 10 in a cluster set up.

Each server is started running

C:\wildfly-10\bin\standalone.bat --server-config=standalone-ha.xml -b 10.09.139.215 -u 230.0.0.4  -Djboss.node.name=MyNode

I want to use Infinispan in distributed mode in order to have a distributed cache. But for mandatory requirements I need to build a JGroups channel for dynamically reading some properties from a file.

This channel is necessary for me to build a cluster-group based on TYPE and NAME (for example Type1-MyCluster). Each server who wants to join a cluster has to use the related channel.

Sailing the net I have found some code like the one below:

public class JGroupsChannelServiceActivator implements ServiceActivator  { 
    @Override 
public void activate(ServiceActivatorContext context) { 
    stackName = "udp"; 
    try { 
        channelServiceName = ChannelService.getServiceName(CHANNEL_NAME); 
        createChannel(context.getServiceTarget()); 
    } catch (IllegalStateException e) { 
        log.log(Level.INFO, "channel seems to already exist, skipping creation and binding."); 
    } 
}
void createChannel(ServiceTarget target) { 

    InjectedValue<ChannelFactory> channelFactory = new InjectedValue<>(); 
    ServiceName serviceName = ChannelFactoryService.getServiceName(stackName); 
    ChannelService channelService = new ChannelService(CHANNEL_NAME, channelFactory); 

    target.addService(channelServiceName, channelService) 
    .addDependency(serviceName, ChannelFactory.class, channelFactory).install(); 
} 

I have created the META-INF/services/....JGroupsChannelServiceActivator file.

When I deploy my war into the server, the operation fails with this error:

"{\"WFLYCTL0180: Services with missing/unavailable dependencies\" => [\"jboss.jgroups.channel.clusterWatchdog is missing [jboss.jgroups.stack.udp]\"]}"

What am I doing wrong? How can I build a channel the way I need? In what way I can tell to infinispan to use that channel for distributed caching?

The proposal you found is implementation dependent and might cause a lot of problems during the upgrade. I wouldn't recommend it.

Let me check if I understand your problem correctly - you need to be able to create a JGroups channel manually because you use some custom properties for it.

If that is the case - you could obtain a JGroups channel as suggested here . But then you obtain a JChannel instance which is already connected (so this might be too late for your case).

Unfortunately since Wildfly manages the JChannel (it is required for clustering sessions, EJB etc) the only way to get full control of JChannel creating process is using Infinispan embedded (library) mode. This would require adding infinispan-embedded into your WAR dependencies. After that you can initialize it similarly to this test .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM