solved bug on remove context

This commit is contained in:
Lucio Lelii 2022-12-06 14:50:36 +01:00
parent c20234af24
commit c80f8896a1
4 changed files with 41 additions and 13 deletions

View File

@ -5,11 +5,7 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java"> <classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>

View File

@ -17,6 +17,8 @@
<properties> <properties>
<distroDirectory>distro</distroDirectory> <distroDirectory>distro</distroDirectory>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties> </properties>
<scm> <scm>
@ -49,7 +51,6 @@
<dependency> <dependency>
<groupId>org.reflections</groupId> <groupId>org.reflections</groupId>
<artifactId>reflections</artifactId> <artifactId>reflections</artifactId>
<version>0.9.10</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.javassist/javassist --> <!-- https://mvnrepository.com/artifact/org.javassist/javassist -->

View File

@ -0,0 +1,26 @@
package org.gcube.smartgears;
import java.util.concurrent.Future;
public class ManagerPair {
private Class<? extends ApplicationManager> clazz;
private Future<ApplicationManager> future;
public ManagerPair(Class<? extends ApplicationManager> clazz, Future<ApplicationManager> future) {
super();
this.clazz = clazz;
this.future = future;
}
public Class<? extends ApplicationManager> getImplementationClass() {
return clazz;
}
public Future<ApplicationManager> getFuture() {
return future;
}
}

View File

@ -16,6 +16,7 @@ import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.Secret; import org.gcube.common.security.secrets.Secret;
import org.gcube.smartgears.ApplicationManager; import org.gcube.smartgears.ApplicationManager;
import org.gcube.smartgears.Constants; import org.gcube.smartgears.Constants;
import org.gcube.smartgears.ManagerPair;
import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.security.AuthorizationProvider; import org.gcube.smartgears.security.AuthorizationProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -27,7 +28,7 @@ public class OnlineObserver implements AppManagerObserver{
private static ExecutorService service = Executors.newCachedThreadPool(); private static ExecutorService service = Executors.newCachedThreadPool();
private Map<String, List<Future<ApplicationManager>>> instanciatedManagerPerScope = new HashMap<String, List<Future<ApplicationManager>>>(); private Map<String, List<ManagerPair>> instanciatedManagerPerScope = new HashMap<String, List<ManagerPair>>();
private OnlineProvider provider; private OnlineProvider provider;
@ -49,7 +50,7 @@ public class OnlineObserver implements AppManagerObserver{
@Observes(value=Constants.token_registered, kind=Kind.safe) @Observes(value=Constants.token_registered, kind=Kind.safe)
public synchronized void onRegistration(String context){ public synchronized void onRegistration(String context){
log.info("registration called in context {}", context); log.info("registration called in context {}", context);
List<Future<ApplicationManager>> futureList = new ArrayList<Future<ApplicationManager>>(); List<ManagerPair> futureList = new ArrayList<ManagerPair>();
try { try {
@ -61,7 +62,7 @@ public class OnlineObserver implements AppManagerObserver{
Future<ApplicationManager> appManagerFuture = service.submit(new InitAppManager(secret, appManager)); Future<ApplicationManager> appManagerFuture = service.submit(new InitAppManager(secret, appManager));
log.info("intializing app using manager {} in context {}",appManager.getClass().getCanonicalName(),context); log.info("intializing app using manager {} in context {}",appManager.getClass().getCanonicalName(),context);
futureList.add(appManagerFuture); futureList.add(new ManagerPair(appManager, appManagerFuture));
if (provider.getAppmanagerMap().containsKey(appManager.getCanonicalName())) if (provider.getAppmanagerMap().containsKey(appManager.getCanonicalName()))
provider.getAppmanagerMap().get(appManager.getCanonicalName()).put(context, appManagerFuture); provider.getAppmanagerMap().get(appManager.getCanonicalName()).put(context, appManagerFuture);
else { else {
@ -85,10 +86,14 @@ public class OnlineObserver implements AppManagerObserver{
Secret secret = authProvider.getSecretForContext(context); Secret secret = authProvider.getSecretForContext(context);
for (Future<ApplicationManager> appManager: instanciatedManagerPerScope.get(context)){ if(instanciatedManagerPerScope.get(context) != null ) {
service.execute(new ShutDownAppManager(secret, appManager)); for (ManagerPair manager: instanciatedManagerPerScope.get(context)){
provider.getAppmanagerMap().get(appManager.getClass().getCanonicalName()).remove(context); service.execute(new ShutDownAppManager(secret, manager.getFuture()));
} provider.getAppmanagerMap().get(manager.getImplementationClass().getCanonicalName()).remove(context);
}
instanciatedManagerPerScope.remove(context);
}
instanciatedManagerPerScope.remove(context); instanciatedManagerPerScope.remove(context);
} catch (Exception e1) { } catch (Exception e1) {
log.error("something failed getting token",e1); log.error("something failed getting token",e1);