Package er.persistentsessionstorage

Source Code of er.persistentsessionstorage.ERPersistentSessionStorage

package er.persistentsessionstorage;

import org.apache.log4j.Logger;

import com.webobjects.appserver.WOApplication;
import com.webobjects.appserver.WOSession;
import com.webobjects.appserver.WOSessionStore;
import com.webobjects.foundation.NSNotification;
import com.webobjects.foundation.NSNotificationCenter;
import com.webobjects.foundation.NSSelector;

import er.extensions.ERXFrameworkPrincipal;

public class ERPersistentSessionStorage extends ERXFrameworkPrincipal {

  public static final Class<?>[] REQUIRES = new Class[] {};

  protected static volatile ERPersistentSessionStorage sharedInstance;

  private static final Logger log = Logger.getLogger(ERPersistentSessionStorage.class);

  // Registers the class as the framework principal
  static {
    log.debug("Static Initializer for ERR2d2w");
    setUpFrameworkPrincipalClass(ERPersistentSessionStorage.class);
  }

  public static ERPersistentSessionStorage sharedInstance() {
    if (sharedInstance == null) {
      synchronized (ERPersistentSessionStorage.class) {
        if (sharedInstance == null) {
          sharedInstance = sharedInstance(ERPersistentSessionStorage.class);
        }
      }
    }
    return sharedInstance;
  }

  @Override
  public void finishInitialization() {
    log.info("Initializing persistent session store.");
    WOSessionStore store = new ERPersistentSessionStore();
   
    //Create the persistent session store
    WOApplication.application().setSessionStore(store);
   
    //Set up notifications for newly created sessions
    NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
    NSSelector<Void> sel = new NSSelector<Void>("enableSessionDistribution", new Class[] {NSNotification.class});
    nc.addObserver(this, sel, WOSession.SessionDidCreateNotification, null);
  }
 
  /**
   * Sets distribution enabled on new sessions
   * @param n a session created notification
   */
  public void enableSessionDistribution(NSNotification n) {
    WOSession session = (WOSession) n.object();
    session.setDistributionEnabled(true);
  }

}
TOP

Related Classes of er.persistentsessionstorage.ERPersistentSessionStorage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.