Exemplo n.º 1
0
 private void writeTransport(
     XMLExtendedStreamWriter writer, GlobalConfiguration globalConfiguration)
     throws XMLStreamException {
   TransportConfiguration transport = globalConfiguration.transport();
   AttributeSet attributes = transport.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.TRANSPORT);
     attributes.write(writer, TransportConfiguration.CLUSTER_NAME, Attribute.CLUSTER);
     attributes.write(writer, TransportConfiguration.MACHINE_ID, Attribute.MACHINE_ID);
     attributes.write(writer, TransportConfiguration.RACK_ID, Attribute.RACK_ID);
     if (transport.siteId() != null) {
       attributes.write(writer, TransportConfiguration.SITE_ID, Attribute.SITE);
     } else if (globalConfiguration.sites().localSite() != null) {
       writer.writeAttribute(Attribute.SITE, globalConfiguration.sites().localSite());
     }
     attributes.write(writer, TransportConfiguration.NODE_NAME, Attribute.NODE_NAME);
     TypedProperties properties = globalConfiguration.transport().properties();
     if (properties.containsKey("stack")) {
       writer.writeAttribute(Attribute.STACK, properties.getProperty("stack"));
     }
     if (transport.remoteCommandThreadPool().threadPoolFactory() != null) {
       writer.writeAttribute(Attribute.REMOTE_COMMAND_EXECUTOR, "remote-command-pool");
     }
     if (transport.transportThreadPool().threadPoolFactory() != null) {
       writer.writeAttribute(Attribute.EXECUTOR, "transport-pool");
     }
     writer.writeEndElement();
   }
 }
Exemplo n.º 2
0
  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.
    channel.setDiscardOwnMessages(true);

    // 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");
        }
      }
    }
  }