/** {@inheritDoc} */ @Override public T create() { synchronized (this) { if (singleton) { if (instance == null) instance = createInstance(); return instance; } return createInstance(); } }
/** * @return Initialized instance. */ private T createInstance() { if (cls == null) throw new IllegalStateException("Failed to create object (object type is not set)."); try { T obj = cls.newInstance(); injectProperties(obj); return obj; } catch (InstantiationException | IllegalAccessException e) { throw new CacheException("Failed to instantiate factory object: " + cls.getName(), e); } }
/** * @param obj Object to initialize with properties. */ private void injectProperties(T obj) { if (!F.isEmpty(props)) { for (Map.Entry<String, Serializable> entry : props.entrySet()) { String fieldName = entry.getKey().trim(); if (fieldName.isEmpty()) continue; Serializable val = entry.getValue(); setWithMethod(obj, fieldName, val); } } }
props.put("booleanField", expBooleanVal); IgniteReflectionFactory<TestClass> factory = new IgniteReflectionFactory<>(TestClass.class); factory.setProperties(props); TestClass instance = factory.create();
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE); IgniteConfiguration c = super.getConfiguration(igniteInstanceName); CacheConfiguration cc = defaultCacheConfiguration(); cc.setCacheMode(cacheMode); if (nearEnabled) cc.setNearConfiguration(new NearCacheConfiguration()); cc.setAtomicityMode(TRANSACTIONAL); cc.setCacheStoreFactory(new IgniteReflectionFactory<CacheStore>(TestStore.class)); cc.setReadThrough(true); cc.setWriteThrough(true); cc.setLoadPreviousValue(true); c.setCacheConfiguration(cc); c.setIncludeEventTypes(EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED); return c; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); DataStorageConfiguration dbCfg = new DataStorageConfiguration(); dbCfg .setDefaultDataRegionConfiguration( new DataRegionConfiguration() .setMaxSize(512L * 1024 * 1024) .setPersistenceEnabled(true)) .setWalMode(WALMode.LOG_ONLY); cfg.setDataStorageConfiguration(dbCfg); CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(CACHE_NAME) .setCacheStoreFactory(new IgniteReflectionFactory<>(TestStore.class)) .setAtomicityMode(atomicityMode) .setBackups(1) .setWriteThrough(true) .setReadThrough(true); cfg.setCacheConfiguration(ccfg); return cfg; }
boolean res = setWithMethod(obj, mtdName, val, paramCls); return false; res = setWithMethod(obj, mtdName, val, paramCls);
cc.setCacheStoreFactory(new IgniteReflectionFactory<CacheStore>(TestStore.class)); cc.setReadThrough(true); cc.setWriteThrough(true);
/** {@inheritDoc} */ @Override public T create() { synchronized (this) { if (singleton) { if (instance == null) instance = createInstance(); return instance; } return createInstance(); } }
/** * @return Initialized instance. */ private T createInstance() { if (cls == null) throw new IllegalStateException("Failed to create object (object type is not set)."); try { T obj = cls.newInstance(); injectProperties(obj); return obj; } catch (InstantiationException | IllegalAccessException e) { throw new CacheException("Failed to instantiate factory object: " + cls.getName(), e); } }
/** * @param obj Object to initialize with properties. */ private void injectProperties(T obj) { if (!F.isEmpty(props)) { for (Map.Entry<String, Serializable> entry : props.entrySet()) { String fieldName = entry.getKey().trim(); if (fieldName.isEmpty()) continue; Serializable val = entry.getValue(); setWithMethod(obj, fieldName, val); } } }
boolean res = setWithMethod(obj, mtdName, val, paramCls); return false; res = setWithMethod(obj, mtdName, val, paramCls);