Skip to content
Snippets Groups Projects
Commit ab4f80f9 authored by Ananth Suryanarayana's avatar Ananth Suryanarayana
Browse files

BSC-1846 : Trigger entities cleanup upon address space configuration change

parent ed16111f
No related branches found
No related tags found
No related merge requests found
...@@ -638,7 +638,7 @@ IFlowReconcileListener, IInfoProvider, IHAListener { ...@@ -638,7 +638,7 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
Runnable ecr = new Runnable() { Runnable ecr = new Runnable() {
@Override @Override
public void run() { public void run() {
cleanupEntities(false); cleanupEntities(false, null);
entityCleanupTask.reschedule(ENTITY_CLEANUP_INTERVAL, entityCleanupTask.reschedule(ENTITY_CLEANUP_INTERVAL,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }
...@@ -1281,12 +1281,16 @@ IFlowReconcileListener, IInfoProvider, IHAListener { ...@@ -1281,12 +1281,16 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
* @param reclassify if true, begin an asynchronous task to reclassify the * @param reclassify if true, begin an asynchronous task to reclassify the
* flushed entities * flushed entities
*/ */
private void flushEntityCache (IEntityClass entityClass, private void flushEntityCache (IEntityClass entityClass, boolean reclassify,
boolean reclassify) { Set<String> entityClassChanged) {
if (reclassify) return; // TODO if (reclassify) return; // TODO
if (entityClass == null) { if (entityClass == null) {
cleanupEntities(true);
/*
* XXX This can be running at the same time by timer thread.
*/
cleanupEntities(true, entityClassChanged);
} else { } else {
// TODO // TODO
} }
...@@ -1301,14 +1305,15 @@ IFlowReconcileListener, IInfoProvider, IHAListener { ...@@ -1301,14 +1305,15 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
/* /*
* Flush the entire device entity cache for now. * Flush the entire device entity cache for now.
*/ */
flushEntityCache(null, false); flushEntityCache(null, false, entityClassNames);
return; return;
} }
/** /**
* Clean up expired entities/devices * Clean up expired entities/devices
*/ */
protected void cleanupEntities(boolean forceExpiry) { protected void cleanupEntities(boolean forceCleanup,
Set<String> specificEntities) {
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.add(Calendar.MILLISECOND, -ENTITY_TIMEOUT); c.add(Calendar.MILLISECOND, -ENTITY_TIMEOUT);
Date cutoff = c.getTime(); Date cutoff = c.getTime();
...@@ -1323,14 +1328,23 @@ IFlowReconcileListener, IInfoProvider, IHAListener { ...@@ -1323,14 +1328,23 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
while (diter.hasNext()) { while (diter.hasNext()) {
Device d = diter.next(); Device d = diter.next();
/*
* If we are cleaning entities for a specific set of devices,
* skip if not applicable.
*/
if (specificEntities != null && d.getEntityClass() != null &&
!specificEntities.contains(d.getEntityClass().getName())) {
continue;
}
while (true) { while (true) {
deviceUpdates.clear(); deviceUpdates.clear();
toRemove.clear(); toRemove.clear();
toKeep.clear(); toKeep.clear();
for (Entity e : d.getEntities()) { for (Entity e : d.getEntities()) {
if (forceExpiry || if (forceCleanup ||
(e.getLastSeenTimestamp() != null && (e.getLastSeenTimestamp() != null &&
0 > e.getLastSeenTimestamp().compareTo(cutoff))) { 0 > e.getLastSeenTimestamp().compareTo(cutoff))) {
// individual entity needs to be removed // individual entity needs to be removed
toRemove.add(e); toRemove.add(e);
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment