summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer')
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrders.java13
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrdersBean.java67
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrdersClient.java19
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/application-client.xml7
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/application.xml10
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/ejb-jar.xml22
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/Readme.txt15
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/build.xml29
8 files changed, 182 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrders.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrders.java
new file mode 100644
index 0000000..55df678
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrders.java
@@ -0,0 +1,13 @@
+package examples.timer;
+
+import javax.ejb.Remote;
+import javax.ejb.Timer;
+
+
+/**
+ * This is the business interface for CleanDayLimitOrders enterprise bean.
+ */
+@Remote
+public interface CleanDayLimitOrders {
+ public void cleanPeriodicallyDayLimitOrders();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrdersBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrdersBean.java
new file mode 100644
index 0000000..1f90550
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrdersBean.java
@@ -0,0 +1,67 @@
+package examples.timer;
+
+import javax.ejb.*;
+import javax.annotation.Resource;
+
+import java.util.Calendar;
+import java.util.TimeZone;
+import java.util.SimpleTimeZone;
+import java.util.GregorianCalendar;
+import java.util.Date;
+
+@Stateless
+public class CleanDayLimitOrdersBean implements CleanDayLimitOrders {
+
+ @Resource private SessionContext ctx;
+
+ public void cleanPeriodicallyDayLimitOrders()
+ {
+ // Get hold of the eastern time zone assuming that the securities are being
+ // traded on NYSE and NASDAQ exchanges.
+ String[] timezoneIDs = TimeZone.getAvailableIDs (-5 * 60 * 60 * 1000);
+
+ SimpleTimeZone est = new SimpleTimeZone (-5 * 60 * 60 * 1000, timezoneIDs[0]);
+
+ // Provide the rules for start and end days of daylight savings time.
+ est.setStartRule (Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
+ est.setEndRule (Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
+
+ // Get hold of a calendar instance for the eastern time zone.
+ Calendar cal = new GregorianCalendar(est);
+
+ // Set the calendar to the current time.
+ cal.setTime (new Date ());
+
+ // Calculate the difference between now and market close i.e. 4 PM Eastern.
+ int hourofday = cal.get (cal.HOUR_OF_DAY);
+ int minuteofhour = cal.get (cal.MINUTE);
+
+ // If this method is invoked after the market close, then set the timer expiration
+ // immediately i.e. start=0. Otherwise, calculate the milliseconds that needs
+ // to elapse until first timer expiration.
+ long start = 0;
+ if (hourofday < 16)
+ {
+ int hourdiff = 16 - hourofday - 1;
+ int mindiff = 60 - minuteofhour;
+
+ start = (hourdiff * 60 * 60 * 1000) + (mindiff * 60 * 1000);
+ }
+
+ // Finally, get hold of the timer service instance from EJBContext object and create the
+ // recurrent expiration timer.
+ TimerService timerService = ctx.getTimerService();
+ Timer timer = timerService.createTimer(start, 86400000, null);
+
+ System.out.println("CleanDayLimitOrdersBean: Timer created to first expire after " + start + " milliseconds.");
+ }
+
+ @Timeout
+ public void handleTimeout(Timer timer)
+ {
+ System.out.println("CleanDayLimitOrdersBean: handleTimeout called.");
+
+ // Put here the code for cleaning the database of day limit orders that have
+ // not been executed.
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrdersClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrdersClient.java
new file mode 100644
index 0000000..749de86
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/CleanDayLimitOrdersClient.java
@@ -0,0 +1,19 @@
+package examples.timer;
+
+import javax.ejb.EJB;
+
+public class CleanDayLimitOrdersClient {
+ @EJB
+ private static CleanDayLimitOrders cleanDayLimitOrders;
+
+ public static void main(String[] args) {
+ try {
+ cleanDayLimitOrders.cleanPeriodicallyDayLimitOrders();
+
+ System.out.println ("cleanPeriodicallyDayLimitOrders() returned successfully. Take a look at the application server log or console for messages from bean.");
+ } catch (Exception ex) {
+ System.err.println("Caught an unexpected exception!");
+ ex.printStackTrace();
+ }
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/application-client.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/application-client.xml
new file mode 100644
index 0000000..7e232d8
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/application-client.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application-client 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/application-client_5.xsd'
+ version="5">
+ <display-name>CleanDayLimitOrdersClient</display-name>
+</application-client>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/application.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/application.xml
new file mode 100644
index 0000000..8fc0433
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/application.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application version="5" 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/application_5.xsd">
+ <display-name>CleanDayLimitOrdersApp</display-name>
+ <module>
+ <ejb>CleanDayLimitOrdersEjb.jar</ejb>
+ </module>
+ <module>
+ <java>CleanDayLimitOrdersClient.jar</java>
+ </module>
+</application>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/ejb-jar.xml
new file mode 100644
index 0000000..a358d5a
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/META-INF/ejb-jar.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" full="false" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
+ <enterprise-beans>
+ <session>
+ <display-name>CleanDayLimitOrdersBean</display-name>
+ <ejb-name>CleanDayLimitOrdersBean</ejb-name>
+ <business-remote>examples.timer.CleanDayLimitOrders</business-remote>
+ <ejb-class>examples.timer.CleanDayLimitOrdersBean</ejb-class>
+ <session-type>Stateless</session-type>
+ <timeout-method>
+ <method-name>handleTimeout</method-name>
+ <method-params>
+ <method-param>javax.ejb.Timer</method-param>
+ </method-params>
+ </timeout-method>
+ <transaction-type>Container</transaction-type>
+ <security-identity>
+ <use-caller-identity/>
+ </security-identity>
+ </session>
+ </enterprise-beans>
+</ejb-jar> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/Readme.txt b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/Readme.txt
new file mode 100644
index 0000000..6e5d1aa
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/Readme.txt
@@ -0,0 +1,15 @@
+1) asant jar
+
+2) asant app_clientjar_common
+
+3) asant create_ear_common_with_clientjar
+
+4) asant deploy_common
+
+5) Turn off the firewall right before running the client (for Glassfish)
+
+6) asant run_client_in_appcontainer
+
+5) asant undeploy_common
+
+6) asant clean_all \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/build.xml
new file mode 100644
index 0000000..7030d4a
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/timer/build.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-session-stateless" default="jar"
+ basedir="../../..">
+
+ <!-- basic settings -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="CleanDayLimitOrders"/>
+ <property name="client.class" value="examples.timer.CleanDayLimitOrdersClient"/>
+ <property name="app.pkg" value="examples/timer"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="examples/timer"/>
+
+
+ <!-- Include common.xml -->
+ &include;
+
+ <property name="assemble.dir" value="${assemble.ear}"/>
+ <property name="deploy.file" value="${ear}"/>
+
+ <target name="jar" depends="compile_common, create_ejbjar_common"/>
+ <target name="ear" depends="jar,create_ear_common"/>
+
+ <target name="clean_all" depends="clean_common, clean_ejbjar_common, clean_clientjar_common"/>
+</project> \ No newline at end of file