Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
� Conflicts:
�	EX2/rmi/client/src/main/java/ClientMain.java
  • Loading branch information
milo1393 committed Dec 22, 2021
2 parents 1528455 + 3a95391 commit d577a6a
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ build
.idea/**/tasks.xml
.idea/**/compiler.xml
.idea/compiler.xml
.idea/misc.xml
.idea/dictionaries
.idea/checkstyleidea-libs

Expand Down
1 change: 1 addition & 0 deletions EX2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ build
.idea/**/tasks.xml
.idea/**/compiler.xml
.idea/compiler.xml
.idea/misc.xml
.idea/dictionaries
.idea/checkstyleidea-libs

Expand Down
10 changes: 0 additions & 10 deletions EX2/.idea/misc.xml

This file was deleted.

14 changes: 13 additions & 1 deletion EX2/interfaces/src/main/java/EnvData.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
public class EnvData {
import java.io.Serializable;
import java.util.Arrays;

public class EnvData implements Serializable {
final String mTimestamp;
final String mSensor;
final int[] mValues;
Expand All @@ -8,4 +11,13 @@ public class EnvData {
mSensor = _sensor;
mValues = _values;
}

@Override
public String toString() {
return "EnvData{"
+ "mTimestamp='" + mTimestamp + '\''
+ ", mSensor='" + mSensor + '\''
+ ", mValues=" + Arrays.toString(mValues)
+ '}';
}
}
9 changes: 5 additions & 4 deletions EX2/rmi/client/src/main/java/ClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ public static void main(String[] _args) {
} while (inputMenu < 1 || inputMenu > 4);

switch (inputMenu) {
case 1 -> envStub.requestEnvironmentDataTypes();
case 2 -> envStub.requestEnvironmentData("air");
case 3 -> envStub.requestAll();
case 1 -> System.out.println(envStub.requestEnvironmentDataTypes());
case 2 -> System.out.println(envStub.requestEnvironmentData("air"));
case 3 -> System.out.println(envStub.requestAll());
default -> exit = true;
}
}



} catch (Exception _e) {
_e.printStackTrace();
}

}
}
7 changes: 1 addition & 6 deletions EX2/rmi/server/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import java.rmi.registry.LocateRegistry
import java.rmi.registry.Registry

fun main(_args: Array<String>) {
val server = Server()
val reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT)
reg.bind("EnvService", server)
ServiceMgmt()
println("Server is waiting for queries ...")
}
41 changes: 35 additions & 6 deletions EX2/rmi/server/src/main/kotlin/ServiceMgmt.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import java.lang.Exception
import java.rmi.NotBoundException
import java.rmi.RemoteException
import java.rmi.registry.LocateRegistry
import java.rmi.registry.Registry
import java.rmi.server.RemoteObject
import java.rmi.server.UnicastRemoteObject

const val ENV_SERVICE = "EnvService"

class ServiceMgmt {
private val registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT)
private val mServer by lazy { Server() }

init {
startMenu()
try {
startMenu()
} catch (_e: RemoteException) {
System.err.println("ERROR CREATING REGISTRY: $_e")
}
}

private fun startMenu() {
Expand All @@ -27,21 +37,40 @@ class ServiceMgmt {
when (inputMenu) {
1u -> startRmi()
2u -> stopRmi()
3u -> quit()
3u -> return quit()
}
}
}

private fun startRmi() {
val reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT)
reg.bind(ENV_SERVICE, mServer)
try {
registry.rebind(ENV_SERVICE, mServer)
println("RMI SERVICE STARTED")
} catch (_e: RemoteException) {
System.err.println("ERROR STARTING SERVER: $_e")
}
}

private fun stopRmi() {

try {
registry.unbind(ENV_SERVICE)
UnicastRemoteObject.unexportObject(mServer, true)
println("RMI SERVICE STOPPED")
} catch (_e: Exception) {
when (_e) {
is RemoteException, is NotBoundException -> {
println("SERVER ALREADY STOPPED")
}
}
}
}

private fun quit() {

stopRmi()
try {
UnicastRemoteObject.unexportObject(registry, true)
} catch (_e: Exception) {
System.err.println("ERROR QUITTING SERVICE MGMT: $_e")
}
}
}

0 comments on commit d577a6a

Please sign in to comment.