lib/perobs/ObjectBase.rb in perobs-2.3.1 vs lib/perobs/ObjectBase.rb in perobs-2.4.0
- old
+ new
@@ -23,10 +23,11 @@
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+require 'perobs/Log'
require 'perobs/ClassMap'
module PEROBS
# This class is used to replace a direct reference to another Ruby object by
@@ -45,17 +46,15 @@
end
# Proxy all calls to unknown methods to the referenced object.
def method_missing(method_sym, *args, &block)
unless (obj = _referenced_object)
- ::Kernel.raise ::RuntimeError,
- "Internal consistency error. No object with ID #{@id} found in " +
- 'the store.'
+ ::PEROBS.log.fatal "Internal consistency error. No object with ID " +
+ "#{@id} found in the store."
end
if obj.respond_to?(:is_poxreference?)
- ::Kernel.raise ::RuntimeError,
- "POXReference that references a POXReference found."
+ ::PEROBS.log.fatal "POXReference that references a POXReference found."
end
obj.send(method_sym, *args, &block)
end
# Proxy all calls to unknown methods to the referenced object. Calling
@@ -145,9 +144,23 @@
# is done this way to prevent the Proc object hanging on to a reference to
# self which would prevent the object from being collected. This internal
# method is not intended for users to call.
def ObjectBase._finalize(store, id)
proc { store._collect(id) }
+ end
+
+ # Library internal method to transfer the Object to a new store.
+ # @param store [Store] New store
+ def _transfer(store)
+ @store = store
+ # Remove the previously defined finalizer as it is attached to the old
+ # store.
+ ObjectSpace.undefine_finalizer(self)
+ # Register the object as in-memory object with the new store.
+ @store._register_in_memory(self, @_id)
+ # Register the finalizer for the new store.
+ ObjectSpace.define_finalizer(self, ObjectBase._finalize(@store, @_id))
+ @myself = POXReference.new(@store, @_id)
end
# This method can be overloaded by derived classes to do some massaging on
# the data after it has been restored from the database. This could either
# be some sanity check or code to migrate the object from one version to