// set of all 'PolicyContainer' instances
static private HashSet<PolicyContainer> containers =
- new HashSet<PolicyContainer>();
+ new HashSet<>();
// maps feature objects to per-PolicyContainer data
private ConcurrentHashMap<Object, Object> adjuncts =
- new ConcurrentHashMap<Object, Object>();
+ new ConcurrentHashMap<>();
// 'KieContainer' associated with this 'PolicyContainer'
private KieContainer kieContainer;
// maps session name into the associated 'PolicySession' instance
private HashMap<String, PolicySession> sessions =
- new HashMap<String, PolicySession>();
+ new HashMap<>();
// if not null, this is a 'KieScanner' looking for updates
private KieScanner scanner = null;
*/
public PolicyContainer(ReleaseId releaseId)
{
- if (releaseId.getVersion().contains(","))
+ ReleaseId newReleaseId = releaseId;
+ if (newReleaseId.getVersion().contains(","))
{
// this is actually a comma-separated list of release ids
- releaseId = loadArtifact(releaseId.getGroupId(),
- releaseId.getArtifactId(),
- releaseId.getVersion());
+ newReleaseId = loadArtifact(newReleaseId.getGroupId(),
+ newReleaseId.getArtifactId(),
+ newReleaseId.getVersion());
}
else
{
- kieContainer = kieServices.newKieContainer(releaseId);
+ kieContainer = kieServices.newKieContainer(newReleaseId);
}
synchronized(containers)
{
- if(releaseId != null){
- logger.info("Add a new kieContainer in containers: releaseId: " + releaseId.toString());
+ if(newReleaseId != null){
+ logger.info("Add a new kieContainer in containers: releaseId: " + newReleaseId.toString());
}else{
logger.warn("input releaseId is null");
}
{
// all of the 'newKieContainer' invocations failed -- throw the
// most recent exception
- throw(exception);
+ throw exception;
}
- return(releaseId);
+ return releaseId;
}
/**
*/
public String getName()
{
- return(kieContainer.getReleaseId().toString());
+ return kieContainer.getReleaseId().toString();
}
/**
*/
public KieContainer getKieContainer()
{
- return(kieContainer);
+ return kieContainer;
}
/**
*/
public ClassLoader getClassLoader()
{
- return(kieContainer.getClassLoader());
+ return kieContainer.getClassLoader();
}
/**
*/
public String getGroupId()
{
- return(kieContainer.getReleaseId().getGroupId());
+ return kieContainer.getReleaseId().getGroupId();
}
/**
*/
public String getArtifactId()
{
- return(kieContainer.getReleaseId().getArtifactId());
+ return kieContainer.getReleaseId().getArtifactId();
}
/**
*/
public String getVersion()
{
- return(kieContainer.getReleaseId().getVersion());
+ return kieContainer.getReleaseId().getVersion();
}
/**
*/
public PolicySession getPolicySession(String name)
{
- return(sessions.get(name));
+ return sessions.get(name);
}
/**
logger.info("activatePolicySession:session - "
+ (session == null ? "null" : session.getFullName())
+ " is returned.");
- return(session);
+ return session;
}
}
if(name == null){
logger.warn("adoptKieSession:input name is null");
- throw(new IllegalArgumentException
+ throw new IllegalArgumentException
("KieSession input name is null "
- + getName()));
+ + getName());
}else if(kieSession == null){
logger.warn("adoptKieSession:input kieSession is null");
- throw(new IllegalArgumentException
+ throw new IllegalArgumentException
("KieSession '" + name + "' is null "
- + getName()));
+ + getName());
}else {
logger.info("adoptKieSession:name: " + name + " kieSession: " + kieSession);
}
// default KieBase, if it exists
if (!match && kieBase != kieContainer.getKieBase())
{
- throw(new IllegalArgumentException
+ throw new IllegalArgumentException
("KieSession '" + name + "' does not reside within container "
- + getName()));
+ + getName());
}
synchronized (sessions)
{
if (sessions.get(name) != null)
{
- throw(new IllegalStateException
- ("PolicySession '" + name + "' already exists"));
+ throw new IllegalStateException
+ ("PolicySession '" + name + "' already exists");
}
// create the new 'PolicySession', add it to the table,
+ feature.getClass().getName(), e);
}
}
- return(policySession);
+ return policySession;
}
}
releaseId.getArtifactId(),
newVersion));
- List<Message> messages = (results == null ? null : results.getMessages());
- return(messages == null ? null : messages.toString());
+ List<Message> messages = results == null ? null : results.getMessages();
+ return messages == null ? null : messages.toString();
}
/**
session.updated();
}
- return(results);
+ return results;
}
/**
{
synchronized(containers)
{
- return(new HashSet<PolicyContainer>(containers));
+ return new HashSet<>(containers);
}
}
// KLUDGE WARNING: this is a temporary workaround -- if there are
// no features, we don't have persistence, and 'activate' is never
// called. In this case, make sure the container is started.
- if (PolicySessionFeatureAPI.impl.getList().size() == 0)
+ if (PolicySessionFeatureAPI.impl.getList().isEmpty())
{
start();
}
// return current set of PolicySessions
synchronized(sessions)
{
- return(new HashSet<PolicySession>(sessions.values()));
+ return new HashSet<>(sessions.values());
}
}
{
String version = releaseId.getVersion();
if (scannerStarted == false && scanner == null && version != null
- && (version.equals("LATEST") || version.equals("RELEASE")
+ && ("LATEST".equals(version) || "RELEASE".equals(version)
|| version.endsWith("-SNAPSHOT")))
{
// create the scanner, and poll at 60 second intervals
// start this in a separate thread -- it can block for a long time
new Thread("Scanner Starter " + getName())
{
+ @Override
public void run()
{
scanner = kieServices.newKieScanner(kieContainer);
if (session != null)
{
session.getKieSession().insert(object);
- return(true);
+ return true;
}
}
- return(false);
+ return false;
}
/**
rval = true;
}
}
- return(rval);
+ return rval;
}
/*************************/
/**
* {@inheritDoc}
*/
+ @Override
public synchronized boolean start()
{
if (!isStarted)
}
isStarted = true;
}
- return(true);
+ return true;
}
/**
* {@inheritDoc}
*/
+ @Override
public synchronized boolean stop()
{
if (isStarted)
synchronized (sessions)
{
// local set containing all of the sessions
- localSessions = new HashSet<PolicySession>(sessions.values());
+ localSessions = new HashSet<>(sessions.values());
// clear the 'name->session' map in 'PolicyContainer'
sessions.clear();
}
isStarted = false;
}
- return(true);
+ return true;
}
/**
* {@inheritDoc}
*/
+ @Override
public synchronized void shutdown()
{
// Note that this method does not call 'destroy' on the 'KieSession'
/**
* {@inheritDoc}
*/
+ @Override
public boolean isAlive()
{
- return(isStarted);
+ return isStarted;
}
/*************************/
synchronized (sessions)
{
// local set containing all of the sessions
- localSessions = new HashSet<PolicySession>(sessions.values());
+ localSessions = new HashSet<>(sessions.values());
// clear the 'name->session' map in 'PolicyContainer'
sessions.clear();
*/
public Object getAdjunct(Object object)
{
- return(adjuncts.get(object));
+ return adjuncts.get(object);
}
/**
// maps feature objects to per-PolicyContainer data
private ConcurrentHashMap<Object, Object> adjuncts =
- new ConcurrentHashMap<Object, Object>();
+ new ConcurrentHashMap<>();
// associated 'KieSession' instance
private KieSession kieSession;
// supports 'getCurrentSession()' method
static private ThreadLocal<PolicySession> policySession =
- new ThreadLocal<PolicySession>();
+ new ThreadLocal<>();
/**
* Internal constructor - create a 'PolicySession' instance
*/
public PolicyContainer getPolicyContainer()
{
- return(container);
+ return container;
}
/**
*/
public KieSession getKieSession()
{
- return(kieSession);
+ return kieSession;
}
/**
*/
public String getName()
{
- return(name);
+ return name;
}
/**
*/
public String getFullName()
{
- return(container.getName() + ":" + name);
+ return container.getName() + ":" + name;
}
/**
*/
public static PolicySession getCurrentSession()
{
- return(policySession.get());
+ return policySession.get();
}
/**
*/
public Object getAdjunct(Object object)
{
- return(adjuncts.get(object));
+ return adjuncts.get(object);
}
/**
// We want to continue looping, despite any exceptions that occur
// while rules are fired.
- KieSession kieSession = session.getKieSession();
+ KieSession kieSession1 = session.getKieSession();
while (repeat)
{
try
{
- kieSession.fireUntilHalt();
+ kieSession1.fireUntilHalt();
- // if we fall through, it means 'KieSession.halt()' was called,
+ // if we fall through, it means 'kieSession1.halt()' was called,
// but this may be a result of 'KieScanner' doing an update
}
catch (Exception | LinkageError e)
{
- logger.error("startThread error in kieSession.fireUntilHalt", e);
+ logger.error("startThread error in kieSession1.fireUntilHalt", e);
}
}
logger.info("fireUntilHalt() returned");