use of org.apache.ignite.cache.store.CacheStoreSessionListener in project ignite by apache.
the class GridCacheStoreManagerAdapter method sessionInit0.
/**
* @param tx Current transaction.
* @throws IgniteCheckedException If failed.
*/
private void sessionInit0(@Nullable IgniteInternalTx tx) throws IgniteCheckedException {
assert sesHolder != null;
SessionData ses;
if (tx != null) {
ses = tx.meta(SES_ATTR);
if (ses == null) {
ses = new SessionData(tx, cctx.name());
tx.addMeta(SES_ATTR, ses);
} else
// Session cache name may change in cross-cache transaction.
ses.cacheName(cctx.name());
} else
ses = new SessionData(null, cctx.name());
sesHolder.set(ses);
try {
if (sesLsnrs != null && !ses.started(this)) {
for (CacheStoreSessionListener lsnr : sesLsnrs) lsnr.onSessionStart(locSes);
}
} catch (Exception e) {
throw new IgniteCheckedException("Failed to start store session: " + e, e);
}
}
use of org.apache.ignite.cache.store.CacheStoreSessionListener in project ignite by apache.
the class CacheSpringStoreExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteException {
ExamplesUtils.checkMinMemory(MIN_MEMORY);
// To start ignite with desired configuration uncomment the appropriate line.
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println(">>> Cache store example started.");
CacheConfiguration<Long, Person> cacheCfg = new CacheConfiguration<>(CACHE_NAME);
// Set atomicity as transaction, since we are showing transactions in example.
cacheCfg.setAtomicityMode(TRANSACTIONAL);
// Configure Spring store.
cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(CacheSpringPersonStore.class));
// Configure Spring session listener.
cacheCfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>() {
@Override
public CacheStoreSessionListener create() {
CacheSpringStoreSessionListener lsnr = new CacheSpringStoreSessionListener();
lsnr.setDataSource(CacheSpringPersonStore.DATA_SRC);
return lsnr;
}
});
cacheCfg.setReadThrough(true);
cacheCfg.setWriteThrough(true);
// Auto-close cache at the end of the example.
try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheCfg)) {
// Make initial cache loading from persistent store. This is a
// distributed operation and will call CacheStore.loadCache(...)
// method on all nodes in topology.
loadCache(cache);
// Start transaction and execute several cache operations with
// read/write-through to persistent store.
executeTransaction(cache);
} finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
ignite.destroyCache(CACHE_NAME);
}
}
}
use of org.apache.ignite.cache.store.CacheStoreSessionListener in project ignite by apache.
the class CacheHibernateStoreExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteException {
ExamplesUtils.checkMinMemory(MIN_MEMORY);
// To start ignite with desired configuration uncomment the appropriate line.
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println(">>> Cache store example started.");
CacheConfiguration<Long, Person> cacheCfg = new CacheConfiguration<>(CACHE_NAME);
// Set atomicity as transaction, since we are showing transactions in example.
cacheCfg.setAtomicityMode(TRANSACTIONAL);
// Configure Hibernate store.
cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(CacheHibernatePersonStore.class));
// Configure Hibernate session listener.
cacheCfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>() {
@Override
public CacheStoreSessionListener create() {
CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
lsnr.setHibernateConfigurationPath(HIBERNATE_CFG);
return lsnr;
}
});
cacheCfg.setReadThrough(true);
cacheCfg.setWriteThrough(true);
// Auto-close cache at the end of the example.
try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheCfg)) {
// Make initial cache loading from persistent store. This is a
// distributed operation and will call CacheStore.loadCache(...)
// method on all nodes in topology.
loadCache(cache);
// Start transaction and execute several cache operations with
// read/write-through to persistent store.
executeTransaction(cache);
} finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
ignite.destroyCache(CACHE_NAME);
}
}
}
use of org.apache.ignite.cache.store.CacheStoreSessionListener in project ignite by apache.
the class GridCacheProcessor method start.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "unchecked" })
@Override
public void start() throws IgniteCheckedException {
ctx.internalSubscriptionProcessor().registerMetastorageListener(recovery);
ctx.internalSubscriptionProcessor().registerDatabaseListener(recovery);
cachesInfo = new ClusterCachesInfo(ctx);
DeploymentMode depMode = ctx.config().getDeploymentMode();
if (!F.isEmpty(ctx.config().getCacheConfiguration())) {
if (depMode != CONTINUOUS && depMode != SHARED)
U.warn(log, "Deployment mode for cache is not CONTINUOUS or SHARED " + "(it is recommended that you change deployment mode and restart): " + depMode);
}
Collection<CacheStoreSessionListener> sessionListeners = CU.startStoreSessionListeners(ctx, ctx.config().getCacheStoreSessionListenerFactories());
sharedCtx = createSharedContext(ctx, sessionListeners);
locCfgMgr = new GridLocalConfigManager(this, ctx);
transactions = new IgniteTransactionsImpl(sharedCtx, null, false);
// Start shared managers.
for (GridCacheSharedManager mgr : sharedCtx.managers()) mgr.start(sharedCtx);
if (!ctx.isDaemon() && (!CU.isPersistenceEnabled(ctx.config())) || ctx.config().isClientMode()) {
CacheJoinNodeDiscoveryData data = locCfgMgr.restoreCacheConfigurations();
if (data != null)
cachesInfo.onStart(data);
}
if (log.isDebugEnabled())
log.debug("Started cache processor.");
ctx.state().cacheProcessorStarted();
ctx.systemView().registerFiltrableView(CACHE_GRP_PAGE_LIST_VIEW, CACHE_GRP_PAGE_LIST_VIEW_DESC, new CachePagesListViewWalker(), this::pagesListViewSupplier, Function.identity());
ctx.systemView().registerFiltrableView(PART_STATES_VIEW, PART_STATES_VIEW_DESC, new PartitionStateViewWalker(), this::partStatesViewSupplier, Function.identity());
ctx.systemView().registerView(CACHE_GRP_IO_VIEW, CACHE_GRP_IO_VIEW_DESC, new CacheGroupIoViewWalker(), () -> F.view(cacheGrps.values(), grp -> !grp.systemCache()), grpCtx -> {
MetricRegistry mreg = ctx.metric().registry(metricName(IoStatisticsType.CACHE_GROUP.metricGroupName(), grpCtx.cacheOrGroupName()));
return new CacheGroupIoView(grpCtx, mreg);
});
}
use of org.apache.ignite.cache.store.CacheStoreSessionListener in project ignite by apache.
the class GridCacheUtils method startStoreSessionListeners.
/**
* Creates and starts store session listeners.
*
* @param ctx Kernal context.
* @param factories Factories.
* @return Listeners.
* @throws IgniteCheckedException In case of error.
*/
public static Collection<CacheStoreSessionListener> startStoreSessionListeners(GridKernalContext ctx, Factory<CacheStoreSessionListener>[] factories) throws IgniteCheckedException {
if (factories == null)
return null;
Collection<CacheStoreSessionListener> lsnrs = new ArrayList<>(factories.length);
for (Factory<CacheStoreSessionListener> factory : factories) {
CacheStoreSessionListener lsnr = factory.create();
if (lsnr != null) {
ctx.resource().injectGeneric(lsnr);
if (lsnr instanceof LifecycleAware)
((LifecycleAware) lsnr).start();
lsnrs.add(lsnr);
}
}
return lsnrs;
}
Aggregations