예제 #1
0
  private static String dump(Collection<ProtocolConfiguration> configs) {
    StringBuilder sb = new StringBuilder();
    String indent = "  ";
    sb.append("<config>\n");

    for (ProtocolConfiguration cfg : configs) {
      sb.append(indent).append("<").append(cfg.getProtocolName());
      Map<String, String> props = cfg.getProperties();
      if (props.isEmpty()) {
        sb.append(" />\n");
      } else {
        sb.append("\n").append(indent).append(indent);
        for (Map.Entry<String, String> entry : props.entrySet()) {
          String key = entry.getKey();
          String val = entry.getValue();
          key = trim(key);
          val = trim(val);
          sb.append(key).append("=\"").append(val).append("\" ");
        }
        sb.append(" />\n");
      }
    }

    sb.append("</config>\n");
    return sb.toString();
  }
예제 #2
0
 private void configureMulticastSocket(
     ProtocolConfiguration protocol,
     org.jgroups.conf.ProtocolConfiguration config,
     String addressProperty,
     String portProperty,
     SocketBinding binding) {
   Map<String, String> properties = config.getProperties();
   try {
     InetSocketAddress mcastSocketAddress = binding.getMulticastSocketAddress();
     if (protocol.hasProperty(addressProperty)) {
       properties.put(addressProperty, mcastSocketAddress.getAddress().getHostAddress());
     }
     if (protocol.hasProperty(portProperty)) {
       properties.put(portProperty, String.valueOf(mcastSocketAddress.getPort()));
     }
   } catch (IllegalStateException e) {
     ROOT_LOGGER.tracef(
         e,
         "Could not set %s.%s and %s.%s, %s socket binding does not specify a multicast socket",
         config.getProtocolName(),
         addressProperty,
         config.getProtocolName(),
         portProperty,
         binding.getName());
   }
 }
예제 #3
0
 private org.jgroups.conf.ProtocolConfiguration createProtocol(
     final ProtocolConfiguration protocolConfig) {
   String protocol = protocolConfig.getName();
   final Map<String, String> properties =
       new HashMap<String, String>(this.configuration.getDefaults().getProperties(protocol));
   properties.putAll(protocolConfig.getProperties());
   return new org.jgroups.conf.ProtocolConfiguration(protocol, properties) {
     @Override
     public Map<String, String> getOriginalProperties() {
       return properties;
     }
   };
 }
예제 #4
0
  /**
   * {@inheritDoc}
   *
   * @see org.jgroups.conf.ProtocolStackConfigurator#getProtocolStack()
   */
  @Override
  public List<org.jgroups.conf.ProtocolConfiguration> getProtocolStack() {
    List<org.jgroups.conf.ProtocolConfiguration> configs =
        new ArrayList<org.jgroups.conf.ProtocolConfiguration>(
            this.configuration.getProtocols().size() + 1);
    TransportConfiguration transport = this.configuration.getTransport();
    org.jgroups.conf.ProtocolConfiguration config = this.createProtocol(transport);
    Map<String, String> properties = config.getProperties();

    if (transport.isShared()) {
      properties.put(Global.SINGLETON_NAME, this.configuration.getName());
    }

    SocketBinding binding = transport.getSocketBinding();
    if (binding != null) {
      this.configureBindAddress(transport, config, binding);
      this.configureServerSocket(transport, config, "bind_port", binding);
      this.configureMulticastSocket(transport, config, "mcast_addr", "mcast_port", binding);
    }

    SocketBinding diagnosticsSocketBinding = transport.getDiagnosticsSocketBinding();
    boolean diagnostics = (diagnosticsSocketBinding != null);
    properties.put("enable_diagnostics", String.valueOf(diagnostics));
    if (diagnostics) {
      this.configureMulticastSocket(
          transport, config, "diagnostics_addr", "diagnostics_port", diagnosticsSocketBinding);
    }

    configs.add(config);

    for (ProtocolConfiguration protocol : this.configuration.getProtocols()) {
      config = this.createProtocol(protocol);
      binding = protocol.getSocketBinding();
      if (binding != null) {
        this.configureBindAddress(protocol, config, binding);
        this.configureServerSocket(protocol, config, "bind_port", binding);
        this.configureServerSocket(protocol, config, "start_port", binding);
        this.configureMulticastSocket(protocol, config, "mcast_addr", "mcast_port", binding);
      } else if (transport.getSocketBinding() != null) {
        // If no socket-binding was specified, use bind address of transport
        this.configureBindAddress(protocol, config, transport.getSocketBinding());
      }

      configs.add(config);
    }
    return configs;
  }
예제 #5
0
 /**
  * @param convert If false: print old plain output, else print new XML format
  * @return String with protocol stack in specified format
  */
 public String getProtocolStackString(boolean convert) {
   StringBuilder buf = new StringBuilder();
   Iterator<ProtocolConfiguration> it = configuration.iterator();
   if (convert) buf.append("<config>\n");
   while (it.hasNext()) {
     ProtocolConfiguration d = it.next();
     if (convert) buf.append("    <");
     buf.append(d.getProtocolString(convert));
     if (convert) buf.append("/>");
     if (it.hasNext()) {
       if (convert) buf.append('\n');
       else buf.append(':');
     }
   }
   if (convert) buf.append("\n</config>");
   return buf.toString();
 }
예제 #6
0
 private void configureServerSocket(
     ProtocolConfiguration protocol,
     org.jgroups.conf.ProtocolConfiguration config,
     String property,
     SocketBinding binding) {
   if (protocol.hasProperty(property)) {
     config.getProperties().put(property, String.valueOf(binding.getSocketAddress().getPort()));
   }
 }
예제 #7
0
 private void configureBindAddress(
     ProtocolConfiguration protocol,
     org.jgroups.conf.ProtocolConfiguration config,
     SocketBinding binding) {
   final String property = "bind_addr";
   if (protocol.hasProperty(property)) {
     config
         .getProperties()
         .put(property, binding.getSocketAddress().getAddress().getHostAddress());
   }
 }