O'Reilly logo

Enterprise JavaBeans 3.1, 6th Edition by Bill Burke, Andrew Lee Rubinger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix C. Stateful Session EJB: FTP Client Example

Description

Often it’s necessary for the server to remember information about a specific client in between requests; this is modeled by components that have “conversational state.” For instance, the File Transfer Protocol is “stateful”—the server knows the current working directory used by each client, for example. In this example we’ll model an FTP client using the stateful session bean.

In order to save resources (i.e., RAM), SFSBs may go through a processes called “passivation” whereby an instance/client session is removed from memory and persisted to disk after some timeout. If the client session is needed again, the state may be activated back into use. Here we must explicitly ensure that our state is properly accounted for in this serialization/deserialization process such that passivation is completely transparent to the client.

Source Listing

Following is a full listing of all source code used in this runnable example.

Implementation Resources

FileTransferBean.java

package org.jboss.ejb3.examples.ch06.filetransfer; import java.io.IOException; import java.io.Serializable; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.ejb.PostActivate; import javax.ejb.PrePassivate; import javax.ejb.Remote; import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required