vre-modeler/src/org/gcube/vremanagement/vremodeler/impl/ServiceContext.java

93 lines
3.6 KiB
Java
Raw Normal View History

package org.gcube.vremanagement.vremodeler.impl;
import java.util.ArrayList;
import javax.xml.namespace.QName;
import org.gcube.common.core.contexts.GCUBEServiceContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.informationsystem.notifier.ISNotifier;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.security.GCUBESecurityManager;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.vremanagement.vremodeler.consumers.CollectionConsumer;
import org.gcube.vremanagement.vremodeler.consumers.FunctionalityConsumer;
import org.gcube.vremanagement.vremodeler.consumers.GHNConsumer;
import org.gcube.vremanagement.vremodeler.consumers.MCollectionConsumer;
import org.gcube.vremanagement.vremodeler.consumers.RunningInstanceConsumer;
import org.gcube.vremanagement.vremodeler.db.IStoDBUtil;
import org.gcube.vremanagement.vremodeler.resources.handlers.CollectionHandler;
import org.gcube.vremanagement.vremodeler.resources.handlers.FunctionalityHandler;
import org.gcube.vremanagement.vremodeler.resources.handlers.GHNHandler;
public class ServiceContext extends GCUBEServiceContext{
/** Single context instance, created eagerly */
private static ServiceContext cache = new ServiceContext();
/** Returns cached instance */
public static ServiceContext getContext() {return cache;}
/** Prevents accidental creation of more instances */
private ServiceContext(){};
/** {@inheritDoc} */
protected String getJNDIName() {return "gcube/vremanagement/vremodeler";}
protected void onReady() throws Exception{
try{
logger.info("ready event invoked on " + this.getName());
this.intializeDB();
}catch (Exception e){
this.setStatus(Status.FAILED);
throw e;
}
}
protected void intializeDB() throws Exception{
ISNotifier notifier= GHNContext.getImplementation(ISNotifier.class);
for (GCUBEScope scope : ServiceContext.getContext().getStartScopes()){
if (scope.isInfrastructure()) continue;
ServiceContext.getContext().setScope(scope);
GCUBESecurityManager secMan= new GCUBESecurityManagerImpl(){
@Override
public boolean isSecurityEnabled() {
// TODO Auto-generated method stub
return false;
}};
IStoDBUtil.initDB(scope);
new GHNHandler().initialize();
new CollectionHandler().initialize();
FunctionalityHandler functionalityHandler= new FunctionalityHandler();
functionalityHandler.initialize();
logger.debug("Service initialized!!");
//GHNNotification
ArrayList<QName> qnameList= new ArrayList<QName>();
qnameList.add(GHNConsumer.ghnQName);
notifier.registerToISNotification(qnameList, new GHNConsumer(scope), secMan, scope);
//RINotification
qnameList= new ArrayList<QName>();
qnameList.add(RunningInstanceConsumer.riQName);
notifier.registerToISNotification(qnameList, new RunningInstanceConsumer(scope), secMan, scope);
//CollectionNotification
qnameList= new ArrayList<QName>();
qnameList.add(CollectionConsumer.collectionQName);
notifier.registerToISNotification(qnameList, new CollectionConsumer(scope), secMan, scope);
//MCollectionNotification
qnameList= new ArrayList<QName>();
qnameList.add(MCollectionConsumer.mCollectionQName);
notifier.registerToISNotification(qnameList, new MCollectionConsumer(scope), secMan, scope);
//FunctionalityResource
qnameList= new ArrayList<QName>();
qnameList.add(FunctionalityConsumer.functionalityQName);
notifier.registerToISNotification(qnameList, new FunctionalityConsumer(scope,functionalityHandler.getFunctionalityResourceId()), secMan, scope);
logger.debug("consumers registered");
}
}
}