Fixed handlers

This commit is contained in:
Luca Frosini 2020-10-26 14:25:54 +01:00
parent 8e35e18b58
commit 625ed37d88
2 changed files with 25 additions and 5 deletions

View File

@ -111,8 +111,7 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
applicationContext.events().subscribe(new Object() {
// @Observes({ activation, stop, failure })
@Observes({ activation })
@Observes({ activation, stop, failure })
void onChanged(ApplicationLifecycle lc) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
String previousToken = SecurityTokenProvider.instance.get();
@ -129,9 +128,9 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
ContextUtility.setContextFromToken(previousToken);
Thread.currentThread().setContextClassLoader(contextCL);
}
}
/*
@Observes({ stop, failure })
void onStop(ApplicationLifecycle lc) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
@ -151,7 +150,8 @@ public class EServiceHandler extends ApplicationLifecycleHandler {
}
}
*/
@Observes(value = addToContext)
void addTo(String token) {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();

View File

@ -181,6 +181,16 @@ public class EServiceManager {
try {
resourceRegistryClient.exists(EService.class, eServiceUUID);
eService = resourceRegistryClient.getInstance(EService.class, eServiceUUID);
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0);
if(serviceStateFacet==null) {
serviceStateFacet = new ServiceStateFacetImpl();
String state = getState();
serviceStateFacet.setValue(state);
eService.addFacet(serviceStateFacet);
resourceRegistryPublisher.update(eService);
}else{
updateServiceStateFacet();
}
} catch (NotFoundException e) {
eService = instantiateEService();
createActivatesRelation(eService);
@ -196,6 +206,16 @@ public class EServiceManager {
// already be in the context due to propagation constraint.
createActivatesRelation(eService);
}
serviceStateFacet = eService.getFacets(ServiceStateFacet.class).get(0);
if(serviceStateFacet==null) {
serviceStateFacet = new ServiceStateFacetImpl();
String state = getState();
serviceStateFacet.setValue(state);
eService.addFacet(serviceStateFacet);
resourceRegistryPublisher.update(eService);
}else{
updateServiceStateFacet();
}
} catch (ResourceRegistryException e) {
throw e;
}