-
-
Save tobias/70c1725255f2fcd8e97b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Method; | |
public class ClusterUtils { | |
public static boolean inCluster() { | |
return channelFactory() != null; | |
} | |
public static JChannel lockableChannel(String id) throws Exception { | |
Object factory = channelFactory(); | |
Class channelInterface; | |
try { | |
channelInterface = Class.forName("org.jboss.as.clustering.jgroups.ChannelFactory"); | |
} catch (ClassNotFoundException e) { | |
try { | |
channelInterface = Class.forName("org.wildfly.clustering.jgroups.ChannelFactory"); | |
} catch (ClassNotFoundException e2) { | |
throw new RuntimeException("ffs", e2); | |
} | |
} | |
if (channelInterface == null) { | |
return null; | |
} | |
Method createChannel = channelInterface.getDeclaredMethod("createChannel", String.class); | |
JChannel chan = (JChannel)createChannel.invoke(factory, id); | |
//TODO: check the stack and see if it already contains a lock proto | |
// and we should doc that as the preferred way, since you can configure the number of backups? | |
CENTRAL_LOCK l = new CENTRAL_LOCK(); | |
l.setNumberOfBackups(1); | |
chan.getProtocolStack().addProtocol(l); | |
l.init(); | |
return chan; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment