ioeventstream.rb

Path: lib/mues/ioeventstream.rb  (CVS)
Last Update: Sat Aug 18 22:54:10 -0700 2007

This file contains the MUES::IOEventStream class, which is is a filtered input/output stream class used for the pipelining and abstraction of object inter-communication in the MUES engine. It is used to route input and output messages in the form of events for any object which requires a complex and mutable I/O abstraction. It is modelled after the Chain of Responsibility pattern from the [Design Patterns] book.

The stream itself is only a container; it is essentially just a stack of filters (MUES::IOEventFilter objects), each of which can potentially act upon the events flowing through the stream. A filter may act on the I/O events in the stream in many different ways, depending on its purpose and configuration. It can redirect, modify, duplicate, and/or inject new events based on the contents of each event.

The stream is bi-directional, meaning that all filters contained in the stream are given both input and output events. This allows a single filter to act on events flowing in both directions. If a filter is not interested in one direction, it can simply return the events it is given unchanged.

The stream starts its own Ruby thread at creation so that I/O in it is processed independently of the main EventQueue. It implements the Observer role of the Observer design pattern (patterndigest.com/patterns/Observer.html) so that filters with pending events may notify the stream they are associated with without the need to poll each filter constantly.

Synopsis

  require 'mues/ioeventstream'
  require 'mues/ioeventfilters'
  require 'mues/events'

  # Create a new stream
  stream = MUES::IOEventStream.new

  # Create three filters
  sockFilter  = MUES::SocketOutputFilter.new( aSocket )
  macroFilter = MUES::MacroFilter.new( aUser )
  shellFilter = MUES::CommandShell.new( aUser )

  # Add the filters to the stream.
  @stream.addHandlers( inputHandler, loginHandler, outputHandler )

  # Send output to the user
  connectMsg = MUES::OutputEvent.new( "Welcome to ExperimentalMUD." )
  @stream.addOutputEvents( loginMsg )

Subversion ID

$Id: ioeventstream.rb 1215 2004-06-14 06:02:09Z deveiant $

Authors

  • Michael Granger <ged@FaerieMUD.org>

Copyright

Copyright (c) 2000-2003 The FaerieMUD Consortium. All rights reserved.

This module is free software. You may use, modify, and/or redistribute this software under the terms of the Perl Artistic License. (See language.perl.com/misc/Artistic.html)

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Required files

sync   timeout   mues/object   mues/ioeventfilters   mues/events   mues/workerthread  

[Validate]