Class MUES::ObjectStore::MemoryManager
In: lib/mues/os-extensions/memorymanager.rb  (CVS)
Parent: MUES::Object

This class is the abstract base class for MUES::ObjectStore memory-management Strategy classes. Derivatives of this class should provide at least a protected method called managerThreadRoutine, which should take a MUES::ObjectSpaceVisitor object as its argument

Methods

Included Modules

MUES::TypeCheckFunctions PluginFactory

Constants

SVNRev = %q$Rev: 1206 $   SVN Revision
SVNId = %q$Id: memorymanager.rb 1206 2004-05-09 21:25:11Z deveiant $   SVN Id
SVNURL = %q$URL: svn+ssh://deveiate.org/usr/local/svn/MUES/trunk/lib/mues/os-extensions/memorymanager.rb $   SVN URL

External Aliases

running -> running?

Attributes

activeObjects  [R]  The Hash of objects in active memory, keyed by id.
running  [R]  Running flag — if true, the memory manager is currently running

Public Class methods

Returns the directory objectstore extensions live under (part of the Factory interface)

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 64
        def self.derivativeDirs
            return 'mues/os-extensions'
        end

Public Instance methods

Get the object associated with the specified id from the objects registered with the MemoryManager.

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 103
        def []( *ids )
            @mutex.synchronize( Sync::SH ) {
                # @activeObjects[ *ids ]
                ids.collect {|id| @activeObjects[id]}
            }
        end

Clear the objectspace

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 195
        def clear
            self.log.notice( "Clearing active objectspace." )
            @mutex.synchronize( Sync::EX ) {
                @activeObjects.clear
            }
        end

Registers the specified objects with the memory-manager.

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 167
        def register( *objects )
            checkEachType( objects, MUES::StorableObject )

            @mutex.synchronize( Sync::EX ) {
                objects.each {|o|
                    @activeObjects[o.objectStoreId] = o
                }
            }

            @activeObjects.rehash
        end

Restart the memory manager, clearing the current active objects and returning them.

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 145
        def restart( visitor )
            objs = nil
            @mutex.synchronize( Sync::EX ) {
                objs = self.shutdown
                self.start( visitor )
            }

            return objs
        end

Kill the memory manager and return all active, non-shallow objects.

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 158
        def shutdown
            @managerThread.raise Shutdown
            @managerThread.join
            return self.unswappedObjects
        end

Starts the memory manager using the specified visitor object.

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 123
        def start( visitor )
            checkType( visitor, MUES::ObjectSpaceVisitor )

            @running = true
            unless @managerThread && @managerThread.alive?
                @managerThread = Thread.new {
                    Thread.current.abort_on_exception = true
                    begin
                        managerThreadRoutine( visitor )
                    rescue Reload
                        self.log.info( "Reloading #{self.inspect}" )
                    rescue Shutdown
                        self.log.info( "Shutting down #{self.inspect}" )
                    end
                    @running = false
                }
            end
        end

Unregister the specified objects with the memory-manager.

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 181
        def unregister( *objects )
            checkEachType( objects, MUES::StorableObject )

            @mutex.synchronize( Sync::EX ) {
                objects.each {|o|
                    @activeObjects.delete( o.objectStoreId )
                }
            }

            @activeObjects.rehash
        end

Returns all of the objects currently registered with the memory manager that are not shallow (ie., haven‘t been swapped into the backing store).

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 114
        def unswappedObjects
            @mutex.synchronize( Sync::SH ) {
                @activeObjects.values.reject {|o| o.shallow?}
            }
        end

Protected Instance methods

Create and return a new MemoryManager with the specified backend (a MUES::ObjectStore::Backend derivative), and the specified config hash.

[Source]

# File lib/mues/os-extensions/memorymanager.rb, line 76
        def initialize( backend, config = {} ) # :notnew:
            super()

            @backend     = backend
            @activeObjects   = {}
            @mutex           = Sync::new
            @managerThread   = nil
            @running     = false
            @config          = config
        end

[Validate]