Thursday, 1 October 2009

jEmbedded - 0.1.3. RC-1 - Weekend Release

Hi,

Yes I know I've skipped 2 versions :) but the work has been progressing so well that I decided to wait a bit and release something more complete.

So I'm releasing a rc this weekend, it's still a bit rough on the edges but it contains most of the features that I'd wanted and works pretty well. Also it will fit with the new documentation that I''m going to start writing this weekend as well.

New features:

- Dynamic Injection/creation of Services: create services just with an
interface + annotations, no implementation neded, in case you are
just composing services:

@Repository(id = "serviceLayer", iocProviders = { "springRepository" }, parent = "persistenceLayer")

@AnnotatedService(id = "serviceLayer", resources= {InvoicingServiceImpl.class})

public interface ServicesLayer extends Service {

@Inject(ref="invoicingService")
public InvoicingService getInvoicingService();

@SpringRepository(configurationFile = "META-INF/invoices-app/layers/ persistence-layer.xml")
public Service getSpringRepository();

}

- Complete Spring integration: a service exporter (from jembedded) into the spring context, @Inject can reference a spring bean, a @SpringProvider annotation that will load a context as a service and can be referenced as well., a ContainerListener for web applications..
etc etc..

- More services: Validation-Service (using annotations, oval), dao-service, hibernate-service, agent-service, proxy-service.

- A payload validator for mule using the the validator-service, so you can validate your payload with annotations.

- More examples including an esb/integration case study including spring/spring-mvc, jms, mule, rules etc.. I think it shows very well what you can do with jEmbedded. Also it's an original cas study, it's not the typical aggregator of responses you can find all over the net.

- jIntegration-Test 1.0 (see the web services post).

- Fixes and more stuff.

Well I think it's pretty good for this version.

Adolfo

Sunday, 20 September 2009

And after the holidays...

I resumed my day job this last week and it wasn't very bad :) at all . So this weekend I resumed my work on jEmbedded. First of all, thanks to all the people who took the time to try it and sent me their comments, you have helped me a lot. Even though it was a early release it has given me a lot of insight in which direction I should go.

I decided to release the version 0.1.1 in the next few days that will be focused in:
  • Improved Spring Integration: The @Inject annotation will be able to reference a Spring Bean and more.
  • Improved Documentation.
  • Improved Web Support.
  • More examples: I'm adding several examples that I'm working on as a complete example of a Invoicing System including Spring MVC integration and a hierarchical services layer (you can have an early peek on the project website). That will show a lot of the jEmbedded features as creating and composing a service layer in a few minutes. Other examples will include jIntegrationTest-0.1, how to package services with jEmbedded etc...
  • Bug fixes and code refactoring.

Tuesday, 1 September 2009

jEmbedded - FAQ III

Well I'm going abroad for my holidays (it's time at last !!) so I won't be writing in a while.

I've just created a new discussion group jEmbedded Discussion Group so you are free to join and post your questions, requests etc...

After holidays want I'm going to do it's to write down a full documentation and upload more examples.

In the meantime here it's more Q/A:

* What's the difference between the @Include and @Repository annotations?

With these two annotations resources can be added to the container but in a different manner as @Repository will create a new container for the resources and @Include will just add them to the current container (default container in case you haven't provided the @Repository ann).

Use @Include if you only want to add some extra resources to the container and not to create a new one.

* Spring Integration, how to do it?

There are many different ways to do this. I've provided a spring-support-module that will help you, but in this stage it's not very comprehensive as I've focused to provide a stand alone IoC container.

In this module a FactoryBean class is provided so an instance of the embedded container can be stored into the spring-context. Then you can inject the container in any bean you want, get the container from Spring or just use ContainerHolder.getCurrentThreadContainer().
Please have a look at the spring-integration-module and the embedded-database example for more information.

You may ignore the integration module and write your own FactoryBean:

@Container(instanceType=
ContainerInstanceType.xxxx)
@Repository(id="database-service-layer", resources={EmbeddedDatabaseImpl.class})
public class EmbeddedDatabaseFactory implements FactoryBean {

public Object getObject() throws Exception {
return EmbeddedHandlerFactory.getInstance(getClass());
}

public Class getObjectType() {
return EmbeddedHandler.class;
}

public boolean isSingleton() {
return false;
}

}

Then you can retrieve the container like this:

ApplicationContex appContex; //SpringContext

EmbeddedHandler handler = (EmbeddedHandler)appContext.getBean("factory-bean-id");

Finally, you can create the container in any spring bean you'd like. Of course watch out what kind of bean it is (singleton, prototype etc...)

* Can the annotation @Inject be used to reference a Spring bean?

No at this moment, but you can inject the container to any spring bean or just accessing the container with ContainerHolder. I will add this feature in the near future.

Monday, 31 August 2009

jEmbedded FAQ II

Here there are more questions that I kept being asked about jEmbedded:

* What's the best way to use jEmbedded in a web environment?

Depends on how are you planning to use the container as a singleton, prototype or instance by thread.

Singleton

If you are planning to use it as a one single container to serve the whole web app you can create and dispose the instance in a ServletContext listener:

import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.*;

@Container(instanceType=SINGLETON_VM)
public class EmbeddedContainerListener implements ServletContextListener {
{
private ServletContext context = null;

private EmbeddedHandler handler = null;

public void contextDestroyed(ServletContextEvent event)
{
this.context = null;
handler.stop();
}

public void contextInitialized(ServletContextEvent event)
{
this.context = event.getServletContext();

handler = EmbeddedHandlerFactory.getInstance(EmbeddedContainerListener.class, *.class);
handler.start();
}
}

In order to access the container from any part of the web app:

EmbededHandler handler = ContainerHolder.getCurrentThreadContainer();

If you are using Spring, you can use an implementation of the ContainerListener to create the contaner.

As an instance per thread.

Let's say that you need a fresh container per request, in a MCV controller for instance. In order to do that just create and dispose the instance there.

Prototype instances.

You can create and dispose these instances anywhere but remember to dispose them!


* What are the differences between @Container and @Repository annotations.

@Container is just an annotation to control how the instances are being created when EmbeddedHandlerFactory.getInstance() is invoked.

@Repository is a way to create logical collections of services, components etc, for example different layers of services or components (as you can create them as a hierarchy).

This is useful even when you don't want to create complex collections (as a tree of services) just as an entry point for the container:

@Repository (id="baseServicesRepo", resources={*.class})
public class RepoEntryPoint {

handler = EmbeddedHandlerFactory.getInstance(RepoEntryPoint.class);
...
}

Now for instance lets say you need to create a different group of services that need to reference the former repository for composition:

@Repository (id="extendedServices", resources={*.class}, parent="myRepo")

Now the new container would have access to the to the parent repository as well.

I will be creating a full documentation in September, some web support out of the box and more examples (after my holidays).

Any feedback and comments are welcome.