From 4708ba199166d777d0b60879398a8e000f7aaf56 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Thu, 14 Nov 2019 19:13:32 +0100 Subject: Setup simple api --- .../java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 22 +++++++++++++++++++++ .../java/pl/edu/mimuw/cloudatlas/agent/Api.java | 11 +++++++++++ .../mimuw/cloudatlas/agent/ApiImplementation.java | 23 ++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/Api.java create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/agent/ApiImplementation.java (limited to 'src/main') 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 set = new HashSet(); + set.add(ValueNull.getInstance()); + return new ValueSet(set, TypePrimitive.STRING); + } +} -- cgit v1.2.3