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
Contructor 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
Contructor 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.getFileMech( @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.
161 162 163 |
# File 'lib/gloo/persist/persist_man.rb', line 161 def file_ext return @mech.file_ext end |
#find_file_storage(obj) ⇒ Object
Find the objects FileStorage in the list.
128 129 130 131 132 133 134 135 |
# File 'lib/gloo/persist/persist_man.rb', line 128 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.
141 142 143 144 145 146 147 148 149 |
# File 'lib/gloo/persist/persist_man.rb', line 141 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.
154 155 156 |
# File 'lib/gloo/persist/persist_man.rb', line 154 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 |
# 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}" fs = Gloo::Persist::FileStorage.new( @engine, pn ) fs.load @maps << fs @engine.event_manager.on_load fs.obj 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.
116 117 118 119 120 121 122 123 |
# File 'lib/gloo/persist/persist_man.rb', line 116 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.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gloo/persist/persist_man.rb', line 100 def reload_all return unless @maps @maps.each do |fs| @engine.event_manager.on_reload fs.obj end # Acutal 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.
169 170 171 172 173 |
# File 'lib/gloo/persist/persist_man.rb', line 169 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.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/gloo/persist/persist_man.rb', line 84 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.
72 73 74 75 76 |
# File 'lib/gloo/persist/persist_man.rb', line 72 def unload_all objs = self.maps.map { |fs| fs.obj } objs.each { |o| o.msg_unload } @engine.reset_state end |