[JAVA-13854] Half list moved (#12598)
* [JAVA-13854] added parent module * [JAVA-13854] moved apache-tapestry(submodule) to web-modules(parent) * [JAVA-13854] moved bootique(submodule) to web-modules(parent) * [JAVA-13854] moved dropwizard(submodule) to web-modules(parent) * [JAVA-13854] moved blade(submodule) to web-modules(parent) * [JAVA-13854] moved java-lite(submodule) to web-modules(parent) * [JAVA-13854] moved jooby(submodule) to web-modules(parent) * [JAVA-13854] moved linkrest(submodule) to web-modules(parent) * [JAVA-13854] moved ninja(submodule) to web-modules(parent) * [JAVA-13854] moved ratpack(submodule) to web-modules(parent) * [JAVA-13854] moved resteasy(submodule) to web-modules(parent) * [JAVA-13854] moved restx(submodule) to web-modules(parent) * [JAVA-13854] moved spark-java(submodule) to web-modules(parent) * [JAVA-13854] moved vraptor(submodule) to web-modules(parent) * [JAVA-13854] delete modules that were moved * [JAVA-13854] * [JAVA-13854] * [JAVA-13854] delete ninja submodule + moved raml(submodule) to web-modules(parent) * [JAVA-13854] moved gwt(submodule) to web-modules(parent) * [JAVA-13854] moved jakarta-ee(submodule) to web-modules(parent) * [JAVA-13854] moved javax-servlets(submodule) to web-modules(parent) * [JAVA-13854] moved javax-servlets-2(submodule) to web-modules(parent) * [JAVA-13854] moved jee-7(submodule) to web-modules(parent) * [JAVA-13854] moved play-framework(not a module) to web-modules * [JAVA-13854] fix failing test * [JAVA-13854] moved struts-2(submodule) to web-modules(parent) * [JAVA-13854] moved wicket(submodule) to web-modules(parent) * [JAVA-13854] deleted modules that were moved to web-modules * JAVA-13854 Removed moved modules from the main pom.xml Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com> Co-authored-by: Dhawal Kapil <dhawalkapil@gmail.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.timer;
|
||||
|
||||
import javax.ejb.Schedule;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Startup;
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Startup
|
||||
@Singleton
|
||||
public class AutomaticTimerBean {
|
||||
|
||||
|
||||
@Inject
|
||||
Event<TimerEvent> event;
|
||||
|
||||
/**
|
||||
* This method will be called every 10 second and will fire an @TimerEvent
|
||||
*/
|
||||
@Schedule(hour = "*", minute = "*", second = "*/10", info = "Every 10 second timer")
|
||||
public void printDate() {
|
||||
event.fire(new TimerEvent("TimerEvent sent at :" + new Date()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.timer;
|
||||
|
||||
import javax.ejb.*;
|
||||
|
||||
/**
|
||||
* Created by ccristianchiovari on 5/2/16.
|
||||
*/
|
||||
@Singleton
|
||||
public class FixedDelayTimerBean {
|
||||
|
||||
@EJB
|
||||
private WorkerBean workerBean;
|
||||
|
||||
@Lock(LockType.READ)
|
||||
@Schedule(second = "*/5", minute = "*", hour = "*", persistent = false)
|
||||
public void atSchedule() throws InterruptedException {
|
||||
workerBean.doTimerWork();
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.timer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.ejb.*;
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* author: Cristian Chiovari
|
||||
*/
|
||||
@Startup
|
||||
@Singleton
|
||||
public class ProgrammaticAtFixedRateTimerBean {
|
||||
|
||||
@Inject
|
||||
Event<TimerEvent> event;
|
||||
|
||||
@Resource
|
||||
TimerService timerService;
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
timerService.createTimer(0,1000, "Every second timer");
|
||||
}
|
||||
|
||||
@Timeout
|
||||
public void programmaticTimout(Timer timer) {
|
||||
event.fire(new TimerEvent(timer.getInfo().toString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.baeldung.timer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.ejb.*;
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* author: Jacek Jackowiak
|
||||
*/
|
||||
@Startup
|
||||
@Singleton
|
||||
public class ProgrammaticTimerBean {
|
||||
|
||||
@Inject
|
||||
Event<TimerEvent> event;
|
||||
|
||||
@Resource
|
||||
TimerService timerService;
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
ScheduleExpression scheduleExpression = new ScheduleExpression()
|
||||
.hour("*")
|
||||
.minute("*")
|
||||
.second("*/5");
|
||||
|
||||
TimerConfig timerConfig = new TimerConfig();
|
||||
timerConfig.setInfo("Every 5 second timer");
|
||||
|
||||
timerService.createCalendarTimer(scheduleExpression, timerConfig);
|
||||
}
|
||||
|
||||
@Timeout
|
||||
public void programmaticTimout(Timer timer) {
|
||||
event.fire(new TimerEvent(timer.getInfo().toString()));
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.timer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.ejb.*;
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* author: Cristian Chiovari
|
||||
*/
|
||||
@Startup
|
||||
@Singleton
|
||||
public class ProgrammaticWithInitialFixedDelayTimerBean {
|
||||
|
||||
@Inject
|
||||
Event<TimerEvent> event;
|
||||
|
||||
@Resource
|
||||
TimerService timerService;
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
timerService.createTimer(10000l,5000l, "Delay 10 seconds then every 5 second timer");
|
||||
}
|
||||
|
||||
@Timeout
|
||||
public void programmaticTimout(Timer timer) {
|
||||
event.fire(new TimerEvent(timer.getInfo().toString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.timer;
|
||||
|
||||
import javax.ejb.Schedule;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Startup;
|
||||
import javax.ejb.Timer;
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
||||
@Startup
|
||||
@Singleton
|
||||
public class ScheduleTimerBean {
|
||||
|
||||
@Inject
|
||||
Event<TimerEvent> event;
|
||||
|
||||
@Schedule(hour = "*", minute = "*", second = "*/5", info = "Every 5 second timer")
|
||||
public void automaticallyScheduled(Timer timer) {
|
||||
fireEvent(timer);
|
||||
}
|
||||
|
||||
|
||||
private void fireEvent(Timer timer) {
|
||||
event.fire(new TimerEvent(timer.getInfo().toString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.timer;
|
||||
|
||||
public class TimerEvent {
|
||||
|
||||
private String eventInfo;
|
||||
private long time = System.currentTimeMillis();
|
||||
|
||||
public TimerEvent(String s) {
|
||||
this.eventInfo = s;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public String getEventInfo() {
|
||||
return eventInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TimerEvent {" +
|
||||
"eventInfo='" + eventInfo + '\'' +
|
||||
", time=" + time +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.timer;
|
||||
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Startup;
|
||||
import javax.enterprise.event.Observes;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* This class will listen to all TimerEvent and will collect them
|
||||
*/
|
||||
@Startup
|
||||
@Singleton
|
||||
public class TimerEventListener {
|
||||
|
||||
final List<TimerEvent> events = new CopyOnWriteArrayList<>();
|
||||
|
||||
public void listen(@Observes TimerEvent event) {
|
||||
System.out.println("event = " + event);
|
||||
events.add(event);
|
||||
}
|
||||
|
||||
public List<TimerEvent> getEvents() {
|
||||
return events;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.timer;
|
||||
|
||||
import javax.ejb.Lock;
|
||||
import javax.ejb.LockType;
|
||||
import javax.ejb.Singleton;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Created by cristianchiovari on 5/2/16.
|
||||
*/
|
||||
@Singleton
|
||||
public class WorkerBean {
|
||||
|
||||
private AtomicBoolean busy = new AtomicBoolean(false);
|
||||
|
||||
@Lock(LockType.READ)
|
||||
public void doTimerWork() throws InterruptedException {
|
||||
|
||||
System.out.println("Timer method called but not started yet !");
|
||||
|
||||
if (!busy.compareAndSet(false, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println("Timer work started");
|
||||
Thread.sleep(12000);
|
||||
System.out.println("Timer work done");
|
||||
} finally {
|
||||
busy.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user