public void testApi() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.sites() .addBackup() .site("LON") .strategy(BackupConfiguration.BackupStrategy.SYNC) .sites() .addBackup() .site("SFO") .sites() .addBackup() .site("NYC"); assertEquals(cb.sites().backups().size(), 3); BackupConfigurationBuilder backup0 = cb.sites().backups().get(0); assertEquals(backup0.site(), "LON"); assertEquals(backup0.strategy(), BackupConfiguration.BackupStrategy.SYNC); BackupConfigurationBuilder backup1 = cb.sites().backups().get(1); assertEquals(backup1.site(), "SFO"); assertEquals(backup1.strategy(), BackupConfiguration.BackupStrategy.ASYNC); BackupConfigurationBuilder backup2 = cb.sites().backups().get(2); assertEquals(backup2.site(), "NYC"); assertEquals(backup2.strategy(), BackupConfiguration.BackupStrategy.ASYNC); Configuration b = cb.build(); assertEquals(b.sites().allBackups().size(), 3); BackupConfiguration b0 = b.sites().allBackups().get(0); assertEquals(b0.site(), "LON"); assertEquals(b0.strategy(), BackupConfiguration.BackupStrategy.SYNC); BackupConfiguration b1 = b.sites().allBackups().get(1); assertEquals(b1.site(), "SFO"); assertEquals(b1.strategy(), BackupConfiguration.BackupStrategy.ASYNC); BackupConfigurationBuilder b2 = cb.sites().backups().get(2); assertEquals(b2.site(), "NYC"); assertEquals(b2.strategy(), BackupConfiguration.BackupStrategy.ASYNC); }
private void writeCommonCacheAttributesElements( XMLExtendedStreamWriter writer, String name, Configuration configuration) throws XMLStreamException { writer.writeAttribute(Attribute.NAME, name); configuration .jmxStatistics() .attributes() .write(writer, JMXStatisticsConfiguration.ENABLED, Attribute.STATISTICS); if (configuration.deadlockDetection().enabled()) { writer.writeAttribute( Attribute.SPIN_DURATION, Long.toString(configuration.deadlockDetection().spinDuration())); } configuration.unsafe().attributes().write(writer); writeBackup(writer, configuration); configuration.sites().backupFor().attributes().write(writer, Element.BACKUP_FOR.getLocalName()); configuration.locking().attributes().write(writer, Element.LOCKING.getLocalName()); writeTransaction(writer, configuration); configuration.eviction().attributes().write(writer, Element.EVICTION.getLocalName()); configuration.expiration().attributes().write(writer, Element.EXPIRATION.getLocalName()); if (configuration.compatibility().enabled()) configuration .compatibility() .attributes() .write(writer, Element.COMPATIBILITY.getLocalName()); if (configuration.storeAsBinary().enabled()) configuration .storeAsBinary() .attributes() .write(writer, Element.STORE_AS_BINARY.getLocalName()); writePersistence(writer, configuration); configuration.versioning().attributes().write(writer, Element.VERSIONING.getLocalName()); writeDataContainer(writer, configuration); writeIndexing(writer, configuration); writeCustomInterceptors(writer, configuration); writeSecurity(writer, configuration); if (configuration.clustering().cacheMode().needsStateTransfer()) { configuration .clustering() .stateTransfer() .attributes() .write(writer, Element.STATE_TRANSFER.getLocalName()); } configuration .clustering() .partitionHandling() .attributes() .write(writer, Element.PARTITION_HANDLING.getLocalName()); }
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(); } }