diff --git a/.idea/DistributedSystems.iml b/.idea/DistributedSystems.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/DistributedSystems.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/README.md b/week2_TinsaeGhilay/Task2/README.md similarity index 100% rename from README.md rename to week2_TinsaeGhilay/Task2/README.md diff --git a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/client/Client.java b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/client/Client.java new file mode 100644 index 0000000..9f7f35c --- /dev/null +++ b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/client/Client.java @@ -0,0 +1,4 @@ +package org.distributed.client; + +public class Client { +} diff --git a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Compute.java b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Compute.java new file mode 100644 index 0000000..adab619 --- /dev/null +++ b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Compute.java @@ -0,0 +1,12 @@ +package org.distributed.engine; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +// this interface extends the interface "java.rmi.Remote" +// so its methods can be invoked from another Java virtual machine +public interface Compute extends Remote { + + // needs a task interface + int executeTask(Operation t) throws RemoteException; +} diff --git a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Operation.java b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Operation.java new file mode 100644 index 0000000..a2b54c9 --- /dev/null +++ b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Operation.java @@ -0,0 +1,24 @@ +package org.distributed.engine; + +public class Operation implements Task { + + int a,b; + String operand; + + public Operation(int a, int b, String operand){ + this.a = a; + this.b = b; + this.operand = operand; + + } + + public Integer execute() { + return switch (this.operand) { + case "+" -> a + b; + case "-" -> a - b; + case "*" -> a * b; + case "/" -> a / b; + default -> a % b; + }; + } +} diff --git a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Task.java b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Task.java new file mode 100644 index 0000000..2217072 --- /dev/null +++ b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Task.java @@ -0,0 +1,15 @@ +package org.distributed.compute; + +/** + * This interface is the type of parameter to the executeTask() method of the + * Compute interface + * it defines the interface between the compute engine + * and the work that it needs to do, providing the way to start the work + * It defines a single method execute() whose return type is T + * The interface itself also has a type T, which represents the result type of + * the task's computation + */ + +public interface Task { + T execute(); +} diff --git a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/engine/ComputeEngine.java b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/engine/ComputeEngine.java new file mode 100644 index 0000000..6d13bc5 --- /dev/null +++ b/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/engine/ComputeEngine.java @@ -0,0 +1,17 @@ +package org.distributed; + +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; + +public class ComputeEngine implements Compute { + + public ComputeEngine() { + super(); + } + @Override + public T executeTask(Task t) throws RemoteException { + return t.execute(); + } +}