示例#1
0
 private void writeTransaction(XMLExtendedStreamWriter writer, Configuration configuration)
     throws XMLStreamException {
   TransactionConfiguration transaction = configuration.transaction();
   AttributeSet attributes = transaction.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.TRANSACTION);
     TransactionMode mode =
         TransactionMode.fromConfiguration(
             transaction.transactionMode(),
             !transaction.useSynchronization(),
             transaction.recovery().enabled(),
             configuration.invocationBatching().enabled());
     writer.writeAttribute(Attribute.MODE, mode.toString());
     attributes.write(writer);
     if (mode != TransactionMode.NONE) {
       attributes.write(writer, TransactionConfiguration.TRANSACTION_MANAGER_LOOKUP);
     }
     if (transaction.recovery().enabled())
       transaction
           .recovery()
           .attributes()
           .write(
               writer,
               RecoveryConfiguration.RECOVERY_INFO_CACHE_NAME,
               Attribute.RECOVERY_INFO_CACHE_NAME);
     writer.writeEndElement();
   }
 }
示例#2
0
  private void writeCommonClusteredCacheAttributes(
      XMLExtendedStreamWriter writer, Configuration configuration) throws XMLStreamException {
    ClusteringConfiguration clustering = configuration.clustering();
    writer.writeAttribute(
        Attribute.MODE, clustering.cacheMode().isSynchronous() ? "SYNC" : "ASYNC");

    AttributeSet syncAttributes = clustering.sync().attributes();
    syncAttributes.write(writer, ClusteringConfiguration.REMOTE_TIMEOUT, Attribute.REMOTE_TIMEOUT);
  }
 public SitesConfiguration(
     AttributeSet attributes,
     List<BackupConfiguration> allBackups,
     BackupForConfiguration backupFor) {
   this.attributes = attributes.checkProtection();
   this.allBackups = Collections.unmodifiableList(allBackups);
   this.disableBackups = attributes.attribute(DISABLE_BACKUPS);
   this.inUseBackupSites = attributes.attribute(IN_USE_BACKUP_SITES);
   this.backupFor = backupFor;
 }
示例#4
0
 private void writeIndexing(XMLExtendedStreamWriter writer, Configuration configuration)
     throws XMLStreamException {
   IndexingConfiguration indexing = configuration.indexing();
   AttributeSet attributes = indexing.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.INDEXING);
     attributes.write(writer, IndexingConfiguration.INDEX, Attribute.INDEX);
     attributes.write(writer, IndexingConfiguration.AUTO_CONFIG, Attribute.AUTO_CONFIG);
     writeTypedProperties(writer, indexing.properties());
     writer.writeEndElement();
   }
 }
示例#5
0
 private void writeSecurity(XMLExtendedStreamWriter writer, Configuration configuration)
     throws XMLStreamException {
   AuthorizationConfiguration authorization = configuration.security().authorization();
   AttributeSet attributes = authorization.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.SECURITY);
     writer.writeStartElement(Element.AUTHORIZATION);
     attributes.write(writer, AuthorizationConfiguration.ENABLED, Attribute.ENABLED);
     writeCollectionAsAttribute(writer, Attribute.ROLES, authorization.roles());
     writer.writeEndElement();
     writer.writeEndElement();
   }
 }
示例#6
0
 private void writePersistence(XMLExtendedStreamWriter writer, Configuration configuration)
     throws XMLStreamException {
   PersistenceConfiguration persistence = configuration.persistence();
   AttributeSet attributes = persistence.attributes();
   if (attributes.isModified() || persistence.stores().size() > 0) {
     writer.writeStartElement(Element.PERSISTENCE);
     attributes.write(writer, PersistenceConfiguration.PASSIVATION, Attribute.PASSIVATION);
     for (StoreConfiguration store : persistence.stores()) {
       writeStore(writer, store);
     }
     writer.writeEndElement();
   }
 }
示例#7
0
 private void writeDataContainer(XMLExtendedStreamWriter writer, Configuration configuration)
     throws XMLStreamException {
   DataContainerConfiguration dataContainer = configuration.dataContainer();
   AttributeSet attributes = dataContainer.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.DATA_CONTAINER);
     attributes.write(writer, DataContainerConfiguration.DATA_CONTAINER, Attribute.CLASS);
     attributes.write(
         writer, DataContainerConfiguration.KEY_EQUIVALENCE, Attribute.KEY_EQUIVALENCE);
     attributes.write(
         writer, DataContainerConfiguration.VALUE_EQUIVALENCE, Attribute.VALUE_EQUIVALENCE);
     writeTypedProperties(writer, dataContainer.properties());
     writer.writeEndElement();
   }
 }
示例#8
0
 private void writeSerialization(
     XMLExtendedStreamWriter writer, GlobalConfiguration globalConfiguration)
     throws XMLStreamException {
   SerializationConfiguration serialization = globalConfiguration.serialization();
   AttributeSet attributes = serialization.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.SERIALIZATION);
     attributes.write(writer, SerializationConfiguration.MARSHALLER, Attribute.MARSHALLER_CLASS);
     if (attributes.attribute(SerializationConfiguration.VERSION).isModified()) {
       writer.writeAttribute(Attribute.VERSION, Version.decodeVersion(serialization.version()));
     }
     writeAdvancedSerializers(writer, globalConfiguration);
     writer.writeEndElement();
   }
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
   return result;
 }
示例#10
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();
   }
 }
示例#11
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   AsyncConfiguration other = (AsyncConfiguration) obj;
   if (attributes == null) {
     if (other.attributes != null) return false;
   } else if (!attributes.equals(other.attributes)) return false;
   return true;
 }
示例#12
0
 AsyncConfiguration(AttributeSet attributes) {
   this.attributes = attributes.checkProtection();
   marshalling = attributes.attribute(MARSHALLING);
   replicationQueue = attributes.attribute(REPLICATION_QUEUE);
   replicationQueueInterval = attributes.attribute(REPLICATION_QUEUE_INTERVAL);
   replicationQueueMaxElements = attributes.attribute(REPLICATION_QUEUE_MAX_ELEMENTS);
   useReplicationQueue = attributes.attribute(USE_REPLICATION_QUEUE);
 }
示例#13
0
 private void writeBackup(XMLExtendedStreamWriter writer, Configuration configuration)
     throws XMLStreamException {
   SitesConfiguration sites = configuration.sites();
   if (sites.allBackups().size() > 0) {
     writer.writeStartElement(Element.BACKUPS);
     for (BackupConfiguration backup : sites.allBackups()) {
       writer.writeStartElement(Element.BACKUP);
       backup.attributes().write(writer);
       AttributeSet stateTransfer = backup.stateTransfer().attributes();
       if (stateTransfer.isModified()) {
         writer.writeStartElement(Element.STATE_TRANSFER);
         stateTransfer.write(
             writer, XSiteStateTransferConfiguration.CHUNK_SIZE, Attribute.CHUNK_SIZE);
         stateTransfer.write(
             writer, XSiteStateTransferConfiguration.MAX_RETRIES, Attribute.MAX_RETRIES);
         stateTransfer.write(writer, XSiteStateTransferConfiguration.TIMEOUT, Attribute.TIMEOUT);
         stateTransfer.write(
             writer, XSiteStateTransferConfiguration.WAIT_TIME, Attribute.WAIT_TIME);
         writer.writeEndElement();
       }
       AttributeSet takeOffline = backup.takeOffline().attributes();
       if (takeOffline.isModified()) {
         writer.writeStartElement(Element.TAKE_OFFLINE);
         takeOffline.write(
             writer,
             TakeOfflineConfiguration.AFTER_FAILURES,
             Attribute.TAKE_BACKUP_OFFLINE_AFTER_FAILURES);
         takeOffline.write(
             writer,
             TakeOfflineConfiguration.MIN_TIME_TO_WAIT,
             Attribute.TAKE_BACKUP_OFFLINE_MIN_WAIT);
         writer.writeEndElement();
       }
       writer.writeEndElement();
     }
     writer.writeEndElement();
   }
 }
示例#14
0
 private void writeCustomInterceptors(XMLExtendedStreamWriter writer, Configuration configuration)
     throws XMLStreamException {
   CustomInterceptorsConfiguration customInterceptors = configuration.customInterceptors();
   if (customInterceptors.interceptors().size() > 0) {
     writer.writeStartElement(Element.CUSTOM_INTERCEPTORS);
     for (InterceptorConfiguration interceptor : customInterceptors.interceptors()) {
       AttributeSet attributes = interceptor.attributes();
       writer.writeStartElement(Element.INTERCEPTOR);
       attributes.write(writer, InterceptorConfiguration.INTERCEPTOR_CLASS, Attribute.CLASS);
       attributes.write(writer, InterceptorConfiguration.AFTER, Attribute.AFTER);
       attributes.write(writer, InterceptorConfiguration.BEFORE, Attribute.BEFORE);
       attributes.write(writer, InterceptorConfiguration.INDEX, Attribute.INDEX);
       attributes.write(writer, InterceptorConfiguration.POSITION, Attribute.POSITION);
       writeTypedProperties(writer, interceptor.properties());
       writer.writeEndElement();
     }
     writer.writeEndElement();
   }
 }
  @Override
  public void validate() {
    Attribute<Class> interceptorClassAttribute = attributes.attribute(INTERCEPTOR_CLASS);
    Attribute<CommandInterceptor> interceptorAttribute = attributes.attribute(INTERCEPTOR);

    if (!interceptorClassAttribute.isNull() && !interceptorAttribute.isNull()) {
      throw log.interceptorClassAndInstanceDefined(
          interceptorClassAttribute.get().getName(), interceptorAttribute.get().toString());
    } else if (interceptorClassAttribute.isNull() && interceptorAttribute.isNull()) {
      throw log.customInterceptorMissingClass();
    }
    Class<? extends CommandInterceptor> interceptorClass = interceptorClassAttribute.get();
    if (interceptorClass == null) {
      interceptorClass = interceptorAttribute.get().getClass();
    }

    if (!BaseCustomInterceptor.class.isAssignableFrom(interceptorClass)) {
      final String className = interceptorClass.getName();
      // Suppress noisy warnings if the interceptor is one of our own (like one of those from
      // Query):
      if (!className.startsWith("org.infinispan.")) {
        log.suggestCustomInterceptorInheritance(className);
      }
    }

    // Make sure more than one 'position' isn't picked.
    int positions = 0;

    if (!attributes.attribute(BEFORE).isNull()) positions++;
    if (!attributes.attribute(AFTER).isNull()) positions++;
    if (attributes.attribute(INDEX).get() > -1) positions++;
    if (attributes.attribute(POSITION).isModified()) positions++;

    switch (positions) {
      case 0:
        throw log.missingCustomInterceptorPosition(interceptorClass.getName());
      case 1:
        break;
      default:
        throw log.multipleCustomInterceptorPositions(interceptorClass.getName());
    }
  }
示例#16
0
 private void writeJMX(XMLExtendedStreamWriter writer, GlobalConfiguration globalConfiguration)
     throws XMLStreamException {
   GlobalJmxStatisticsConfiguration globalJmxStatistics =
       globalConfiguration.globalJmxStatistics();
   AttributeSet attributes = globalJmxStatistics.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.JMX);
     attributes.write(writer, GlobalJmxStatisticsConfiguration.JMX_DOMAIN, Attribute.JMX_DOMAIN);
     attributes.write(
         writer,
         GlobalJmxStatisticsConfiguration.ALLOW_DUPLICATE_DOMAINS,
         Attribute.ALLOW_DUPLICATE_DOMAINS);
     attributes.write(
         writer,
         GlobalJmxStatisticsConfiguration.MBEAN_SERVER_LOOKUP,
         Attribute.MBEAN_SERVER_LOOKUP);
     writeTypedProperties(
         writer, attributes.attribute(GlobalJmxStatisticsConfiguration.PROPERTIES).get());
     writer.writeEndElement();
   }
 }
 /**
  * Class of the new custom interceptor to add to the configuration.
  *
  * @param interceptorClass an instance of {@link CommandInterceptor}
  */
 public InterceptorConfigurationBuilder interceptorClass(
     Class<? extends CommandInterceptor> interceptorClass) {
   attributes.attribute(INTERCEPTOR_CLASS).set(interceptorClass);
   return this;
 }
 /**
  * Time period that determines how often is lock acquisition attempted within maximum time allowed
  * to acquire a particular lock
  */
 public long spinDuration() {
   return attributes.attribute(SPIN_DURATION).get();
 }
 DeadlockDetectionConfiguration(AttributeSet attributes) {
   this.attributes = attributes.checkProtection();
   enabled = attributes.attribute(ENABLED);
   spinDuration = attributes.attribute(SPIN_DURATION);
 }
 GroupsConfiguration(AttributeSet attributes) {
   this.attributes = attributes.checkProtection();
   enabled = attributes.attribute(ENABLED);
   groupers = attributes.attribute(GROUPERS);
 }
 /**
  * Specifies a position, denoted by the {@link Position} enumeration, where to place the new
  * interceptor.
  *
  * @param p position to place the new interceptor
  */
 public InterceptorConfigurationBuilder position(Position p) {
   attributes.attribute(POSITION).set(p);
   return this;
 }
 /**
  * Specifies a position in the interceptor chain to place the new interceptor. The index starts at
  * 0 and goes up to the number of interceptors in a given configuration. An {@link
  * IllegalArgumentException} is thrown if the index is less than 0 or greater than the maximum
  * number of interceptors in the chain.
  *
  * @param i positional index in the interceptor chain to place the new interceptor.
  */
 public InterceptorConfigurationBuilder index(int i) {
   if (i < 0) throw new IllegalArgumentException("Index cannot be negative");
   attributes.attribute(INDEX).set(i);
   return this;
 }
 /**
  * Clears the interceptor properties
  *
  * @return this InterceptorConfigurationBuilder
  */
 public InterceptorConfigurationBuilder clearProperties() {
   TypedProperties properties = attributes.attribute(PROPERTIES).get();
   properties.clear();
   attributes.attribute(PROPERTIES).set(TypedProperties.toTypedProperties(properties));
   return this;
 }
 public InterceptorConfigurationBuilder addProperty(String key, String value) {
   TypedProperties properties = attributes.attribute(PROPERTIES).get();
   properties.put(key, value);
   attributes.attribute(PROPERTIES).set(TypedProperties.toTypedProperties(properties));
   return this;
 }
 /**
  * Dictates that the custom interceptor appears immediately <i>before</i> the specified
  * interceptor. If the specified interceptor is not found in the interceptor chain, a {@link
  * CacheConfigurationException} will be thrown when the cache starts.
  *
  * @param before the class of the interceptor to look for
  */
 public InterceptorConfigurationBuilder before(Class<? extends CommandInterceptor> before) {
   attributes.attribute(BEFORE).set(before);
   return this;
 }
 /**
  * Dictates that the custom interceptor appears immediately <i>after</i> the specified
  * interceptor. If the specified interceptor is not found in the interceptor chain, a {@link
  * CacheConfigurationException} will be thrown when the cache starts.
  *
  * @param after the class of the interceptor to look for
  */
 public InterceptorConfigurationBuilder after(Class<? extends CommandInterceptor> after) {
   attributes.attribute(AFTER).set(after);
   return this;
 }
 @Override
 public InterceptorConfigurationBuilder read(InterceptorConfiguration template) {
   attributes.read(template.attributes());
   return this;
 }
 public InterceptorConfigurationBuilder removeProperty(String key) {
   TypedProperties properties = attributes.attribute(PROPERTIES).get();
   properties.remove(key);
   attributes.attribute(PROPERTIES).set(TypedProperties.toTypedProperties(properties));
   return this;
 }
 @Override
 public InterceptorConfiguration create() {
   return new InterceptorConfiguration(attributes.protect());
 }
 /**
  * An instance of the new custom interceptor to add to the configuration. Warning: if you use this
  * configuration for multiple caches, the interceptor instance will be shared, which will corrupt
  * interceptor stack. Use {@link #interceptorClass} instead.
  *
  * @param interceptor an instance of {@link CommandInterceptor}
  */
 public InterceptorConfigurationBuilder interceptor(CommandInterceptor interceptor) {
   attributes.attribute(INTERCEPTOR).set(interceptor);
   return this;
 }