BEA Systems, Inc.

com.beasys.commerce.axiom.contact.security
Class GroupCache

java.lang.Object
  |
  +--com.beasys.commerce.axiom.contact.security.GroupCache

public class GroupCache
extends java.lang.Object
implements weblogic.time.common.Schedulable, weblogic.common.T3StartupDef, weblogic.time.common.Triggerable

This class implements a periodically self-refreshing cache of security groups. The cache maintained by this class is reloaded periodically. Reloads are triggered by the WLS time service, and the reload period is determined by a property provided in weblogic.properties


Field Summary
protected static java.lang.String CACHE_TABLE
           
static long DEFAULT_RELOAD_INTERVAL
          The default value for the reload interval (in seconds)
protected  boolean firstTime
           
static long INITIAL_LOAD_INTERVAL
          The interval to wait before performing the initial load (in seconds)
static java.lang.String JNDI_LOCATION
           
protected static java.lang.String p13nTablePrefix
           
static java.lang.String RELOAD_INTERVAL_PROPERTY_NAME
          The name of the property in weblogic.properties that specifies the reload interval (in seconds) for the instance of GroupCache
protected  long reloadInterval
          The cache reload interval
protected  weblogic.common.T3ServicesDef services
          The services object passed in by WLS
static java.lang.String UPDATE_PROPERTY_NAME
          flag to indicate that this copy should do the database updates
protected  boolean updateDb
          Flag to indicate that database updates should occur
static boolean VERBOSE
          A flag used to indicate whether or not messages should be printed
 
Constructor Summary
GroupCache()
          Default Constructor A default constructor is required by WLS
 
Method Summary
protected static void close(java.sql.Connection c)
           
protected static void close(java.sql.PreparedStatement ps)
           
protected static void close(java.sql.ResultSet rs)
           
static java.lang.String[] getCachedGroupNamesForUser(java.lang.String userName)
          Gets a list of names of the groups to which a user has membership
protected static java.sql.Connection getReadConnection()
          Returns a connection for reading from the pre-calculated table.
protected static java.sql.Connection getWriteConnection()
          Returns a connection to use when regenerating the pre-calculated table.
protected  void insertGroupMembers(java.lang.String groupName, java.util.Set members, java.sql.Connection conn)
          Get the user id's of the members of the group specified by groupId; add them to the members Set; insert them into the cache table for that group; then call itself recursively for each child of the given group, with the augmented set of members.
protected  void regenerateGroupTable()
          Kicks off the pre-calculated membership table process by dropping all rows, getting a list of the top level groups, and then calling insertGroupMembers for each of them.
protected  void reloadCache()
          Reloads the group cache
 long schedule(long time)
          Determines schedule for trigger
 void setServices(weblogic.common.T3ServicesDef services)
          Sets the T3ServicesDef object to be used by the instance of GroupCache
 java.lang.String startup(java.lang.String name, java.util.Hashtable startupArgs)
          Starts the instance of GroupCache
 void trigger(weblogic.time.common.Schedulable schedulable)
          Call back for WLS time service to notify the group cache that a cache reload should be performed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JNDI_LOCATION

public static final java.lang.String JNDI_LOCATION

DEFAULT_RELOAD_INTERVAL

public static final long DEFAULT_RELOAD_INTERVAL
The default value for the reload interval (in seconds)

INITIAL_LOAD_INTERVAL

public static final long INITIAL_LOAD_INTERVAL
The interval to wait before performing the initial load (in seconds)

RELOAD_INTERVAL_PROPERTY_NAME

public static final java.lang.String RELOAD_INTERVAL_PROPERTY_NAME
The name of the property in weblogic.properties that specifies the reload interval (in seconds) for the instance of GroupCache

UPDATE_PROPERTY_NAME

public static final java.lang.String UPDATE_PROPERTY_NAME
flag to indicate that this copy should do the database updates

VERBOSE

public static final boolean VERBOSE
A flag used to indicate whether or not messages should be printed

reloadInterval

protected long reloadInterval
The cache reload interval

services

protected weblogic.common.T3ServicesDef services
The services object passed in by WLS

firstTime

protected boolean firstTime

updateDb

protected boolean updateDb
Flag to indicate that database updates should occur

p13nTablePrefix

protected static java.lang.String p13nTablePrefix

CACHE_TABLE

protected static final java.lang.String CACHE_TABLE
Constructor Detail

GroupCache

public GroupCache()
Default Constructor A default constructor is required by WLS
Method Detail

getCachedGroupNamesForUser

public static java.lang.String[] getCachedGroupNamesForUser(java.lang.String userName)
                                                     throws ServiceProviderException
Gets a list of names of the groups to which a user has membership
Parameters:
userName - A user name
Returns:
A list of group names

schedule

public long schedule(long time)
Determines schedule for trigger
Specified by:
schedule in interface weblogic.time.common.Schedulable
Parameters:
time - The time to which the reload interval should be added
Returns:
The scheduled trigger time

setServices

public void setServices(weblogic.common.T3ServicesDef services)
Sets the T3ServicesDef object to be used by the instance of GroupCache
Specified by:
setServices in interface weblogic.common.T3StartupDef

startup

public java.lang.String startup(java.lang.String name,
                                java.util.Hashtable startupArgs)
                         throws java.lang.Exception
Starts the instance of GroupCache
Specified by:
startup in interface weblogic.common.T3StartupDef
Parameters:
name - The name GroupCache name set in weblogic.properties
startupArgs - The startup args set in weblogic.properties
Returns:
String A startup message that is sent to the log
Throws:
java.lang.Exception - Thrown if anything whatsoever goes wrong

trigger

public void trigger(weblogic.time.common.Schedulable schedulable)
Call back for WLS time service to notify the group cache that a cache reload should be performed
Specified by:
trigger in interface weblogic.time.common.Triggerable
Parameters:
schedulable - The cache reload schedulable

regenerateGroupTable

protected void regenerateGroupTable()
Kicks off the pre-calculated membership table process by dropping all rows, getting a list of the top level groups, and then calling insertGroupMembers for each of them.

insertGroupMembers

protected void insertGroupMembers(java.lang.String groupName,
                                  java.util.Set members,
                                  java.sql.Connection conn)
                           throws java.sql.SQLException,
                                  ServiceProviderException
Get the user id's of the members of the group specified by groupId; add them to the members Set; insert them into the cache table for that group; then call itself recursively for each child of the given group, with the augmented set of members. This will build the cached group membership table hierarchically.

reloadCache

protected void reloadCache()
Reloads the group cache

close

protected static void close(java.sql.ResultSet rs)

close

protected static void close(java.sql.PreparedStatement ps)

close

protected static void close(java.sql.Connection c)

getReadConnection

protected static java.sql.Connection getReadConnection()
                                                throws java.sql.SQLException
Returns a connection for reading from the pre-calculated table. This connection tries to be TRANSACTION_READ_COMMITTED, but will fall back to TRANSACTION_SERIALIZABLE if the database or driver does not support it.

getWriteConnection

protected static java.sql.Connection getWriteConnection()
                                                 throws java.sql.SQLException
Returns a connection to use when regenerating the pre-calculated table. This connection is marked TRANSACTION_SERIALIZABLE, and has AutoCommit set to false so that the entire operation will be done in a single transaction. This will prevent queries from reading partially calculated information.

BEA Systems, Inc.

Copyright © 2000 BEA Systems, Inc. All Rights Reserved