Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

AS7-5265 EJB timer - @Schedule and @Timer #317

Closed
wants to merge 1 commit into from

4 participants

@OndraZizka

No description provided.

ejb-timer/README.md
@@ -0,0 +1,95 @@
+wicket-war: Wicket Framework used in a WAR.
+===========================================
+Author: Ondrej Zizka <ozizka@redhat.com>
+Level: Basic
@pmuir Owner
pmuir added a note

Should be "Beginner" :-)

I will change this, as well as remove notions of Wicket (result of copy-paste)

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/README.md
((39 lines not shown))
+ For Linux: JBOSS_HOME/bin/standalone.sh
+ For Windows: JBOSS_HOME\bin\standalone.bat
+
+
+Build and Deploy the Quickstart
+-------------------------
+
+_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Build and Deploy the Quickstarts](../README.md#buildanddeploy) for complete instructions and additional options._
+
+1. Make sure you have started the JBoss Server as described above.
+2. Open a command line and navigate to the root directory of this quickstart.
+3. Type this command to build and deploy the archive:
+
+ mvn clean package jboss-as:deploy
+
+4. This will deploy `target/jboss-as-wicket-war.war` to the running instance of the server.
@pmuir Owner
pmuir added a note

Needs an update :-)

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...org/jboss/as/quickstarts/ejbTimer/TimeoutExample.java
((10 lines not shown))
+
+/**
+ * Demonstrates how to use the EJB's @Timeout.
+ *
+ * @author <a href="mailto:ozizka@redhat.com">Ondrej Zizka</a>
+ */
+@Singleton
+@Startup
+public class TimeoutExample {
+
+ @Resource
+ private TimerService timerService;
+
+ @Timeout
+ public void scheduler(Timer timer) {
+ System.out.println("SingletonTimer: Info="+timer.getInfo());
@pmuir Owner
pmuir added a note

Some more spaces might be nice here.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/src/main/webapp/WEB-INF/web.xml
((10 lines not shown))
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ version="2.5">
+
+ <display-name>JBoss AS Quickstart: Wicket WAR</display-name>
+
+ <!-- A message displayed on the page, externalized into web.xml -->
+ <env-entry>
+ <env-entry-name>welcomeMessage</env-entry-name>
+ <env-entry-type>java.lang.String</env-entry-type>
+ <env-entry-value>Welcome to the JBoss AS Quickstart showing the use of Wicket, packaged in an EAR</env-entry-value>
+ </env-entry>
+
+</web-app>
@pmuir Owner
pmuir added a note

Do we need this file at all?

Nope :) I originally intended to make it a web app, but keeping web out keeps it much clearer.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
...r/src/main/webapp/WEB-INF/ejb-timer-quickstart-ds.xml
((17 lines not shown))
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_1.xsd">
+ <!-- The datasource is bound into JNDI at this location. We reference
+ this in META-INF/persistence.xml -->
+ <datasource jndi-name="java:jboss/datasources/EjbTimerQuickstartDS"
+ pool-name="ejb-timer-quickstart" enabled="true"
+ use-java-context="true">
+ <connection-url>jdbc:h2:mem:ejb-timer-quickstart;DB_CLOSE_ON_EXIT=FALSE</connection-url>
+ <driver>h2</driver>
+ <security>
+ <user-name>sa</user-name>
+ <password>sa</password>
+ </security>
+ </datasource>
+</datasources>
+
@pmuir Owner
pmuir added a note

Probable we don't need a DS at all?

Regarding DS - I thought it might be necessary for persistent timeouts. But that's probably only true for AS 5 and 6, right? AS 7 puts this to files?

@pmuir Owner
pmuir added a note

I think the app server will just use it's own persistent store for that, not one you define.

Removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/src/main/webapp/WEB-INF/beans.xml
((4 lines not shown))
+ the copyright.txt in the distribution for a full listing of individual contributors.
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ use this file except in compliance with the License. You may obtain a copy
+ of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<!-- This file can be an empty text file (0 bytes) -->
+<!-- We're declaring the schema to save you time if you do have to configure
+ this in the future -->
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>
@pmuir Owner
pmuir added a note

Does this use CDI?

I am so messy. Will fix.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sgilda
Owner

Following the instructions in the README, I get a deployment errror. This is in the server log:

14:25:11,069 INFO org.jboss.weld.deployer JBAS016005: Starting Services for CDI deployment: jboss-as-ejb-timer.war
14:25:11,093 INFO org.jboss.as.connector.subsystems.datasources JBAS010400: Bound data source [jboss/datasources/EjbTimerQuickstartDS]
14:25:11,228 INFO org.jboss.as.server JBAS015870: Deploy of deployment "jboss-as-ejb-timer.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"jboss-as-ejb-timer.war#primary\"jboss.naming.context.java.jboss.datasources.WicketQuickstartDSMissing[jboss.persistenceunit.\"jboss-as-ejb-timer.war#primary\"jboss.naming.context.java.jboss.datasources.WicketQuickstartDS]"]}
14:25:11,237 INFO org.jboss.as.connector.subsystems.datasources JBAS010409: Unbound data source [jboss/datasources/EjbTimerQuickstartDS]
14:25:11,251 INFO org.jboss.as.server.deployment JBAS015877: Stopped deployment jboss-as-ejb-timer.war in 24ms
14:25:11,253 INFO org.jboss.as.controller JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.naming.context.java.jboss.datasources.WicketQuickstartDS (missing) dependents: [service jboss.persistenceunit."jboss-as-ejb-timer.war#primary

As Pete suggested, maybe the datasource isn't needed?

@sgilda
Owner

I got it to work by doing the following:

  • I removed the resources/ directory and its contents as you don't need the persistence.xml file.
  • I removed the webapp/WEB-INF/ejb-timer-quickstart-ds.xml file.

Removing the web.xml file resulted in the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project jboss-as-ejb-timer: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

I got around that by adding this plugin to the pom.xml build section:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch
up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>

@OndraZizka

I've reflected all comments and pushed the result.

@sgilda
Owner

When I build and deploy this, I get BUILD FAILURE and this error in the server log:

10:33:47,348 INFO org.jboss.as.server JBAS015870: Deploy of deployment "jboss-as-ejb-timer.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"jboss-as-ejb-timer.war#primary\"jboss.naming.context.java.jboss.datasources.WicketQuickstartDSMissing[jboss.persistenceunit.\"jboss-as-ejb-timer.war#primary\"jboss.naming.context.java.jboss.datasources.WicketQuickstartDS]"]}
10:33:47,357 INFO org.jboss.as.server.deployment JBAS015877: Stopped deployment jboss-as-ejb-timer.war in 8ms
10:33:47,358 INFO org.jboss.as.controller JBAS014774: Service status report
JBAS014776: Newly corrected services:
service jboss.naming.context.java.jboss.datasources.WicketQuickstartDS (new available)

You removed the datasource, but I believe you also need to remove the persistence.xml file as well since it is not needed. It deploys fine when I remove it.

Also, would you mind squashing all the commits into one so it's easier to review? :-)

@pmuir
Owner

@OndraZizka just a quick status check

@OndraZizka

Ah, right... I will fix this during this week, hopefully.

@sgilda
Owner

20121217: Sent email reminder.

@sgilda
Owner

2013-04-09: At the time we last talked, this only had a minor issue to remove the persistence.xml file and squash the commits.

I ran the QS Tools report and believe the only other changes required are the following:

  • Add the following metadata to the README.md file:

    Target Product: EAP
    Source: <https://github.com/jboss-jdf/jboss-as-quickstart/>
    
  • Make sure the licenses match the license template in the root of the quickstart directory.

@sgilda
Owner

@OndraZizka : Just checking in to see how things are going with your quickstart. Please let me know when it's ready for review again.

@sgilda
Owner

@OndraZizka : Just checking on the status of this quickstart. :-)

@sgilda
Owner

@OndraZizka thinks this will be a quick fix and hopes to finish it up in the next week.

@sgilda
Owner

Sent email to @OndraZizka to let him know we will be closing pull requests in a few days to reorganize the quickstarts, so this needs to be finished ASAP.

@sgilda
Owner

Since I haven't had a response from Ondra, I will close this one for now. He can repen it at a later date.

@sgilda sgilda closed this
@sgilda sgilda reopened this
@OndraZizka

Now it should be okay to merge.

@sgilda
Owner

Thanks Ondra. I'll check it out next!

@sgilda
Owner

@OndraZizka : There 41 files changed in your 6 commits. The first commit even says
Java source 1.6 for some quickstarts, mostly DeltaSpike

I believe you should only have 4 files committed for this quickstart. Can you clean up the commits so that only the ejb-timer source is included?

Also, can you run the QS tools utility on your quickstart? It's reporting some violations. Some are due to changes since you started this quickstart. See step 8 here: https://github.com/jboss-jdf/jboss-as-quickstart/blob/master/CONTRIBUTING.md

I did test the quickstart and it compiles, deploys, and works fine.

ejb-timer/README.md
@@ -0,0 +1,98 @@
+ejb-timer: EJB Timers example - @Schedule and @Timeout
+===========================================
+Author: Ondrej Zizka <ozizka@redhat.com>
+Level: Beginner
+Technologies: EJB 3.1 Timer
+Summary: Demonstrates how to use EJB 3.1 Timer (@Schedule and @Timeout) with the JBoss AS server.
+
@sgilda Owner
sgilda added a note

Please add the following:

Target Product: EAP
Source: https://github.com/jboss-jdf/jboss-as-quickstart/

Can't get rid of Content for metadata [Source: = https://github.com/jboss-jdf/jboss-as-quickstart/] should follow the [<(http|https)://\w.*>] pattern

The other warnings are gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
((28 lines not shown))
+ </licenses>
+
+ <description>
+ A sample JAVA EE 6 project demonstrating how to use EJB 3.1 timer (@Schedule and @Timeout).
+ </description>
+
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <!-- Define the version of JBoss' Java EE 6 APIs we want to import. -->
+ <jboss.spec.version>3.0.0.Final</jboss.spec.version>
+ <!-- Alternatively, comment out the above line, and un-comment the
+ line below to use version 3.0.0.Final-redhat-1 which is a release certified
+ to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6
+ maven repository. -->
+ <!-- <jboss.spec.version>3.0.0.Final-redhat-1</jboss.spec.version> -->
@sgilda Owner
sgilda added a note

These property names were changed and the versions have been updated. This section should now be:

    <version.jboss.spec.javaee.6.0>3.0.2.Final</version.jboss.spec.javaee.6.0>
    <!-- Alternatively, comment out the above line, and un-comment the 
        line below to use version 3.0.2.Final-redhat-3 which is a release certified 
        to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6 
        maven repository. -->
    <!-- <version.jboss.spec.javaee.6.0>3.0.2.Final-redhat-3</version.jboss.spec.javaee.6.0> -->

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
((44 lines not shown))
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- JBoss distributes a complete set of Java EE 6 APIs including
+ a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
+ a collection) of artifacts. We use this here so that we always get the correct
+ versions of artifacts. Here we use the jboss-javaee-6.0-with-tools stack
+ (you can read this as the JBoss stack of the Java EE 6 APIs, with some extras
+ tools for your project, such as Arquillian for testing) and the jboss-javaee-6.0-with-hibernate
+ stack you can read this as the JBoss stack of the Java EE 6 APIs, with extras
+ from the Hibernate family of projects) -->
+ <dependency>
+ <groupId>org.jboss.spec</groupId>
+ <artifactId>jboss-javaee-6.0</artifactId>
+ <version>${jboss.spec.version}</version>
@sgilda Owner
sgilda added a note
    <version>${version.jboss.spec.javaee.6.0}</version>

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
@@ -0,0 +1,135 @@
+<?xml version="1.0"?>
+<!-- JBoss, Home of Professional Open Source Copyright 2012, Red Hat, Inc.
+ and/or its affiliates, and individual contributors by the @authors tag. See
+ the copyright.txt in the distribution for a full listing of individual contributors.
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ use this file except in compliance with the License. You may obtain a copy
+ of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
@sgilda Owner
sgilda added a note

This license text is out of date. You can copy it from one of he other quickstart POM files. It should be:

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
((23 lines not shown))
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <distribution>repo</distribution>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
+ </license>
+ </licenses>
+
+ <description>
+ A sample JAVA EE 6 project demonstrating how to use EJB 3.1 timer (@Schedule and @Timeout).
+ </description>
+
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <!-- Define the version of JBoss' Java EE 6 APIs we want to import. -->
+ <jboss.spec.version>3.0.0.Final</jboss.spec.version>
@sgilda Owner
sgilda added a note

Before this line, define the maven plugin property here:

    <version.jboss.maven.plugin>7.3.Final</version.jboss.maven.plugin>

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
ejb-timer/pom.xml
((90 lines not shown))
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <!-- Set the name of the war, used as the context root when the app
+ is deployed. -->
+ <finalName>${project.artifactId}</finalName>
+
+ <plugins>
+ <!-- JBoss AS plugin to deploy the war. -->
+ <plugin>
+ <groupId>org.jboss.as.plugins</groupId>
+ <artifactId>jboss-as-maven-plugin</artifactId>
+ <version>7.4.Final</version>
@sgilda Owner
sgilda added a note

We don't use hard-coded versions. Use the property:

    <version>${version.jboss.maven.plugin}</version>

Just for this one or any plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sgilda sgilda commented on the diff
...rg/jboss/as/quickstarts/ejbTimer/ScheduleExample.java
@@ -0,0 +1,21 @@
+
@sgilda Owner
sgilda added a note

This file is missing the license header.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sgilda sgilda commented on the diff
...org/jboss/as/quickstarts/ejbTimer/TimeoutExample.java
@@ -0,0 +1,44 @@
+
@sgilda Owner
sgilda added a note

This file is missing the license header.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@OndraZizka

Regarding "Java source 1.6 for some quickstarts, mostly DeltaSpike", that's because those were unbuildable. They need the changes, otherwise fail to compile as Java 1.3 source format. But I'll remove these changes and offer as separate PR.

@OndraZizka

Squashed to one commit. Removed DeltaSpike stuff.

@sgilda
Owner

@OndraZizka : This looks much better. I'll review it tomorrow.

@sgilda
Owner

@OndraZizka - This looks good. One minor issue is still reported by the QS tools utility. The URL for the 'Source:' metadata tag should be linkable: Source: <https://github.com/jboss-jdf/jboss-as-quickstart/>. I can fix what when I merge it.

@VineetReynolds will do a code review on this tomorrow and if he gives the word, I will merge.

...org/jboss/as/quickstarts/ejbTimer/TimeoutExample.java
((31 lines not shown))
+@Singleton
+@Startup
+public class TimeoutExample {
+
+ @Resource
+ private TimerService timerService;
+
+ @Timeout
+ public void scheduler(Timer timer) {
+ System.out.println("EJB Timer: Info=" + timer.getInfo());
+ }
+
+ @PostConstruct
+ public void initialize( InvocationContext ctx ) {
+ ScheduleExpression se = new ScheduleExpression();
+ // Set schedule to every 10 seconds.

The 'second' expression for the ScheduleExpressions is '0/3' which implies 'every 3 seconds starting at second 0' i.e. 0,3,6,9,...57,60 seconds. So this comment should not read 'every 10 seconds'. Maybe you could incorporate what I wrote in the previous sentence.

Otherwise this looks good.

Right. I changed to more frequent and forgot to change the comment. Changing.

// Set schedule to every 3 seconds (starting at second 0 of every minute).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sgilda
Owner

Made minor adjustments to fix new qstools issues and merged.

@sgilda sgilda closed this
@OndraZizka

I see, so the <...> brackets are meant literally... I thought it's JUnit's style string comparison. Get it.

@sgilda
Owner

@OndraZizka : Are you referring to the change I made to the Source metadata URL?

@OndraZizka

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 28, 2013
  1. @OndraZizka

    @Schedule example, @Timeout example.

    Ondrej Zizka authored OndraZizka committed
This page is out of date. Refresh to see the latest.
View
100 ejb-timer/README.md
@@ -0,0 +1,100 @@
+ejb-timer: EJB Timers example - @Schedule and @Timeout
+===========================================
+Author: Ondrej Zizka <ozizka@redhat.com>
+Level: Beginner
+Technologies: EJB 3.1 Timer
+Summary: Demonstrates how to use EJB 3.1 Timer (@Schedule and @Timeout) with the JBoss AS server.
+Target Product: EAP
+Source: https://github.com/jboss-jdf/jboss-as-quickstart/
+
+What is it?
+-----------
+
+Demonstrates how to use EJB 3.1 Timer (@Schedule and @Timeout) with the JBoss AS server.
+
+
+Features used:
+
+ * Usage of `@Schedule`
+ * Usage of `@Timeout`
+
+
+System requirements
+-------------------
+
+All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.
+
+The application this project produces is designed to be run on JBoss Enterprise Application Platform 6 or JBoss AS 7.
+
+
+Configure Maven
+---------------
+
+If you have not yet done so, you must [Configure Maven](../README.md#mavenconfiguration) before testing the quickstarts.
+
+
+Start JBoss Enterprise Application Platform 6 or JBoss AS 7 with the Web Profile
+-------------------------
+
+1. Open a command line and navigate to the root of the JBoss server directory.
+2. The following shows the command line to start the server with the web profile:
+
+ For Linux: JBOSS_HOME/bin/standalone.sh
+ For Windows: JBOSS_HOME\bin\standalone.bat
+
+
+Build and Deploy the Quickstart
+-------------------------
+
+_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Build and Deploy the Quickstarts](../README.md#buildanddeploy) for complete instructions and additional options._
+
+1. Make sure you have started the JBoss Application Server as described above.
+2. Open a command line and navigate to the root directory of this quickstart.
+3. Type this command to build and deploy the archive:
+
+ mvn clean package jboss-as:deploy
+
+This will deploy `target/jboss-as-ejb-timer.war` to the running instance of the server.
+To undeploy, use
+
+ mvn jboss-as:undeploy
+
+
+Access the application
+----------------------
+
+This application only prints messages to stdout.
+To see it working, check the server log. You should see similar output:
+
+ ...
+ 18:33:36,004 INFO [stdout] (EJB default - 7) Hi from the EJB timer example!
+ 18:33:38,003 INFO [stdout] (EJB default - 8) Hi from the EJB timer example!
+ 18:33:40,002 INFO [stdout] (EJB default - 9) Hi from the EJB timer example!
+ 18:33:42,002 INFO [stdout] (EJB default - 10) Hi from the EJB timer example!
+ 18:33:44,003 INFO [stdout] (EJB default - 1) Hi from the EJB timer example!
+ 18:33:46,004 INFO [stdout] (EJB default - 2) Hi from the EJB timer example!
+ 18:33:48,003 INFO [stdout] (EJB default - 3) Hi from the EJB timer example!
+ ...
+
+The parentheses contain name of thread executing the particular invocation.
+There are pre-created threads in thread pool, and they are rotated. Hence the changing number.
+
+
+Undeploy the Archive
+--------------------
+
+1. Make sure you have started the JBoss Server as described above.
+2. Open a command line and navigate to the root directory of this quickstart.
+3. When you are finished testing, type this command to undeploy the archive:
+
+ mvn jboss-as:undeploy
+
+
+Debug the Application
+------------------------------------
+
+If you want to debug the source code or look at the Javadocs of any library in the project,
+run either of the following commands to pull them into your local repository. The IDE should then detect them.
+
+ mvn dependency:sources
+ mvn dependency:resolve -Dclassifier=javadoc
View
141 ejb-timer/pom.xml
@@ -0,0 +1,141 @@
+<?xml version="1.0"?>
+<!--
+ JBoss, Home of Professional Open Source
+ Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
+ contributors by the @authors tag. See the copyright.txt in the
+ distribution for a full listing of individual contributors.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.jboss.as.quickstarts</groupId>
+ <artifactId>jboss-as-ejb-timer</artifactId>
+ <version>7.1.2-SNAPSHOT</version>
+ <packaging>war</packaging>
+
+ <name>JBoss AS Quickstarts: EJB Timer</name>
+ <licenses>
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <distribution>repo</distribution>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
+ </license>
+ </licenses>
+
+ <description>
+ A sample JAVA EE 6 project demonstrating how to use EJB 3.1 timer (@Schedule and @Timeout).
+ </description>
+
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <version.jboss.maven.plugin>7.4.Final</version.jboss.maven.plugin>
+ <!-- Define the version of JBoss' Java EE 6 APIs we want to import. -->
+ <version.jboss.spec.javaee.6.0>3.0.2.Final</version.jboss.spec.javaee.6.0>
+ <!-- Alternatively, comment out the above line, and un-comment the line below
+ to use version 3.0.2.Final-redhat-3 which is a release certified to work
+ with JBoss EAP 6. It requires you have access to the JBoss EAP 6 maven repository. -->
+ <!-- <version.jboss.spec.javaee.6.0>3.0.2.Final-redhat-3</version.jboss.spec.javaee.6.0> -->
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- JBoss distributes a complete set of Java EE 6 APIs including
+ a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
+ a collection) of artifacts. We use this here so that we always get the correct
+ versions of artifacts. Here we use the jboss-javaee-6.0-with-tools stack
+ (you can read this as the JBoss stack of the Java EE 6 APIs, with some extras
+ tools for your project, such as Arquillian for testing) and the jboss-javaee-6.0-with-hibernate
+ stack you can read this as the JBoss stack of the Java EE 6 APIs, with extras
+ from the Hibernate family of projects) -->
+ <dependency>
+ <groupId>org.jboss.spec</groupId>
+ <artifactId>jboss-javaee-6.0</artifactId>
+ <version>${version.jboss.spec.javaee.6.0}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <!-- Dependencies. -->
+
+ <dependencies>
+ <!-- "provided" scope used for API's included in JBoss AS 7. -->
+
+ <!-- Import the CDI API. -->
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Import the Common Annotations API (JSR-250). -->
+ <dependency>
+ <groupId>org.jboss.spec.javax.annotation</groupId>
+ <artifactId>jboss-annotations-api_1.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Import the EJB API. -->
+ <dependency>
+ <groupId>org.jboss.spec.javax.ejb</groupId>
+ <artifactId>jboss-ejb-api_3.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <!-- Set the name of the war, used as the context root when the app
+ is deployed. -->
+ <finalName>${project.artifactId}</finalName>
+
+ <plugins>
+ <!-- JBoss AS plugin to deploy the war. -->
+ <plugin>
+ <groupId>org.jboss.as.plugins</groupId>
+ <artifactId>jboss-as-maven-plugin</artifactId>
+ <version>${version.jboss.maven.plugin}</version>
+ <configuration>
+ <fileNames>
+ <fileName>target/${build.finalName}.war</fileName>
+ </fileNames>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <!-- Prevent Maven complaining about missing web.xml - not needed in Java EE 6. -->
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+
+ <!-- Enforce Java 1.6 compatibility and activate annotation processors. -->
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+
View
36 ejb-timer/src/main/java/org/jboss/as/quickstarts/ejbTimer/ScheduleExample.java
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.as.quickstarts.ejbTimer;
+
@sgilda Owner
sgilda added a note

This file is missing the license header.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+import javax.ejb.Schedule;
+import javax.ejb.Singleton;
+
+
+/**
+ * Demonstrates how to use the EJB's @Schedule.
+ *
+ * @author <a href="mailto:ozizka@redhat.com">Ondrej Zizka</a>
+ */
+@Singleton
+public class ScheduleExample {
+
+ @Schedule(second="*/2", minute="*",hour="*", persistent=false)
+ public void doWork(){
+ System.out.println( "Hi from the EJB timer example!" );
+ }
+
+}
View
59 ejb-timer/src/main/java/org/jboss/as/quickstarts/ejbTimer/TimeoutExample.java
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.as.quickstarts.ejbTimer;
+
@sgilda Owner
sgilda added a note

This file is missing the license header.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.ejb.*;
+import javax.interceptor.InvocationContext;
+
+
+/**
+ * Demonstrates how to use the EJB's @Timeout.
+ *
+ * @author <a href="mailto:ozizka@redhat.com">Ondrej Zizka</a>
+ */
+@Singleton
+@Startup
+public class TimeoutExample {
+
+ @Resource
+ private TimerService timerService;
+
+ @Timeout
+ public void scheduler(Timer timer) {
+ System.out.println("EJB Timer: Info=" + timer.getInfo());
+ }
+
+ @PostConstruct
+ public void initialize( InvocationContext ctx ) {
+ ScheduleExpression se = new ScheduleExpression();
+ // Set schedule to every 3 seconds (starting at second 0 of every minute).
+ se.hour("*").minute("*").second("0/3");
+ timerService.createCalendarTimer( se, new TimerConfig("Hi from TimeoutExample!", false) );
+ }
+
+ @PreDestroy
+ public void stop() {
+ System.out.println("Stop all existing timers");
+ for (Timer timer : timerService.getTimers()) {
+ System.out.println("Stopping timer: " + timer.getInfo());
+ timer.cancel();
+ }
+ }
+}
View
1  pom.xml
@@ -203,6 +203,7 @@
<module>ejb-security-plus</module>
<module>ejb-security-interceptors</module>
<module>ejb-throws-exception</module>
+ <module>ejb-timer</module>
<module>ejb-multi-server</module>
<module>greeter</module>
<module>greeter-spring</module>
Something went wrong with that request. Please try again.