MBeanServer mbeanServer =
MBeanServerFactory.createMBeanServer("mockPartition");
try {
ClusterNode localAddress = factory.getClusterNode(new IpAddress("localhost", 12345));
MockHAPartition partition = new MockHAPartition(localAddress);
DistributedReplicantManagerImpl drm = new DistributedReplicantManagerImpl(partition);
drm.createService();
// Create a fake view for the MockHAPartition
Vector<ClusterNode> remoteAddresses = new Vector<ClusterNode>();
ClusterNode remote = factory.getClusterNode(new IpAddress("localhost", 12341));
remoteAddresses.add(remote);
Vector<ClusterNode> allNodes = new Vector<ClusterNode>(remoteAddresses);
allNodes.add(localAddress);
partition.setCurrentViewClusterNodes(allNodes);
drm.startService();
MockDeployer deployer = new MockDeployer(drm);
if (!conflicting)
{
// Register a MockHASingletonDeployer, but since we're in
// non-conflicting mode, the DeployerThreads won't deal with it
MockHASingletonDeployer listener =
new MockHASingletonDeployer(deployer, "HASingleton", log);
drm.registerListener("HASingleton", listener);
drm.add("HASingleton", "HASingleton");
}
// Create a semaphore to gate the threads and acquire all its permits
Semaphore semaphore = new Semaphore(count + 1);
for (int i = 0; i <= count; i++)
semaphore.acquire();
DeployerThread[] deployers = new DeployerThread[keys.length];
for (int i = 0; i < count; i++)
{
DistributedReplicantManager.ReplicantListener listener = null;
if (conflicting)
{
listener = new MockHASingletonDeployer(deployer, keys[i], log);
}
else
{
listener = new NullListener();
}
deployers[i] = new DeployerThread(deployer, keys[i], listener, semaphore, log);
deployers[i].start();
}
String[] jgKeys = keys;
if (!conflicting)
{
// The JGroups thread also deals with the MockHASingletonDeployer
// key that the DeployerThreads don't
jgKeys = new String[keys.length + 1];
System.arraycopy(keys, 0, jgKeys, 0, keys.length);
jgKeys[keys.length] = "HASingleton";
}
JGroupsThread jgThread = new JGroupsThread(drm, jgKeys, remote.getName(), semaphore);
jgThread.start();
// Launch the threads
semaphore.release(count + 1);