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(); } }
public static void verifyConfiguredAsClustered(final EmbeddedCacheManager cacheManager) { final GlobalConfiguration globalConfiguration = cacheManager.getCacheManagerConfiguration(); Assert.assertTrue( "This CacheManager is not configured for clustering", globalConfiguration.isClustered()); Assert.assertNotNull( "This CacheManager is configured for clustering but the Transport was not found", cacheManager.getTransport()); }
private void writeCacheContainer(XMLExtendedStreamWriter writer, ConfigurationHolder holder) throws XMLStreamException { writer.writeStartElement(Element.CACHE_CONTAINER); GlobalConfiguration globalConfiguration = holder.getGlobalConfiguration(); writer.writeAttribute( Attribute.NAME, globalConfiguration.globalJmxStatistics().cacheManagerName()); if (globalConfiguration.shutdown().hookBehavior() != ShutdownHookBehavior.DEFAULT) { writer.writeAttribute( Attribute.SHUTDOWN_HOOK, globalConfiguration.shutdown().hookBehavior().name()); } globalConfiguration .globalJmxStatistics() .attributes() .write(writer, GlobalJmxStatisticsConfiguration.ENABLED, Attribute.STATISTICS); if (globalConfiguration.asyncThreadPool().threadPoolFactory() != null) { writer.writeAttribute(Attribute.ASYNC_EXECUTOR, "async-pool"); } if (globalConfiguration.expirationThreadPool().threadPoolFactory() != null) { writer.writeAttribute(Attribute.EXPIRATION_EXECUTOR, "expiration-pool"); } if (globalConfiguration.listenerThreadPool().threadPoolFactory() != null) { writer.writeAttribute(Attribute.LISTENER_EXECUTOR, "listener-pool"); } if (globalConfiguration.persistenceThreadPool().threadPoolFactory() != null) { writer.writeAttribute(Attribute.PERSISTENCE_EXECUTOR, "persistence-pool"); } if (globalConfiguration.stateTransferThreadPool().threadPoolFactory() != null) { writer.writeAttribute(Attribute.STATE_TRANSFER_EXECUTOR, "state-transfer-pool"); } writeTransport(writer, globalConfiguration); writeSerialization(writer, globalConfiguration); writeJMX(writer, globalConfiguration); for (Entry<String, Configuration> configuration : holder.getConfigurations().entrySet()) { Configuration config = configuration.getValue(); switch (config.clustering().cacheMode()) { case LOCAL: writeLocalCache(writer, configuration.getKey(), config); break; case DIST_ASYNC: case DIST_SYNC: writeDistributedCache(writer, configuration.getKey(), config); break; case INVALIDATION_ASYNC: case INVALIDATION_SYNC: writeInvalidationCache(writer, configuration.getKey(), config); break; case REPL_ASYNC: case REPL_SYNC: writeReplicatedCache(writer, configuration.getKey(), config); break; default: break; } } }
/** * Build the JMX domain name. * * @param cfg configuration instance containig rules on JMX domains allowed * @param mBeanServer the {@link javax.management.MBeanServer} where to check whether the JMX * domain is allowed or not. * @param groupName String containing the group name for the JMX MBean * @return A string that combines the allowed JMX domain and the group name */ public static String buildJmxDomain( GlobalConfiguration cfg, MBeanServer mBeanServer, String groupName) { String jmxDomain = findJmxDomain(cfg.globalJmxStatistics().domain(), mBeanServer, groupName); String configJmxDomain = cfg.globalJmxStatistics().domain(); if (!jmxDomain.equals(configJmxDomain) && !cfg.globalJmxStatistics().allowDuplicateDomains()) { log.cacheManagerAlreadyRegistered(configJmxDomain); throw new JmxDomainConflictException( String.format( "Domain already registered %s when trying to register: %s", configJmxDomain, groupName)); } return jmxDomain; }
@Override public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalCfg) { Map<Integer, AdvancedExternalizer<?>> externalizerMap = globalCfg.serialization().advancedExternalizers(); externalizerMap.put(1000, new NodeKey.Externalizer()); externalizerMap.put(1001, new Fqn.Externalizer()); }
@Override public void start() { super.start(); baseCfg.setObjectTable(externalizerTable); proxy = new ExternalizerTableProxy(externalizerTable); baseCfg.setObjectTable(proxy); ClassResolver classResolver = globalCfg.serialization().classResolver(); if (classResolver == null) { // Override the class resolver with one that can detect injected // classloaders via AdvancedCache.with(ClassLoader) calls. ClassLoader cl = cfg == null ? globalCfg.classLoader() : cfg.classLoader(); classResolver = new EmbeddedContextClassResolver(cl, icc); } baseCfg.setClassResolver(classResolver); }
private void writeJGroups(XMLExtendedStreamWriter writer, GlobalConfiguration globalConfiguration) throws XMLStreamException { if (globalConfiguration.isClustered()) { writer.writeStartElement(Element.JGROUPS); writer.writeAttribute( Attribute.TRANSPORT, globalConfiguration.transport().transport().getClass().getName()); TypedProperties properties = globalConfiguration.transport().properties(); for (String property : properties.stringPropertyNames()) { if (property.startsWith("stack-")) { String stackName = properties.getProperty(property); String path = properties.getProperty("stackFilePath-" + stackName); writer.writeStartElement(Element.STACK_FILE); writer.writeAttribute(Attribute.NAME, stackName); writer.writeAttribute(Attribute.PATH, path); writer.writeEndElement(); } } writer.writeEndElement(); } }
private void writeAdvancedSerializers( XMLExtendedStreamWriter writer, GlobalConfiguration globalConfiguration) throws XMLStreamException { Map<Integer, AdvancedExternalizer<?>> externalizers = globalConfiguration.serialization().advancedExternalizers(); for (Entry<Integer, AdvancedExternalizer<?>> externalizer : externalizers.entrySet()) { writer.writeStartElement(Element.ADVANCED_EXTERNALIZER); writer.writeAttribute(Attribute.ID, Integer.toString(externalizer.getKey())); writer.writeAttribute(Attribute.CLASS, externalizer.getValue().getClass().getName()); writer.writeEndElement(); } }
public void testNoNamedCaches() throws Exception { String config = INFINISPAN_START_TAG + " <global>\n" + " <transport clusterName=\"demoCluster\"/>\n" + " </global>\n" + "\n" + " <default>\n" + " <clustering mode=\"replication\">\n" + " </clustering>\n" + " </default>\n" + TestingUtil.INFINISPAN_END_TAG; InputStream is = new ByteArrayInputStream(config.getBytes()); EmbeddedCacheManager cm = TestCacheManagerFactory.fromStream(is); GlobalConfiguration globalCfg = cm.getCacheManagerConfiguration(); assert globalCfg.transport().transport() instanceof JGroupsTransport; assert globalCfg.transport().clusterName().equals("demoCluster"); Configuration cfg = cm.getDefaultCacheConfiguration(); assert cfg.clustering().cacheMode() == CacheMode.REPL_SYNC; }
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(); } }
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(); } }
private void loadForeignMarshallables(GlobalConfiguration globalCfg) { log.trace("Loading user defined externalizers"); for (Map.Entry<Integer, AdvancedExternalizer<?>> config : globalCfg.serialization().advancedExternalizers().entrySet()) { AdvancedExternalizer<?> ext = config.getValue(); // If no XML or programmatic config, id in annotation is used // as long as it's not default one (meaning, user did not set it). // If XML or programmatic config in use ignore @Marshalls annotation and use value in config. Integer id = ext.getId(); if (config.getKey() == null && id == null) throw new CacheConfigurationException( String.format( "No advanced externalizer identifier set for externalizer %s", ext.getClass().getName())); else if (config.getKey() != null) id = config.getKey(); id = checkForeignIdLimit(id, ext); updateExtReadersWritersWithTypes( new ForeignExternalizerAdapter(id, ext), generateForeignReaderIndex(id)); } }
@Override public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalCfg) { Map<Integer, AdvancedExternalizer<?>> externalizerMap = globalCfg.serialization().advancedExternalizers(); externalizerMap.put( ExternalizerIds.PROTOBUF_VALUE_WRAPPER, new ProtobufValueWrapper.Externalizer()); externalizerMap.put( ExternalizerIds.JPA_PROTOBUF_CACHE_EVENT_FILTER_CONVERTER, new JPAProtobufCacheEventFilterConverter.Externalizer()); externalizerMap.put( ExternalizerIds.JPA_PROTOBUF_FILTER_AND_CONVERTER, new JPAProtobufFilterAndConverter.Externalizer()); externalizerMap.put( ExternalizerIds.JPA_CONTINUOUS_QUERY_CACHE_EVENT_FILTER_CONVERTER, new JPAContinuousQueryProtobufCacheEventFilterConverter.Externalizer()); externalizerMap.put( ExternalizerIds.JPA_BINARY_PROTOBUF_FILTER_AND_CONVERTER, new JPABinaryProtobufFilterAndConverter.Externalizer()); externalizerMap.put( ExternalizerIds.JPA_CONTINUOUS_QUERY_RESULT, new ContinuousQueryResultExternalizer()); externalizerMap.put(ExternalizerIds.JPA_FILTER_RESULT, new FilterResultExternalizer()); }
/** * Looks up the {@link javax.management.MBeanServer} instance based on the configuration * parameters. * * @param cfg configuration instance indicating how to lookup the {@link * javax.management.MBeanServer} * @return an instance of {@link javax.management.MBeanServer} */ public static MBeanServer lookupMBeanServer(GlobalConfiguration cfg) { MBeanServerLookup lookup = cfg.globalJmxStatistics().mbeanServerLookup(); return lookup.getMBeanServer(cfg.globalJmxStatistics().properties()); }
private int getGlobalTimeout() { // TODO Rename setting to something like globalRpcTimeout return (int) globalConfiguration.transport().distributedSyncTimeout(); }
private void assertNamedCacheFile(EmbeddedCacheManager cm) { final GlobalConfiguration gc = cm.getCacheManagerConfiguration(); assert gc.asyncListenerExecutor().factory() instanceof DefaultExecutorFactory; assert gc.asyncListenerExecutor().properties().getProperty("maxThreads").equals("5"); assert gc.asyncListenerExecutor() .properties() .getProperty("threadNamePrefix") .equals("AsyncListenerThread"); assert gc.asyncTransportExecutor().factory() instanceof DefaultExecutorFactory; assert gc.asyncTransportExecutor().properties().getProperty("maxThreads").equals("25"); assert gc.asyncTransportExecutor() .properties() .getProperty("threadNamePrefix") .equals("AsyncSerializationThread"); assert gc.evictionScheduledExecutor().factory() instanceof DefaultScheduledExecutorFactory; assert gc.evictionScheduledExecutor() .properties() .getProperty("threadNamePrefix") .equals("EvictionThread"); assert gc.replicationQueueScheduledExecutor().factory() instanceof DefaultScheduledExecutorFactory; assert gc.replicationQueueScheduledExecutor() .properties() .getProperty("threadNamePrefix") .equals("ReplicationQueueThread"); assert gc.transport().transport() instanceof JGroupsTransport; assert gc.transport().clusterName().equals("infinispan-cluster"); assert gc.transport().nodeName().equals("Jalapeno"); assert gc.transport().distributedSyncTimeout() == 50000; assert gc.shutdown().hookBehavior().equals(ShutdownHookBehavior.REGISTER); assert gc.serialization().marshaller() instanceof VersionAwareMarshaller; assert gc.serialization().version() == Version.getVersionShort("1.0"); final Map<Integer, AdvancedExternalizer<?>> externalizers = gc.serialization().advancedExternalizers(); assert externalizers.size() == 3; assert externalizers.get(1234) instanceof AdvancedExternalizerTest.IdViaConfigObj.Externalizer; assert externalizers.get(5678) instanceof AdvancedExternalizerTest.IdViaAnnotationObj.Externalizer; assert externalizers.get(3456) instanceof AdvancedExternalizerTest.IdViaBothObj.Externalizer; Configuration defaultCfg = cm.getDefaultCacheConfiguration(); assert defaultCfg.locking().lockAcquisitionTimeout() == 1000; assert defaultCfg.locking().concurrencyLevel() == 100; assert defaultCfg.locking().isolationLevel() == IsolationLevel.READ_COMMITTED; Configuration c = cm.getCacheConfiguration("transactional"); assert !c.clustering().cacheMode().isClustered(); assert c.transaction().transactionManagerLookup() instanceof GenericTransactionManagerLookup; assert c.transaction().useEagerLocking(); assert c.transaction().eagerLockingSingleNode(); assert !c.transaction().syncRollbackPhase(); c = cm.getCacheConfiguration("transactional2"); assert c.transaction().transactionManagerLookup() instanceof Lookup; assert c.transaction().cacheStopTimeout() == 10000; assert c.transaction().lockingMode().equals(LockingMode.PESSIMISTIC); assert !c.transaction().autoCommit(); c = cm.getCacheConfiguration("syncRepl"); assert c.clustering().cacheMode() == CacheMode.REPL_SYNC; assert !c.clustering().stateRetrieval().fetchInMemoryState(); assert c.clustering().sync().replTimeout() == 15000; c = cm.getCacheConfiguration("asyncRepl"); assert c.clustering().cacheMode() == CacheMode.REPL_ASYNC; assert !c.clustering().async().useReplQueue(); assert !c.clustering().async().asyncMarshalling(); assert !c.clustering().stateRetrieval().fetchInMemoryState(); c = cm.getCacheConfiguration("asyncReplQueue"); assert c.clustering().cacheMode() == CacheMode.REPL_ASYNC; assert c.clustering().async().useReplQueue(); assert !c.clustering().async().asyncMarshalling(); assert !c.clustering().stateRetrieval().fetchInMemoryState(); c = cm.getCacheConfiguration("txSyncRepl"); assert c.transaction().transactionManagerLookup() instanceof GenericTransactionManagerLookup; assert c.clustering().cacheMode() == CacheMode.REPL_SYNC; assert !c.clustering().stateRetrieval().fetchInMemoryState(); assert c.clustering().sync().replTimeout() == 15000; c = cm.getCacheConfiguration("overriding"); assert c.clustering().cacheMode() == CacheMode.LOCAL; assert c.locking().lockAcquisitionTimeout() == 20000; assert c.locking().concurrencyLevel() == 1000; assert c.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ; assert !c.storeAsBinary().enabled(); c = cm.getCacheConfiguration("storeAsBinary"); assert c.storeAsBinary().enabled(); c = cm.getCacheConfiguration("withLoader"); assert c.loaders().preload(); assert !c.loaders().passivation(); assert !c.loaders().shared(); assert c.loaders().cacheLoaders().size() == 1; FileCacheStoreConfiguration loaderCfg = (FileCacheStoreConfiguration) c.loaders().cacheLoaders().get(0); assert loaderCfg.fetchPersistentState(); assert loaderCfg.ignoreModifications(); assert loaderCfg.purgeOnStartup(); assert loaderCfg.location().equals("/tmp/FileCacheStore-Location"); assert loaderCfg.fsyncMode() == FileCacheStoreConfigurationBuilder.FsyncMode.PERIODIC; assert loaderCfg.fsyncInterval() == 2000; assert loaderCfg.singletonStore().pushStateTimeout() == 20000; assert loaderCfg.singletonStore().pushStateWhenCoordinator(); assert loaderCfg.async().threadPoolSize() == 5; assert loaderCfg.async().flushLockTimeout() == 15000; assert loaderCfg.async().enabled(); assert loaderCfg.async().modificationQueueSize() == 700; c = cm.getCacheConfiguration("withLoaderDefaults"); loaderCfg = (FileCacheStoreConfiguration) c.loaders().cacheLoaders().get(0); assert loaderCfg.location().equals("/tmp/Another-FileCacheStore-Location"); assert loaderCfg.fsyncMode() == FileCacheStoreConfigurationBuilder.FsyncMode.DEFAULT; c = cm.getCacheConfiguration("withouthJmxEnabled"); assert !c.jmxStatistics().enabled(); assert gc.globalJmxStatistics().enabled(); assert gc.globalJmxStatistics().allowDuplicateDomains(); assert gc.globalJmxStatistics().domain().equals("funky_domain"); assert gc.globalJmxStatistics().mbeanServerLookup() instanceof PerThreadMBeanServerLookup; c = cm.getCacheConfiguration("dist"); assert c.clustering().cacheMode() == CacheMode.DIST_SYNC; assert c.clustering().l1().lifespan() == 600000; assert c.clustering().hash().rehashRpcTimeout() == 120000; assert c.clustering().stateTransfer().timeout() == 120000; assert c.clustering().hash().consistentHash() instanceof TopologyAwareConsistentHash; assert c.clustering().hash().numOwners() == 3; assert c.clustering().l1().enabled(); c = cm.getCacheConfiguration("groups"); assert c.clustering().hash().groups().enabled(); assert c.clustering().hash().groups().groupers().size() == 1; assert c.clustering().hash().groups().groupers().get(0).getKeyType().equals(String.class); c = cm.getCacheConfiguration("chunkSize"); assert c.clustering().stateTransfer().fetchInMemoryState(); assert c.clustering().stateTransfer().timeout() == 120000; assert c.clustering().stateTransfer().chunkSize() == 1000; c = cm.getCacheConfiguration("cacheWithCustomInterceptors"); assert !c.customInterceptors().interceptors().isEmpty(); assert c.customInterceptors().interceptors().size() == 5; c = cm.getCacheConfiguration("evictionCache"); assert c.eviction().maxEntries() == 5000; assert c.eviction().strategy().equals(EvictionStrategy.FIFO); assert c.expiration().lifespan() == 60000; assert c.expiration().maxIdle() == 1000; assert c.eviction().threadPolicy() == EvictionThreadPolicy.PIGGYBACK; assert c.expiration().wakeUpInterval() == 500; c = cm.getCacheConfiguration("withDeadlockDetection"); assert c.deadlockDetection().enabled(); assert c.deadlockDetection().spinDuration() == 1221; assert c.clustering().cacheMode() == CacheMode.DIST_SYNC; c = cm.getCacheConfiguration("storeKeyValueBinary"); assert c.storeAsBinary().enabled(); assert c.storeAsBinary().storeKeysAsBinary(); assert !c.storeAsBinary().storeValuesAsBinary(); }
private void writeThreads(XMLExtendedStreamWriter writer, GlobalConfiguration globalConfiguration) throws XMLStreamException { writer.writeStartElement(Element.THREADS); ConcurrentMap<String, DefaultThreadFactory> threadFactories = CollectionFactory.makeConcurrentMap(); for (ThreadPoolConfiguration threadPoolConfiguration : Arrays.asList( globalConfiguration.expirationThreadPool(), globalConfiguration.listenerThreadPool(), globalConfiguration.persistenceThreadPool(), globalConfiguration.replicationQueueThreadPool(), globalConfiguration.stateTransferThreadPool(), globalConfiguration.transport().remoteCommandThreadPool(), globalConfiguration.transport().transportThreadPool())) { ThreadFactory threadFactory = threadPoolConfiguration.threadFactory(); if (threadFactory instanceof DefaultThreadFactory) { DefaultThreadFactory tf = (DefaultThreadFactory) threadFactory; threadFactories.putIfAbsent(tf.getName(), tf); } } for (DefaultThreadFactory threadFactory : threadFactories.values()) { writeThreadFactory(writer, threadFactory); } writeThreadPool(writer, "async-pool", globalConfiguration.asyncThreadPool()); writeThreadPool(writer, "expiration-pool", globalConfiguration.expirationThreadPool()); writeThreadPool(writer, "listener-pool", globalConfiguration.listenerThreadPool()); writeThreadPool(writer, "persistence-pool", globalConfiguration.persistenceThreadPool()); writeThreadPool( writer, "replication-queue-pool", globalConfiguration.replicationQueueThreadPool()); writeThreadPool(writer, "state-transfer-pool", globalConfiguration.stateTransferThreadPool()); writeThreadPool( writer, "remote-command-pool", globalConfiguration.transport().remoteCommandThreadPool()); writeThreadPool( writer, "transport-pool", globalConfiguration.transport().transportThreadPool()); writer.writeEndElement(); }