PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/vendor/memcached/com/util/JavaLoader.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 75 lines | 62 code | 10 blank | 3 comment | 3 complexity | 99b9cb6cbc0bbb28072ae0d7bfc1c679 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent name="JavaLoader" hint="Loads External Java Classes for Memcached">
  2. <cffunction name="init" hint="Constructor" access="public" returntype="JavaLoader" output="false">
  3. <cfargument name="serverFacade" type="any" required="Yes" hint="the server facade for the javaloader">
  4. <cfargument name="jarDir" type="string" required="false" default="">
  5. <cfargument name="lockName" type="string" required="false" default="memcached.server.JavaLoader">
  6. <cfscript>
  7. variables.instance = StructNew();
  8. setServerFacade(arguments.serverFacade);
  9. </cfscript>
  10. <!--- double check lock for safety --->
  11. <cfif NOT getServerFacade().hasJavaLoader()>
  12. <cflock name="#arguments.lockName#" throwontimeout="true" timeout="60">
  13. <cfscript>
  14. if(NOT getServerFacade().hasJavaLoader())
  15. {
  16. getServerFacade().setJavaLoader(createObject("component", "javaloader.JavaLoader").init(queryJars(arguments.jarDir), true));
  17. }
  18. </cfscript>
  19. </cflock>
  20. </cfif>
  21. <cfscript>
  22. return this;
  23. </cfscript>
  24. </cffunction>
  25. <cffunction name="create" access="public" returntype="any" output="false"
  26. hint="Retrieves a reference to the java class. To create a instance, you must run init() on this object">
  27. <cfargument name="className" type="string" required="Yes" hint="The name of the class to create">
  28. <cfscript>
  29. return getServerFacade().getJavaLoader().create(arguments.className);
  30. </cfscript>
  31. </cffunction>
  32. <cffunction name="queryJars" access="private" returntype="array" output="false" hint="pulls a query of all the jars in the /lib folder" >
  33. <cfargument name="jarDir" type="string" required="false" default="">
  34. <cfscript>
  35. var qJars = 0;
  36. //the path to my jar library
  37. //var path = expandPath(arguments.jarDir);
  38. var jarList = "";
  39. var aJars = ArrayNew(1);
  40. var libName = 0;
  41. </cfscript>
  42. <cfif len(trim(arguments.jardir)) gt 0 and directoryExists(arguments.jarDir)>
  43. <cfdirectory action="list" name="qJars" directory="#arguments.jarDir#" filter="*.jar" sort="name desc"/>
  44. <cfloop query="qJars">
  45. <cfscript>
  46. libName = ListGetAt(name, 1, "-");
  47. //let's not use the lib's that have the same name, but a lower datestamp
  48. if(NOT ListFind(jarList, libName))
  49. {
  50. ArrayAppend(aJars, directory & "/" & name);
  51. jarList = ListAppend(jarList, libName);
  52. }
  53. </cfscript>
  54. </cfloop>
  55. </cfif>
  56. <cfreturn aJars>
  57. </cffunction>
  58. <cffunction name="getServerFacade" access="private" returntype="any" output="false">
  59. <cfreturn instance.serverFacade />
  60. </cffunction>
  61. <cffunction name="setServerFacade" access="private" returntype="void" output="false">
  62. <cfargument name="serverFacade" type="any" required="true">
  63. <cfset instance.serverFacade = arguments.serverFacade />
  64. </cffunction>
  65. </cfcomponent>