Home > Documentation > Reference > Samples > Java EE sample applications > ejbtimer-javaee6 - A simple EJB timer service application |
This sample demonstrates a calender based timer service that triggers certain callbacks to enterprise beans at a specified time or interval programmatically. The cron-style timer service is managed by the EJB container and can be created using @Schedule annotation.
Also this sample introduces the annotation way to define servlets, stateless session beans and Persistence Context.
ejbtimer-javaee6 application consists of following list of packages and classes.
org.apache.geronimo.samples.javaee6.ejbtimer
The list of web application files in the application is depicted in the following.
+-WEB-INF
|_ web.xml
|_ geronimo-web.xml
+- Resources
|_ persistence.xml
|_ index.html
|_ header.html
|_ intro.html
geronimo-web.xml specifies the module's information and the url for the web application
Information about the project sucha as module's unique identification, dependencies is described inside the <sys:environment/> tags. It is a good practise to give a module an unique identification, so that it can later be referenced by some other deployable application. This module is in the group org.apache.geronimo.samples. The path specified in the <context-root> tag will be the entry point of this web application. Therefore you can access this web application at http://<hostname>:<port>/ejbtimer-javaee6.
ShowLog.java is a servlet component which is annotated with @WebServlet and defines the url pattern using urlPatterns attribute. And a business interface of the session bean logFacade is injected using @ejb annotation so that the servlet could invoke count()
and findAll()
methods from logFacade.
urlPatterns
or value
attribute specified.scheduleTask is a stateless session bean with multiple methods annotated with @Schedule annotations. Each method will be invoked according to the attributes specified to @Schedule. Also, there are two specified methods logIntoDB(String event)
and clearLogs()
to perform actions on an entity EJBTimerPU
injected with @PersistenceContext annotation.
logFacade is a stateless session bean to define another two actions on an entity EJBTimerPU
, where both methods are invoked from the servlet component ShowLog.
persistence.xml is the configuration file to define a persistence unit named EJBTimerPU
, which represents a table named OPENJPASEQ in a derby database ejbtimerdb
.
Log.java is an entity bean representing a primary key class of the database table. A primary key class must implement the hashCode()
and equals(Object object)
methods.
Please reference Samples General Information for information on obtaining and building the source for this and other samples.
Once all the sources get checked out the next step is to build ejbtimer-javaee6. It requires Maven 2 for building the binaries.
From the <ejbtimer-javaee6_home> directory run the following command.
mvn clean install
This process will take a couple of minutes. The binaries will be generated in the corresponding target directory .
Deploying sample application is pretty straight forward as we are going to use the Geronimo Console.
The app is visible at http://localhost:8080/ejbtimer-javaee6/
This page is about what kind of timers defined in the sample application and for each task, an log entry is created.
Click Check the log list, you will see all log info with specific time and event details.
Bookmark this on Delicious Digg this | Privacy Policy - Copyright © 2003-2013, The Apache Software Foundation, Licensed under ASL 2.0. |