Develop and use "aspects" to believe how Fuji made it easier for you! You can start right here with your own "echo" aspect development.

In Fuji Milestone 9 (M9), aspects became more simpler and dynamic. Its a breeze to develop and use aspects.

From M9 onwards, you can also have aspects that are integral to your integration application, by scoping thoseaspects with the components of that application and taking advantage of thatapplication's life cycle.Moreover, you can also develop "type"d aspects in that application itself by simple POJOs and then inject corresponding aspects.


A Java Developer develops an interceptor that can behave by its own set of properties. The interceptor can be "type"d , by which aspects can be injected to the Fuji runtime. The typed interceptor is an innovative design concept that cleared many obstacles to make aspects more appealing.

An aspects user can inject aspects to the fuji runtime by Fuji CLI (Command Line Interface), Integration Application, aspects archetypes and your own applications. He can also control the behavior of the aspects by changing the aspects property values through Fuji CLI.


Here, I explain developing an echo typed aspect, creating echo aspects and changing their behavior. Your "echo" aspect simply echoes your message at your desired message exchange point. Do have the latest Fuji environment and take the ride on.


Echo Aspect Development

Step1: Create a project in Netbeans using interceptor archetype.

In Netbeans choose, File -> New Project

In the dialog choose, Maven in categories and then select Maven Project in projects. Click Next -> for next dialog.

Choose Fuji Interceptor Archetype in the Maven Archetypes. Ensure the description says "Version: 1.0-M9-SNAPSHOT" . Click Next -> for next dialog.

Type EchoAspect at Project Name. You can change other values of your choice or leave as is. Click Finish

Step 2: Chose FujiInterceptor.java for editing

In Netbeans, In Projects window, select Interceptor - EchoAspect (jar)

Expand Source Packages by clicking "+" sign next to the entry

Expand com.mycompany.EchoAspect by clicking "+" sign next to the entry

Select FujiInterceptor.java by double clicking on the entry



Step 3: Write Java code for "echo" functionality.
i. Define echoProperty variable in FujiInterceptor class as
private String echoProperty = "This is my default echo";

ii. Make the messageExchangeInterceptor function as "echo" aspect by having just the type property of the aspect as "echo".

@Intercept(type="echo")
public boolean messageExchangeInterceptor(MessageExchange exchange) {


Note: You can also leave the default priority and status annotated properties to inject an functioning aspect to Fuji.


iii. Print the value of echoProperty variable for echoing in the messageExchangeInterceptor.
System.out.println("From EchoAspect:" + echoProperty);
At the end of these changes, the messageExchangeInterceptor function looks like

@Intercept(type="echo")
public boolean messageExchangeInterceptor(MessageExchange exchange) {
//TODO: add message exchange interceptor processing code here.
NormalizedMessage msg = exchange.getMessage("in");
// msg.setProperty("Fuji1", "Value1");
System.out.println("From EchoAspect:" + echoProperty);
return true;
}

Step 4: Add dynamic behavior for the echo aspect
You can make your aspect behave by your own set of properties.These properties can be dynamically changed by Fuji CLI. And, the setConfiguration will be called whenever properties got set by the user.

To have a dynamic echo aspect, add the following code to setConfiguration function in that same FujiInterceptor.java class

if(properties.containsKey("echoProperty")){
echoProperty = properties.getProperty("echoProperty");
}
The setConfiguration function looks like..
/**
* This method is invoked by the runtime when the interceptors
* configuration is created/updated.
*
* @param interceptorName - name of the interceptor that this configuration applies to
* @param properties - updated configuration properties
*/
public void setConfiguration(String interceptorName, Properties properties)
{
// TODO: handle the configuration change notification
// System.out.println("Configuration for interceptor "
// + interceptorName + " is " + properties.toString());
if(properties.containsKey("echoProperty")){
echoProperty = properties.getProperty("echoProperty");
}
}


Step 5: Build and deploy Echo Aspect project

In Netbeans, Projects window, Select Interceptor - EchoAspect(jar) entry.

Right click on mouse and select Build. In the output window, observe the BUILD SUCCESSFUL message.

Make sure that your Fuji runtime is running.


Right click on mouse and select Deploy...

In the output window, Fuji Server tab, you can see message similar to

-> -> Apache Derby Network Server - 10.4.1.3 - (648739) started and ready to accept connections on port 1600 at 2009-10-08 19:07:27.922 GMT
Deploying D:\Netbeans\Aspects\EchoAspect\target\app.jar
Installing bundle= file:/D:/Netbeans/Aspects/EchoAspect/target/app.jar
Deploy Results: 70

You can verify the deployment by Fuji CLI's list-configurations command, which should list com.mycompany.EchoAspect.FujiInterceptor.messageEx changeInterceptor.
-> fuji list-configurations

Configuration Names
-------------------
com.mycompany.EchoAspect.FujiInterceptor.messageEx changeInterceptor
org.glassfish.openesb.aspects.policy.PolicyImpl.ex ecute
org.glassfish.openesb.aspects.log.LogImpl.execute
Command list-configurations executed successfully.
Thats it! You have already developed and deployed "echo" typed aspect. And, Its time for injection of aspects.


Echo Aspect Injection


Aspects can be injected to Fuji runtime by CLI (Command LineInterface), by Integration Application or by your own application.Additionally, out-of-the-box aspects, like Log and Policy, can beinjected by their maven archetype projects.

The "type" of your interceptor is instrumental for creation and injection of dynamic aspects to the Fuji runtime.


Echo Aspect Injection by CLI command : create-aspect

The create-aspect command injects an aspect to the Fuji runtime. All interceptor scoping parameters, the "type" parameter and and aspect specific commands can be provided as part of the command. For example,

-> fuji create-aspect type=echo name=echo-1 status=Active echoProperty="I am echoing from echo-1 aspect injected at Fuji CLI"
Created Aspect: echo-1

Command create-aspect executed successfully.
->



The above command injects "echo-1" aspect. The interceptor scope, status=Active, will trigger execution of this aspect, at every message exchange point of all the active messages. As per the logic of echo, for all active messages, we see the message,

->From EchoAspect:I am echoing from echo-1 aspect injected at Fuji CLI

delete-aspect command can be used to delete an aspect by its name.


Integration Applications


Aspects can also be injected to Fuji runtime by integration applications. The life cycle of such aspects are tied to the application that contained them. Means, aspects are created when that application is installed and are deleted when that application uninstalled.

To inject aspects, go to aspects folder under Other Sources folder of any integration application of Milestone 9 and higher. Right click on that aspects folder and add property files. Each property file under this aspects folder, represents one aspect.


Have a properties file similar to the following to inject a echo-2 aspect ..

type=echo
name=echo-2
status=Active
echoProperty=This echo-2 aspect is created in the integration application.

Build and deploy your application and notice availability of echo-2 by Fuji CLI command, list-configurations.
You can have as many aspects as you want. You can also organize your aspects in sub-directories.


Your own applications


You can also inject aspects from your own applications! What all you need to do is package all your aspect properties files under META-INF/aspects folder in your deployment jar.

Deploy your application. JBI Framework bundle keeps track of bundles for META-INF/aspects folders and will inject aspects from the property files beneath it.


Dynamic Aspects

By now, you have already experienced how simple its easy to develop your own aspects and various means of injecting aspects to the Fuji runtime.


And these aspects are dynamic. You can switch the injection point by changing the interceptor specific properties. And you can control the behavior of the aspect by changing your aspect specific properties.


Fuji CLI provides set-configuration command to change the properties of your "name"d aspect by its name.


For example, if you want to inject echo-1 at an endpoint, say, file1-endpoint, the command looks like

-> fuji set-configuration --name=echo-1 endpoint=file1-endpoint


from now onwards, the echo-1 aspect echoes only for the messages delivered or originated from file1-endpont.

And to change the echo message for your echo-1,

-> fuji set-configuration --name=echo-1 echoProperty="Echo message is changed by set-configuration CLI"
Your setConfiguration method of the corresponding aspect's instance is identified and called by JBI framework!

Conclusion

As an java aspect developer, you just concentrate developing aspect's behavior method and handle the configuration method. And Fuji backs you up with dealing aspects injection, interception and dynamic behavior of your aspects.

Fuji is evolving at fast pace for more support and functionality.

Stay tuned for more advancements and start developing your aspects. And yes, its open source and contribute back.




More...