praktikum1/aufgabe2
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
package org.example.demo.praktikum1.aufgabe2;
|
||||||
|
import javax.naming.InitialContext;
|
||||||
|
import javax.naming.Context;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class Client {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||||
|
"org.wildfly.naming.client.WildFlyInitialContextFactory");
|
||||||
|
props.setProperty(Context.PROVIDER_URL, "http-remoting://localhost:8080");
|
||||||
|
|
||||||
|
InitialContext ctx = new InitialContext(props);
|
||||||
|
String jndiName = "ejb:/ejb-server-1.0-SNAPSHOT/StatefulCalculator!org.example.demo.praktikum1.aufgabe2.StatefulCalculatorRemote";
|
||||||
|
var calc = (StatefulCalculatorRemote) ctx.lookup(jndiName);
|
||||||
|
|
||||||
|
System.out.println("6 + 7 = " + calc.addiere(6, 7));
|
||||||
|
System.out.println("6 + 7 + 8 = " + calc.addiere(8));
|
||||||
|
System.out.println("6 - 7 = " + calc.subtrahiere(6, 7));
|
||||||
|
System.out.println("6 - 7 - 8 = " + calc.subtrahiere(8));
|
||||||
|
System.out.println("6 * 7 = " + calc.multipliziere(6, 7));
|
||||||
|
System.out.println("6 * 7 * 8 = " + calc.multipliziere(8));
|
||||||
|
System.out.println("6 / 7 = " + calc.dividiere(6, 7));
|
||||||
|
System.out.println("6 / 7 / 8 = " + calc.dividiere(8));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.example.demo.praktikum1.aufgabe2;
|
||||||
|
import org.example.demo.praktikum1.aufgabe1.Calculator;
|
||||||
|
|
||||||
|
import jakarta.ejb.Stateful;
|
||||||
|
|
||||||
|
@Stateful
|
||||||
|
public class StatefulCalculator implements StatefulCalculatorRemote {
|
||||||
|
private double state;
|
||||||
|
|
||||||
|
public double addiere(float zahl1, float zahl2) {
|
||||||
|
return state = new Calculator().addiere(zahl1, zahl2);
|
||||||
|
}
|
||||||
|
public double subtrahiere(float zahl1, float zahl2) {
|
||||||
|
return state = new Calculator().subtrahiere(zahl1, zahl2);
|
||||||
|
}
|
||||||
|
public double multipliziere(float zahl1, float zahl2) {
|
||||||
|
return state = new Calculator().multipliziere(zahl1, zahl2);
|
||||||
|
}
|
||||||
|
public double dividiere(float zahl1, float zahl2) {
|
||||||
|
return state = new Calculator().dividiere(zahl1, zahl2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double addiere(float zahl) {
|
||||||
|
return state = new Calculator().addiere((float)state, zahl);
|
||||||
|
}
|
||||||
|
public double subtrahiere(float zahl) {
|
||||||
|
return state = new Calculator().subtrahiere((float)state, zahl);
|
||||||
|
}
|
||||||
|
public double multipliziere(float zahl) {
|
||||||
|
return state = new Calculator().multipliziere((float)state, zahl);
|
||||||
|
}
|
||||||
|
public double dividiere(float zahl) {
|
||||||
|
return state = new Calculator().dividiere((float)state, zahl);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.example.demo.praktikum1.aufgabe2;
|
||||||
|
import jakarta.ejb.Remote;
|
||||||
|
|
||||||
|
@Remote
|
||||||
|
public interface StatefulCalculatorRemote {
|
||||||
|
double addiere(float zahl1, float zahl2);
|
||||||
|
double subtrahiere(float zahl1, float zahl2);
|
||||||
|
double multipliziere(float zahl1, float zahl2);
|
||||||
|
double dividiere(float zahl1, float zahl2);
|
||||||
|
|
||||||
|
double addiere(float zahl);
|
||||||
|
double subtrahiere(float zahl);
|
||||||
|
double multipliziere(float zahl);
|
||||||
|
double dividiere(float zahl);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user