Pointer to handler?

After examining the Coldbox Cache (in Coldbox Debug information), I
don't see any reference to handlers. I know they are cached, however,
if the setting for handler caching is on.

I'm wondering, if I wanted to do a little runtime analysis on a given
handler file, what's the best way to:
1) Get a pointer to the cached version of that handler so I can look
at the functions metadata
or
2) Properly create the object (without using runEvent()) so that my
instantiation of it allows Coldbox to use it later when it's ready.

Thoughts? (Luis: This is part of the handler mapper we discussed.)

- Will B.

I also need this.

Handler’s are controlled by the HandlerService. You have full access to the handler service for any kind of funkyness you need to accomplish.

handlerService = controller.getHandlerService();

There are several useful methods in there, like for example, getHandler(). You can easily get a reference to a handler.

This is what I ended up doing:

I created an array of the paths, from the most specific potential
customized handler first and the most generic last. Then I loop over
the array and used this code to determine if a) the handler itself (as
a file) existed and b) that the handler actually had the event I
needed. The variable sMap is the full path along with the event nameI
needed. This the one the interceptor would use as the overrideEvent()
value. The nice thing is, using the Coldbox getRegisteredHandler()
function allows me to access the object whether it is cached or not,
allowing Coldbox to create it if it hasn't done so yet.

<cfloop from="1" to="#arrayLen(local.aPaths)#" index="local.iterPath">
  <cftry>
    <!--- Use the controller to "correctly" create this handler --->
    <cfset local.oEventHandlerBean = getController().getHandlerService
().getRegisteredHandler(local.aPaths[local.iterPath] & '.' &
args.event) />

    <!--- Actually try to grab the handler.event, will fail if not found
--->
    <cfset local.oHandler = getController().getHandlerService
().getHandler(local.oEventHandlerBean, arguments.eventString) />

    <!--- If we didn't have an error, then we found our deepest file
path, save it and break out --->
    <cfset local.sMap = local.aPaths[local.iterPath] & '.' & args.event /

    <cflock name="EventMapper-write" type="exclusive" timeout="5"
throwontimeout="false">
      <cfset instance.stMap[local.lookupKey] = local.sMap />
    </cflock>
    <cfbreak />

    <!--- Catch the error Coldbox throws when the HANDLER doesn't exist
--->
    <cfcatch type="Framework.EventHandlerNotRegisteredException">
      <!--- The handler wasn't found with this path, keep going. --->
      <!--- Unless this is the last of the files to check, in that case,
rethrow --->
      <cfif local.iterPath eq arrayLen(local.aPaths)>
        <cfrethrow />
      </cfif>
    </cfcatch>
    <!--- Catch the error Coldbox throws when the EVENT doesn't exist ---

    <cfcatch type="Framework.invalidEventException">
      <!--- Found the handler, but the EVENT doesn't exist in it, keep
going. --->
      <!--- Unless this is the last of the files to check, in that case,
rethrow --->
      <cfif local.iterPath eq arrayLen(local.aPaths)>
        <cfrethrow />
      </cfif>
    </cfcatch>
  </cftry>
</cfloop>