cold box advanced techniques workshop

31
Luis Majano & Ortus Solutions, Corp [email protected] Advanced Techniques with the ColdBox Framework #SU3B

Upload: yoman

Post on 18-Nov-2014

143 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Cold Box Advanced Techniques Workshop

Luis Majano & Ortus Solutions, Corp

[email protected]

Advanced Techniques with the

ColdBox Framework#SU3B

Page 2: Cold Box Advanced Techniques Workshop

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

Page 3: Cold Box Advanced Techniques Workshop

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

Page 4: Cold Box Advanced Techniques Workshop

ColdBox Installation• Standard Installation

– Download from www.coldboxframework.com– Place in your webroot– Expand and you are done!!

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

• Demo– Standard Installation– Eclipse Plugins– CFEclipse Additions– Re-factoring

C

V

M

ColdBox Proxy

Page 5: Cold Box Advanced Techniques Workshop

Generating Applications• Several ways to create applications

– ColdBox Dashboard– Eclipse ANT– Copy & Paste

• Demo– Let’s Create some apps!!

Page 6: Cold Box Advanced Techniques Workshop

Layout Manipulation• ColdBox includes a layout manager for the

rendering of views.• Implicitly set views or folders to be

rendered in specific layouts or• Assign a layout at runtime without altering

the view code.• Render views with no layouts• Render multiple views• Demo

– Create a PDF Layout– Render a view with no Layout– Viewlets, Folder inheritance, Caching– Much more...

c

Layout(s)

ViewCCV

View

Set View

View

or No Layout

Page 7: Cold Box Advanced Techniques Workshop

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...

Page 8: Cold Box Advanced Techniques Workshop

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

Page 9: Cold Box Advanced Techniques Workshop

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)

Page 10: Cold Box Advanced Techniques Workshop

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

Page 11: Cold Box Advanced Techniques Workshop

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

Page 12: Cold Box Advanced Techniques Workshop

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

Page 13: Cold Box Advanced Techniques Workshop

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

Publisher

Interceptor X

Interceptor X

Interceptor X

data

data

data

• Custom Interceptors: Observer-Observable

– Create via conventions– Announce interceptions (publisher) with data to all interceptors (subscribers)

– Very flexible and powerful

Page 14: Cold Box Advanced Techniques Workshop

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)

Page 15: Cold Box Advanced Techniques Workshop

Core Interceptors - Autowire– Autowire is used to wire the following with dependencies from an object

factory:• plugins• handlers• interceptors

– Available object factories• ColdSpring• LightWire

– Can also execute a method right after dependencies have been injected: onDIComplete()

– Why?• Ease of use, your framework objects get configured with what they

need.– Quick Demo

• Autowire• Custom Interceptors

My Handler

My Service

Page 16: Cold Box Advanced Techniques Workshop

Core Interceptors - Environment Control– Help you create or overwrite settings for each tier you work on:

• Development• Staging• Production• etc....

– How to use?• Declare the interceptor with properties• Create your environment settings xml file

– Quick Demodev

qa

prd

Page 17: Cold Box Advanced Techniques Workshop

Core Interceptors - SES• Help you have ses pretty URL’s

• Based on ColdCourse

• Advanced Custom Routing System

• No extra server configuration needed– 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.

• Demo– ses Setup– Core Routes– 1 Custom Route– 1 Numerical Route

Page 18: Cold Box Advanced Techniques Workshop

Request Context Decorator• Request Context object contains the request collection

• Models a User’s single request

• Decorate the request collection object– Extend its functionality– Change its behavior– Override methods– Control how it behaves

• Demo– 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

FORM URL

Request Collection

Page 19: Cold Box Advanced Techniques Workshop

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

Page 20: Cold Box Advanced Techniques Workshop

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

Page 21: Cold Box Advanced Techniques Workshop

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

Page 22: Cold Box Advanced Techniques Workshop

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

Page 23: Cold Box Advanced Techniques Workshop

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.

Page 24: Cold Box Advanced Techniques Workshop

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

Page 25: Cold Box Advanced Techniques Workshop

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.

Page 26: Cold Box Advanced Techniques Workshop

ColdBox Proxy

• 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

ColdBox Events

Remoting

Remoting

ColdBox Cache

ColdBoxPlugins

ColdBoxInterceptors

ColdspringLightWire

TransferReactor

events

events

Announce Interceptions

ColdBox/ApplicationSettings

get settings

Page 27: Cold Box Advanced Techniques Workshop

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

Page 28: Cold Box Advanced Techniques Workshop

CodexWiki

Page 29: Cold Box Advanced Techniques Workshop

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

Page 31: Cold Box Advanced Techniques Workshop

Q & A

Thanks!!