001 package examples.ejb.ejb21.timerService;
002
003 import java.util.Calendar;
004 import javax.ejb.*;
005 import weblogic.ejbgen.*;
006 import weblogic.ejb.GenericSessionBean;
007
008 /**
009 * TimerBean is a stateless Session Bean. This bean illustrates:
010 * <ul>
011 * <li> No persistence of state between calls to the Session Bean
012 * <li> Use of Timer Service feature offered in EJB 2.1
013 * </ul>
014 *
015 * @author Copyright (c) 1999,2009, Oracle and/or its affiliates. All Rights Reserved.
016 */
017
018 //use of TimerService must implement TimedObject interface
019 @FileGeneration(remoteClass = Constants.Bool.TRUE,
020 localHome = Constants.Bool.FALSE,
021 remoteHome = Constants.Bool.TRUE,
022 remoteClassName = "TimerRemote",
023 remoteHomeName = "TimerHome",
024 localClass = Constants.Bool.FALSE)
025 @JarSettings(ejbClientJar = "ejb21_timerService_statelessSession_client.jar")
026 @JndiName(remote = "ejb21-statelessSession-TimerHome")
027 @Session(maxBeansInFreePool = "1000",
028 initialBeansInFreePool = "0",
029 transTimeoutSeconds = "0",
030 type = Session.SessionType.STATELESS,
031 defaultTransaction = Constants.TransactionAttribute.REQUIRED,
032 ejbName = "statelessSession",
033 enableCallByReference = Constants.Bool.TRUE)
034 //use of TimerService must implement TimedObject interface
035 public class TimerBean extends GenericSessionBean implements TimedObject {
036 private static final boolean VERBOSE = true;
037 private MedRecSystem system = null;
038
039 // You might also consider using WebLogic's log service
040 private void log(String s) {
041 if (VERBOSE) System.out.println(s);
042 }
043
044 /**
045 * This method corresponds to the create method in the home interface
046 * "TimerHome.java".
047 * The parameter sets of the two methods are identical. When the client calls
048 * <code>TimerHome.create()</code>, the container allocates an instance of
049 * the EJBean and calls <code>ejbCreate()</code>.
050 *
051 * @throws javax.ejb.CreateException if there is
052 * a communications or systems failure
053 * @see examples.ejb.ejb21.timerService.TimerRemote
054 */
055 public void ejbCreate() throws CreateException {
056 log("ejbCreate() method invoked...");
057 system = MedRecSystem.getInstance();
058 }
059
060 /**
061 * Creates a timer.
062 *
063 * @param intervalDuration long interval duration
064 * @return TimerHandle
065 */
066 @RemoteMethod()
067 public void createTimerService(long intervalDuration) {
068
069 log("createTimerService() method invoked... ");
070 TimerService timerService = getSessionContext().getTimerService();
071 javax.ejb.Timer timer = timerService.createTimer(intervalDuration,
072 "Timer Created...");
073 Calendar calendar = Calendar.getInstance();
074 int minute = calendar.get(Calendar.MINUTE);
075 String minuteStr = "";
076 if(minute < 10){
077 minuteStr = "0"+minute;
078 }else{
079 minuteStr = ""+minute;
080 }
081 log("MEDREC SYSTEM ACCESS LOCKED: "+calendar.get(Calendar.HOUR)+":"+
082 minuteStr+":"+calendar.get(Calendar.SECOND));
083
084 //turning off access to MedRecSystem
085 system.setAccess(false);
086 }
087 /**
088 * EJB Time Out method.
089 *
090 * @param timer Timer
091 */
092 @RemoteMethod()
093 public void ejbTimeout(javax.ejb.Timer timer) {
094 log("ejbTimeout() method invoked... ");
095 Calendar calendar = Calendar.getInstance();
096 int minute = calendar.get(Calendar.MINUTE);
097 String minuteStr = "";
098 if(minute < 10){
099 minuteStr = "0"+minute;
100 }else{
101 minuteStr = ""+minute;
102 }
103 log("MEDREC SYSTEM ACCESS RELEASED: "+calendar.get(Calendar.HOUR)+":"+
104 minuteStr+":"+calendar.get(Calendar.SECOND));
105
106 //permitting access to the MedRecSystem
107 system = MedRecSystem.getInstance();
108 system.setAccess(true);
109 }
110
111 /**
112 * Logging into MedRecSystem.
113 */
114 @RemoteMethod()
115 public void login() {
116 log("Attempting to log into the MedRec System... ");
117 system.login();
118 }
119
120 /**
121 * Logging out of the MedRecSystem.
122 */
123 @RemoteMethod()
124 public void logout() {
125 log("Attempting to log out of the MedRec System... ");
126 system.logout();
127 }
128
129 }
|