// loop through all of the features, and give each one
// a chance to create the 'KieSession'
- for (PolicySessionFeatureAPI feature : PolicySessionFeatureAPI.impl.getList())
+ for (PolicySessionFeatureAPI feature :
+ PolicySessionFeatureAPI.impl.getList())
{
- if ((kieSession = feature.activatePolicySession
- (this, name, kieBaseName)) != null)
- break;
+ try
+ {
+ if ((kieSession = feature.activatePolicySession
+ (this, name, kieBaseName)) != null)
+ break;
+ }
+ catch (Exception e)
+ {
+ logger.error("ERROR: Feature API: "
+ + feature.getClass().getName(), e);
+ }
}
// if none of the features created the session, create one now
// a PolicySession
session = new PolicySession(name, this, kieSession);
sessions.put(name, session);
+
+ // notify features
+ for (PolicySessionFeatureAPI feature :
+ PolicySessionFeatureAPI.impl.getList())
+ {
+ try
+ {
+ feature.newPolicySession(session);
+ }
+ catch (Exception e)
+ {
+ logger.error("ERROR: Feature API: "
+ + feature.getClass().getName(), e);
+ }
+ }
logger.info("activatePolicySession:new session was added in sessions with name " + name);
}
}
PolicySession policySession =
new PolicySession(name, this, kieSession);
sessions.put(name, policySession);
+
+ // notify features
+ for (PolicySessionFeatureAPI feature :
+ PolicySessionFeatureAPI.impl.getList())
+ {
+ try
+ {
+ feature.newPolicySession(policySession);
+ }
+ catch (Exception e)
+ {
+ logger.error("ERROR: Feature API: "
+ + feature.getClass().getName(), e);
+ }
+ }
return(policySession);
}
}
session.getKieSession().dispose();
// notify features
- for (PolicySessionFeatureAPI feature : PolicySessionFeatureAPI.impl.getList())
+ for (PolicySessionFeatureAPI feature :
+ PolicySessionFeatureAPI.impl.getList())
{
- feature.disposeKieSession(session);
+ try
+ {
+ feature.disposeKieSession(session);
+ }
+ catch (Exception e)
+ {
+ logger.error("ERROR: Feature API: "
+ + feature.getClass().getName(), e);
+ }
}
}
isStarted = false;
session.getKieSession().destroy();
// notify features
- for (PolicySessionFeatureAPI feature : PolicySessionFeatureAPI.impl.getList())
+ for (PolicySessionFeatureAPI feature :
+ PolicySessionFeatureAPI.impl.getList())
{
- feature.destroyKieSession(session);
+ try
+ {
+ feature.destroyKieSession(session);
+ }
+ catch (Exception e)
+ {
+ logger.error("ERROR: Feature API: "
+ + feature.getClass().getName(), e);
+ }
}
}
isStarted = false;
logger.info("initlogger returned");
// invoke 'globalInit' on all of the features
- for (PolicySessionFeatureAPI feature : PolicySessionFeatureAPI.impl.getList())
+ for (PolicySessionFeatureAPI feature :
+ PolicySessionFeatureAPI.impl.getList())
{
- feature.globalInit(args, configDir);
+ try
+ {
+ feature.globalInit(args, configDir);
+ }
+ catch (Exception e)
+ {
+ logger.error("ERROR: Feature API: "
+ + feature.getClass().getName(), e);
+ }
}
}
package org.openecomp.policy.drools.core;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.kie.api.event.rule.AfterMatchFiredEvent;
import org.kie.api.event.rule.AgendaEventListener;
import org.kie.api.event.rule.AgendaGroupPoppedEvent;
// 'PolicySession' instances in addition to this one
private PolicyContainer container;
+ // maps feature objects to per-PolicyContainer data
+ private ConcurrentHashMap<Object, Object> adjuncts =
+ new ConcurrentHashMap<Object, Object>();
+
// associated 'KieSession' instance
private KieSession kieSession;
{
return(policySession.get());
}
+
+ /**
+ * Fetch the adjunct object associated with a given feature
+ *
+ * @param object this is typically the singleton feature object that is
+ * used as a key, but it might also be useful to use nested objects
+ * within the feature as keys.
+ * @return a feature-specific object associated with the key, or 'null'
+ * if it is not found.
+ */
+ public Object getAdjunct(Object object)
+ {
+ return(adjuncts.get(object));
+ }
+
+ /**
+ * Store the adjunct object associated with a given feature
+ *
+ * @param object this is typically the singleton feature object that is
+ * used as a key, but it might also be useful to use nested objects
+ * within the feature as keys.
+ * @param value a feature-specific object associated with the key, or 'null'
+ * if the feature-specific object should be removed
+ */
+ public void setAdjunct(Object object, Object value)
+ {
+ if (value == null)
+ {
+ adjuncts.remove(object);
+ }
+ else
+ {
+ adjuncts.put(object, value);
+ }
+ }
/***********************************/
/* 'AgendaEventListener' interface */
* @param args standard 'main' arguments, which are currently ignored
* @param configDir the relative directory containing configuration files
*/
- public void globalInit(String args[], String configDir);
+ default public void globalInit(String args[], String configDir) {}
/**
* This method is used to create a 'KieSession' as part of a
* (this depends on the capabilities and state of the object implementing
* this interface)
*/
- public KieSession activatePolicySession
- (PolicyContainer policyContainer, String name, String kieBaseName);
+ default public KieSession activatePolicySession
+ (PolicyContainer policyContainer, String name, String kieBaseName)
+ {
+ return(null);
+ }
/**
- * This method is called after 'KieSession.dispose()' is called
+ * This method is called after a new 'PolicySession' has been initialized,
+ * and linked to the 'PolicyContainer'.
*
- * @param policySession the 'PolicySession' object that wrapped the
- * 'KieSession'
+ * @param policySession the new 'PolicySession' instance
*/
- public void disposeKieSession(PolicySession policySession);
+ default public void newPolicySession(PolicySession policySession) {}
/**
- * This method is called after 'KieSession.destroy()' is called
+ * This method is called after 'KieSession.dispose()' is called
*
* @param policySession the 'PolicySession' object that wrapped the
* 'KieSession'
*/
- public void destroyKieSession(PolicySession policySession);
+ default public void disposeKieSession(PolicySession policySession) {}
/**
- * NOTE: this method is probably temporary
+ * This method is called after 'KieSession.destroy()' is called
*
- * @return 'true' if persistence is enabled, and 'false' if not, or if
- * this feature is not related to persistence.
+ * @param policySession the 'PolicySession' object that wrapped the
+ * 'KieSession'
*/
- public boolean isPersistenceEnabled();
+ default public void destroyKieSession(PolicySession policySession) {}
}
getContainerAdjunct(policySession.getPolicyContainer())
.destroyKieSession();
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isPersistenceEnabled()
- {
- return(!persistenceDisabled);
- }
/**
* {@inheritDoc}