org.enhydra.barracuda.plankton.data
Class ObjectRepository

java.lang.Object
  extended byorg.enhydra.barracuda.plankton.data.DefaultStateMap
      extended byorg.enhydra.barracuda.plankton.data.ObjectRepository
All Implemented Interfaces:
StateMap
Direct Known Subclasses:
ObjectRepository.SessionRepository

public class ObjectRepository
extends DefaultStateMap

This class provides access to several different generic statemap repositories, scoped for Global, Session, Local, or custom (NameSpace or Name...you provide the cleanup). The basic idea here is to make it easy to access object repositories without having to pass references around. The Global object repository represents a common (threadsafe) statemap that is shared across the JVM. You would typically put things here like DataSources, global variables, etc. Any objects that you make available globally need to be threadsafe. The Session object repository is a statemap wrapper around HttpSession. This provides a convenient bridge to the Session interface, without having to have a reference to the HttpServletRequest. Storing items in this object places them in the underlying session. Note that ApplicationGateway and ComponentGateway classes invoke the setupSessionRepository() call for you, so all you have to do is call getSessionRepository() and you're in business. The Local object repository is a statemap object that lasts for the duration of a req-resp cycle. Note that the ApplicationGateway and ComponentGateway classes clean up both Session and Local repositories. The Weak and Soft maps are backed by WeakHashMap and SoftHashMap maps respectively (the basic distinction being that weak references will generally be cleaned up as soon as possible while soft references will generally be held on to as long as possible). The soft map is generally a better choice for caching. You can also get non-scoped ObjectRepositories by using either NameSpace or String keys. IF you use this approach, its up to you to manually remove the repositories when you're done with them (or else you'll end up leaving them in memory taking up space).

Version:
1.0
Author:
Christian Cryder

Nested Class Summary
static class ObjectRepository.SessionRepository
          The basic idea behind this is that we want to wrap the session as a ObjectRepository object.
 
Field Summary
protected static Map custom
           
protected static ObjectRepository global
           
protected static Map local
           
protected  String name
           
protected static SoftHashMap rawSessions
           
protected static Map session
           
protected static Map sessionIDs
           
protected static ObjectRepository softGlobal
           
protected static Map softsession
           
protected static ObjectRepository weakGlobal
           
protected static Map weaksession
           
 
Fields inherited from class org.enhydra.barracuda.plankton.data.DefaultStateMap
props
 
Constructor Summary
protected ObjectRepository()
          protected constructor
protected ObjectRepository(String iname)
           
 
Method Summary
static ObjectRepository getGlobalRepository()
          Get a reference to the Global repository.
static ObjectRepository getLocalRepository()
          Get a reference to the Local repository.
 String getName()
          Return the name of this object repository
static ObjectRepository getObjectRepository(NameSpace ns)
          Get an object repository associated with a given NameSpace.
static ObjectRepository getObjectRepository(String name)
          Get an object repository based on a given name.
static Map getObjectRepositoryStore()
          This method gives you direct access to the underlying data structures in which everything related the the object repository is kept.
static javax.servlet.http.HttpSession getRawSession()
          get raw session - this gives you access to the underlying session object
static SoftHashMap getRawSessionStore()
          This method gives you direct access to the underlying HttpSession data structure.
static ObjectRepository getSessionRepository()
          Get a reference to the Session repository.
protected static ObjectRepository getSessionRepository(String key)
           
static Map getSessionStore()
          This method gives you direct access to the underlying HttpSession data structures (as many as are registered by Barracuda apps).
static ObjectRepository getSoftGlobalRepository()
          Get a reference to the Soft Global repository.
static ObjectRepository getSoftSessionRepository()
          Get a reference to a Soft Session repository.
static ObjectRepository getWeakGlobalRepository()
          Get a reference to the Weak Global repository.
static ObjectRepository getWeakSessionRepository()
          Get a reference to a Weak Session repository.
static void invalidateAllSessions()
          allows you to invalidate all rawSessions.
static void invalidateSession()
          allows you to invalidate a session by its unique identifier.
static void invalidateSession(String sessionID)
          allows you to invalidate a session by its unique identifier.
static void printStackTrace()
           
static void printStackTrace(String msg)
           
static void printStackTrace(String msg, OutputStream out)
           
static void removeLocalRepository()
          Release the Local repository.
static void removeObjectRepository(NameSpace ns)
          Release an object repository associated with a given NameSpace
static void removeObjectRepository(String name)
          Release an object repository associated with a given name
static void removeSessionRepository()
          Release the Session repository
static void setupSessionRepository(javax.servlet.http.HttpServletRequest req)
          Set up the Session repository for this particular thread.
 
Methods inherited from class org.enhydra.barracuda.plankton.data.DefaultStateMap
clearState, getState, getStateKeys, getStateValues, putState, removeState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

global

protected static ObjectRepository global

weakGlobal

protected static ObjectRepository weakGlobal

softGlobal

protected static ObjectRepository softGlobal

rawSessions

protected static SoftHashMap rawSessions

session

protected static Map session

sessionIDs

protected static Map sessionIDs

weaksession

protected static Map weaksession

softsession

protected static Map softsession

local

protected static Map local

custom

protected static Map custom

name

protected String name
Constructor Detail

ObjectRepository

protected ObjectRepository()
protected constructor


ObjectRepository

protected ObjectRepository(String iname)
Method Detail

getGlobalRepository

public static ObjectRepository getGlobalRepository()
Get a reference to the Global repository. This repository is shared across the entire JVM (consequently its threadsafe). The global repository never really goes away, so you don't need to do any cleanup on this one.


getWeakGlobalRepository

public static ObjectRepository getWeakGlobalRepository()
Get a reference to the Weak Global repository. This repository is shared across the entire JVM (consequently its threadsafe), but like the Weak Session repository, its backed by a weak hash map, allowing object which are placed in here to be gc'd as needed.


getSoftGlobalRepository

public static ObjectRepository getSoftGlobalRepository()
Get a reference to the Soft Global repository. This repository is shared across the entire JVM (consequently its threadsafe), but like the Soft Session repository, its backed by a soft hash map, allowing object which are placed in here to be gc'd as needed, but only when really needed.


setupSessionRepository

public static void setupSessionRepository(javax.servlet.http.HttpServletRequest req)
Set up the Session repository for this particular thread. You must invoke this method before actually getting the session repository, IFF you actually want the repository to wrapp the Servlet's Session structure. Otherwise, when you get the Session repository (below) it will simply return a regular state map.


getSessionRepository

public static ObjectRepository getSessionRepository()
Get a reference to the Session repository. If you are using this within Barracuda (ie. ApplicationGateway or ComponentGateway), this will return a StateMap that wraps the Servlet session.


getSessionRepository

protected static ObjectRepository getSessionRepository(String key)

removeSessionRepository

public static void removeSessionRepository()
Release the Session repository


getWeakSessionRepository

public static ObjectRepository getWeakSessionRepository()
Get a reference to a Weak Session repository. Objects placed in here are scoped to Session, but may be reclaimed by garbage collecter as needed (so you must always check for null and reinitialize if necessary)


getSoftSessionRepository

public static ObjectRepository getSoftSessionRepository()
Get a reference to a Soft Session repository. Objects placed in here are scoped to Session, but may be reclaimed by garbage collecter as needed (so you must always check for null and reinitialize if necessary)


getLocalRepository

public static ObjectRepository getLocalRepository()
Get a reference to the Local repository. This repository is shared across the thread. If you use this repository, it is your responsibility to clean things up (unless something else is cleaning it up for you, like the Barracuda ApplicationGateway or ComponentGateway)


removeLocalRepository

public static void removeLocalRepository()
Release the Local repository.


getObjectRepository

public static ObjectRepository getObjectRepository(NameSpace ns)
Get an object repository associated with a given NameSpace. If the object repository for this namespace does not already exist, it will be created automatically.


removeObjectRepository

public static void removeObjectRepository(NameSpace ns)
Release an object repository associated with a given NameSpace


getObjectRepository

public static ObjectRepository getObjectRepository(String name)
Get an object repository based on a given name. If the object repository for this namespace does not already exist, it will be created automatically.


removeObjectRepository

public static void removeObjectRepository(String name)
Release an object repository associated with a given name


getName

public String getName()
Return the name of this object repository


getRawSession

public static javax.servlet.http.HttpSession getRawSession()
get raw session - this gives you access to the underlying session object


invalidateSession

public static void invalidateSession()
allows you to invalidate a session by its unique identifier. You should only need to call this if you are performing large scale session management (ie. logging out all users, etc)


invalidateSession

public static void invalidateSession(String sessionID)
allows you to invalidate a session by its unique identifier. You should only need to call this if you are performing large scale session management (ie. logging out all users, etc)


invalidateAllSessions

public static void invalidateAllSessions()
allows you to invalidate all rawSessions. You should only need to call this if you are performing large scale session management (ie. logging out all users, etc)


getSessionStore

public static Map getSessionStore()
This method gives you direct access to the underlying HttpSession data structures (as many as are registered by Barracuda apps). Developers should almost never need to interact with these objects directly - this method is primarily intended for debugging purposes. Note that the Map returned is actually a copy of the underlying store, with keys conveniently extracted from their SoftReference wrappers.


getRawSessionStore

public static SoftHashMap getRawSessionStore()
This method gives you direct access to the underlying HttpSession data structure. You shouldn't ever need to use this method unless you really know what you are doing.


getObjectRepositoryStore

public static Map getObjectRepositoryStore()
This method gives you direct access to the underlying data structures in which everything related the the object repository is kept. Developers should almost never need to interact with these objects directly - this method is primarily intended for debugging purposes


printStackTrace

public static void printStackTrace()

printStackTrace

public static void printStackTrace(String msg)

printStackTrace

public static void printStackTrace(String msg,
                                   OutputStream out)


Copyright © 2003 BarracudaMVC.org All Rights Reserved.