solved bug on remove context
This commit is contained in:
parent
c20234af24
commit
c80f8896a1
|
@ -5,11 +5,7 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
|
|
3
pom.xml
3
pom.xml
|
@ -17,6 +17,8 @@
|
|||
|
||||
<properties>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
|
@ -49,7 +51,6 @@
|
|||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.10</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@ import org.gcube.common.security.providers.SecretManagerProvider;
|
|||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.smartgears.ApplicationManager;
|
||||
import org.gcube.smartgears.Constants;
|
||||
import org.gcube.smartgears.ManagerPair;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -27,7 +28,7 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
|
||||
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;
|
||||
|
||||
|
@ -49,7 +50,7 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
@Observes(value=Constants.token_registered, kind=Kind.safe)
|
||||
public synchronized void onRegistration(String context){
|
||||
log.info("registration called in context {}", context);
|
||||
List<Future<ApplicationManager>> futureList = new ArrayList<Future<ApplicationManager>>();
|
||||
List<ManagerPair> futureList = new ArrayList<ManagerPair>();
|
||||
|
||||
try {
|
||||
|
||||
|
@ -61,7 +62,7 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
Future<ApplicationManager> appManagerFuture = service.submit(new InitAppManager(secret, appManager));
|
||||
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()))
|
||||
provider.getAppmanagerMap().get(appManager.getCanonicalName()).put(context, appManagerFuture);
|
||||
else {
|
||||
|
@ -85,10 +86,14 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
|
||||
Secret secret = authProvider.getSecretForContext(context);
|
||||
|
||||
for (Future<ApplicationManager> appManager: instanciatedManagerPerScope.get(context)){
|
||||
service.execute(new ShutDownAppManager(secret, appManager));
|
||||
provider.getAppmanagerMap().get(appManager.getClass().getCanonicalName()).remove(context);
|
||||
}
|
||||
if(instanciatedManagerPerScope.get(context) != null ) {
|
||||
for (ManagerPair manager: instanciatedManagerPerScope.get(context)){
|
||||
service.execute(new ShutDownAppManager(secret, manager.getFuture()));
|
||||
provider.getAppmanagerMap().get(manager.getImplementationClass().getCanonicalName()).remove(context);
|
||||
}
|
||||
instanciatedManagerPerScope.remove(context);
|
||||
}
|
||||
|
||||
instanciatedManagerPerScope.remove(context);
|
||||
} catch (Exception e1) {
|
||||
log.error("something failed getting token",e1);
|
||||
|
|
Loading…
Reference in New Issue