TECHNICALFACILITATION.COM - THE ULTIMATE WEBSPHERE AND JAVA CERTIFICATION GUIDES AND RESOURCES
Google
Download the Completed Solution: 10SessionEJBs.ear.

Scroll to the bottom of the page for pertinent code snippets.

Creating Stateless Session Beans (SLSB)

This free, multimedia tutorial shows you how to use IBM's Rational Application Developer (IRAD) 6.0 to create a StatelessSession Bean (SLSB) based on the Stateful Session Bean (SFSB) created in a previous tutorial. Essentially, we present ideas on how to move state out of the EJB layer, and perhaps move client state into the HttpSession layer, or another state management mechanism for the client.

If you found something helpful here, please do your part and help support the site. Link to us, buy some books, support our sponsors, tell your developer friends about us, and remember: Happy Java!

package com.examscam.ejb;
/**
 * Bean implementation class for Enterprise Bean: StatelessTimer
 */
public class StatelessTimerBean implements javax.ejb.SessionBean {
	
	
	
	public long start() {
		return System.currentTimeMillis();
	}

	public long getElapsedTime(long startTime) {
		return System.currentTimeMillis() - startTime;
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	private javax.ejb.SessionContext mySessionCtx;
	
	
	
	
	
	/**
	 * getSessionContext
	 */
	public javax.ejb.SessionContext getSessionContext() {
		return mySessionCtx;
	}
	/**
	 * setSessionContext
	 */
	public void setSessionContext(javax.ejb.SessionContext ctx) {
		mySessionCtx = ctx;
	}
	/**
	 * ejbCreate
	 */
	public void ejbCreate() throws javax.ejb.CreateException {
	}
	/**
	 * ejbActivate
	 */
	public void ejbActivate() {
	}
	/**
	 * ejbPassivate
	 */
	public void ejbPassivate() {
	}
	/**
	 * ejbRemove
	 */
	public void ejbRemove() {
	}
}

  package com.examscam.ejb;
/**
* Home interface for Enterprise Bean: StatelessTimer
*/
public interface StatelessTimerHome extends javax.ejb.EJBHome {
/**
* Creates a default instance of Session Bean: StatelessTimer
*/
public com.examscam.ejb.StatelessTimerRemote create()
throws javax.ejb.CreateException,
java.rmi.RemoteException;
}

package com.examscam.ejb;
/**
* Remote interface for Enterprise Bean: StatelessTimer
*/
public interface StatelessTimerRemote extends javax.ejb.EJBObject {
public long start() throws java.rmi.RemoteException;
public long getElapsedTime(long startTime) throws java.rmi.RemoteException;
}
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>
ExamScamEJB</display-name>
<enterprise-beans>
<session id="StatefulTimer">
<ejb-name>StatefulTimer</ejb-name>
<home>com.examscam.ejb.StatefulTimerHome</home>
<remote>com.examscam.ejb.StatefulTimerRemote</remote>
<ejb-class>com.examscam.ejb.StatefulTimerBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
<session id="StatelessTimer">
<ejb-name>StatelessTimer</ejb-name>
<home>com.examscam.ejb.StatelessTimerHome</home>
<remote>com.examscam.ejb.StatelessTimerRemote</remote>
<ejb-class>com.examscam.ejb.StatelessTimerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<ejb-client-jar>ExamScamEJBClient.jar</ejb-client-jar>
</ejb-jar>
Google
THE ULTIMATE CERTIFICATION AND WEBSPHERE RESOURCES - BUY THEM NOW ON AMAZON
eXTReMe Tracker