diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2019-11-14 19:13:32 +0100 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2019-11-14 19:13:32 +0100 |
commit | 4708ba199166d777d0b60879398a8e000f7aaf56 (patch) | |
tree | 130fdf9aa0a83869138866cd64658f6cf1ebb6dd /src/main/java | |
parent | a014f22d8c8c5c15aa08500a02da0d0717d62b64 (diff) |
Setup simple api
Diffstat (limited to 'src/main/java')
3 files changed, 56 insertions, 0 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java new file mode 100644 index 0000000..79df04e --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -0,0 +1,22 @@ +package pl.edu.mimuw.cloudatlas.agent; + +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; + +public class Agent { + public static void main(String[] args) { + try { + ApiImplementation api = new ApiImplementation(); + Api apiStub = + (Api) UnicastRemoteObject.exportObject(api, 0); + Registry registry = LocateRegistry.getRegistry(); + registry.rebind("Api", apiStub); + System.out.println("Api bound"); + } catch (Exception e) { + System.err.println("Agent exception:"); + e.printStackTrace(); + } + } +} diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Api.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Api.java new file mode 100644 index 0000000..c0003a8 --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Api.java @@ -0,0 +1,11 @@ +package pl.edu.mimuw.cloudatlas.agent; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +import pl.edu.mimuw.cloudatlas.model.ValueSet; + +public interface Api extends Remote { + public int ping(int n) throws RemoteException; + public ValueSet getZones() throws RemoteException; +} diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java new file mode 100644 index 0000000..fc7532d --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java @@ -0,0 +1,23 @@ +package pl.edu.mimuw.cloudatlas.agent; + +import java.rmi.RemoteException; + +import java.util.Set; +import java.util.HashSet; + +import pl.edu.mimuw.cloudatlas.model.Value; +import pl.edu.mimuw.cloudatlas.model.ValueSet; +import pl.edu.mimuw.cloudatlas.model.ValueNull; +import pl.edu.mimuw.cloudatlas.model.TypePrimitive; + +public class ApiImplementation implements Api { + public int ping(int n) throws RemoteException { + return n + 1; + } + + public ValueSet getZones() throws RemoteException { + Set<Value> set = new HashSet(); + set.add(ValueNull.getInstance()); + return new ValueSet(set, TypePrimitive.STRING); + } +} |