done task 1 of week 3 - distributed systems
This commit is contained in:
9
.idea/DistributedSystems.iml
generated
Normal file
9
.idea/DistributedSystems.iml
generated
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package org.distributed.client;
|
||||||
|
|
||||||
|
public class Client {
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.distributed.engine;
|
||||||
|
|
||||||
|
public class Operation implements Task<Integer> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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> {
|
||||||
|
T execute();
|
||||||
|
}
|
||||||
@@ -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> T executeTask(Task<T> t) throws RemoteException {
|
||||||
|
return t.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user