isCoordinator = false;
dispatcher = null;
}
protected void initChannel() {
final TransportConfiguration transportCfg = configuration.transport();
if (channel == null) {
buildChannel();
String transportNodeName = transportCfg.nodeName();
if (transportNodeName != null && transportNodeName.length() > 0) {
long range = Short.MAX_VALUE * 2;
long randomInRange = (long) ((Math.random() * range) % range) + 1;
transportNodeName = transportNodeName + "-" + randomInRange;
channel.setName(transportNodeName);
}
}
// Channel.LOCAL *must* be set to false so we don't see our own messages - otherwise
// invalidations targeted at remote instances will be received by self.
// NOTE: total order needs to deliver own messages. the invokeRemotely method has a total order boolean
// that when it is false, it discard our own messages, maintaining the property needed
channel.setDiscardOwnMessages(false);
// if we have a TopologyAwareConsistentHash, we need to set our own address generator in JGroups
if (transportCfg.hasTopologyInfo()) {
// We can do this only if the channel hasn't been started already
if (startChannel) {
((JChannel) channel).setAddressGenerator(new AddressGenerator() {
@Override
public org.jgroups.Address generateAddress() {
return TopologyUUID.randomUUID(channel.getName(),
transportCfg.siteId(), transportCfg.rackId(),
transportCfg.machineId());
}
});
} else {
if (channel.getAddress() instanceof TopologyUUID) {
TopologyUUID topologyAddress = (TopologyUUID) channel.getAddress();
if (!transportCfg.siteId().equals(topologyAddress.getSiteId())
|| !transportCfg.rackId().equals(topologyAddress.getRackId())
|| !transportCfg.machineId().equals(topologyAddress.getMachineId())) {
throw new CacheException("Topology information does not match the one set by the provided JGroups channel");
}
} else {
throw new CacheException("JGroups address does not contain topology coordinates");
}