forked from seancoyne/transfer
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
372 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<!--- Document Information ----------------------------------------------------- | ||
Title: SoftReferenceHandler.cfc | ||
Author: Mark Mandel | ||
Email: mark@compoundtheory.com | ||
Website: http://www.compoundtheory.com | ||
Purpose: A place to manage all the soft references in the system | ||
Usage: | ||
Modification Log: | ||
Name Date Description | ||
================================================================================ | ||
Mark Mandel 20/02/2007 Created | ||
-------------------------------------------------------------------------------> | ||
|
||
<cfcomponent name="SoftReferenceHandler" hint="Handles Soft References in Transfer" output="false"> | ||
|
||
<!------------------------------------------- PUBLIC -------------------------------------------> | ||
|
||
<cffunction name="init" hint="Constructor" access="public" returntype="SoftReferenceHandler" output="false"> | ||
<cfargument name="cacheConfigManager" hint="The cache config manager" type="transfer.com.cache.CacheConfigManager" required="Yes" _autocreate="false"> | ||
<cfargument name="facadeFactory" hint="The facade factpry for getting to the cache" type="transfer.com.facade.FacadeFactory" required="Yes" _autocreate="false"> | ||
<cfscript> | ||
variables.instance = StructNew(); | ||
|
||
setFacadeFactory(arguments.facadeFactory); | ||
setCacheConfigManager(arguments.cacheConfigManager); | ||
|
||
return this; | ||
</cfscript> | ||
</cffunction> | ||
|
||
<cffunction name="register" hint="Registers a new TransferObject with the Handler, and returns a java.ref.softReference" access="public" returntype="any" output="false"> | ||
<cfargument name="transfer" hint="The transfer object" type="transfer.com.TransferObject" required="Yes"> | ||
<cfscript> | ||
var scope = getCacheConfigManager().getCacheConfig().getConfig(arguments.transfer.getClassName()).getScope(); | ||
var facade = getFacadeFactory().getFacadeByScope(scope); | ||
|
||
return facade.getSoftReferenceRegister().register(arguments.transfer); | ||
</cfscript> | ||
</cffunction> | ||
|
||
<cffunction name="clearAllReferences" hint="clear and queue all the soft refrences stored in here" access="public" returntype="void" output="false"> | ||
<cfscript> | ||
eachSoftReferenceRegister(executeClearAllReferences); | ||
</cfscript> | ||
</cffunction> | ||
|
||
<cffunction name="reap" hint="this has been seperated out, so the cf8 version can do this async" access="public" returntype="void" output="false"> | ||
<cfscript> | ||
syncronousReap(5); | ||
</cfscript> | ||
</cffunction> | ||
|
||
<!------------------------------------------- PACKAGE -------------------------------------------> | ||
|
||
<!------------------------------------------- PRIVATE -------------------------------------------> | ||
|
||
<cffunction name="syncronousReap" hint="syncronous Reap: reaps the collected objects out of the pool" access="private" returntype="void" output="false"> | ||
<cfargument name="secondLimit" hint="The second limit on reaping, 0 is unlimited" type="numeric" required="No" default="0"> | ||
<cfscript> | ||
eachSoftReferenceRegister(executeReap, arguments); | ||
</cfscript> | ||
</cffunction> | ||
|
||
<cffunction name="eachSoftReferenceRegister" hint="HOF that runs a function against each facade's ConfigManager, if it has one" access="private" returntype="void" output="false"> | ||
<cfargument name="function" hint="the function to call on the SoftReferenceRegister" type="any" required="Yes"> | ||
<cfargument name="args" hint="the argument data to pass from function call to function call" type="struct" required="false" default="#StructNew()#"> | ||
<cfscript> | ||
var factory = getFacadeFactory(); //speed | ||
|
||
invokeFacadeSoftReferenceRegister(factory.getInstanceFacade(), arguments.function, arguments.args); | ||
invokeFacadeSoftReferenceRegister(factory.getApplicationFacade(), arguments.function, arguments.args); | ||
|
||
try | ||
{ | ||
//we do this, as the request scope variables can just dissapear | ||
invokeFacadeSoftReferenceRegister(factory.getRequestFacade(), arguments.function, arguments.args); | ||
} | ||
catch(coldfusion.runtime.UndefinedElementException exc) { /*do nothing*/ } | ||
|
||
invokeFacadeSoftReferenceRegister(factory.getServerFacade(), arguments.function, arguments.args); | ||
|
||
try | ||
{ | ||
//we do this, as the session scope variables can just dissapear | ||
invokeFacadeSoftReferenceRegister(factory.getSessionFacade(), arguments.function, arguments.args); | ||
} | ||
catch(coldfusion.runtime.UndefinedElementException exc) { /*do nothing*/ } | ||
catch(coldfusion.runtime.NoOperScope$ScopeDisabledException exc) { /* do nothing */ } | ||
|
||
//really not required, but to keep clean | ||
invokeFacadeSoftReferenceRegister(factory.getNoneFacade(), arguments.function, arguments.args); | ||
</cfscript> | ||
</cffunction> | ||
|
||
<cffunction name="invokeFacadeSoftReferenceRegister" hint="invokes the function against the soft reference register if the facade has one" access="private" returntype="void" output="false"> | ||
<cfargument name="facade" hint="the facade to call against" type="transfer.com.facade.AbstractBaseFacade" required="Yes"> | ||
<cfargument name="function" hint="the function to call on the SoftReferenceRegister" type="any" required="Yes"> | ||
<cfargument name="args" hint="the argument data to pass from function call to function call" type="struct" required="true"> | ||
<cfscript> | ||
var call = arguments.function; | ||
|
||
if(facade.hasSoftReferenceRegister()) | ||
{ | ||
arguments.args.softReferenceRegister = facade.getSoftReferenceRegister(); | ||
call(argumentCollection=arguments.args); | ||
} | ||
</cfscript> | ||
</cffunction> | ||
|
||
<!--- HOF function arguments ---> | ||
|
||
<cffunction name="executeClearAllReferences" hint="calls 'clearAllReference' on each of the facades" access="private" returntype="void" output="false"> | ||
<cfargument name="softReferenceRegister" hint="the soft reference register to call on" type="transfer.com.cache.SoftReferenceRegister" required="Yes"> | ||
<cfscript> | ||
arguments.softReferenceRegister.clearAllReferences(); | ||
</cfscript> | ||
</cffunction> | ||
|
||
<cffunction name="executeReap" hint="executes the reap action on each of the facades" access="private" returntype="void" output="false"> | ||
<cfargument name="softReferenceRegister" hint="the soft reference register to call on" type="transfer.com.cache.SoftReferenceRegister" required="Yes"> | ||
<cfargument name="secondLimit" hint="The second limit on reaping, 0 is unlimited" type="numeric" required="Yes"> | ||
<cfscript> | ||
arguments.softReferenceRegister.reap(argumentCollection=arguments); | ||
</cfscript> | ||
</cffunction> | ||
|
||
<!--- /HOF function arguments ---> | ||
|
||
|
||
<cffunction name="getFacadeFactory" access="private" returntype="transfer.com.facade.FacadeFactory" output="false"> | ||
<cfreturn instance.FacadeFactory /> | ||
</cffunction> | ||
|
||
<cffunction name="setFacadeFactory" access="private" returntype="void" output="false"> | ||
<cfargument name="FacadeFactory" type="transfer.com.facade.FacadeFactory" required="true"> | ||
<cfset instance.FacadeFactory = arguments.FacadeFactory /> | ||
</cffunction> | ||
|
||
<cffunction name="getCacheConfigManager" access="private" returntype="transfer.com.cache.CacheConfigManager" output="false"> | ||
<cfreturn instance.CacheConfigManager /> | ||
</cffunction> | ||
|
||
<cffunction name="setCacheConfigManager" access="private" returntype="void" output="false"> | ||
<cfargument name="CacheConfigManager" type="transfer.com.cache.CacheConfigManager" required="true"> | ||
<cfset instance.CacheConfigManager = arguments.CacheConfigManager /> | ||
</cffunction> | ||
|
||
</cfcomponent> |
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,98 @@ | ||
<!--- Document Information ----------------------------------------------------- | ||
Title: AbstractBaseEventActionAdapter.cfc | ||
Author: Mark Mandel | ||
Email: mark@compoundtheory.com | ||
Website: http://www.compoundtheory.com | ||
Purpose: Abstact base class for event adapters | ||
Usage: | ||
Modification Log: | ||
Name Date Description | ||
================================================================================ | ||
Mark Mandel 20/02/2007 Created | ||
-------------------------------------------------------------------------------> | ||
<cfcomponent name="AbstractBaseEventActionAdapter" hint="An abstract base adapter that allows for the event menthods to be fired on it" output="false"> | ||
|
||
<!------------------------------------------- PUBLIC -------------------------------------------> | ||
|
||
<cffunction name="init" hint="Constructor" access="private" returntype="void" output="false"> | ||
<cfscript> | ||
variables.instance = StructNew(); | ||
setSystem(createObject("java", "java.lang.System")); | ||
</cfscript> | ||
</cffunction> | ||
|
||
<cffunction name="equalsAdapted" hint="returns if the object passed in is the same instance as the adapted" access="public" returntype="boolean" output="false"> | ||
<cfargument name="object" hint="The object to check against" type="any" required="Yes"> | ||
<cfreturn getSystem().identityHashCode(arguments.object) eq getSystem().identityHashCode(getAdapted())> | ||
</cffunction> | ||
|
||
<cffunction name="getAdapted" hint="returns the object that is adapted" access="public" returntype="any" output="false"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("getAdapted", this) /> | ||
</cffunction> | ||
|
||
<cffunction name="getKey" hint="returns a unique identifier key for the object contained for this adapter. Used for observer storage" access="public" returntype="any" output="false"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("getKey", this) /> | ||
</cffunction> | ||
|
||
<cffunction name="actionBeforeCreateTransferEvent" hint="virtual: Actions a event before a create happens" access="public" returntype="boolean" output="false"> | ||
<cfargument name="event" hint="The event object" type="transfer.com.events.TransferEvent" required="Yes"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("actionBeforeCreateTransferEvent", this) /> | ||
</cffunction> | ||
|
||
<cffunction name="actionAfterCreateTransferEvent" hint="virtual: Actions a event After a create happens" access="public" returntype="boolean" output="false"> | ||
<cfargument name="event" hint="The event object" type="transfer.com.events.TransferEvent" required="Yes"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("actionAfterCreateTransferEvent", this) /> | ||
</cffunction> | ||
|
||
<cffunction name="actionBeforeUpdateTransferEvent" hint="virtual: Actions a event Before a create happens" access="public" returntype="boolean" output="false"> | ||
<cfargument name="event" hint="The event object" type="transfer.com.events.TransferEvent" required="Yes"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("actionBeforeUpdateTransferEvent", this) /> | ||
</cffunction> | ||
|
||
<cffunction name="actionAfterUpdateTransferEvent" hint="virtual: Actions a event After a create happens" access="public" returntype="boolean" output="false"> | ||
<cfargument name="event" hint="The event object" type="transfer.com.events.TransferEvent" required="Yes"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("actionAfterUpdateTransferEvent", this) /> | ||
</cffunction> | ||
|
||
<cffunction name="actionBeforeDeleteTransferEvent" hint="virtual: Actions a event Before a create happens" access="public" returntype="boolean" output="false"> | ||
<cfargument name="event" hint="The event object" type="transfer.com.events.TransferEvent" required="Yes"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("actionBeforeDeleteTransferEvent", this) /> | ||
</cffunction> | ||
|
||
<cffunction name="actionAfterDeleteTransferEvent" hint="virtual: Actions a event After a create happens" access="public" returntype="boolean" output="false"> | ||
<cfargument name="event" hint="The event object" type="transfer.com.events.TransferEvent" required="Yes"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("actionAfterDeleteTransferEvent", this) /> | ||
</cffunction> | ||
|
||
<cffunction name="actionAfterDiscardTransferEvent" hint="virtual: Actions a event After a create happens" access="public" returntype="boolean" output="false"> | ||
<cfargument name="event" hint="The event object" type="transfer.com.events.TransferEvent" required="Yes"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("actionAfterDiscardTransferEvent", this) /> | ||
</cffunction> | ||
|
||
<cffunction name="actionAfterNewTransferEvent" hint="virtual: Actions a event after a New() happens" access="public" returntype="boolean" output="false"> | ||
<cfargument name="event" hint="The event object" type="transfer.com.events.TransferEvent" required="Yes"> | ||
<cfset createObject("component", "transfer.com.exception.VirtualMethodException").init("actionAfterNewTransferEvent", this) /> | ||
</cffunction> | ||
|
||
<!------------------------------------------- PACKAGE -------------------------------------------> | ||
|
||
<!------------------------------------------- PRIVATE -------------------------------------------> | ||
|
||
<cffunction name="getSystem" access="private" returntype="any" output="false"> | ||
<cfreturn instance.System /> | ||
</cffunction> | ||
|
||
<cffunction name="setSystem" access="private" returntype="void" output="false"> | ||
<cfargument name="System" type="any" required="true"> | ||
<cfset instance.System = arguments.System /> | ||
</cffunction> | ||
|
||
</cfcomponent> |
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
Oops, something went wrong.