public void storeSipApplicationSessionData(OutgoingDistributableSipApplicationSessionData sipApplicationSessionData) { String fqnId = sipApplicationSessionData.getSipApplicationSessionKey(); if (log_.isTraceEnabled()) { log_.trace("putSipSession(): putting sip session " + fqnId); } Fqn<String> fqn = getSipApplicationSessionFqn(jBossCacheService.combinedPath_, fqnId); Map<Object, Object> map = new HashMap<Object, Object>(); // Swap in/out the webapp classloader so we can deserialize // attributes whose classes are only available to the webapp ClassLoader prevTCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(manager.getApplicationClassLoader()); try { storeSipApplicationSessionMetaData(fqn, sipApplicationSessionData); ((DistributedCacheConvergedSipManager)jBossCacheService).storeSipApplicationSessionAttributes(Fqn.fromString(fqn.toString() + "/" + AbstractJBossCacheService.ATTRIBUTE_KEY), sipApplicationSessionData); } finally { Thread.currentThread().setContextClassLoader(prevTCL); } }
@Override public String locate(String sessionId) { return this.manager.getJvmRoute(); }
@CacheEntryActivated public void activated(CacheEntryActivatedEvent<String, Map<Object, Object>> event) { if (event.isPre()) return; this.manager.sessionActivated(); }
@Override public <K, V> Cache<K, V> getCache(LocalDistributableSessionManager manager) { ReplicationConfig config = manager.getReplicationConfig(); String containerName = config.getCacheName(); String templateCacheName = null; if ((containerName != null) && !containerName.isEmpty()) { String[] parts = containerName.split(DELIMITER); if (parts.length == 2) { containerName = parts[0]; templateCacheName = parts[1]; } } String cacheName = manager.getName(); EmbeddedCacheManager container = this.registry.getCacheContainer(containerName); this.applyOverrides(container.defineConfiguration(cacheName, templateCacheName, new Configuration()), config); return container.<K, V>getCache(cacheName); }
/** * {@inheritDoc} * @see org.jboss.web.tomcat.service.session.distributedcache.ispn.CacheSource#getCache(org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager) */ @Override public <K, V> Cache<K, V> getCache(LocalDistributableSessionManager manager) { return this.registry.getCacheContainer().getCache(manager.getEngineName()); } }
@CacheEntryRemoved public void removed(CacheEntryRemovedEvent<String, Map<Object, Object>> event) { if (event.isPre() || event.isOriginLocal()) return; this.manager.notifyRemoteInvalidation(event.getKey()); }
@CacheEntryModified public void modified(CacheEntryModifiedEvent<String, Map<Object, Object>> event) { if (event.isPre() || event.isOriginLocal()) return; Map<Object, Object> map = event.getValue(); if (map.isEmpty()) return; String sessionId = event.getKey(); Integer version = SessionMapEntry.VERSION.get(map); Long timestamp = SessionMapEntry.TIMESTAMP.get(map); DistributableSessionMetadata metadata = SessionMapEntry.METADATA.get(map); if ((version != null) && (timestamp != null) && (metadata != null)) { boolean updated = this.manager.sessionChangedInDistributedCache(sessionId, null, version.intValue(), timestamp.longValue(), metadata); if (!updated) { log.warn(String.format("Possible concurrency problem: Replicated version id %d is less than or equal to in-memory version for session %s", version, mask(sessionId))); } } }
private void createCacheListeners() { sipCacheListener_ = new SipCacheListener( jBossCacheService.cacheWrapper_, manager, jBossCacheService.combinedPath_, Util.getReplicationGranularity(manager), sipApplicationName, sipApplicationNameHashed); if (log_.isDebugEnabled()) { log_.debug("DistributedCacheConvergedSipManagerDelegate.start() : sipCacheListener " + sipCacheListener_); } jBossCacheService.getCache().addCacheListener(sipCacheListener_); if (manager.isPassivationEnabled()) { log_.debug("Passivation is enabled"); sipPassivationListener_ = new SipPassivationListener( manager, jBossCacheService.combinedPath_, sipApplicationNameHashed); jBossCacheService.getCache().addCacheListener( sipPassivationListener_); } }
@Override public <T extends OutgoingDistributableSessionData> org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager<T> getDistributedCacheManager(LocalDistributableSessionManager manager) { Cache<String, Map<Object, Object>> sessionCache = this.sessionCacheSource.getCache(manager); SharedLocalYieldingClusterLockManager lockManager = this.lockManagerSource.getLockManager(sessionCache); TransactionManager tm = sessionCache.getAdvancedCache().getTransactionManager(); if (!(tm instanceof BatchModeTransactionManager)) { throw new IllegalStateException("Unexpected transaction manager type: " + ((tm != null) ? tm.getClass().getName() : "null")); } BatchingManager batchingManager = new BatchingManagerImpl(tm); SessionAttributeMarshaller marshaller = this.marshallerFactory.createMarshaller(manager); SessionAttributeStorage<T> storage = this.storageFactory.createStorage(manager.getReplicationConfig().getReplicationGranularity(), marshaller); return new DistributedCacheManager<T>(manager, new AtomicMapCache<String, Object, Object>(sessionCache), this.jvmRouteCacheSource, lockManager, storage, batchingManager, this.invoker); }
return this.manager.getJvmRoute();
public void storeSipSessionData( OutgoingDistributableSipSessionData sipSessionData) { String sipApplicationSessionKey = sipSessionData.getSipApplicationSessionKey(); String sessionKey = sipSessionData.getSipSessionKey(); if (log_.isDebugEnabled()) { log_.debug("storeSipSessionData(): putting sip session " + sessionKey.toString()); } Fqn<String> fqn = getSipSessionFqn(jBossCacheService.combinedPath_, sipApplicationSessionKey, sessionKey); // Swap in/out the webapp classloader so we can deserialize // attributes whose classes are only available to the webapp ClassLoader prevTCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(manager.getApplicationClassLoader()); try { storeSipSessionMetaData(fqn, sipSessionData); ((DistributedCacheConvergedSipManager)jBossCacheService).storeSipSessionAttributes(Fqn.fromString(fqn.toString() + "/" + AbstractJBossCacheService.ATTRIBUTE_KEY), sipSessionData); } finally { Thread.currentThread().setContextClassLoader(prevTCL); } }
@NodeActivated public void nodeActivated(NodeActivatedEvent event) { @SuppressWarnings("unchecked") Fqn<String> fqn = event.getFqn(); boolean isBuddy = isBuddyFqn(fqn); if (isFqnForOurSipapp(fqn, isBuddy)) { String sessId = null; if (SipCacheListener.isFqnSessionRootSized(fqn.size(), isBuddy) && SipCacheListener.isFqnSipApplicationSessionRootSized(fqn.size(), isBuddy)) { sessId = SipCacheListener.getSipApplicationSessionIdFromFqn(fqn, isBuddy); ((LocalDistributableConvergedSessionManager) manager_) .sipApplicationSessionActivated(); } else { sessId = SipCacheListener.getSipSessionIdFromFqn(fqn, isBuddy); ((LocalDistributableConvergedSessionManager) manager_) .sipSessionActivated(); } manager_.sessionActivated(); } }
final String jvmRoute = this.manager.getJvmRoute();
/** * {@inheritDoc} * @see org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller#unmarshal(java.lang.Object) */ @Override public Object unmarshal(Object object) throws IOException, ClassNotFoundException { if ((object == null) || !(object instanceof SimpleCachableMarshalledValue)) return object; SimpleCachableMarshalledValue value = (SimpleCachableMarshalledValue) object; // Swap in/out the class loader for this web app. Needed only for unmarshalling. ContextClassLoaderSwitcher.SwitchContext switchContext = this.switcher.getSwitchContext(this.manager.getApplicationClassLoader()); try { value.setObjectStreamSource(this.source); return value.get(); } finally { switchContext.reset(); } } }
/** * {@inheritDoc} * @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#start() */ @Override public void start() { if (!this.sessionCache.getStatus().allowInvocations()) { this.sessionCache.start(); } this.sessionCache.addListener(this); if (this.jvmRouteHandler != null) { EmbeddedCacheManager container = (EmbeddedCacheManager) this.sessionCache.getCacheManager(); container.addListener(this.jvmRouteHandler); String jvmRoute = this.manager.getJvmRoute(); if (jvmRoute != null) { this.jvmRouteHandler.getCache().putIfAbsent(container.getAddress(), jvmRoute); } } }