Refine search
@Override @SuppressWarnings("unchecked") // on purpose, it would not work otherwise public Set getTypeClasses() { return Util.asSet(List[].class); } }
/** * Constructs a {@link ConnectionFactory} based on the supplied class * name. */ public static ConnectionFactory getConnectionFactory(Class<? extends ConnectionFactory> connectionFactoryClass) throws PersistenceException { return Util.getInstance(connectionFactoryClass); }
public TransactionManager tryLookup(ClassLoader classLoader) { Class<?> clazz; try { clazz = Util.loadClassStrict(factoryClazz, classLoader); Method method = clazz.getMethod(factoryMethod); return (TransactionManager) method.invoke(null); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { return null; } } }
@Override public String toString() { return "KeyEvent{" + "version=" + version + ", messageId=" + messageId + ", op=" + op + ", listenerId=" + Util.printArray(listenerId, false) + ", isRetried=" + isRetried + ", key=" + Util.toStr(key) + '}'; }
/** * Similar to {@link #getInstance(String, ClassLoader)} except that exceptions are propagated to the caller. * * @param classname class to instantiate * @return an instance of classname * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException */ public static <T> T getInstanceStrict(String classname, ClassLoader cl) throws ClassNotFoundException, InstantiationException, IllegalAccessException { if (classname == null) throw new IllegalArgumentException("Cannot load null class!"); Class<T> clazz = loadClassStrict(classname, cl); return getInstanceStrict(clazz); }
public static StreamingMarshaller getMarshaller(StoreProperties props) { switch (getMarshallerType(props)) { case CURRENT: if (props.isTargetStore()) return null; GlobalConfigurationBuilder globalConfig = new GlobalConfigurationBuilder() .defaultCacheName(props.cacheName()); configureExternalizers(props, globalConfig.serialization()); EmbeddedCacheManager manager = new DefaultCacheManager(globalConfig.build(), new ConfigurationBuilder().build()); return manager.getCache().getAdvancedCache().getComponentRegistry().getComponent(StreamingMarshaller.class); case CUSTOM: String marshallerClass = props.get(MARSHALLER, CLASS); if (marshallerClass == null) throw new CacheConfigurationException( String.format("The property %s.%s must be set if a custom marshaller type is specified", MARSHALLER, CLASS)); try { return (StreamingMarshaller) Util.loadClass(marshallerClass, SerializationConfigUtil.class.getClassLoader()).newInstance(); } catch (IllegalAccessException | InstantiationException e) { throw new CacheConfigurationException(String.format("Unable to load StreamingMarshaller '%s' for %s store", marshallerClass, SOURCE), e); } case LEGACY: if (props.isTargetStore()) throw new CacheConfigurationException("The legacy marshaller can only be specified for source stores."); return new LegacyVersionAwareMarshaller(getExternalizersFromProps(props)); default: throw new IllegalStateException("Unexpected marshaller type"); } }
protected void createStatefulCacheManager(String id, boolean clear) { String stateDirectory = TestingUtil.tmpDirectory(this.getClass().getSimpleName() + File.separator + id); if (clear) Util.recursiveFileRemove(stateDirectory); GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder(); global.globalState().enable().persistentLocation(stateDirectory). configurationStorage(ConfigurationStorage.OVERLAY); if (isShared()) { String sharedDirectory = TestingUtil.tmpDirectory(this.getClass().getSimpleName() + File.separator + "COMMON"); global.globalState().sharedPersistentLocation(sharedDirectory); } else { global.globalState().sharedPersistentLocation(stateDirectory); } ConfigurationBuilder builder = new ConfigurationBuilder(); builder.clustering().cacheMode(CacheMode.DIST_SYNC); addClusterEnabledCacheManager(global, builder); }
private void createStatefulCacheManager(String id, boolean clear) { String stateDirectory = TestingUtil.tmpDirectory(this.getClass().getSimpleName() + File.separator + id); if (clear) Util.recursiveFileRemove(stateDirectory); GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder(); global.globalState().enable().persistentLocation(stateDirectory); ConfigurationBuilder config = new ConfigurationBuilder(); applyCacheManagerClusteringConfiguration(config); config.persistence().addSingleFileStore().location(stateDirectory); addClusterEnabledCacheManager(global, config); }
@BeforeMethod(alwaysRun = true) public void setUp() throws Exception { tmpDirectory = TestingUtil.tmpDirectory(this.getClass()); Util.recursiveFileRemove(tmpDirectory); marshaller = new TestObjectStreamMarshaller(); factory = new InternalEntryFactoryImpl(); store = new SoftIndexFileStore(); ConfigurationBuilder builder = TestCacheManagerFactory .getDefaultCacheConfiguration(false); log.info("Using directory " + tmpDirectory); builder.persistence() .addStore(SoftIndexFileStoreConfigurationBuilder.class) .indexLocation(tmpDirectory).dataLocation(tmpDirectory + "/data") .purgeOnStartup(false) .maxFileSize(1000); timeService = new EmbeddedTimeService(); store.init(PersistenceMockUtil.createContext(getClass().getSimpleName(), builder.build(), marshaller, timeService)); TestingUtil.inject(factory, timeService); store.start(); executorService = Executors.newFixedThreadPool(THREADS + 1); }
public void testParsingElement() throws Exception { String config = TestingUtil.wrapXMLWithoutSchema( "<cache-container default-cache=\"default\">" + " <local-cache name=\"default\">\n" + " <persistence passivation=\"false\"> \n" + " <file-store path=\"other-location\" max-entries=\"100\" shared=\"false\" preload=\"true\" fragmentation-factor=\"0.75\"/> \n" + " </persistence>\n" + " </local-cache>\n" + "</cache-container>"); InputStream is = new ByteArrayInputStream(config.getBytes()); ConfigurationBuilderHolder holder = new ParserRegistry().parse(config); List<StoreConfiguration> storeConfigs = holder.getDefaultConfigurationBuilder().build().persistence().stores(); assertEquals(1, storeConfigs.size()); SingleFileStoreConfiguration fileStoreConfig = (SingleFileStoreConfiguration) storeConfigs.get(0); assertEquals("other-location", fileStoreConfig.location()); assertEquals(100, fileStoreConfig.maxEntries()); assertEquals(0.75f, fileStoreConfig.fragmentationFactor(), 0f); Util.recursiveFileRemove("other-location"); }
private void parseHash(final XMLExtendedStreamReader reader, final ConfigurationBuilderHolder holder) throws XMLStreamException { ConfigurationBuilder builder = holder.getCurrentConfigurationBuilder(); for (int i = 0; i < reader.getAttributeCount(); i++) { ParseUtils.requireNoNamespaceAttribute(reader, i); switch (attribute) { case FACTORY: builder.clustering().hash().consistentHashFactory(Util.<ConsistentHashFactory>getInstance(value, holder.getClassLoader())); break; case HASH_FUNCTION_CLASS: builder.clustering().hash().hash(Util.<Hash>getInstance(value, holder.getClassLoader())); break; case NUM_OWNERS: builder.clustering().hash().numOwners(Integer.parseInt(value)); break; case NUM_SEGMENTS:
@Override protected void createCacheManagers() throws Throwable { Util.recursiveFileRemove(tmpDirectory); ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.persistence() .addStore(SingleFileStoreConfigurationBuilder.class) .location(tmpDirectory); // ensure the data container contains minimal data so the store will need to be accessed to get the rest cfg.locking().concurrencyLevel(1).dataContainer().memory().size(1L); createClusteredCaches(1, cfg); } }
private void parseStore(final XMLExtendedStreamReader reader, final ConfigurationBuilderHolder holder) throws XMLStreamException { ConfigurationBuilder builder = holder.getCurrentConfigurationBuilder(); CacheLoader store = null; Boolean fetchPersistentState = null; switch (attribute) { case CLASS: store = Util.getInstance(value, holder.getClassLoader()); break; case FETCH_PERSISTENT_STATE: AbstractStoreConfigurationBuilder storeConfigurationBuilder = null; if (store instanceof SingleFileStore) { storeConfigurationBuilder = builder.persistence().addSingleFileStore(); parseStoreChildren(reader, storeConfigurationBuilder); } else if (store instanceof ClusterLoader) { storeConfigurationBuilder = builder.persistence().addClusterLoader(); parseLoaderChildren(reader, storeConfigurationBuilder);
private void parseTransaction(final XMLExtendedStreamReader reader, final ConfigurationBuilderHolder holder) throws XMLStreamException { ConfigurationBuilder builder = holder.getCurrentConfigurationBuilder(); boolean forceSetTransactional = false; boolean transactionModeSpecified = false; switch (attribute) { case AUTO_COMMIT: builder.transaction().autoCommit(Boolean.parseBoolean(value)); break; case CACHE_STOP_TIMEOUT: builder.transaction().cacheStopTimeout(Long.parseLong(value)); break; case EAGER_LOCK_SINGLE_NODE: break; case LOCKING_MODE: builder.transaction().lockingMode(LockingMode.valueOf(value)); break; case SYNC_COMMIT_PHASE: break; case TRANSACTION_MANAGER_LOOKUP_CLASS: builder.transaction().transactionManagerLookup(Util.<TransactionManagerLookup>getInstance(value, holder.getClassLoader())); forceSetTransactional = true; break;
@AfterClass(alwaysRun = true) protected void clearTempDir() { Util.recursiveFileRemove(tmpDirectory); }
@Override protected void createCacheManagers() { tmpDir = new File(TestingUtil.tmpDirectory(this.getClass())); Util.recursiveFileRemove(tmpDir); // reproduce the MODE-1754 config as closely as possible builder = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, true, true); builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL).lockingMode(LockingMode.PESSIMISTIC) .transactionManagerLookup(new EmbeddedTransactionManagerLookup()) .memory().size(1000) .locking().lockAcquisitionTimeout(20000) .concurrencyLevel(5000) // lowering this to 50 makes the test pass also on 5.2 but it's just a temporary workaround .useLockStriping(false).isolationLevel(IsolationLevel.READ_COMMITTED) .dataContainer().storeAsBinary() .clustering().remoteTimeout(20000) .stateTransfer().timeout(240000).fetchInMemoryState(false).chunkSize(10000) .persistence().passivation(false).addSingleFileStore().location(new File(tmpDir, "store0").getAbsolutePath()).shared(false).preload(false) .fetchPersistentState(true) .ignoreModifications(false) .purgeOnStartup(false); createCluster(builder, 1); waitForClusterToForm(); }
private static void markAsTransactional(boolean transactional, ConfigurationBuilder builder) { if (!transactional) { builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); } else { builder.transaction() .transactionMode(TransactionMode.TRANSACTIONAL); if (!Util.isOSGiContext()) { //automatically change default TM lookup to the desired one but only outside OSGi. In OSGi we need to use GenericTransactionManagerLookup builder.transaction().transactionManagerLookup(Util.getInstance(TransactionSetup.getManagerLookup(), TestCacheManagerFactory.class.getClassLoader())); } } }
private void parseInterceptor(final XMLExtendedStreamReader reader, final ConfigurationBuilderHolder holder) throws XMLStreamException { ConfigurationBuilder builder = holder.getCurrentConfigurationBuilder(); InterceptorConfigurationBuilder interceptorBuilder = builder.customInterceptors().addInterceptor(); switch (attribute) { case AFTER: interceptorBuilder.after(Util.<CommandInterceptor>loadClass(value, holder.getClassLoader())); break; case BEFORE: interceptorBuilder.before(Util.<CommandInterceptor>loadClass(value, holder.getClassLoader())); break; case CLASS: try { interceptorBuilder.interceptorClass(Util.loadClassStrict(value, holder.getClassLoader()).asSubclass(CommandInterceptor.class)); } catch (ClassNotFoundException e) { throw new CacheConfigurationException(e);
private static void amendJTA(ConfigurationBuilder builder) { if (builder.transaction().transactionMode() == TransactionMode.TRANSACTIONAL && builder.transaction().transactionManagerLookup() == null) { builder.transaction().transactionManagerLookup(Util.getInstance(TransactionSetup.getManagerLookup(), TestCacheManagerFactory.class.getClassLoader())); } }