private void destroyCache(Cache<Object, Object> cache) { if (cache.getCacheStatus() == CacheStatus.STARTED) { cache.stop(); } if (cache.getCacheStatus() != CacheStatus.DESTROYED && cache.getCacheStatus() != CacheStatus.INSTANTIATED) { cache.destroy(); } } }
public BasicRegionAdapter(Cache jbcCache, String regionName, String regionPrefix) { this.log = LoggerFactory.getLogger(getClass()); this.jbcCache = jbcCache; this.transactionManager = jbcCache.getConfiguration().getRuntimeConfig().getTransactionManager(); this.regionName = regionName; this.regionFqn = createRegionFqn(regionName, regionPrefix); this.internalFqn = CacheHelper.getInternalFqn(regionFqn); this.optimistic = jbcCache.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC; this.memberId = jbcCache.getLocalAddress(); this.replication = CacheHelper.isClusteredReplication(jbcCache); this.jbcCache.addCacheListener(this); synchronized (currentView) { List view = jbcCache.getMembers(); if (view != null) { currentView.addAll(view); } } activateLocalClusterNode(); log.debug("Created Region for " + regionName + " -- regionPrefix is " + regionPrefix); }
/** * Allows direct injection of the underlying cache. * * @param cache */ public void setCache(Cache<K, V> cache) { if (cacheStatus != CacheStatus.INSTANTIATED && cacheStatus != CacheStatus.CREATING && cacheStatus != CacheStatus.DESTROYED) { throw new IllegalStateException("Cannot set underlying cache after call to create()"); } this.cache = (CacheSPI<K, V>) cache; this.config = (cache == null ? null : cache.getConfiguration()); synchronized (listenerCount) { if (listenerCount.get() > 0 && cache != null) { cache.addCacheListener(cacheNotificationListener); } } }
@CacheStopped public void cacheStopped(CacheStoppedEvent cacheStoppedEvent) { if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_INFO)) { clusteredlogger.logInfo( "Mobicents Cache stopped, status: " + cacheStoppedEvent.getCache().getCacheStatus() + ", Mode: " + cacheStoppedEvent.getCache().getConfiguration().getCacheModeString()); } }
public EntityRegionImpl(Cache jbcCache, String regionName, String regionPrefix, CacheDataDescription metadata) { super(jbcCache, regionName, regionPrefix, metadata); optimistic = (jbcCache.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC); }
/** * Returns a {@link Map}, where map entries are partitioned into child nodes, * within the cache root, by key hash code. * * @param cache cache to use * @return a Map representation of the cache */ public static <K, V> Map<K, V> asPartitionedMap(Cache<K, V> cache) { return asPartitionedMap(cache.getRoot()); }
Configuration cfg = jbcCache.getConfiguration(); if (cfg.isUseRegionBasedMarshalling()) { org.jboss.cache.Region jbcRegion = jbcCache.getRegion(regionFqn, true); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { regionRoot = jbcCache.getRoot().getChild( regionFqn ); if (regionRoot == null || !regionRoot.isValid()) {
/** * {@inheritDoc} */ public void start(Settings settings, Properties properties) throws CacheException { use2ndLevel = settings.isSecondLevelCacheEnabled(); useQuery = settings.isQueryCacheEnabled(); if (cache == null) { if (channelFactory == null) { String muxStacks = PropertiesHelper.getString(CHANNEL_FACTORY_RESOURCE_PROP, properties, DEF_JGROUPS_RESOURCE); if (muxStacks != null) { channelFactory = new JChannelFactory(); try { channelFactory.setMultiplexerConfig(muxStacks); } catch (Exception e) { throw new CacheException("Problem setting ChannelFactory config", e); } } } cache = createSharedCache(settings, properties); configureTransactionManager(cache, settings, properties); if (cache.getConfiguration().getMultiplexerStack() != null && cache.getConfiguration().getRuntimeConfig().getMuxChannelFactory() == null) { cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(channelFactory); } } cache.start(); }
@Override protected void updateTicket(final Ticket ticket) { try { this.cache.put(FQN_TICKET, ticket.getId(), ticket); } catch (final CacheException e) { throw new RuntimeException(e); } }
public Object get(Object key) { return cache.get(createFqn(key), RESOURCE); }
public void start() throws SipCacheException { try { cache.start(); } catch (Exception e) { throw new SipCacheException("Couldn't start JBoss Cache", e); } dialogRootNode = cache.getRoot().getChild(SipCache.DIALOG_PARENT_FQN_ELEMENT); if(dialogRootNode == null) { dialogRootNode = cache.getRoot().addChild(Fqn.fromElements(SipCache.DIALOG_PARENT_FQN_ELEMENT)); } if(clusteredSipStack.getReplicationStrategy() == ReplicationStrategy.EarlyDialog) { serverTxRootNode = cache.getRoot().getChild(SipCache.SERVER_TX_PARENT_FQN_ELEMENT); if(serverTxRootNode == null) { serverTxRootNode = cache.getRoot().addChild(Fqn.fromElements(SipCache.SERVER_TX_PARENT_FQN_ELEMENT)); } } }
/** * Create a new TimestampsRegionImpl. * * @param jbcCache The JBC cache instance to use to store the timestamps data * @param regionName The name of the region (within the JBC cache) * @param regionPrefix Any region prefix to apply * @param properties The configuration properties. */ public TimestampsRegionImpl(Cache jbcCache, String regionName, String regionPrefix, Properties properties) { super(jbcCache, regionName, regionPrefix, null); jbcCache.addCacheListener(this); populateLocalCache(); }
public void destroy() throws CacheException { try { // NOTE : this is being used from the process of shutting down a // SessionFactory. Specific things to consider: // (1) this clearing of the region should not propagate to // other nodes on the cluster (if any); this is the // cache-mode-local option bit... // (2) really just trying a best effort to cleanup after // ourselves; lock failures, etc are not critical here; // this is the fail-silently option bit... Option option = new Option(); option.setCacheModeLocal(true); option.setFailSilently(true); if (optimistic) { option.setDataVersion(NonLockingDataVersion.INSTANCE); } jbcCache.getInvocationContext().setOptionOverrides(option); jbcCache.removeNode(regionFqn); deactivateLocalNode(); } catch (Exception e) { throw new CacheException(e); } finally { jbcCache.removeCacheListener(this); } }
public void start() { cache.start(); }
public void stop() { cache.stop(); } }
public void put(Object key, Object value, Date expired) { Map<String, Object> map = new HashMap<String, Object>(3); map.put(RESOURCE, value); if (expired != null) { map.put(ExpirationAlgorithmConfig.EXPIRATION_KEY, expired.getTime()); } cache.put(createFqn(key), map); Transaction transaction = cache.getInvocationContext().getTransaction(); try { // TODO: to review if ((transaction != null) && (transaction.getStatus() == Status.STATUS_ACTIVE)) { transaction.commit(); } } catch (SystemException e) { LOGGER.error(e.getMessage(), e); } catch (SecurityException e) { LOGGER.error(e.getMessage(), e); } catch (IllegalStateException e) { LOGGER.error(e.getMessage(), e); } catch (RollbackException e) { LOGGER.error(e.getMessage(), e); } catch (HeuristicMixedException e) { LOGGER.error(e.getMessage(), e); } catch (HeuristicRollbackException e) { LOGGER.error(e.getMessage(), e); } }
@Override public void destroy() throws Exception { logger.info("Shutting down TreeCache service."); this.cache.destroy(); } }