for (MembershipManager appDomainMembershipManager : applicationDomainMembershipManagers) {
appDomainMembershipManager.setStaticMembershipInterceptor(staticMembershipInterceptor);
// Create an RpcChannel for each localDomain
String domain = new String(appDomainMembershipManager.getDomain());
RpcChannel rpcMembershipChannel =
new RpcChannel(TribesUtil.getRpcMembershipChannelId(appDomainMembershipManager.getDomain()),
channel,
new RpcMembershipRequestHandler(appDomainMembershipManager,
this));
appDomainMembershipManager.setRpcMembershipChannel(rpcMembershipChannel);
if (log.isDebugEnabled()) {
log.debug("Created RPC Membership Channel for application domain " + domain);
}
}
// Create a Membership channel for handling membership requests
RpcChannel rpcMembershipChannel =
new RpcChannel(TribesUtil.getRpcMembershipChannelId(localDomain),
channel, new RpcMembershipRequestHandler(primaryMembershipManager,
this));
if (log.isDebugEnabled()) {
log.debug("Created primary membership channel " + new String(localDomain));
}
primaryMembershipManager.setRpcMembershipChannel(rpcMembershipChannel);
// Send JOIN message to a WKA member
if (primaryMembershipManager.getMembers().length > 0) {
log.info("Sending JOIN message to WKA members...");
org.apache.catalina.tribes.Member[] wkaMembers = primaryMembershipManager.getMembers(); // The well-known members
/*try {
Thread.sleep(3000); // Wait for sometime so that the WKA members can receive the MEMBER_LIST message, if they have just joined the group
} catch (InterruptedException ignored) {
}*/ //TODO: #### Need to double check whether this sleep is necessary
Response[] responses = null;
do {
try {
responses = rpcMembershipChannel.send(wkaMembers,
new JoinGroupCommand(),
RpcChannel.ALL_REPLY,
Channel.SEND_OPTIONS_ASYNCHRONOUS |
TribesConstants.MEMBERSHIP_MSG_OPTION,
10000);