我们需要三个类:remote interface, home interface 和bean实现类。remote interface远程接口类,文件名Interest.java。代码如下:
package org.jboss.docs.interest; import javax.ejb.EJBObject; import java.rmi.RemoteException; /** This interface defines the `Remote' interface for the `Interest' EJB. Its single method is the only method eXPosed to the outside world. The class InterestBean implements the method. */ public interface Interest extends EJBObject { /** Calulates the compound interest on the sum `principle', with interest rate per period `rate' over `periods' time periods. This method also prints a message to standard output; this is picked up by the EJB server and logged. In this way we can demonstrate that the method is actually being executed on the server, rather than the client. */
public double calculateCompoundInterest(double principle, double rate, double periods) throws RemoteException;
/** This interface defines the 'home' interface for the 'Interest' EJB. */ public interface InterestHome extends EJBHome { /** Creates an instance of the `InterestBean' class on the server, and returns a remote reference to an Interest interface on the client. */ Interest create() throws RemoteException, CreateException; } 最后我们给出bean实现类,文件名称:InterestBean.java。代码如下: