2008-04-22 14:11:53 +02:00
|
|
|
package org.gcube.vremanagement.vremodeler.impl;
|
|
|
|
|
2009-07-06 19:36:03 +02:00
|
|
|
|
2009-09-30 11:29:45 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
2008-04-22 14:11:53 +02:00
|
|
|
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
2009-09-30 11:29:45 +02:00
|
|
|
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;
|
2008-10-21 19:09:24 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.db.IStoDBUtil;
|
2009-09-30 11:29:45 +02:00
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.CollectionHandler;
|
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.FunctionalityHandler;
|
|
|
|
import org.gcube.vremanagement.vremodeler.resources.handlers.GHNHandler;
|
2008-04-22 14:11:53 +02:00
|
|
|
|
|
|
|
public class ServiceContext extends GCUBEServiceContext{
|
|
|
|
|
2008-04-22 15:04:13 +02:00
|
|
|
/** 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} */
|
2008-10-30 19:54:34 +01:00
|
|
|
protected String getJNDIName() {return "gcube/vremanagement/vremodeler";}
|
2008-04-22 15:04:13 +02:00
|
|
|
|
|
|
|
protected void onReady() throws Exception{
|
2009-04-01 01:05:14 +02:00
|
|
|
try{
|
2009-02-10 19:54:48 +01:00
|
|
|
logger.info("ready event invoked on " + this.getName());
|
2009-02-13 20:04:00 +01:00
|
|
|
this.intializeDB();
|
2009-02-10 19:54:48 +01:00
|
|
|
}catch (Exception e){
|
2009-05-08 19:58:31 +02:00
|
|
|
this.setStatus(Status.FAILED);
|
2009-02-10 19:54:48 +01:00
|
|
|
throw e;
|
|
|
|
}
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|
|
|
|
|
2009-02-13 20:04:00 +01:00
|
|
|
protected void intializeDB() throws Exception{
|
2009-09-30 11:29:45 +02:00
|
|
|
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");
|
|
|
|
}
|
2009-02-13 20:04:00 +01:00
|
|
|
}
|
2008-04-22 14:11:53 +02:00
|
|
|
}
|