You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@tomee.apache.org by bu...@apache.org on 2012/10/19 07:21:15 UTC
svn commit: r835568 - in /websites/staging/openejb/trunk: cgi-bin/ content/
content/examples-trunk/ content/examples-trunk/schedule-events/
content/examples-trunk/schedule-events/src/
content/examples-trunk/schedule-events/src/main/ content/examples-tr...
Author: buildbot
Date: Fri Oct 19 05:21:15 2012
New Revision: 835568
Log:
Staging update by buildbot for openejb
Added:
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/java/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/java/org/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/java/org/superbiz/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/java/org/superbiz/schedule/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/java/org/superbiz/schedule/events/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/java/org/superbiz/schedule/events/Scheduler.java
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/java/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/java/org/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/java/org/superbiz/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/java/org/superbiz/schedule/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/java/org/superbiz/schedule/events/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/java/org/superbiz/schedule/events/SchedulerTest.java
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/resources/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/resources/META-INF/
websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/resources/META-INF/beans.xml
Modified:
websites/staging/openejb/trunk/cgi-bin/ (props changed)
websites/staging/openejb/trunk/content/ (props changed)
websites/staging/openejb/trunk/content/examples-trunk/pom.xml
Propchange: websites/staging/openejb/trunk/cgi-bin/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Fri Oct 19 05:21:15 2012
@@ -1 +1 @@
-1399435
+1399967
Propchange: websites/staging/openejb/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Fri Oct 19 05:21:15 2012
@@ -1 +1 @@
-1399435
+1399967
Modified: websites/staging/openejb/trunk/content/examples-trunk/pom.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/pom.xml (original)
+++ websites/staging/openejb/trunk/content/examples-trunk/pom.xml Fri Oct 19 05:21:15 2012
@@ -17,7 +17,7 @@
limitations under the License.
-->
<!--test 2-->
-<!-- $Rev: 1391499 $ $Date: 2012-09-28 15:11:14 +0000 (Fri, 28 Sep 2012) $ -->
+<!-- $Rev: 1399967 $ $Date: 2012-10-19 05:20:53 +0000 (Fri, 19 Oct 2012) $ -->
<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">
<parent>
@@ -102,6 +102,7 @@
<module>rest-example</module>
<module>rest-example-with-application</module>
<module>schedule-expression</module>
+ <module>schedule-events</module>
<module>schedule-methods-meta</module>
<module>schedule-methods</module>
<module>server-events</module>
Added: websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/java/org/superbiz/schedule/events/Scheduler.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/java/org/superbiz/schedule/events/Scheduler.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/main/java/org/superbiz/schedule/events/Scheduler.java Fri Oct 19 05:21:15 2012
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.superbiz.schedule.events;
+
+import javax.annotation.Resource;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.ScheduleExpression;
+import javax.ejb.SessionContext;
+import javax.ejb.Startup;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerConfig;
+import javax.ejb.TimerService;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.ejb.Singleton;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@Singleton
+@Lock(LockType.READ)
+@Startup
+public class Scheduler {
+
+ @Resource
+ private TimerService timerService;
+
+ @Resource
+ private SessionContext sessionContext;
+
+ @Resource
+ private BeanManager beanManager;
+
+ public void scheduleEvent(ScheduleExpression schedule, Object event, Annotation... qualifiers) {
+
+ timerService.createCalendarTimer(schedule, new TimerConfig(new EventConfig(event, qualifiers), false));
+ }
+
+ // @Produces
+// public Scheduler produce() {
+// return sessionContext.getBusinessObject(Scheduler.class);
+// }
+//
+ @Timeout
+ public void timeout(Timer timer) {
+ final EventConfig config = (EventConfig) timer.getInfo();
+
+ beanManager.fireEvent(config.getEvent(), config.getQualifiers());
+ }
+
+ // Doesn't actually need to be serializable, just has to implement it
+ private final class EventConfig implements Serializable {
+
+ private final Object event;
+ private final Annotation[] qualifiers;
+
+ private EventConfig(Object event, Annotation[] qualifiers) {
+ this.event = event;
+ this.qualifiers = qualifiers;
+ }
+
+ public Object getEvent() {
+ return event;
+ }
+
+ public Annotation[] getQualifiers() {
+ return qualifiers;
+ }
+ }
+}
Added: websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/java/org/superbiz/schedule/events/SchedulerTest.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/java/org/superbiz/schedule/events/SchedulerTest.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/java/org/superbiz/schedule/events/SchedulerTest.java Fri Oct 19 05:21:15 2012
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.superbiz.schedule.events;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.ejb.EJB;
+import javax.ejb.ScheduleExpression;
+import javax.ejb.embeddable.EJBContainer;
+import javax.enterprise.event.Observes;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class SchedulerTest {
+
+ public static final CountDownLatch events = new CountDownLatch(3);
+
+ @EJB
+ private Scheduler scheduler;
+
+ @Test
+ public void test() throws Exception {
+
+ scheduler.scheduleEvent(new ScheduleExpression().hour("*").minute("*").second("*/5"), new TestEvent("five"));
+
+ Assert.assertTrue(events.await(1, TimeUnit.MINUTES));
+ }
+
+
+ public void observe(@Observes TestEvent event) {
+ if ("five".equals(event.getMessage())) {
+ events.countDown();
+ }
+ }
+
+ public static class TestEvent {
+ private final String message;
+
+ public TestEvent(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+ }
+
+ @Before
+ public void setup() throws Exception {
+ EJBContainer.createEJBContainer().getContext().bind("inject", this);
+ }
+}
Added: websites/staging/openejb/trunk/content/examples-trunk/schedule-events/src/test/resources/META-INF/beans.xml
==============================================================================
(empty)