Created
June 22, 2012 03:50
-
-
Save fumingshih/2970112 to your computer and use it in GitHub Desktop.
Fix FunfManager.unrequestAllData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void unrequestAllData2(DataListener listener){ | |
Map<IJsonObject,List<DataRequestInfo>> changedEntrySet = new HashMap<IJsonObject, List<DataRequestInfo>>(); | |
synchronized (dataRequests) { | |
for (Entry<IJsonObject,List<DataRequestInfo>> entry : dataRequests.entrySet()) { | |
IJsonObject probeConfig = entry.getKey(); | |
List<DataRequestInfo> dataRequestInfos = entry.getValue(); | |
for(int i = 0 ; i < dataRequestInfos.size(); i++){ | |
// go through each entrySet of <IJsonObject, List<DataReqyestInfo>> to look for DataRequest.listener | |
DataRequestInfo removalTarget = dataRequestInfos.get(i); | |
if(removalTarget.listener == listener){ | |
Probe probe = gson.fromJson(probeConfig, Probe.class); | |
Log.i(TAG, "unregistering:" + probeConfig.toString()); | |
Log.i(TAG, "Old dataRequestInfos size for this probe:" + dataRequestInfos.size()); | |
if (probe instanceof ContinuousProbe) { | |
((ContinuousProbe)probe).unregisterListener(listener); | |
} | |
if (probe instanceof PassiveProbe) { | |
((PassiveProbe)probe).unregisterPassiveListener(listener); | |
} | |
// | |
dataRequestInfos.remove(i); | |
changedEntrySet.put(probeConfig, dataRequestInfos); //record those (probeConfig, DataRequestInfo_List) that are changed | |
break;//Should only have one request for this listener and probe | |
} | |
} | |
} | |
for(Entry<IJsonObject,List<DataRequestInfo>> entry : changedEntrySet.entrySet()){ | |
//now overwrite the old dataRequests | |
Log.i(TAG, "rewiring dataRequests with probe key:" + entry.getKey().toString()); | |
Log.i(TAG, "rewiring the dataRequestInfo(List)'s size should be smaller by 1:" + entry.getValue().size()); | |
dataRequests.put(entry.getKey(), entry.getValue()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment