Child pages
  • FRAPI Examples in ColdFusion

This documentation relates to FusionReactor 3.5.x - If you use an other Version please check here: All Versions

Skip to end of metadata
Go to start of metadata

The FRAPI lets you call FusionReactor methods directly from your ColdFusion pages.  JavaDocs are available for the FRAPI and are available from the FusionReactor site. Lets first start with some simple examples though...

This is one of the simplest FRAPI calls:

<cfset frapiClass = createObject("java", "com.intergral.fusionreactor.api.FRAPI")>
<cfset frapi = frapiClass.getInstance()>

<cfoutput>Is FR Running?: #frapi.isFusionReactorRunning()#</cfoutput>

This page simply outputs a YES/NO value depending on the running state of FusionReactor.

Now for something a little more interesting:

<cfset frapiClass = createObject("java", "com.intergral.fusionreactor.api.FRAPI")>
<cfset frapi = frapiClass.getInstance()>
<cfset dateClass = createObject("java", "java.util.Date")>

<!--- Loop over each running request --->

<cfset requestArray = frapi.getRunningRequests()/>
<cfloop index="i" from=1 to=#ArrayLen(requestArray)#>

   <cfset dateObject = dateClass.init(requestArray[i].getStartTimeMillis())>
      ID: #requestArray[i].getFusionRequestId()#<br/>
      URL: #requestArray[i].getRequestUrl()#<br/>
      Start: #dateObject.toString()#<br/>


<!--- Sleep for 5 seconds --->

<cfobject type="java" action="create" class="java.lang.Thread" name="Thread">

    Thread.sleep( JavaCast( "long", 5000 ) );

This bit of code will print out a list of all requests currently running. (We've added a wait at the bottom so we can run it several times and get a result something like this:

As well as getting information from FusionReactor, you can also use the FRAPI to change FusionReactor itself. The following code will change the timeout setting for Crash Protection for this request:

<cfset frapiClass = createObject("java", "com.intergral.fusionreactor.api.FRAPI")>
<cfset frapi = frapiClass.getInstance()>

<!--- Force Crash Protection to 10 seconds for this page --->
<cfset frapi.setPageTimeout( 10000 )>

We also have the ability to set markers in pages. Look at this example:

<cfset frapiClass = createObject("java", "com.intergral.fusionreactor.api.FRAPI")>
<cfset frapi = frapiClass.getInstance()>

<!--- Set a marker --->
<cfset frapi.trace( "Hello World!" )>

After this page has run, if we go into FusionReactor and look at the request details for this request we fill see this marker listed along with the time at which it was set:

The ability to set markers within your pages has many useful purposes including following the path of execution, measuring execution time or simply outputting debug information without changing the final output or needing to read through log files.

As we hope you can see, the FRAPI is a very powerful new tool which has a lot of potential. As ever, if you have any feedback or suggestions for this or any other feature within FusionReactor, please let us know and we will try our best to include them in upcoming builds.

  • No labels