Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Atmos leak fix #1663

Merged
merged 4 commits into from
Nov 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
*/
package org.openhab.io.rest.internal.filter;

import java.util.concurrent.ConcurrentMap;

import javax.servlet.http.HttpServletRequest;

import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceFactory;
import org.atmosphere.cpr.BroadcastFilter.BroadcastAction.ACTION;
import org.atmosphere.cpr.PerRequestBroadcastFilter;
import org.codehaus.jackson.map.ObjectMapper;
Expand Down Expand Up @@ -65,13 +67,27 @@ private boolean isDoubleBroadcast(HttpServletRequest request, Object responseEnt
}
ObjectMapper mapper = new ObjectMapper();
try{
/*
* This map object will start to collect dead uuid entries over time, but its
* difficult to know when this uuid's are really not valid anymore. this
* checks for dead entries before adding any new ones.
*/
ConcurrentMap<String, Object> resources = ResourceStateChangeListener.getMap();
for(String uuid : resources.keySet()){
AtmosphereResource resource = AtmosphereResourceFactory.getDefault().find(uuid);
if(resource == null){
logger.trace("removing {} from duplicate cache", uuid);
resources.remove(uuid);
}
}
String firedResponse = mapper.writeValueAsString(ResourceStateChangeListener.getMap().put(clientId, responseEntity));
String responseValue = mapper.writeValueAsString(responseEntity);
if(responseValue.equals(firedResponse)) {
logger.trace("Duplicate message for uuid {}", clientId);
return true;
}
} catch (Exception e) {
logger.error(e.getMessage());
logger.error("Could not check if double broadcast",e);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public void run() {
try {
Thread.sleep(300);
GeneralBroadcaster delayedBroadcaster = (GeneralBroadcaster) BroadcasterFactory.getDefault().lookup(GeneralBroadcaster.class, delayedBroadcasterName);
delayedBroadcaster.broadcast(message, resource);

if(delayedBroadcaster != null)
delayedBroadcaster.broadcast(message, resource);
} catch (Exception e) {
logger.error(e.getMessage());
logger.error("Could not broadcast message",e);
}
}
});
Expand Down