Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
public function disconnectFitting(output:IPipeFitting):IPipeFitting
is there anything to do to remove the other (unused) fittings of pipes which are used by module and shell together before the module is unloaded?
Pipe + Filter + Queue + Pipe
Filter + Queue + Pipe
Queue + Pipe
Pipe
However, I believe that removing the references to both ends of the pipe will suffice for the entire pipeline to be GC'd because there are no outside references to these objects.
var shellOutPipe: TeeSplit = junction.retrievePipe( PipeAwareModuleConstants.SHELL_TO_MODULE_PIPE ) as TeeSplit;shellOutPipe.disconnect();
var moduleOutPipe: Pipe = junction.retrievePipe( PipeAwareModuleConstants.MODULE_TO_SHELL_PIPE ) as Pipe;moduleOutPipe.disconnect();
junction.removePipe( PipeAwareModuleConstants.MODULE_TO_SHELL_PIPE );junction.removePipe( PipeAwareModuleConstants.SHELL_TO_MODULE_PIPE );
override public function onRegister():void { // The SHELL_TO_MODULE_PIPE pipe from the shell to all modules. junction.registerPipe(PipeAwareModuleConstants.SHELL_TO_MODULE_PIPE, Junction.OUTPUT, new TeeSplit()); // The MODULE_TO_SHELL_PIPE pipe to the shell from all modules. junction.registerPipe(PipeAwareModuleConstants.MODULE_TO_SHELL_PIPE, Junction.INPUT, new TeeMerge()); // Add a pipe listener for incoming messages to the shell. junction.addPipeListener(PipeAwareModuleConstants.MODULE_TO_SHELL_PIPE, this, handlePipeMessage); }......override public function handleNotification(note:INotification):void { switch (note.getName()) { case ApplicationFacade.MODULE_ADDED: // Connect module passed in the notification body to shell. // Connect a pipe from module to shell. This pipe is output pipe for module and tee merge for shell. var module:IPipeAwareModule = note.getBody() as IPipeAwareModule; var moduleToShell:Pipe = new Pipe(); module.acceptOutputPipe(PipeAwareModuleConstants.MODULE_TO_SHELL_PIPE, moduleToShell); var shellIn:TeeMerge = junction.retrievePipe(PipeAwareModuleConstants.MODULE_TO_SHELL_PIPE) as TeeMerge; shellIn.connectInput(moduleToShell); // Connect a pipe from shell to module. This pipe is tee split for shell and input pipe for module. var shellToModule:Pipe = new Pipe(); module.acceptInputPipe(PipeAwareModuleConstants.SHELL_TO_MODULE_PIPE, shellToModule); var shellOut:TeeSplit = junction.retrievePipe(PipeAwareModuleConstants.SHELL_TO_MODULE_PIPE) as TeeSplit; shellOut.connect(shellToModule); break; } }......override public function handlePipeMessage(message:IPipeMessage):void { switch (message.getType()) { case PipeAwareModuleConstants.MODULE_DISPOSAL_MESSAGE: // Call the dispose method of the module. // HOW DO I REMOVE PIPES FROM THE SHELL TO THIS MODULE HERE?? var module:IPipeAwareModule = message.getBody() as IPipeAwareModule; module.dispose(); break; } }
module.cacheFitting(moduleToApp,appIn);
public function cacheFitting(localFitting:IPipeFitting,remoteFitting:IPipeFitting):void{cachedFittings.push({local:localFitting,remote:remoteFitting});}
public function cleanup():void{ while(cachedFittings.length > 0) { var localFitting:IPipeFitting = cachedFittings[cachedFittings.length-1].local; var remoteFitting:IPipeFitting = cachedFittings[cachedFittings.length-1].remote; if(remoteFitting is DynamicTeeSplit) (remoteFitting as DynamicTeeSplit).disconnectFitting(localFitting); localFitting.disconnect(); cachedFittings.pop(); }}
module.cacheFitting(appToModule,appOut); // It was ...(moduleToApp,appIn) before
public function disconnectFitting(output:IPipeFitting):IPipeFitting{ for (var i:int=0;i<outputs.length;i++) { if (outputs[i] == output) { // Remove the ith IPipeFitting. outputs.splice(i, 1); } } return output; }
// This is a method in the module's junction mediator.override public function onRemove():void { // Remove both pipes (shell -> module && module -> shell ) junction.removePipe(PipeAwareModuleConstants.MODULE_TO_SHELL_PIPE); junction.removePipe(PipeAwareModuleConstants.SHELL_TO_MODULE_PIPE); }
while (Facade.hasCore(CORE_NAME) != null) { // infinite loop}// Now remove childapp.removeChild(...);
override public function onRemove():void {// Remove both pipes (shell -> module && module -> shell )junction.sendMessage(PipeAwareModuleConstants.MODULE_TO_SHELL_PIPE, new Message(PipeAwareModuleConstants.MODULE_DISPOSED_MESSAGE, null, PipeAwareModuleConstants.MY_MODULE));junction.removePipe(PipeAwareModuleConstants.MODULE_TO_SHELL_PIPE);junction.removePipe(PipeAwareModuleConstants.SHELL_TO_MODULE_PIPE); }