private static ConsistentHash constructConsistentHashInstance(Configuration c) { Class<? extends ConsistentHash> chClass = Util.loadClass(c.getConsistentHashClass(), c.getClassLoader()); Hash h = (Hash) Util.getInstance(c.getHashFunctionClass(), c.getClassLoader()); HashSeed hs = c.getHashSeed() != null ? c.getHashSeed() : (HashSeed) Util.getInstance(c.getHashSeedClass(), c.getClassLoader()); return constructConsistentHashInstance( chClass, h, hs, c.getNumVirtualNodes(), new GroupManagerImpl(c.getGroupers())); }
@Override public void start() throws CacheLoaderException { try { dataSource = new DataSource(config.getPoolProperties()); readConsistencyLevel = ConsistencyLevel.valueOf(config.readConsistencyLevel); writeConsistencyLevel = ConsistencyLevel.valueOf(config.writeConsistencyLevel); entryColumnPath = new ColumnPath(config.entryColumnFamily) .setColumn(ENTRY_COLUMN_NAME.getBytes(UTF8Charset)); entryColumnParent = new ColumnParent(config.entryColumnFamily); entryKeyPrefix = ENTRY_KEY_PREFIX + (config.isSharedKeyspace() ? cacheName + "_" : ""); expirationColumnParent = new ColumnParent(config.expirationColumnFamily); expirationKey = ByteBufferUtil.bytes(EXPIRATION_KEY + (config.isSharedKeyspace() ? "_" + cacheName : "")); keyMapper = (TwoWayKey2StringMapper) Util.getInstance(config.getKeyMapper()); } catch (Exception e) { throw new ConfigurationException(e); } log.debug("cleaning up expired entries..."); purgeInternal(); log.debug("started"); super.start(); }
private static ConsistentHash constructConsistentHashInstance( Class<? extends ConsistentHash> clazz, Hash hashFunction, HashSeed hashSeed, int numVirtualNodes, GroupManager groupManager) { ConsistentHash ch = Util.getInstance(clazz); if (ch instanceof AbstractWheelConsistentHash) { AbstractWheelConsistentHash wch = (AbstractWheelConsistentHash) ch; wch.setHashFunction(hashFunction); wch.setHashSeed(hashSeed); wch.setNumVirtualNodes(numVirtualNodes); } if (ch instanceof AbstractConsistentHash) { AbstractConsistentHash ach = (AbstractConsistentHash) ch; if (groupManager != null) ach.setGroupManager(groupManager); } return ch; }
public TransportConfigurationBuilder defaultTransport() { transport(Util.getInstance(DEFAULT_TRANSPORT)); return this; }
// This is per CM, so the CL in use should be the CM CL private void buildChannel() { // in order of preference - we first look for an external JGroups file, then a set of XML // properties, and // finally the legacy JGroups String properties. String cfg; if (props != null) { if (props.containsKey(CHANNEL_LOOKUP)) { String channelLookupClassName = props.getProperty(CHANNEL_LOOKUP); try { JGroupsChannelLookup lookup = (JGroupsChannelLookup) Util.getInstance(channelLookupClassName, configuration.getClassLoader()); channel = lookup.getJGroupsChannel(props); startChannel = lookup.shouldStartAndConnect(); stopChannel = lookup.shouldStopAndDisconnect(); } catch (ClassCastException e) { log.wrongTypeForJGroupsChannelLookup(channelLookupClassName, e); throw new CacheException(e); } catch (Exception e) { log.errorInstantiatingJGroupsChannelLookup(channelLookupClassName, e); throw new CacheException(e); } if (configuration.isStrictPeerToPeer() && !startChannel) { log.warnStrictPeerToPeerWithInjectedChannel(); } } if (channel == null && props.containsKey(CONFIGURATION_FILE)) { cfg = props.getProperty(CONFIGURATION_FILE); try { channel = new JChannel( FileLookupFactory.newInstance() .lookupFileLocation(cfg, configuration.getClassLoader())); } catch (Exception e) { log.errorCreatingChannelFromConfigFile(cfg); throw new CacheException(e); } } if (channel == null && props.containsKey(CONFIGURATION_XML)) { cfg = props.getProperty(CONFIGURATION_XML); try { channel = new JChannel(XmlConfigHelper.stringToElement(cfg)); } catch (Exception e) { log.errorCreatingChannelFromXML(cfg); throw new CacheException(e); } } if (channel == null && props.containsKey(CONFIGURATION_STRING)) { cfg = props.getProperty(CONFIGURATION_STRING); try { channel = new JChannel(cfg); } catch (Exception e) { log.errorCreatingChannelFromConfigString(cfg); throw new CacheException(e); } } } if (channel == null) { log.unableToUseJGroupsPropertiesProvided(props); try { channel = new JChannel( FileLookupFactory.newInstance() .lookupFileLocation( DEFAULT_JGROUPS_CONFIGURATION_FILE, configuration.getClassLoader())); } catch (Exception e) { throw new CacheException("Unable to start JGroups channel", e); } } }
/** * Configures whether global statistics are gathered and reported via JMX for all caches under this * cache manager. */ public class GlobalJmxStatisticsConfigurationBuilder extends AbstractGlobalConfigurationBuilder<GlobalJmxStatisticsConfiguration> { private Properties properties = new Properties(); private String jmxDomain = "org.infinispan"; private Boolean allowDuplicateDomains = false; private String cacheManagerName = "DefaultCacheManager"; private MBeanServerLookup mBeanServerLookupInstance = Util.getInstance(PlatformMBeanServerLookup.class); private boolean enabled = false; GlobalJmxStatisticsConfigurationBuilder(GlobalConfigurationBuilder globalConfig) { super(globalConfig); } /** * Sets properties which are then passed to the MBean Server Lookup implementation specified. * * @param properties properties to pass to the MBean Server Lookup */ public GlobalJmxStatisticsConfigurationBuilder withProperties(Properties properties) { this.properties = properties; return this; } public GlobalJmxStatisticsConfigurationBuilder addProperty(String key, String value) { properties.put(key, value); return this; } /** * If JMX statistics are enabled then all 'published' JMX objects will appear under this name. * This is optional, if not specified an object name will be created for you by default. * * @param jmxDomain */ public GlobalJmxStatisticsConfigurationBuilder jmxDomain(String jmxDomain) { this.jmxDomain = jmxDomain; return this; } /** * If true, multiple cache manager instances could be configured under the same configured JMX * domain. Each cache manager will in practice use a different JMX domain that has been calculated * based on the configured one by adding an incrementing index to it. * * @param allowDuplicateDomains */ public GlobalJmxStatisticsConfigurationBuilder allowDuplicateDomains( Boolean allowDuplicateDomains) { this.allowDuplicateDomains = allowDuplicateDomains; return this; } /** * If JMX statistics are enabled, this property represents the name of this cache manager. It * offers the possibility for clients to provide a user-defined name to the cache manager which * later can be used to identify the cache manager within a JMX based management tool amongst * other cache managers that might be running under the same JVM. * * @param cacheManagerName */ public GlobalJmxStatisticsConfigurationBuilder cacheManagerName(String cacheManagerName) { this.cacheManagerName = cacheManagerName; return this; } /** * Sets the instance of the {@link org.infinispan.jmx.MBeanServerLookup} class to be used to bound * JMX MBeans to. * * @param mBeanServerLookupInstance An instance of {@link org.infinispan.jmx.MBeanServerLookup} */ public GlobalJmxStatisticsConfigurationBuilder mBeanServerLookup( MBeanServerLookup mBeanServerLookupInstance) { this.mBeanServerLookupInstance = mBeanServerLookupInstance; return this; } public GlobalJmxStatisticsConfigurationBuilder disable() { this.enabled = false; return this; } public GlobalJmxStatisticsConfigurationBuilder enable() { this.enabled = true; return this; } public GlobalJmxStatisticsConfigurationBuilder enabled(boolean enabled) { this.enabled = enabled; return this; } @Override void validate() { // No-op, no validation required } @Override GlobalJmxStatisticsConfiguration create() { return new GlobalJmxStatisticsConfiguration( enabled, jmxDomain, mBeanServerLookupInstance, allowDuplicateDomains, cacheManagerName, TypedProperties.toTypedProperties(properties)); } @Override protected GlobalJmxStatisticsConfigurationBuilder read( GlobalJmxStatisticsConfiguration template) { this.allowDuplicateDomains = template.allowDuplicateDomains(); this.cacheManagerName = template.cacheManagerName(); this.enabled = template.enabled(); this.jmxDomain = template.domain(); this.mBeanServerLookupInstance = template.mbeanServerLookup(); this.properties = template.properties(); return this; } @Override public String toString() { return "GlobalJmxStatisticsConfigurationBuilder{" + "allowDuplicateDomains=" + allowDuplicateDomains + ", properties=" + properties + ", jmxDomain='" + jmxDomain + '\'' + ", cacheManagerName='" + cacheManagerName + '\'' + ", mBeanServerLookupInstance=" + mBeanServerLookupInstance + ", enabled=" + enabled + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; GlobalJmxStatisticsConfigurationBuilder that = (GlobalJmxStatisticsConfigurationBuilder) o; if (enabled != that.enabled) return false; if (allowDuplicateDomains != null ? !allowDuplicateDomains.equals(that.allowDuplicateDomains) : that.allowDuplicateDomains != null) return false; if (cacheManagerName != null ? !cacheManagerName.equals(that.cacheManagerName) : that.cacheManagerName != null) return false; if (jmxDomain != null ? !jmxDomain.equals(that.jmxDomain) : that.jmxDomain != null) return false; if (mBeanServerLookupInstance != null ? !mBeanServerLookupInstance.equals(that.mBeanServerLookupInstance) : that.mBeanServerLookupInstance != null) return false; if (properties != null ? !properties.equals(that.properties) : that.properties != null) return false; return true; } @Override public int hashCode() { int result = properties != null ? properties.hashCode() : 0; result = 31 * result + (jmxDomain != null ? jmxDomain.hashCode() : 0); result = 31 * result + (allowDuplicateDomains != null ? allowDuplicateDomains.hashCode() : 0); result = 31 * result + (cacheManagerName != null ? cacheManagerName.hashCode() : 0); result = 31 * result + (mBeanServerLookupInstance != null ? mBeanServerLookupInstance.hashCode() : 0); result = 31 * result + (enabled ? 1 : 0); return result; } }
/** * Name of the class implementing Key2StringMapper. The default value is {@link * org.infinispan.loaders.keymappers.DefaultTwoWayKey2StringMapper} * * @see org.infinispan.loaders.keymappers.Key2StringMapper */ public void setKey2StringMapperClass(String className) { testImmutability("key2StringMapper"); key2StringMapper = (Key2StringMapper) Util.getInstance(className); }