Sei sulla pagina 1di 31

Advanced Techniques

with the
ColdBox Framework
#SU3B

Luis Majano &


Ortus Solutions, Corp
lmajano@coldboxframework.com
Who am I?
• Luis Majano
• Computer Engineer
• Born in San Salvador, El Salvador
• Work for ESRI
(Environmental Systems Research Institute)
www.esri.com
• Manager of the IE CFUG (www.iecfug.com)
• Working with ColdFusion since version 4.5
• Creator & Maintainer of the ColdBox
Framework
• Blog at www.luismajano.com
What will we cover?
• ColdBox Installation
– CFEclipse Dictionary Installation
– CFEclipse Snippets Installation
– Eclipse Plugins
• Application Generation
• Layout Manipulation
• Core Plugins/Custom Plugins
• Core Interceptors/Custom Interceptors
• Request Context Decorator
• Caching
• ColdBox Proxy
• CodeX Wiki Putting it all together
• Tips & Tricks
ColdBox Installation
• Standard Installation
– Download from www.coldboxframework.com ColdBox
– Place in your webroot Proxy
– Expand and you are done!!

• Alternate Methods:
– Coldfusion Mapping + Alias/Virtual Folder M C
– Code Re-factoring via refactor.xml ANT Script

• Demo
– Standard Installation V
– Eclipse Plugins
– CFEclipse Additions
– Re-factoring
Generating Applications
• Several ways to create applications
– ColdBox Dashboard
– Eclipse ANT
– Copy & Paste

• Demo
– Let’s Create some apps!!
Layout Manipulation
• ColdBox includes a layout manager for the
rendering of views. Layout(s)
• Implicitly set views or folders to be
rendered in specific layouts or
View
• Assign a layout at runtime without altering View c
the view code.
CCV Set View
• Render views with no layouts
• Render multiple views
• Demo
– Create a PDF Layout
– Render a view with no Layout or No Layout
– Viewlets, Folder inheritance, Caching
– Much more...
View
Core Plugins
• Plugins are used to increase application or
framework functionality.
• ColdBox is also a software toolkit.
• Extensible and reusable architecture.
• 21 Core Plugins
• ColdBox keeps track of their persistence
• Have access to all of a request’s life cycle
• Can be shared
• Can be packaged
• Much more...
Core Plugins - Storage
• Storage Plugins
• applicationstorage
• sessionstorage
• clientstorage
• cookiestorage
• Facilitate the use of the scopes
• Automatically locks for you
• Client/Cookie can use simple or complex values
• Plugin automatically serializes/deserializes complex data
• Can even clean the storage scope, without affecting other variables in scope
• Quick Demo
• setting variables
• retrieveing variables
Core Plugins - Utilities
• *Utilties: A wide array of utilities for your application:
• isEmail, isURL, isCFUUID, File Operations (read,append,write,etc), CreateArray,
CreateStruct, Java metrics, OS utiltities, and much more.
• JavaLoader : Based on Mark Mandel’s work, to load java classes.
• queryHelper: sort/filter/join/append queries.
• zip : Easy to use zipping/unzipping utility
• webservices : Easily use webservice declarations (coldbox.xml) and refresh stubs.
• StringBuffer : Need tons of string operations? Go the java way.
• *timer: Time your code and see it on your debugging panel.
• *beanFactory: Create & populate beans from the request collection.
• *logger: Log errors, bug reports, log anything you like.
• Archives log files when file size limit reaches (.zip)
• Log Rotation
• Multi-Threaded
• Quick Demo (Not all plugins will be shown)
Core Plugins - Visual Plugins
• MessageBox
• Easily create snappy info boxes for
• information
• warnings
• errors
• Completely Skinnable and based on CSS
• cfcViewer
• Document your cfc’s with ease
• A good base to build cfc explorers
• Quick Demo
Core Plugins - Internationalization
• Both plugins based on Paul Hastings work.
• resourceBundle
• Gives you the ability to read java resource bundles per language locale
• Caches the language translations for you
• i18n
• It uses standard Java locale names and has its own storage mechanisms via the
resource bundles plugin
• Tons of i18n utilities
• Both plugins work off settings in the coldbox.xml
• Default Resource Bundle to use
• Default Locale (language) to load
• Locale Storage Setting: Where to store the locale setting for tracking.
• Attesoro Resource Bundles Language Editing Tool
• http://www.attesoro.org
• Please look at the Samples Gallery and the i18NSample application for an in depth demo
of the internationalization features of ColdBox
Custom Plugins
• Extend your application or framework

• Creation Guidelines
– Extend the base plugin
– Add persistence metadata
• cache
• caheTimeout
– Create an init() Method

• Snippets make life sooooo easy!!

• Let’s Create one! Quick Demo


Interceptors
• Interceptors wrap themselves around a request at specific points
– afterConfigurationLoad, afterAspectsLoad
– preProcess, preEvent, postEvent, preRender, postRender, postProcess, sessionStart, sessionEnd
– afterCacheElementInsert, afterCacheElementRemoved
– afterPluginCreation, afterHandlerCreation
– Create chains, AOP interceptions, Much more

• Custom Interceptors: Observer-Observable


– Create via conventions
– Announce interceptions (publisher) with data to all interceptors (subscribers)
– Very flexible and powerful
Interceptor
X
a
dat

data
Publisher Interceptor
X
da
ta

Interceptor
X
Core Interceptors
• Core Interceptors
– autowire (Inject Dependencies from IoC Factories)
– ses (Pretty URL’s)
– environmentControl (Per-Environment Settings)
– executionTracer (For simple tracing)
– security (Event Security Rule Engine)
Core Interceptors - Autowire
– Autowire is used to wire the following with dependencies from an object
factory:
• plugins
My Handler
• handlers
• interceptors
– Available object factories
• ColdSpring
• LightWire
– Can also execute a method right after dependencies have been injected:
onDIComplete()
My Service
– Why?
• Ease of use, your framework objects get configured with what they
need.
– Quick Demo
• Autowire
• Custom Interceptors
Core Interceptors - Environment Control
– Help you create or overwrite settings for each tier you work on:
• Development
prd
• Staging
• Production
• etc....
– How to use? qa
• Declare the interceptor with properties
• Create your environment settings xml file
– Quick Demo
dev
Core Interceptors - SES
• Help you have ses pretty URL’s • Demo
• Based on ColdCourse – ses Setup

• Advanced Custom Routing System – Core Routes


– 1 Custom Route
• No extra server configuration needed
– 1 Numerical Route
– http://mysite.com/index.cfm/handler/action
• Works also with server rewrite engines
(mod_rewrite,isapi_rewrite)
– http://mysite.com/handler/action
• Custom Routes
– wiki/:pageName
– /forums/:forum/:id
– The :var get translated into a variable with that name.
• /wiki/:pageName ==> /wiki/Dashboard
• pageName = Dashboard
• Easily obfuscate handler/action events.
Request Context Decorator
• Request Context object contains the request collection
FORM URL
• Models a User’s single request
• Decorate the request collection object
– Extend its functionality
– Change its behavior
– Override methods
– Control how it behaves
• Demo
Request Collection
– Trim all the values in the collection when created
– Create Implicit Arrays & Structures
• [1,2,3]
• {fname:luis, lname:majano, id:123}
Request Context Decorator
ColdBox Cache
• Dynamic Cache
• Fixed Limits
• Memory Sensitive
• Usage of JDK 1.5 >
Concurrency classes
• Eviction Policies
• Visual Feedback
• Multi-Threaded
• Highly Customizable
• Event Model
Tweaking The Cache
• Object Default Timeout (60)
– The life span of your objects (*Not Guaranteed)
• Object Last Access Timeout (30)
– If an object does not get used within (X) minutes, the cache will purge it. (*Not Guaranteed)
• Use Last Access Timeout (true)
– If this is set to true, then last access timeouts take into effect, else object live until they are
cleared, they timeout or the JVM garbage collects them
• Reap Frequency (1)
– The interval in minutes of when the internal cleaning routines should run. (At least)
• Max Objects (100) 0 = Unlimited
– This limits the amount of objects the cache can hold, if this is reached, the cache purges an
object using the eviction policy
• Eviction Policy (LRU) - 2.6 you can create your own, get as fancy as you want!
– Least Recently Used : The object that has not been accessed the longest.
– Least Frequently Used : The object that has the lowest access hits
• Free Memory Percentage Threshold (1%) 0 = No Check
– If the JVM has less than 1% of available memory, no new objects will be cached

• *Not Guaranteed = JVM could garbage collect them if needed


Configuration Settings
• ColdBox also has a set of settings you can use to further tweak the cache.
– ConfigAutoReload : Boolean
• This is a master switch that if set to true, recreates the application on every
request
• Can be useful on development
– HandlerCaching : Boolean
• Setting to tell the framework to cache or not event handlers
• Very useful to set to false in development.
– EventCaching : Boolean
• Setting to tell the framework to cache or not events
• Very useful to set to false in development
– IOCObjectCaching : Boolean
• Setting to tell the framework to cache the objects created by any of the IoC
factories.
• Advanced usage only
• It caches only what the factories produce
Persistence Settings & MetaData
• Persistence works via metadata on the <cfcomponent> tag
– <cfcomponent name=”obj” cache=”true” cacheTimeout=”45” cacheLastAccessTimeout=”10”>
– That’s it. The framework will read these settings and cache accordingly
• Plugins
– NOT cached by default, you must set the cache property to true.
– Can have timeout and last access timeout
• Handlers
– Cached by default, no need to say cache=true
– Can have timeout and last access timeout
• Interceptors
– Cached by default at application startup
– They are eternal objects, no timeouts.
– You will have to re-initialize the application for interceptor changes to take effect
• IOC Object Caching
– NOT cached by default, you must set the cache property to true
– Can have timeout and last access timeouts
• Quick Demo : Setting the metadata parameters
Event Caching
• ColdBox can cache the output of your events
• The cache will cache events according to their request collection and event combination
– event=site.home
– event=site.home&id=123
– event=site.home&id=12334
– The above query strings are all three different cacheable entries
– ColdBox calculates unique event hashes according to event and request collection
• How to set it up? Metadata
– cache = true
– cacheTimeout = X (minutes)
– cacheLastAccessTimeout = X (minutes)
• If you set the timeout to 0, the cache will override it to the default as a protection for event
caching.
Event Caching
• Purging & Testing Events
– URL keyword: fwCache
– This overrides the incoming cached event, purges it and re-caches it so you can view changes
• event=site.home&fwcache=true
– Use the purging mechanism in the ColdBox Cache Manager : getColdBoxOCM()
• clearAllEvents([async=true])
Clears all the events from the cache (MT)
• clearEvent(eventsnippet, [querystring], [async=true])
Clears events according to event snippet + querystring combination
– Specific event + all query string combinations:
» clearEvent(‘site.home’)
– Specific event + specific query string
» clearEvent(‘site.home’,’id=123’)
– All events in the site handler
» clearEvent(‘site’)
– All events that start with ‘dsp’
» clearEvent(‘site.dsp’)
– An extensive event purging mechanism
– Demo
View Caching
• ColdBox can also cache views
• In your event handler, whenever you use the method: setView(), you can tell the
framework to cache that specific view
• setView(name=‘myView’,cache=’true’,cacheTimeout=’40’,cacheLastAccessTimeout=’10’)
• Once the framework renders this view, it will cache it according to the parameters set.
• Once an event sets this view for rendering, it will grab it from the cache instead of processing it.
• Purging Views
– purgeView(name) : Purge a single view
– clearView(viewSnippet, async) : Purge a view according to the snippet sent
– clearAllViews(async) : Purge all views
• Also cache views at rendering time via RenderView()
– renderView(name=‘myView’,cache=’true’,cacheTimeout=’40’,cacheLastAccessTimeout=’10’)
• Anytime a view that is cached is requested for rendering, it will be rendered from cache until it
expires or you purge it.
ColdBox Proxy
ColdBox/Application
get settings
Settings

ColdBox ColdBox
Cache Plugins
Coldspring
Remoting LightWire
events
ColdBox Events
events

Remoting Transfer
ColdBox Reactor
Announce Interceptions
Interceptors

• Let’s you tap into your ColdBox Application from: Flex/Air/Ajax and even Event Gateways
• Enhance service layers or create your remote proxies with ease
• No more MVC land...
• One common application language - Multiple Interfaces
• Demo of ColdBox Flex Tester Code
• Demo of basic CF8 Ajax Sample Code
A few Tips & Tricks
• UDF Helper File: UDFLibraryFile setting.
• Programmatic UDF mixins: includeUDF( udfLibrary )
• Programmatic Mixins use methodInjector (methods,properties,calling private methods)
• Viewlets that can dispatch an event or broadcast interceptions
• Eclipse Snippets will make you happy
• Dashboard really helps you create apps and tweak the framework.
• Rendering multiple views
– Use <cfoutput>#renderView(“tags/header”)#</cfoutput>
• Set JVM Threshold to 0 in development (Use evironment control interceptor)
• HandlerIndexAutoReload much faster than ConfigAutoReload
• You can turn IoC Object Caching: IOCObjectCaching for performance
• Use the last access timeouts for better memory tuning
• Build your urls via event.buildLink(event or route)
• event.isSES(), event.isProxyRequest()
• Request Decorator is powerful
• Custom Interceptors (Broadcasters) Incredibly Powerful
CodexWiki
CodexWiki
• An application that puts it all together
• CodeX Wiki is an enterprise Wiki application built on ColdBox - ColdSpring - Transfer
• What Techniques are involved:
– Caching Layers
• Event Caching
• Data/Object Caching
• Transfer Caching
– Transfer Event Model
– UDF Helpers (mixins)
– Security Interceptions, Custom Interceptions
– Autowiring, JavaLoader
– Custom Plugins
– Much more...
• Quick overview of the running application and code
• YES! CodeX will be open source
• Private beta until our first iteration is complete. Those interested bother MARK!!!
• We will have it available for beta testing in the next few weeks
Resources
• Official Site
– http://www.coldboxframework.com
• Forums
– http://forums.coldboxframework.com
Luis Majano &
• Wiki, Bugs, Trac Site
Ortus Solutions, Corp
– http://ortus.svnrepository.com/coldbox lmajano@coldboxframework.com
lmajano@ortussolutions.com
• Google Group
– http://groups.google.com/group/coldbox
• Official Bug Email
– bugs@coldboxframework.com
Q&A

Thanks!!

Potrebbero piacerti anche