diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..639900d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..d600c59
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
index d53ecaf..144146e 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,4 +1,5 @@
{
"java.compile.nullAnalysis.mode": "automatic",
- "java.configuration.updateBuildConfiguration": "automatic"
+ "java.configuration.updateBuildConfiguration": "automatic",
+ "java.debug.settings.onBuildFailureProceed": true
}
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/.gitignore b/week1_TinsaeGhilay/app/.gitignore
deleted file mode 100644
index 42afabf..0000000
--- a/week1_TinsaeGhilay/app/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/build
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/build.gradle b/week1_TinsaeGhilay/app/build.gradle
deleted file mode 100644
index 924061d..0000000
--- a/week1_TinsaeGhilay/app/build.gradle
+++ /dev/null
@@ -1,37 +0,0 @@
-plugins {
- id 'com.android.application'
-}
-
-android {
- compileSdk 31
-
- defaultConfig {
- applicationId "com.tgk.test"
- minSdk 21
- targetSdk 31
- versionCode 1
- versionName "1.0"
-
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- }
-
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
- }
- }
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
-}
-
-dependencies {
-
- implementation 'androidx.appcompat:appcompat:1.3.1'
- implementation 'com.google.android.material:material:1.4.0'
- testImplementation 'junit:junit:4.+'
- androidTestImplementation 'androidx.test.ext:junit:1.1.3'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
-}
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/libs/.gitkeep b/week1_TinsaeGhilay/app/libs/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/week1_TinsaeGhilay/app/proguard-rules.pro b/week1_TinsaeGhilay/app/proguard-rules.pro
deleted file mode 100644
index 481bb43..0000000
--- a/week1_TinsaeGhilay/app/proguard-rules.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-# Add project specific ProGuard rules here.
-# You can control the set of applied configuration files using the
-# proguardFiles setting in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
-
-# Uncomment this to preserve the line number information for
-# debugging stack traces.
-#-keepattributes SourceFile,LineNumberTable
-
-# If you keep the line number information, uncomment this to
-# hide the original source file name.
-#-renamesourcefileattribute SourceFile
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/androidTest/java/com/tgk/test/ExampleInstrumentedTest.java b/week1_TinsaeGhilay/app/src/androidTest/java/com/tgk/test/ExampleInstrumentedTest.java
deleted file mode 100644
index 470d75a..0000000
--- a/week1_TinsaeGhilay/app/src/androidTest/java/com/tgk/test/ExampleInstrumentedTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.tgk.test;
-
-import android.content.Context;
-
-import androidx.test.platform.app.InstrumentationRegistry;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static org.junit.Assert.*;
-
-/**
- * Instrumented test, which will execute on an Android device.
- *
- * @see Testing documentation
- */
-@RunWith(AndroidJUnit4.class)
-public class ExampleInstrumentedTest {
- @Test
- public void useAppContext() {
- // Context of the app under test.
- Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
- assertEquals("com.tgk.test", appContext.getPackageName());
- }
-}
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/main/AndroidManifest.xml b/week1_TinsaeGhilay/app/src/main/AndroidManifest.xml
deleted file mode 100644
index fb69ac2..0000000
--- a/week1_TinsaeGhilay/app/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/main/java/com/tgk/test/.gitkeep b/week1_TinsaeGhilay/app/src/main/java/com/tgk/test/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/week1_TinsaeGhilay/app/src/main/java/com/tgk/test/MainActivity.kt b/week1_TinsaeGhilay/app/src/main/java/com/tgk/test/MainActivity.kt
deleted file mode 100644
index e69de29..0000000
diff --git a/week1_TinsaeGhilay/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/week1_TinsaeGhilay/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
deleted file mode 100644
index 2b068d1..0000000
--- a/week1_TinsaeGhilay/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/main/res/drawable/ic_launcher_background.xml b/week1_TinsaeGhilay/app/src/main/res/drawable/ic_launcher_background.xml
deleted file mode 100644
index 07d5da9..0000000
--- a/week1_TinsaeGhilay/app/src/main/res/drawable/ic_launcher_background.xml
+++ /dev/null
@@ -1,170 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/week1_TinsaeGhilay/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
deleted file mode 100644
index eca70cf..0000000
--- a/week1_TinsaeGhilay/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/week1_TinsaeGhilay/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
deleted file mode 100644
index eca70cf..0000000
--- a/week1_TinsaeGhilay/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-hdpi/ic_launcher.webp
deleted file mode 100644
index 801563d..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-hdpi/ic_launcher.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
deleted file mode 100644
index 14ecbb5..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-mdpi/ic_launcher.webp
deleted file mode 100644
index 19b4549..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-mdpi/ic_launcher.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
deleted file mode 100644
index 2155e20..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
deleted file mode 100644
index a6b14be..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-xhdpi/ic_launcher.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
deleted file mode 100644
index ebe3ce0..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
deleted file mode 100644
index 3ed8cc3..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
deleted file mode 100644
index 1f8b5d0..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
deleted file mode 100644
index 960ac6a..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/week1_TinsaeGhilay/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
deleted file mode 100644
index 01649d7..0000000
Binary files a/week1_TinsaeGhilay/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp and /dev/null differ
diff --git a/week1_TinsaeGhilay/app/src/main/res/values-night/themes.xml b/week1_TinsaeGhilay/app/src/main/res/values-night/themes.xml
deleted file mode 100644
index dd8a87e..0000000
--- a/week1_TinsaeGhilay/app/src/main/res/values-night/themes.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/main/res/values/colors.xml b/week1_TinsaeGhilay/app/src/main/res/values/colors.xml
deleted file mode 100644
index f8c6127..0000000
--- a/week1_TinsaeGhilay/app/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- #FFBB86FC
- #FF6200EE
- #FF3700B3
- #FF03DAC5
- #FF018786
- #FF000000
- #FFFFFFFF
-
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/main/res/values/strings.xml b/week1_TinsaeGhilay/app/src/main/res/values/strings.xml
deleted file mode 100644
index ce714ae..0000000
--- a/week1_TinsaeGhilay/app/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
- Test
-
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/main/res/values/themes.xml b/week1_TinsaeGhilay/app/src/main/res/values/themes.xml
deleted file mode 100644
index e6a340f..0000000
--- a/week1_TinsaeGhilay/app/src/main/res/values/themes.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/app/src/test/java/com/tgk/test/ExampleUnitTest.java b/week1_TinsaeGhilay/app/src/test/java/com/tgk/test/ExampleUnitTest.java
deleted file mode 100644
index c63113b..0000000
--- a/week1_TinsaeGhilay/app/src/test/java/com/tgk/test/ExampleUnitTest.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.tgk.test;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Example local unit test, which will execute on the development machine (host).
- *
- * @see Testing documentation
- */
-public class ExampleUnitTest {
- @Test
- public void addition_isCorrect() {
- assertEquals(4, 2 + 2);
- }
-}
\ No newline at end of file
diff --git a/week1_TinsaeGhilay/gradle/wrapper/gradle-wrapper.jar b/week1_TinsaeGhilay/gradle/wrapper/gradle-wrapper.jar
deleted file mode 100644
index e708b1c..0000000
Binary files a/week1_TinsaeGhilay/gradle/wrapper/gradle-wrapper.jar and /dev/null differ
diff --git a/week1_TinsaeGhilay/gradle/wrapper/gradle-wrapper.properties b/week1_TinsaeGhilay/gradle/wrapper/gradle-wrapper.properties
deleted file mode 100644
index 488723f..0000000
--- a/week1_TinsaeGhilay/gradle/wrapper/gradle-wrapper.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-#Mon Oct 18 19:16:13 CEST 2021
-distributionBase=GRADLE_USER_HOME
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
-distributionPath=wrapper/dists
-zipStorePath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
diff --git a/week3_TinsaeGhilay/Task 1/README.md b/week3_TinsaeGhilay/Task 1/README.md
new file mode 100644
index 0000000..9451dda
--- /dev/null
+++ b/week3_TinsaeGhilay/Task 1/README.md
@@ -0,0 +1,31 @@
+## Structure
+The files are in 3 packages (directories)
+
+1. **compute:** Package contains the interfaces. `Compute.java` and `Task.java`
+2. **eingine:** package contains the server class `ComputeEngine.java`
+3. **client:** package contains the client classes `Client.java` and `Operation.java`
+## How to run
+Each of the following commands are to be run in theit own terminal instance.
+
i.e. open a new terminal and run the neccessary command.
+1. First we compile the classeswith the output directory `out` so we have `srs` for source code and `out` for class files using the command
+ ```bash
+ # this compiles any file in any directory under 'srs' in its oun parent directory under 'out'.
+ javac -d out $(find src -name "*.java")
+ ```
+2. Then we start the rmiregistry. since I am on linux, we do this as such:
+ ```bash
+ # cd in to 'out' directory
+ cd out
+ # and start rmi registry server in the background
+ rmiregistry &
+ ```
+3. Start the server with the command
+ ```bash
+ # this command runs the Server class 'ComputEngine'
+ java -cp out engine.ComputeEngine
+ ```
+4. And finally we start the client with the following command
+ ```bash
+ # command runs the client class Client
+ java -cp out client.Client
+ ```
\ No newline at end of file
diff --git a/week3_TinsaeGhilay/Task 1/out/client/Client.class b/week3_TinsaeGhilay/Task 1/out/client/Client.class
new file mode 100644
index 0000000..d07b99b
Binary files /dev/null and b/week3_TinsaeGhilay/Task 1/out/client/Client.class differ
diff --git a/week3_TinsaeGhilay/Task 1/out/client/Operation.class b/week3_TinsaeGhilay/Task 1/out/client/Operation.class
new file mode 100644
index 0000000..4ce7c4f
Binary files /dev/null and b/week3_TinsaeGhilay/Task 1/out/client/Operation.class differ
diff --git a/week3_TinsaeGhilay/Task 1/out/compute/Compute.class b/week3_TinsaeGhilay/Task 1/out/compute/Compute.class
new file mode 100644
index 0000000..dd4ac07
Binary files /dev/null and b/week3_TinsaeGhilay/Task 1/out/compute/Compute.class differ
diff --git a/week3_TinsaeGhilay/Task 1/out/compute/Task.class b/week3_TinsaeGhilay/Task 1/out/compute/Task.class
new file mode 100644
index 0000000..6760205
Binary files /dev/null and b/week3_TinsaeGhilay/Task 1/out/compute/Task.class differ
diff --git a/week3_TinsaeGhilay/Task 1/out/engine/ComputeEngine.class b/week3_TinsaeGhilay/Task 1/out/engine/ComputeEngine.class
new file mode 100644
index 0000000..edb660a
Binary files /dev/null and b/week3_TinsaeGhilay/Task 1/out/engine/ComputeEngine.class differ
diff --git a/week3_TinsaeGhilay/Task 1/src/client/Client.java b/week3_TinsaeGhilay/Task 1/src/client/Client.java
new file mode 100644
index 0000000..2dada84
--- /dev/null
+++ b/week3_TinsaeGhilay/Task 1/src/client/Client.java
@@ -0,0 +1,103 @@
+package client;
+
+// Client/Client.java class represents the client that has to relay on the compute engine
+// to perform tasks remotely.
+// it needs the compute interface from compute package
+import compute.Compute;
+
+// it also needs those to access the registry,
+// so it can get remote object reference of the server
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.util.Scanner;
+
+public class Client {
+ private Client() {
+ }
+
+ public static void main(String[] args) {
+
+ // normally, the address of the server is passed here on the command line as an
+ // argument
+ // we get that address from args[0] if provided, else we use null for localhost
+ String host = (args.length < 1) ? null : args[0];
+ String name = "Compute";
+
+ try (Scanner scanner = new Scanner(System.in);) {
+
+ // get the registry from host(server)
+ Registry registry = LocateRegistry.getRegistry(host);
+
+ // look up the remote object by name in the registry
+ // stub is the a reference to the remote object
+ Compute stub = (Compute) registry.lookup(name);
+
+ // interactive client to perform operations
+ System.out.println("Connected to ComputeEngine. Type 'exit' to quit.");
+ while (true) {
+
+ // get user input for first number
+ System.out.println("Enter first number: ");
+ String input = scanner.next();
+ if (input.equalsIgnoreCase("exit")) {
+ System.out.println("Exiting client.");
+ break;
+ }
+ int a = validateNumber(input);
+
+ // get user input for second number
+ System.out.println("Enter second number: ");
+ input = scanner.next();
+ if (input.equalsIgnoreCase("exit")) {
+ System.out.println("Exiting client.");
+ break;
+ }
+ int b = validateNumber(input);
+
+ // get user input for operand
+ System.out.println("Enter operand (+, -, *, /, %): ");
+ input = scanner.next();
+ if (input.equalsIgnoreCase("exit")) {
+ System.out.println("Exiting client.");
+ break;
+ }
+ String operand = validateOperand(input);
+
+ // create operation task
+ Operation op = new Operation(a, b, operand);
+ // execute task remotely
+ int result = stub.executeTask(op);
+ System.out.println("Result: " + a + " " + operand + " " + b + " = " + result);
+ }
+ } catch (Exception e) {
+ System.err.println("Client exception: " + e.getMessage());
+ }
+ }
+
+ // simple validation methods. Because It is said
+ // "Be conservative on what you do, be liberal on what you accept from others"
+ // for int parsing
+ private static int validateNumber(String a) {
+ try {
+ return Integer.parseInt(a);
+ } catch (NumberFormatException e) {
+ System.err.println("Invalid number format: " + a + ". Defaulting to 0.");
+ return 0;
+ }
+ }
+
+ // For operand validation
+ private static String validateOperand(String op) {
+ switch (op) {
+ case "+":
+ case "-":
+ case "*":
+ case "/":
+ case "%":
+ return op;
+ default:
+ System.err.println("Invalid operand: " + op + ". Defaulting to '+'.");
+ return "+";
+ }
+ }
+}
diff --git a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Operation.java b/week3_TinsaeGhilay/Task 1/src/client/Operation.java
similarity index 55%
rename from week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Operation.java
rename to week3_TinsaeGhilay/Task 1/src/client/Operation.java
index a2b54c9..4e9c958 100644
--- a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Operation.java
+++ b/week3_TinsaeGhilay/Task 1/src/client/Operation.java
@@ -1,17 +1,24 @@
-package org.distributed.engine;
-public class Operation implements Task {
+package client;
- int a,b;
+import java.io.Serializable;
+import compute.Task;
+
+public class Operation implements Task, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ int a, b;
String operand;
- public Operation(int a, int b, String operand){
+ public Operation(int a, int b, String operand) {
this.a = a;
this.b = b;
this.operand = operand;
}
+ // do the operation
public Integer execute() {
return switch (this.operand) {
case "+" -> a + b;
diff --git a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Compute.java b/week3_TinsaeGhilay/Task 1/src/compute/Compute.java
similarity index 74%
rename from week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Compute.java
rename to week3_TinsaeGhilay/Task 1/src/compute/Compute.java
index adab619..7ec1e29 100644
--- a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Compute.java
+++ b/week3_TinsaeGhilay/Task 1/src/compute/Compute.java
@@ -1,4 +1,4 @@
-package org.distributed.engine;
+package compute;
import java.rmi.Remote;
import java.rmi.RemoteException;
@@ -8,5 +8,5 @@ import java.rmi.RemoteException;
public interface Compute extends Remote {
// needs a task interface
- int executeTask(Operation t) throws RemoteException;
+ T executeTask(Task t) throws RemoteException;
}
diff --git a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Task.java b/week3_TinsaeGhilay/Task 1/src/compute/Task.java
similarity index 93%
rename from week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Task.java
rename to week3_TinsaeGhilay/Task 1/src/compute/Task.java
index 2217072..7ce4dfc 100644
--- a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/compute/Task.java
+++ b/week3_TinsaeGhilay/Task 1/src/compute/Task.java
@@ -1,4 +1,4 @@
-package org.distributed.compute;
+package compute;
/**
* This interface is the type of parameter to the executeTask() method of the
diff --git a/week3_TinsaeGhilay/Task 1/src/engine/ComputeEngine.java b/week3_TinsaeGhilay/Task 1/src/engine/ComputeEngine.java
new file mode 100644
index 0000000..fb4ad5b
--- /dev/null
+++ b/week3_TinsaeGhilay/Task 1/src/engine/ComputeEngine.java
@@ -0,0 +1,58 @@
+
+package engine;
+
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
+
+// needs the compute and task interfaces from compute package
+// define constructor for each
+// and provide an implementation for each remote method in the remote interfaces
+import compute.Compute;
+import compute.Task;
+
+/**
+ * The implementation of the Compute interface for the compute engine.
+ * it has to declare the remote class to be implemented (in this case Compute
+ * (implements it)
+ */
+public class ComputeEngine implements Compute {
+
+ public ComputeEngine() {
+ super();
+ }
+
+ @Override
+ public T executeTask(Task t) throws RemoteException {
+ return t.execute();
+ }
+
+ // entry
+ public static void main(String[] args) {
+
+ // the code provided on the tutorial was deprecated.
+ // so google led me to
+ // [this](https://docs.oracle.com/javase/8/docs/technotes/guides/rmi/hello/hello-world.html#create)
+ try {
+ String name = "Compute";
+ // create remote object that provides service (server).
+ Compute engine = new ComputeEngine();
+
+ // and export remote object to java RMI runtime
+ // so it may receive remote incoming calls
+ Compute stub = (Compute) UnicastRemoteObject.exportObject(engine, 0);
+
+ // the register the remote object with java RMI registry
+ // the registry is a name service that allows clients get a reference of remote
+ // objects
+ // once a remote object is registered, callers can look up the object by name
+ // and obtain its remote object reference
+ Registry registry = LocateRegistry.getRegistry();
+ registry.rebind(name, stub);
+ System.out.println("ComputeEngine bound");
+ } catch (Exception e) {
+ System.err.println("ComputeEngine exception: " + e.getMessage());
+ }
+ }
+}
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
deleted file mode 100644
index 9f7f35c..0000000
--- a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/client/Client.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package org.distributed.client;
-
-public class Client {
-}
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
deleted file mode 100644
index 6d13bc5..0000000
--- a/week3_TinsaeGhilay/Task 1/src/main/java/org/distributed/engine/ComputeEngine.java
+++ /dev/null
@@ -1,17 +0,0 @@
-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();
- }
-}