Saturday, 5 February 2011

Puzzle Arcade Lite v1.1 is now Live!

Puzzle Arcade Lite v1.1 is now available at the App Store, or just looking for "Puzzle Arcade Lite" "Puzzle Arcade Lite" or "PuzzleArcade".

More information at the game's blog.







Monday, 25 January 2010

Anatomy of a Service

One of the reasons that I developed jEmbedded was my obsession with services :)

From 2002 onwards I haven´t stopped designing and developing using Services (and a DOM of course) to express and group the business logic of applications.

Make no mistake, we are working in Information Technology and that means that the core of our business is the information and how to store and manage it.

Of course, we have to sell that information and for that we need fancy screens, complex Ajax frameworks etc... and sometimes because of that we lose the perspective and spent a lot of time making that screens look great and forgetting about to organize and develop the business logic.

The business logic it´s where the real value of the company lies, not the UI. In fact, the business logic could stay forever meanwhile the UI changes (look at the banks for instance). Despite that fact, most of the Companies I worked in the past had their business logic buried into the code, with no organization or services whatsoever. That lead to the disaster as you may well know, when you need to change something, add more rules etc...

So Services and SOA comes to rescue, but what is a Service (I will talk about SOA in another post) ?.

A Service is just a piece of code that can be invoked by a client (being a client an application, a controller, a web service, another service etc..) that express some business logic grouped in a logical fashion.
The service acts as a facade for the client so only a few methods are exposed being each method the solution to a complete use case. For instance, a correct method would be

approveInvoice(invoice:Invoice):boolean

and a incorrect one would be

getCountryDescription():String.

It´s easy to see the advantages of doing this and I´m sure you are aware of them so I´m not going to explore this further.

There is many ways to develop a Service being the most common way to have an interface and a implementation for that interface. You can do this with jEmbedded of course but it provides more advanced and simpler ways to do it.

Simpler, because you don´t need to implement a interface (you still can do it if you really need it) or any other class just annotations.

Advanced, because you can create your services as an abstract class using composition (reusing other services through the @Compose annotation and linking its life cycle to the parent service) or injection (@Inject) and letting the SOC container implements the abstract methods.

So once you have figured out what part of your business logic you want to expose to the client you can decide which methods will you need and how you are going to implement then. The best way to implement that methods it´s to use other services that you already have using composition or injection to promote re usability.

So let´s say you want to implement a simple service that evaluates if a list of numbers are odd or not.

It´s obvious we only would need a method:

public List checkOddNumberRS (Object... numbers)
And now we can implement the skeleton of the service or if you are following TDD in a strict way the unit test (by the way, jEmbedded comes with a testing infrastructure for the core and for each service provided based on jUnit):

@AbstractAnnotatedService (id="evenOddService")
public abstract class EvenOddService {
public List checkOddNumbers (Object... numbers) {
return null;
}
}

That´s good but how can we implement it? We could do it using just a List and the formula (i%2==0) but we´ll use the RulesService that´s provided with jEmbedded showing how to use the composition:

@AbstractAnnotatedService (id="evenOddService")
public abstract class EvenOddService {
@Compose
@AnnotatedRulesService
public abstract RulesService getRulesService();
public List checkOddNumbers (Object... numbers) {
return (List )getRulesService().execute(numbers);
}
}

As you can see the composition is made through and abstract method that the container will implement. The only restriction is that the method must start with get. The method will be implemented at runtime so you can use it to implement the service methods.

All the services that you create using the jEmbedded container have a properties service that will help you to configure it using a properties file. You can parse attributes of the annotations or variables of the service. You can do that either using the attribute propertiesFile (from the annotations) or using the AnnotationsPropertiesService:

@Compose
@AnnotatedPropertiesService(propertiesFile="META-INF/evenodd/even-odd-service.properties")
public abstract PropertiesService getPropertiesService();

We need to use the properties service not the propertiesFile attribute as we need to configure the RuleService not the the service we are creating.




Friday, 15 January 2010

Learning RoadMap with jEmbedded 0.2

Hi everybody,

I have added new examples and refactored the existing ones using the new features of the 0.2 version.

In order to learn how to use the framework here it's the roadmap you could follow:

- Start learning the hello world service example, it's easy to follow and it's explained in the wiki. You can learn how to create your custom annotations, etc...

- Then you can learn how to create other services using composition with the included services: jetty example, calculator service, even
odd example etc...

- Once you are comfortable creating services, composing etc you can learn how to organize the services in layers with the layers example.

- When you know how to create a layer you can learn how to use the container in a web environment (using the previous layer example).

- Then you can have a look at the ESB case study that comprises all the previous stuff, services, layers, web environment etc...

I will continue improving the documentation and adding examples, and please feel free to ask everything you need.

Keep in mind that you can create and annotate your services and elements in many ways, I've tried to show this in the examples. There is no just one right way, you can create your custom annotations or not, you can inject fields or methods etc.. depends on the particular case.

Take care

Adolfo