Skip to content

Commit

Permalink
Merging pluggable_cache into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ghidinelli committed Jul 12, 2014
2 parents 4fb6671 + 2787788 commit 14d574e
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 0 deletions.
156 changes: 156 additions & 0 deletions com/cache/SoftReferenceHandler.cfc
@@ -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>
98 changes: 98 additions & 0 deletions com/events/adapter/AbstractBaseEventActionAdapter.cfc
@@ -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>
10 changes: 10 additions & 0 deletions com/factory/exception/AutoWireException.cfc
Expand Up @@ -9,7 +9,11 @@ Website: http://www.compoundtheory.com
Purpose: Exception thrown when internal autowiring fails
<<<<<<< HEAD
Usage:
=======
Usage:
>>>>>>> master
Modification Log:
Expand All @@ -25,9 +29,15 @@ Mark Mandel 05/06/2009 Created

<cffunction name="init" hint="Constructor" access="public" returntype="void" output="false">
<cfargument name="target" hint="the autowiring target" type="any" required="Yes">
<<<<<<< HEAD
<cfargument name="exception" hint="the exception" type="any" required="Yes">
<cfscript>
super.init("Error while attempting to autowire object of type #getMetaData(arguments.target).name#",
=======
<cfargument name="exception" hint="the exception" type="struct" required="Yes">
<cfscript>
super.init("Error while attempting to autowire object of type #getMetaData(arguments.target).name#",
>>>>>>> master
"<br/>[Line: #arguments.exception.tagContext[1].line# :: #arguments.exception.tagContext[1].template# :: #arguments.exception.message# :: #arguments.exception.detail#]");
</cfscript>
</cffunction>
Expand Down

0 comments on commit 14d574e

Please sign in to comment.