Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/Stack.java48
-rw-r--r--platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageAgent.java4
-rw-r--r--platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageConnection.java215
-rw-r--r--platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/ExtResourceImpl.java1
-rw-r--r--platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/GenericActivator.java17
-rw-r--r--platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/InoResourceImpl.java65
-rw-r--r--platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/InovalleeActivator.java6
-rw-r--r--platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/EliorFetcher.java2
-rw-r--r--platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/MobilityFetcher.java3
9 files changed, 239 insertions, 122 deletions
diff --git a/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/Stack.java b/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/Stack.java
new file mode 100644
index 00000000..3aa424e0
--- /dev/null
+++ b/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/Stack.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 CEA.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA - initial API and implementation
+ */
+package org.eclipse.sensinact.gateway.agent.storage.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONObject;
+
+public class Stack {
+ private List<JSONObject> list = new ArrayList<>();
+
+ public boolean isEmpty() {
+ synchronized (list) {
+ return list.isEmpty();
+ }
+ }
+
+ public int size() {
+ synchronized (list) {
+ return list.size();
+ }
+ }
+
+ public void push(JSONObject element) {
+ if (element == null)
+ throw new IllegalArgumentException("Can't Push a null element");
+ synchronized (list) {
+ list.add(element);
+ }
+ }
+
+ public JSONObject pop() {
+ synchronized (list) {
+ if (list.isEmpty())
+ return null;
+ return list.remove(list.size()-1);
+ }
+ }
+}
diff --git a/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageAgent.java b/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageAgent.java
index 1a1f0c06..f18a8442 100644
--- a/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageAgent.java
+++ b/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageAgent.java
@@ -115,8 +115,8 @@ public class StorageAgent extends AbstractMidAgentCallback {
jsonObject.put("resource", resource);
jsonObject.put(DataResource.VALUE, initialValue);
jsonObject.put("timestamp", timestampStr);
- LOG.debug("pushing to database {}/{}/{}/{}...", serviceProvider, service, resource, initialValue);
- this.storageConnection.push(jsonObject);
+ LOG.debug("pushing to stack {}/{}/{}/{}...", serviceProvider, service, resource, initialValue);
+ this.storageConnection.stack.push(jsonObject);
LOG.debug("...done");
}
diff --git a/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageConnection.java b/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageConnection.java
index 77113dd4..056ee1d0 100644
--- a/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageConnection.java
+++ b/platform/northbound/storage-agent/src/main/java/org/eclipse/sensinact/gateway/agent/storage/internal/StorageConnection.java
@@ -19,13 +19,14 @@ import org.eclipse.sensinact.gateway.protocol.http.client.SimpleRequest;
import org.eclipse.sensinact.gateway.protocol.http.client.SimpleResponse;
import org.eclipse.sensinact.gateway.util.crypto.Base64;
import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Stack;
/**
* HTTP Agent dedicated to storage service
@@ -33,120 +34,108 @@ import java.util.Stack;
* @author <a href="mailto:christophe.munilla@cea.fr">Christophe Munilla</a>
*/
class StorageConnection {
- private String authorization;
- private String uri;
- private Mediator mediator;
- private Stack<JSONObject> stack;
- private boolean running = false;
+ private static final Logger LOG = LoggerFactory.getLogger(StorageConnection.class);
- /**
- * Constructor
- *
- * @param mediator the associated {@link Mediator}
- * @param uri the string URI of the storage server
- * @param login the user login
- * @param password the user password
- * @throws IOException Exception on connection problem
- */
- StorageConnection(Mediator mediator, String uri, String login, String password) throws IOException {
- this.mediator = mediator;
- this.uri = uri;
- this.authorization = Base64.encodeBytes((login + ":" + password).getBytes());
- this.stack = new Stack<>();
- this.running = true;
- Runnable runner = new Runnable() {
- @Override
- public void run() {
- while (true) {
- if (!StorageConnection.this.running) {
- break;
- }
- JSONObject config = StorageConnection.this.pop();
- if (config != null) {
- StorageConnection.this.httpRequest(config);
- } else {
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- Thread.interrupted();
- break;
- }
- }
- }
- }
- };
- new Thread(runner).start();
- }
+ private String authorization;
+ private String uri;
+ private Mediator mediator;
+ Stack stack;
+ private boolean running = false;
- /**
- * @param request
- */
- final void push(JSONObject request) {
- if (request == null || !this.running) {
- return;
- }
- synchronized (this.stack) {
- this.stack.push(request);
- }
- }
+ /**
+ * Constructor
+ *
+ * @param mediator the associated {@link Mediator}
+ * @param uri the string URI of the storage server
+ * @param login the user login
+ * @param password the user password
+ * @throws IOException Exception on connection problem
+ */
+ StorageConnection(Mediator mediator, String uri, String login, String password) throws IOException {
+ this.mediator = mediator;
+ this.uri = uri;
+ this.authorization = Base64.encodeBytes((login + ":" + password).getBytes());
+ this.stack = new Stack();
+ this.running = true;
+
+ Runnable runner = new Runnable() {
+ @Override
+ public void run() {
+ LOG.info("POP thread started");
+ while (running) {
+ try {
+ JSONObject element = stack.pop();
+ if (element != null) {
+ sendRequest(element);
+ } else {
+ if (! shortSleep(200)) {
+ running = false;
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("POP thread error", e);
+ }
+ }
+ LOG.info("POP thread terminated");
+ }
+ };
+ new Thread(runner).start();
+ }
- /**
- * @return
- */
- private JSONObject pop() {
- JSONObject request = null;
- synchronized (this.stack) {
- if (!this.stack.isEmpty()) {
- request = this.stack.pop();
- }
- }
- return request;
- }
+ /**
+ * Executes the HTTP request defined by the method, target, headers and entity
+ * arguments
+ */
+ private void sendRequest(JSONObject object) {
+ ConnectionConfiguration<SimpleResponse, SimpleRequest> configuration = new ConnectionConfigurationImpl<>();
+ try {
+ configuration.setContentType("application/json");
+ configuration.setAccept("application/json");
+ configuration.setUri(this.uri);
+ configuration.setContent(object.toString());
+ configuration.setHttpMethod("POST");
+ configuration.addHeader("Authorization", "Basic " + authorization);
+ configuration.addHeader("User-Agent", "java/sensiNact-storage");
+ Request request = new SimpleRequest(configuration);
+ Response response = request.send();
+ if (mediator.isDebugLoggable()) {
+ this.mediator.debug(" >> response status code: " + response.getStatusCode());
+ }
+ Iterator<Map.Entry<String, List<String>>> iterator = response.getHeaders().entrySet().iterator();
+ if (!iterator.hasNext()) {
+ return;
+ }
+ Map.Entry<String, List<String>> entry = iterator.next();
+ for (; iterator.hasNext(); entry = iterator.next()) {
+ this.mediator.debug(entry.getKey() + " :: " + (entry.getValue() == null ? "null"
+ : Arrays.toString(entry.getValue().toArray(new String[0]))));
+ }
+ } catch (Exception e) {
+ LOG.error("Can't send request", e);
+ if (this.mediator.isErrorLoggable()) {
+ this.mediator.error(e.getMessage(), e);
+ }
+ }
+ }
- /**
- * Executes the HTTP request defined by the method, target,
- * headers and entity arguments
- */
- private void httpRequest(JSONObject object) {
- ConnectionConfiguration<SimpleResponse, SimpleRequest> configuration = new ConnectionConfigurationImpl<>();
- try {
- configuration.setContentType("application/json");
- configuration.setAccept("application/json");
- configuration.setUri(this.uri);
- configuration.setContent(object.toString());
- configuration.setHttpMethod("POST");
- configuration.addHeader("Authorization", "Basic " + authorization);
- configuration.addHeader("User-Agent", "java/sensiNact-storage");
- Request request = new SimpleRequest(configuration);
- Response response = request.send();
- if (mediator.isDebugLoggable()) {
- this.mediator.debug(" >> response status code: " + response.getStatusCode());
- }
- Iterator<Map.Entry<String, List<String>>> iterator = response.getHeaders().entrySet().iterator();
- if (!iterator.hasNext()) {
- return;
- }
- Map.Entry<String, List<String>> entry = iterator.next();
- for (; iterator.hasNext(); entry = iterator.next()) {
- this.mediator.debug(entry.getKey() + " :: " + (entry.getValue() == null ? "null" : Arrays.toString(entry.getValue().toArray(new String[0]))));
- }
- } catch (Exception e) {
- e.printStackTrace();
- if (this.mediator.isErrorLoggable()) {
- this.mediator.error(e.getMessage(), e);
- }
- }
- }
-
- void close() {
- this.running = false;
- while (!this.stack.isEmpty()) {
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- Thread.interrupted();
- break;
- }
- }
- }
+ void close() {
+ for (int i=0; i< 10_000 && !this.stack.isEmpty(); i++) {
+ if (! shortSleep(200)) {
+ return;
+ }
+ }
+ LOG.info("close operation ended");
+ this.running = false;
+ }
+
+ private boolean shortSleep(long millis) {
+ try {
+ Thread.sleep(millis);
+ return true;
+ } catch (InterruptedException e) {
+ LOG.error("Sleep operation error", e);
+ Thread.interrupted();
+ return false;
+ }
+ }
}
diff --git a/platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/ExtResourceImpl.java b/platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/ExtResourceImpl.java
index e89ee345..795d5987 100644
--- a/platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/ExtResourceImpl.java
+++ b/platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/ExtResourceImpl.java
@@ -14,6 +14,7 @@
package org.eclipse.sensinact.gateway.generic;
import org.eclipse.sensinact.gateway.common.primitive.InvalidValueException;
+import org.eclipse.sensinact.gateway.core.Resource.Type;
import org.eclipse.sensinact.gateway.core.ResourceImpl;
import org.eclipse.sensinact.gateway.core.method.AbstractAccessMethod;
import org.eclipse.sensinact.gateway.core.method.AccessMethod;
diff --git a/platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/GenericActivator.java b/platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/GenericActivator.java
index 9d071f32..d526beeb 100644
--- a/platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/GenericActivator.java
+++ b/platform/sensinact-generic/src/main/java/org/eclipse/sensinact/gateway/generic/GenericActivator.java
@@ -17,16 +17,21 @@ public abstract class GenericActivator extends AbstractActivator<Mediator> {
@Override
public void doStart() throws Exception {
- ExtModelConfiguration<?> configuration = ExtModelConfigurationBuilder.instance(
- mediator, getPacketClass()
- ).withServiceBuildPolicy((byte) (SensiNactResourceModelConfiguration.BuildPolicy.BUILD_ON_DESCRIPTION.getPolicy() | SensiNactResourceModelConfiguration.BuildPolicy.BUILD_NON_DESCRIBED.getPolicy())
- ).withResourceBuildPolicy((byte) (SensiNactResourceModelConfiguration.BuildPolicy.BUILD_ON_DESCRIPTION.getPolicy() | SensiNactResourceModelConfiguration.BuildPolicy.BUILD_NON_DESCRIBED.getPolicy())
- ).withStartAtInitializationTime(true
- ).build(this.getClass().getName()+".xml", Collections.emptyMap());
+ ExtModelConfigurationBuilder builder = ExtModelConfigurationBuilder.instance(mediator, getPacketClass());
+
+ ExtModelConfiguration configuration = configureBuilder(builder)
+ .withServiceBuildPolicy((byte) (SensiNactResourceModelConfiguration.BuildPolicy.BUILD_ON_DESCRIPTION.getPolicy() | SensiNactResourceModelConfiguration.BuildPolicy.BUILD_NON_DESCRIBED.getPolicy()))
+ .withResourceBuildPolicy((byte) (SensiNactResourceModelConfiguration.BuildPolicy.BUILD_ON_DESCRIPTION.getPolicy() | SensiNactResourceModelConfiguration.BuildPolicy.BUILD_NON_DESCRIBED.getPolicy()))
+ .withStartAtInitializationTime(true)
+ .build(this.getClass().getName()+".xml", Collections.emptyMap());
endPoint = getEndPoint();
this.connect(configuration);
}
+ protected ExtModelConfigurationBuilder configureBuilder(ExtModelConfigurationBuilder builder) {
+ return builder;
+ }
+
@Override
public void doStop() {
try {
diff --git a/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/InoResourceImpl.java b/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/InoResourceImpl.java
new file mode 100644
index 00000000..c16cef5b
--- /dev/null
+++ b/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/InoResourceImpl.java
@@ -0,0 +1,65 @@
+package org.eclipse.sensinact.gateway.sthbnd.inovallee;
+
+import org.eclipse.sensinact.gateway.common.primitive.InvalidValueException;
+import org.eclipse.sensinact.gateway.core.ModelInstance;
+import org.eclipse.sensinact.gateway.core.ResourceConfig;
+import org.eclipse.sensinact.gateway.core.ResourceImpl;
+import org.eclipse.sensinact.gateway.core.ServiceImpl;
+import org.eclipse.sensinact.gateway.core.method.AbstractAccessMethod;
+import org.eclipse.sensinact.gateway.core.method.AccessMethod;
+import org.eclipse.sensinact.gateway.core.method.AccessMethod.Type;
+import org.eclipse.sensinact.gateway.core.method.AccessMethodExecutor;
+import org.eclipse.sensinact.gateway.core.method.AccessMethodExecutor.ExecutionPolicy;
+import org.eclipse.sensinact.gateway.core.method.AccessMethodResponseBuilder;
+import org.eclipse.sensinact.gateway.core.method.Signature;
+import org.eclipse.sensinact.gateway.generic.ExtModelInstance;
+import org.eclipse.sensinact.gateway.generic.ExtResourceConfig;
+import org.eclipse.sensinact.gateway.generic.ExtResourceImpl;
+import org.eclipse.sensinact.gateway.generic.ExtServiceImpl;
+import org.eclipse.sensinact.gateway.generic.annotation.Act;
+import org.eclipse.sensinact.gateway.generic.annotation.Get;
+import org.eclipse.sensinact.gateway.generic.annotation.Subscribe;
+import org.eclipse.sensinact.gateway.generic.annotation.Unsubscribe;
+import org.eclipse.sensinact.gateway.generic.parser.MethodDefinition;
+import org.eclipse.sensinact.gateway.generic.parser.SignatureDefinition;
+import org.eclipse.sensinact.gateway.util.ReflectUtils;
+import org.json.JSONObject;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+
+public class InoResourceImpl extends ExtResourceImpl {
+
+ protected InoResourceImpl(ExtModelInstance<?> modelInstance, ExtResourceConfig resourceConfig, ExtServiceImpl service) {
+ super(modelInstance, resourceConfig, service);
+ System.out.println("-----------> INIT");
+ System.out.println("-----------> " + getName());
+ System.out.println("-----------> " + getPath());
+
+ }
+
+ @Get
+ public JSONObject notNamedAct() {
+ System.out.println("-----------> NO ARGS");
+ return new JSONObject();
+ }
+
+
+ @Get
+ public JSONObject notNamedAct(String arg1) {
+ System.out.println("-----------> 1 arg : " + arg1);
+ return new JSONObject();
+ }
+
+
+ @Get
+ public JSONObject notNamedAct(String arg1, String arg2) {
+ System.out.println("-----------> 2 args : " + arg1 + " " + arg2);
+ return new JSONObject();
+ }
+}
+
diff --git a/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/InovalleeActivator.java b/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/InovalleeActivator.java
index 3ea4b6ab..d7d1d72f 100644
--- a/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/InovalleeActivator.java
+++ b/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/InovalleeActivator.java
@@ -15,6 +15,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.sensinact.gateway.generic.ExtModelConfigurationBuilder;
import org.eclipse.sensinact.gateway.generic.GenericActivator;
import org.eclipse.sensinact.gateway.generic.model.Resource;
import org.eclipse.sensinact.gateway.generic.model.Tree;
@@ -49,6 +50,11 @@ public class InovalleeActivator extends GenericActivator {
}
@Override
+ protected ExtModelConfigurationBuilder configureBuilder(ExtModelConfigurationBuilder builder) {
+ return builder.withResourceImplementationType(InoResourceImpl.class);
+ }
+
+ @Override
public void doStop() {
super.doStop();
LOG.info("Thread killed for " + InovalleeActivator.class.getName());
diff --git a/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/EliorFetcher.java b/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/EliorFetcher.java
index c4f6f740..e0b95353 100644
--- a/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/EliorFetcher.java
+++ b/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/EliorFetcher.java
@@ -32,6 +32,8 @@ public class EliorFetcher extends Fetcher {
private final BasicHttpClient client = new BasicHttpClient();
private final String url = "http://193.48.18.251:8095/restaurants/aggregated";
+ //private final String url = "http://localhost:8095/restaurants/aggregated";
+
public Tree fetch() throws IOException {
diff --git a/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/MobilityFetcher.java b/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/MobilityFetcher.java
index a2593f3a..04186e52 100644
--- a/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/MobilityFetcher.java
+++ b/platform/southbound/inovallee/src/main/java/org/eclipse/sensinact/gateway/sthbnd/inovallee/fetcher/MobilityFetcher.java
@@ -22,7 +22,8 @@ public class MobilityFetcher extends Fetcher {
private final BasicHttpClient client = new BasicHttpClient();
private final String urlStations = "http://193.48.18.251:8095/mobilite/stations";
-
+ //private final String urlStations = "http://localhost:8095/mobilite/stations";
+
public Tree fetch() throws IOException {
Response response = get(client, urlStations);
JSONArray array = new JSONArray(response.getPayload());

Back to the top