Add business method signatures to the StatefulCalculator interface:
public double add(double a); public double subtract(double a); public double multiply(double a); public double divide(double a); public void clean(); public void turnOff();
In the Package Explorer View, right click on the StatelessCalculatorBean class and select Source > Override/Implement Methods....

Accept the default selection and press the OK button:

Open the StatefulCalculatorBean.java file (if not already open), add instance variables and modify the newly created methods as shown below:
@EJB private StatelessCalculator calculator;
double register = 0;
public double add(double a) {
register = calculator.add(register, a);
return register;
}
public double subtract(double a) {
register = calculator.subtract(register, a);
return register;
}
public double multiply(double a) {
register = calculator.multiply(register, a);
return register;
}
public double divide(double a) {
register = calculator.divide(register, a);
return register;
}
public void clean() {
register = 0;
}
@Remove
public void turnOff() {
System.out.println("[StatefulCalculatorBean] Good bye ! I gotta split !");
}
@SuppressWarnings("unused")
@PostConstruct
private void afterCreated() {
System.out.println("[StatefulCalculatorBean] PostConstruct callback !");
}
@SuppressWarnings("unused")
@PreDestroy
private void beforeRemoved() {
System.out.println("[StatefulCalculatorBean] PreDestroy callback !");
}
NOTE: To resolve imports problems press Shift + Ctrl + O. Press Ctrl + S to save the Java class.
The Statful Session EJB is complete. With EJB 3, there is no need to code deployment descriptors or the home interface. The next step is to package the EJB in the EJB JAR file and deploy on the server.
|
|
|
|
Hosting provided by PerfoHost: KVM VPS. Unix VPS. Windows VPS. VPN. Domains. Dedicated servers. Colocation.