-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distributed Session Management #7529
- Loading branch information
Showing
5 changed files
with
159 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...ession/src/main/java/com/enonic/xp/web/session/impl/SessionDataStoreFactoryActivator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.enonic.xp.web.session.impl; | ||
|
||
import java.util.Hashtable; | ||
|
||
import org.apache.ignite.Ignite; | ||
import org.eclipse.jetty.server.session.DefaultSessionCache; | ||
import org.eclipse.jetty.server.session.NullSessionCacheFactory; | ||
import org.eclipse.jetty.server.session.NullSessionDataStoreFactory; | ||
import org.eclipse.jetty.server.session.SessionCacheFactory; | ||
import org.eclipse.jetty.server.session.SessionDataStoreFactory; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.ServiceRegistration; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Deactivate; | ||
import org.osgi.service.component.annotations.Reference; | ||
import org.osgi.service.component.annotations.ReferenceCardinality; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.enonic.xp.cluster.ClusterConfig; | ||
import com.enonic.xp.web.session.impl.ignite.IgniteSessionDataStoreFactory; | ||
|
||
@Component(immediate = true, configurationPid = "com.enonic.xp.web.session") | ||
public class SessionDataStoreFactoryActivator | ||
{ | ||
private final static Logger LOG = LoggerFactory.getLogger( SessionDataStoreFactoryActivator.class ); | ||
|
||
private Ignite ignite; | ||
|
||
private ServiceRegistration sessionDataStoreFactoryReg; | ||
|
||
private ServiceRegistration sessionCacheReg; | ||
|
||
private ClusterConfig clusterConfig; | ||
|
||
@Activate | ||
public void activate( final BundleContext context, final WebSessionConfig config ) | ||
{ | ||
if ( clusterConfig.isEnabled() && clusterConfig.isSessionReplicationEnabled() ) | ||
{ | ||
if ( ignite == null ) | ||
{ | ||
LOG.debug( "Waiting for ignite" ); | ||
} | ||
else | ||
{ | ||
final IgniteSessionDataStoreFactory sessionDataStoreFactory = new IgniteSessionDataStoreFactory( ignite, config ); | ||
sessionDataStoreFactory.setSavePeriodSec( config.session_save_period() ); | ||
|
||
NullSessionCacheFactory sessionCacheFactory = new NullSessionCacheFactory(); | ||
sessionCacheFactory.setSaveOnCreate( true ); | ||
sessionCacheFactory.setRemoveUnloadableSessions( true ); | ||
sessionCacheFactory.setFlushOnResponseCommit( true ); | ||
sessionDataStoreFactoryReg = | ||
context.registerService( SessionDataStoreFactory.class, sessionDataStoreFactory, new Hashtable<>() ); | ||
sessionCacheReg = context.registerService( SessionCacheFactory.class, sessionCacheFactory, new Hashtable<>() ); | ||
} | ||
} | ||
else | ||
{ | ||
final NullSessionDataStoreFactory sessionDataStoreFactory = new NullSessionDataStoreFactory(); | ||
sessionDataStoreFactory.setSavePeriodSec( config.session_save_period() ); | ||
sessionDataStoreFactoryReg = | ||
context.registerService( SessionDataStoreFactory.class, sessionDataStoreFactory, new Hashtable<>() ); | ||
sessionCacheReg = context.registerService( SessionCacheFactory.class, DefaultSessionCache::new, new Hashtable<>() ); | ||
} | ||
} | ||
|
||
@Deactivate | ||
public void deactivate() | ||
throws Exception | ||
{ | ||
ignite = null; | ||
sessionDataStoreFactoryReg.unregister(); | ||
sessionCacheReg.unregister(); | ||
} | ||
|
||
@Reference(cardinality = ReferenceCardinality.OPTIONAL) | ||
public void setIgnite( final Ignite ignite ) | ||
{ | ||
this.ignite = ignite; | ||
} | ||
|
||
@Reference | ||
public void setClusterConfig( final ClusterConfig clusterConfig ) | ||
{ | ||
this.clusterConfig = clusterConfig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters