Cleans the internal data and prepares this object to be collected
()
| 255 | * Cleans the internal data and prepares this object to be collected |
| 256 | */ |
| 257 | @Override |
| 258 | public void cleanup() { |
| 259 | //stop listening to Creole events. |
| 260 | Gate.getCreoleRegister().removeCreoleListener(this); |
| 261 | // close all PRs in this controller, if not members of other apps. |
| 262 | if(prList != null && !prList.isEmpty()) { |
| 263 | try { |
| 264 | //get all the other controllers |
| 265 | List<Resource> allOtherControllers = |
| 266 | Gate.getCreoleRegister().getAllInstances("gate.Controller"); |
| 267 | allOtherControllers.remove(this); |
| 268 | //get all the PRs in all the other controllers |
| 269 | List<Resource> prsInOtherControllers = new ArrayList<Resource>(); |
| 270 | for(Resource aController : allOtherControllers){ |
| 271 | prsInOtherControllers.addAll(((Controller)aController).getPRs()); |
| 272 | } |
| 273 | //remove all PRs in this controller, that are not also in other |
| 274 | //controllers |
| 275 | // for(Iterator prIter = getPRs().iterator(); prIter.hasNext();){ |
| 276 | // ProcessingResource aPr = (ProcessingResource)prIter.next(); |
| 277 | // if(!prsInOtherControllers.contains(aPr)){ |
| 278 | // prIter.remove(); |
| 279 | // Factory.deleteResource((Resource)aPr); |
| 280 | // } |
| 281 | // } |
| 282 | for(Resource aPr : new ArrayList<Resource>(getPRs())){ |
| 283 | if(!prsInOtherControllers.contains(aPr)){ |
| 284 | Factory.deleteResource(aPr); |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | catch(GateException e) { |
| 289 | //ignore |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Duplicate this controller. We perform a default duplication of |
nothing calls this directly
no test coverage detected