Class: Gloo::Persist::PersistMan
- Inherits:
-
Object
- Object
- Gloo::Persist::PersistMan
- Defined in:
- lib/gloo/persist/persist_man.rb
Instance Attribute Summary collapse
-
#maps ⇒ Object
readonly
Returns the value of attribute maps.
-
#mech ⇒ Object
readonly
Returns the value of attribute mech.
Instance Method Summary collapse
-
#file_ext ⇒ Object
Get the default file extention.
-
#find_file_storage(obj) ⇒ Object
Find the objects FileStorage in the list.
-
#get_full_path_names(name) ⇒ Object
Get the full path and name of the file.
-
#gloo_file?(name) ⇒ Boolean
Check to see if a given path name refers to a gloo object file.
-
#initialize(engine) ⇒ PersistMan
constructor
Constructor for the persistence manager.
-
#load(name) ⇒ Object
Load the object from the file.
-
#reload(obj) ⇒ Object
Re-load the given object from file.
-
#reload_all ⇒ Object
Reload all objects.
-
#save(name = '') ⇒ Object
Save one object to the file.
-
#save_all ⇒ Object
Save one object to the file.
-
#save_one(name) ⇒ Object
Save one object to the file.
-
#show_maps ⇒ Object
Print out all object - persistance mappings.
-
#unload(obj) ⇒ Object
The given object is unloading.
-
#unload_all ⇒ Object
Unload all loaded objects.
Constructor Details
#initialize(engine) ⇒ PersistMan
Constructor for the persistence manager.
18 19 20 21 22 |
# File 'lib/gloo/persist/persist_man.rb', line 18 def initialize( engine ) @engine = engine @maps = [] @mech = @engine.platform.get_file_mech( @engine ) end |
Instance Attribute Details
#maps ⇒ Object (readonly)
Returns the value of attribute maps.
13 14 15 |
# File 'lib/gloo/persist/persist_man.rb', line 13 def maps @maps end |
#mech ⇒ Object (readonly)
Returns the value of attribute mech.
13 14 15 |
# File 'lib/gloo/persist/persist_man.rb', line 13 def mech @mech end |
Instance Method Details
#file_ext ⇒ Object
Get the default file extention.
165 166 167 |
# File 'lib/gloo/persist/persist_man.rb', line 165 def file_ext return @mech.file_ext end |
#find_file_storage(obj) ⇒ Object
Find the objects FileStorage in the list.
132 133 134 135 136 137 138 139 |
# File 'lib/gloo/persist/persist_man.rb', line 132 def find_file_storage( obj ) @maps.each do |o| return o if ( o.obj.pn === obj.pn ) end # It was not found, so return nil. return nil end |
#get_full_path_names(name) ⇒ Object
Get the full path and name of the file.
145 146 147 148 149 150 151 152 153 |
# File 'lib/gloo/persist/persist_man.rb', line 145 def get_full_path_names( name ) return nil if name.strip.empty? if name.strip[ -1 ] == '*' return @mech.get_all_files_in( name[ 0..-2 ] ) else return @mech.( name ) end end |
#gloo_file?(name) ⇒ Boolean
Check to see if a given path name refers to a gloo object file.
158 159 160 |
# File 'lib/gloo/persist/persist_man.rb', line 158 def gloo_file?( name ) return @mech.valid?( name ) end |
#load(name) ⇒ Object
Load the object from the file.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gloo/persist/persist_man.rb', line 55 def load( name ) pns = get_full_path_names name return unless pns pns.each do |pn| @engine.log.debug "Load file(s) at: #{pn}" begin fs = Gloo::Persist::FileStorage.new( @engine, pn ) fs.load @maps << fs @engine.event_manager.on_load fs.obj rescue => ex @engine.handle_exception( ex ) end end end |
#reload(obj) ⇒ Object
Re-load the given object from file. This is used to reload a single object and comes from a message sent to the object.
120 121 122 123 124 125 126 127 |
# File 'lib/gloo/persist/persist_man.rb', line 120 def reload( obj ) fs = find_file_storage( obj ) return unless fs @engine.event_manager.on_reload obj @engine.heap.unload obj fs.load end |
#reload_all ⇒ Object
Reload all objects. First send a message to each object to let it know it is being reloaded. Then let the engine restart to reload the files.
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gloo/persist/persist_man.rb', line 104 def reload_all return unless @maps @maps.each do |fs| @engine.event_manager.on_reload fs.obj end # Actual unloading is done in the engine.restart. @engine.restart end |
#save(name = '') ⇒ Object
Save one object to the file.
27 28 29 |
# File 'lib/gloo/persist/persist_man.rb', line 27 def save( name = '' ) name.blank? ? save_all : save_one( name ) end |
#save_all ⇒ Object
Save one object to the file.
34 35 36 |
# File 'lib/gloo/persist/persist_man.rb', line 34 def save_all @maps.each( &:save ) end |
#save_one(name) ⇒ Object
Save one object to the file.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gloo/persist/persist_man.rb', line 41 def save_one( name ) ref = Gloo::Core::Pn.new( @engine, name ) obj = ref.resolve # Send an on_save event @engine.event_manager.on_save obj fs = find_file_storage( obj ) fs.save end |
#show_maps ⇒ Object
Print out all object - persistance mappings. This is a debugging tool.
173 174 175 176 177 |
# File 'lib/gloo/persist/persist_man.rb', line 173 def show_maps @maps.each do |o| puts " \t #{o.pn} \t #{o.obj.name}" end end |
#unload(obj) ⇒ Object
The given object is unloading. Do any necessary clean up here. This is used to unload a single object and comes from a message sent to the object.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gloo/persist/persist_man.rb', line 88 def unload( obj ) @engine.event_manager.on_unload obj @engine.heap.unload obj @maps.each_with_index do |o, i| if o.obj.pn === obj.pn @maps.delete_at( i ) return end end end |
#unload_all ⇒ Object
Unload all loaded objects. The engine is reset to a clean state.
76 77 78 79 80 |
# File 'lib/gloo/persist/persist_man.rb', line 76 def unload_all objs = self.maps.map { |fs| fs.obj } objs.each { |o| o.msg_unload } @engine.reset_state end |