Skip to content

Commit 4e01eb6

Browse files
authored
Merge pull request eugenp#443 from ccristian/master
jee7schedule
2 parents 73471f6 + 2452e58 commit 4e01eb6

18 files changed

Lines changed: 898 additions & 0 deletions

‎jee7schedule/pom.xml‎

Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.baeldung</groupId>
6+
<artifactId>jee7schedule</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<description>JavaEE 7 Arquillian Archetype Sample</description>
9+
<packaging>war</packaging>
10+
11+
<properties>
12+
<java.min.version>1.7</java.min.version>
13+
<maven.min.version>3.0.0</maven.min.version>
14+
15+
<version.junit>4.11</version.junit>
16+
<version.javaee_api>7.0</version.javaee_api>
17+
18+
<version.arquillian_core>1.1.4.Final</version.arquillian_core>
19+
20+
<version.wildfly>8.0.0.Final</version.wildfly>
21+
</properties>
22+
23+
<prerequisites>
24+
<maven>${maven.min.version}</maven>
25+
</prerequisites>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.jboss.arquillian</groupId>
31+
<artifactId>arquillian-bom</artifactId>
32+
<version>${version.arquillian_core}</version>
33+
<scope>import</scope>
34+
<type>pom</type>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>javax</groupId>
42+
<artifactId>javaee-api</artifactId>
43+
<version>${version.javaee_api}</version>
44+
<scope>provided</scope>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>junit</groupId>
49+
<artifactId>junit</artifactId>
50+
<version>${version.junit}</version>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.jboss.arquillian.junit</groupId>
55+
<artifactId>arquillian-junit-container</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.jayway.awaitility</groupId>
60+
<artifactId>awaitility</artifactId>
61+
<version>1.6.0</version>
62+
<scope>test</scope>
63+
</dependency>
64+
65+
<dependency>
66+
<groupId>org.jboss.shrinkwrap.resolver</groupId>
67+
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
68+
<scope>test</scope>
69+
<type>jar</type>
70+
</dependency>
71+
72+
<dependency>
73+
<groupId>org.jboss.shrinkwrap.resolver</groupId>
74+
<artifactId>shrinkwrap-resolver-impl-maven-archive</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
78+
</dependencies>
79+
80+
<build>
81+
<plugins>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-compiler-plugin</artifactId>
85+
<version>3.1</version>
86+
<configuration>
87+
<source>${java.min.version}</source>
88+
<target>${java.min.version}</target>
89+
</configuration>
90+
</plugin>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-war-plugin</artifactId>
94+
<version>2.1.1</version>
95+
<configuration>
96+
<failOnMissingWebXml>false</failOnMissingWebXml>
97+
</configuration>
98+
</plugin>
99+
</plugins>
100+
</build>
101+
102+
<profiles>
103+
104+
<profile>
105+
<id>wildfly-managed-arquillian</id>
106+
<activation>
107+
<activeByDefault>true</activeByDefault>
108+
</activation>
109+
<properties>
110+
<serverProfile>standalone-full.xml</serverProfile>
111+
<serverRoot>${project.build.directory}/wildfly-${version.wildfly}</serverRoot>
112+
</properties>
113+
<dependencies>
114+
<dependency>
115+
<groupId>io.undertow</groupId>
116+
<artifactId>undertow-websockets-jsr</artifactId>
117+
<version>1.0.0.Beta25</version>
118+
<scope>test</scope>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.jboss.resteasy</groupId>
122+
<artifactId>resteasy-client</artifactId>
123+
<version>3.0.5.Final</version>
124+
<scope>test</scope>
125+
</dependency>
126+
<dependency>
127+
<groupId>org.jboss.resteasy</groupId>
128+
<artifactId>resteasy-jaxb-provider</artifactId>
129+
<version>3.0.5.Final</version>
130+
<scope>test</scope>
131+
</dependency>
132+
<dependency>
133+
<groupId>org.jboss.resteasy</groupId>
134+
<artifactId>resteasy-json-p-provider</artifactId>
135+
<version>3.0.5.Final</version>
136+
<scope>test</scope>
137+
</dependency>
138+
<dependency>
139+
<groupId>org.wildfly</groupId>
140+
<artifactId>wildfly-arquillian-container-managed</artifactId>
141+
<version>${version.wildfly}</version>
142+
<scope>test</scope>
143+
</dependency>
144+
</dependencies>
145+
<build>
146+
<plugins>
147+
<plugin>
148+
<artifactId>maven-dependency-plugin</artifactId>
149+
<version>2.8</version>
150+
<configuration>
151+
<skip>${maven.test.skip}</skip>
152+
</configuration>
153+
<executions>
154+
<execution>
155+
<id>unpack</id>
156+
<phase>process-test-classes</phase>
157+
<goals>
158+
<goal>unpack</goal>
159+
</goals>
160+
<configuration>
161+
<artifactItems>
162+
<artifactItem>
163+
<groupId>org.wildfly</groupId>
164+
<artifactId>wildfly-dist</artifactId>
165+
<version>${version.wildfly}</version>
166+
<type>zip</type>
167+
<overWrite>false</overWrite>
168+
<outputDirectory>${project.build.directory}</outputDirectory>
169+
</artifactItem>
170+
</artifactItems>
171+
</configuration>
172+
</execution>
173+
</executions>
174+
</plugin>
175+
<plugin>
176+
<artifactId>maven-surefire-plugin</artifactId>
177+
<version>2.17</version>
178+
<configuration>
179+
<environmentVariables>
180+
<JBOSS_HOME>${project.build.directory}/wildfly-${version.wildfly}</JBOSS_HOME>
181+
</environmentVariables>
182+
</configuration>
183+
</plugin>
184+
</plugins>
185+
</build>
186+
</profile>
187+
<profile>
188+
<id>wildfly-remote-arquillian</id>
189+
<dependencies>
190+
<dependency>
191+
<groupId>io.undertow</groupId>
192+
<artifactId>undertow-websockets-jsr</artifactId>
193+
<version>1.0.0.Beta25</version>
194+
<scope>test</scope>
195+
</dependency>
196+
<dependency>
197+
<groupId>org.jboss.resteasy</groupId>
198+
<artifactId>resteasy-client</artifactId>
199+
<version>3.0.5.Final</version>
200+
<scope>test</scope>
201+
</dependency>
202+
<dependency>
203+
<groupId>org.jboss.resteasy</groupId>
204+
<artifactId>resteasy-jaxb-provider</artifactId>
205+
<version>3.0.5.Final</version>
206+
<scope>test</scope>
207+
</dependency>
208+
<dependency>
209+
<groupId>org.jboss.resteasy</groupId>
210+
<artifactId>resteasy-json-p-provider</artifactId>
211+
<version>3.0.5.Final</version>
212+
<scope>test</scope>
213+
</dependency>
214+
<dependency>
215+
<groupId>org.wildfly</groupId>
216+
<artifactId>wildfly-arquillian-container-remote</artifactId>
217+
<version>${version.wildfly}</version>
218+
<scope>test</scope>
219+
</dependency>
220+
</dependencies>
221+
</profile>
222+
<profile>
223+
<id>glassfish-embedded-arquillian</id>
224+
<dependencies>
225+
<dependency>
226+
<groupId>org.glassfish.main.extras</groupId>
227+
<artifactId>glassfish-embedded-all</artifactId>
228+
<version>4.0</version>
229+
<scope>test</scope>
230+
</dependency>
231+
<dependency>
232+
<groupId>org.glassfish</groupId>
233+
<artifactId>javax.json</artifactId>
234+
<version>1.0.4</version>
235+
<scope>test</scope>
236+
</dependency>
237+
<dependency>
238+
<groupId>org.glassfish.tyrus</groupId>
239+
<artifactId>tyrus-client</artifactId>
240+
<version>1.3</version>
241+
<scope>test</scope>
242+
</dependency>
243+
<dependency>
244+
<groupId>org.glassfish.tyrus</groupId>
245+
<artifactId>tyrus-container-grizzly-client</artifactId>
246+
<version>1.3</version>
247+
<scope>test</scope>
248+
</dependency>
249+
<dependency>
250+
<groupId>org.glassfish.jersey.core</groupId>
251+
<artifactId>jersey-client</artifactId>
252+
<version>2.4</version>
253+
<scope>test</scope>
254+
</dependency>
255+
<dependency>
256+
<groupId>org.jboss.arquillian.container</groupId>
257+
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
258+
<version>1.0.0.CR4</version>
259+
<scope>test</scope>
260+
</dependency>
261+
</dependencies>
262+
</profile>
263+
<profile>
264+
<id>glassfish-remote-arquillian</id>
265+
<dependencies>
266+
<dependency>
267+
<groupId>org.glassfish</groupId>
268+
<artifactId>javax.json</artifactId>
269+
<version>1.0.4</version>
270+
<scope>test</scope>
271+
</dependency>
272+
<dependency>
273+
<groupId>org.glassfish.tyrus</groupId>
274+
<artifactId>tyrus-client</artifactId>
275+
<version>1.3</version>
276+
<scope>test</scope>
277+
</dependency>
278+
<dependency>
279+
<groupId>org.glassfish.tyrus</groupId>
280+
<artifactId>tyrus-container-grizzly-client</artifactId>
281+
<version>1.3</version>
282+
<scope>test</scope>
283+
</dependency>
284+
<dependency>
285+
<groupId>org.glassfish.jersey.core</groupId>
286+
<artifactId>jersey-client</artifactId>
287+
<version>2.4</version>
288+
<scope>test</scope>
289+
</dependency>
290+
<dependency>
291+
<groupId>org.glassfish.jersey.media</groupId>
292+
<artifactId>jersey-media-json-jackson</artifactId>
293+
<version>2.4</version>
294+
<scope>test</scope>
295+
</dependency>
296+
<dependency>
297+
<groupId>org.glassfish.jersey.media</groupId>
298+
<artifactId>jersey-media-json-processing</artifactId>
299+
<version>2.4</version>
300+
<scope>test</scope>
301+
</dependency>
302+
<dependency>
303+
<groupId>org.jboss.arquillian.container</groupId>
304+
<artifactId>arquillian-glassfish-remote-3.1</artifactId>
305+
<version>1.0.0.CR4</version>
306+
<scope>test</scope>
307+
</dependency>
308+
</dependencies>
309+
</profile>
310+
</profiles>
311+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.timer;
2+
3+
import javax.ejb.Schedule;
4+
import javax.ejb.Singleton;
5+
import javax.ejb.Startup;
6+
import javax.enterprise.event.Event;
7+
import javax.inject.Inject;
8+
import java.util.Date;
9+
10+
11+
@Startup
12+
@Singleton
13+
public class AutomaticTimerBean {
14+
15+
16+
@Inject
17+
Event<TimerEvent> event;
18+
19+
/**
20+
* This method will be called every 10 second and will fire an @TimerEvent
21+
*/
22+
@Schedule(hour = "*", minute = "*", second = "*/10", info = "Every 10 second timer")
23+
public void printDate() {
24+
event.fire(new TimerEvent("TimerEvent sent at :" + new Date()));
25+
}
26+
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.timer;
2+
3+
import javax.ejb.*;
4+
5+
/**
6+
* Created by ccristianchiovari on 5/2/16.
7+
*/
8+
@Singleton
9+
public class FixedDelayTimerBean {
10+
11+
@EJB
12+
private WorkerBean workerBean;
13+
14+
@Lock(LockType.READ)
15+
@Schedule(second = "*/5", minute = "*", hour = "*", persistent = false)
16+
public void atSchedule() throws InterruptedException {
17+
workerBean.doTimerWork();
18+
}
19+
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.timer;
2+
3+
import javax.annotation.PostConstruct;
4+
import javax.annotation.Resource;
5+
import javax.ejb.*;
6+
import javax.enterprise.event.Event;
7+
import javax.inject.Inject;
8+
9+
/**
10+
* author: Cristian Chiovari
11+
*/
12+
@Startup
13+
@Singleton
14+
public class ProgrammaticAtFixedRateTimerBean {
15+
16+
@Inject
17+
Event<TimerEvent> event;
18+
19+
@Resource
20+
TimerService timerService;
21+
22+
@PostConstruct
23+
public void initialize() {
24+
timerService.createTimer(0,1000, "Every second timer");
25+
}
26+
27+
@Timeout
28+
public void programmaticTimout(Timer timer) {
29+
event.fire(new TimerEvent(timer.getInfo().toString()));
30+
}
31+
}

0 commit comments

Comments
 (0)