Dependency injection between two local EJBs with Netbeans

This a simple tutorial about how to create a local dependecy injection within two EJBs 3.0.

The point is creating one EJB that calls a method from another local EJB with Netbeans and Glassfish.

Start Netbeans and create a new EJB project called Util and add a new session bean to it. Make it stateless and local.

@Local
public interface UtilLocal
{
int returnInt();
}



@Stateless
public class UtilBean implements UtilLocal
{
public int returnSomething()
{
return 0;
}
}

Now create a second EJB project called Main and add a new session bean to it, like in the Util EJB. Include the Util EJB inside the Main EJB project.

@Local
public interface MainLocal
{
int doSomeLogic();
}


@Stateless
public class MainBean implements MainLocal
{
@EJB(beanName="UtilBean")
UtilLocal utilEJB;

public int doSomeLogic()
{
return utilEJB.returnSomething();
}
}

Note that we use @EJB to instantiate the Util EJB object.

Simple yet effective :mrgreen:

J2ME Game Template

Some time ago I decided to write a simple template to facilitate the task of creating a new J2ME project.

The template is a Netbeans project that can be used as a base to build a J2ME game or application. It is ready to build projects for MIDP 1 and MIDP 2 as well as specific versions for Nokia. This can be achieved by changing simple processor directives.

The template has one thread to run the main loop. Inside this loop, the input and the screen are automatically updated in each frame.

It also has some input functions and code to detect if the device supports double buffering or not. In case it doesn’t the template manages double buffering for you.

The main functions are in MainCanvas class:



private final static void MAIN_Render(Graphics g)

private final static void MAIN_Loop()

private final static boolean INP_KeyDown(int key)

private final static boolean INP_AnyKeyDown()

private final static boolean INP_KeyPress(int key)

private final static boolean INP_AnyKeyPress()


The first two functions are where you are going to put your render and logic code. The template first calls MAIN_Loop, for your logic code, and then it calls MAIN_Render, where you draw whatever you want.

The input functions are provided for detecting if a key is down or whether it has been pressed within the last frame.

The template comes with an example of its use so you can test it and hack it as much as you may want to.

You can download the template from here­.

Warming up

The site is almost ready.

It still needs some work to do and some sections need to be filled out but my new site is getting almost done 🙂

In a few days I will begin with my new XNA project called Spin (working title).

More news to come. Stay tuned!!