diff --git a/.classpath b/.classpath
index 502bd4a..32f3561 100644
--- a/.classpath
+++ b/.classpath
@@ -16,10 +16,9 @@
-
-
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index db24ee7..da3b103 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -12,4 +12,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.compiler.source=11
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ae81762..c6aeae9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [v2.1.1-SNAPSHOT] - [2022-12-06]
+
+solved a bug on removeContext
+
## [v2.1.0] - [2022-02-04]
added OfflineObserver for test purpose
diff --git a/pom.xml b/pom.xml
index c510f21..1a9c6a6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,5 @@
-
4.0.0
@@ -10,12 +11,14 @@
org.gcube.core
common-smartgears-app
- 2.1.0
+ 2.1.1-SNAPSHOT
Smartgears Application
-
+
distro
+ 1.8
+ 1.8
@@ -56,7 +59,7 @@
org.gcube.core
common-smartgears
- [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)
+ [3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)
provided
@@ -77,7 +80,6 @@
org.apache.maven.plugins
maven-resources-plugin
- 2.5
copy-profile
diff --git a/src/main/java/org/gcube/smartgears/ManagerPair.java b/src/main/java/org/gcube/smartgears/ManagerPair.java
new file mode 100644
index 0000000..2fd896a
--- /dev/null
+++ b/src/main/java/org/gcube/smartgears/ManagerPair.java
@@ -0,0 +1,26 @@
+package org.gcube.smartgears;
+
+import java.util.concurrent.Future;
+
+public class ManagerPair {
+
+ private Class extends ApplicationManager> clazz;
+
+ private Future future;
+
+ public ManagerPair(Class extends ApplicationManager> clazz, Future future) {
+ super();
+ this.clazz = clazz;
+ this.future = future;
+ }
+
+ public Class extends ApplicationManager> getImplementationClass() {
+ return clazz;
+ }
+
+ public Future getFuture() {
+ return future;
+ }
+
+
+}
diff --git a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java
index 7463379..fd66ecf 100644
--- a/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java
+++ b/src/main/java/org/gcube/smartgears/application/manager/OnlineObserver.java
@@ -20,6 +20,7 @@ import org.gcube.common.events.Observes.Kind;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.smartgears.ApplicationManager;
import org.gcube.smartgears.Constants;
+import org.gcube.smartgears.ManagerPair;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,28 +31,28 @@ public class OnlineObserver implements AppManagerObserver{
private static ExecutorService service = Executors.newCachedThreadPool();
- private Map>> instanciatedManagerPerScope = new HashMap>>();
+ private Map> instanciatedManagerPerScope = new HashMap>();
private OnlineProvider provider;
-
+
private Collection startingTokens;
-
+
private Set> managersClasses;
-
+
public OnlineObserver(OnlineProvider provider) {
this.provider = provider;
-
+
}
public void register() {
for (String startingToken : startingTokens )
this.onRegistration(startingToken);
}
-
+
@Observes(value=Constants.token_registered, kind=Kind.safe)
public synchronized void onRegistration(final String securityToken){
log.info("token registered called with token {}", securityToken);
- List> futureList = new ArrayList>();
+ List futureList = new ArrayList();
try {
final String context = authorizationService().get(securityToken).getContext();
@@ -60,7 +61,7 @@ public class OnlineObserver implements AppManagerObserver{
Future appManagerFuture = service.submit(new InitAppManager(securityToken, context, appManager));
log.info("intializing app in context {} with token {} ",context, securityToken);
- futureList.add(appManagerFuture);
+ futureList.add(new ManagerPair(appManager, appManagerFuture));
if (provider.getAppmanagerMap().containsKey(appManager.getCanonicalName()))
provider.getAppmanagerMap().get(appManager.getCanonicalName()).put(context, appManagerFuture);
else {
@@ -86,12 +87,14 @@ public class OnlineObserver implements AppManagerObserver{
try {
final String context = authorizationService().get(securityToken).getContext();
- for (Future appManager: instanciatedManagerPerScope.get(context)){
- service.execute(new ShutDownAppManager(securityToken, context, appManager));
- provider.getAppmanagerMap().get(appManager).remove(context);
- }
+ if(instanciatedManagerPerScope.get(context) != null ) {
+ for (ManagerPair manager: instanciatedManagerPerScope.get(context)){
+ service.execute(new ShutDownAppManager(securityToken, context, manager.getFuture()));
+ provider.getAppmanagerMap().get(manager.getImplementationClass().getCanonicalName()).remove(context);
+ }
+ instanciatedManagerPerScope.remove(context);
+ }
- instanciatedManagerPerScope.remove(context);
SecurityTokenProvider.instance.reset();
} catch (ObjectNotFound e1) {
log.error("it should never happen (token has just been created)",e1);
@@ -107,24 +110,26 @@ public class OnlineObserver implements AppManagerObserver{
for (String token :appContext.configuration().startTokens()){
try {
String context = authorizationService().get(token).getContext();
- for (Future appManagerEntry: instanciatedManagerPerScope.get(context)){
- try{
- log.info("stoppping {} in context {} ",appContext.name(), context);
+ if(instanciatedManagerPerScope.get(context) != null ) {
+ for (ManagerPair manager: instanciatedManagerPerScope.get(context)){
+ try{
+ log.info("stoppping {} in context {} ",appContext.name(), context);
- SecurityTokenProvider.instance.set(token);
- ScopeProvider.instance.set(context);
- try {
- appManagerEntry.get().onShutdown();
- log.info("manager {} correctly suhtdown on context {}",appContext.name(), context);
- } catch (Exception e){
- log.warn("problem calling onShutdown for context {}", context, e);
+ SecurityTokenProvider.instance.set(token);
+ ScopeProvider.instance.set(context);
+ try {
+ manager.getFuture().get().onShutdown();
+ log.info("manager {} correctly suhtdown on context {}",appContext.name(), context);
+ } catch (Exception e){
+ log.warn("problem calling onShutdown for context {}", context, e);
+ }
+ }catch(Exception e){
+ log.error("error retrieving token on shutdown on context {}", context,e);
+ throw new RuntimeException("error retrieving token on shutdown",e);
+ }finally{
+ ScopeProvider.instance.reset();
+ SecurityTokenProvider.instance.reset();
}
- }catch(Exception e){
- log.error("error retrieving token on shutdown on context {}", context,e);
- throw new RuntimeException("error retrieving token on shutdown",e);
- }finally{
- ScopeProvider.instance.reset();
- SecurityTokenProvider.instance.reset();
}
}
} catch (ObjectNotFound e1) {
@@ -201,7 +206,7 @@ public class OnlineObserver implements AppManagerObserver{
@Override
public void setStartingTokens(Collection startingTokens) {
this.startingTokens = startingTokens;
-
+
}
@Override
@@ -209,5 +214,5 @@ public class OnlineObserver implements AppManagerObserver{
this.managersClasses = managersClasses;
}
-
+
}