Appendix C. Stateful Session EJB: FTP Client Example


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

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

Get Enterprise JavaBeans 3.1, 6th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.