diff options
author | Magdalena GrodziĆska <mag.grodzinska@gmail.com> | 2019-12-25 16:18:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-25 16:18:53 +0100 |
commit | cbb43ba62d11888ce73314465dcffb537b6cd295 (patch) | |
tree | f07bb9663d4224190bdcef077fa8db12df82d121 /src/main/java/pl/edu/mimuw/cloudatlas/agent/modules | |
parent | a4c5b93eca9966f3816ebc3e82d5ef344768a1cb (diff) | |
parent | 8189c108befee400be89b8a0989bf367187fd375 (diff) |
Merge pull request #73 from m-chrzan/rmi
Move registry binding to RMI module
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/RMI.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/RMI.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/RMI.java new file mode 100644 index 0000000..452b214 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/RMI.java @@ -0,0 +1,39 @@ +package pl.edu.mimuw.cloudatlas.agent.modules; + +import pl.edu.mimuw.cloudatlas.agent.ApiImplementation; +import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.TimerSchedulerMessage; +import pl.edu.mimuw.cloudatlas.api.Api; +import pl.edu.mimuw.cloudatlas.interpreter.Main; +import pl.edu.mimuw.cloudatlas.model.ZMI; + +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; + +public class RMI extends Module { + public RMI(AgentMessage.AgentModule moduleType) { + super(moduleType); + runRegistry(); + } + + public void runRegistry() { + try { + ZMI root = Main.createTestHierarchy2(); + ApiImplementation api = new ApiImplementation(root); + Api apiStub = + (Api) UnicastRemoteObject.exportObject(api, 0); + Registry registry = LocateRegistry.getRegistry(); + registry.rebind("Api", apiStub); + System.out.println("Agent: api bound"); + } catch (Exception e) { + System.err.println("Agent registry initialization exception:"); + e.printStackTrace(); + } + } + + @Override + public void handle(AgentMessage event) throws InterruptedException { + assert event.getDestinationModule() == event.getCorrectMessageType(); + } +} |