protected void ResetEvent(InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { if (persistenceEvent == null) { throw Fx.Exception.ArgumentNull("persistenceEvent"); } if (owner == null) { throw Fx.Exception.ArgumentNull("owner"); } lock (this.ThisLock) { InstanceNormalEvent event2; WeakReference reference; if (!this.owners.TryGetValue(owner.InstanceOwnerId, out reference) || !object.ReferenceEquals(reference.Target, owner)) { throw Fx.Exception.Argument("owner", SRCore.OwnerBelongsToWrongStore); } if (owner.Events.TryGetValue(persistenceEvent.Name, out event2) && event2.IsSignaled) { event2.IsSignaled = false; if ((event2.BoundHandles.Count == 0) && (event2.PendingHandles.Count == 0)) { owner.Events.Remove(persistenceEvent.Name); } } } }
internal void Signaled(InstancePersistenceEvent persistenceEvent) { Signaled(new List <InstancePersistenceEvent>(1) { persistenceEvent }); }
internal void PendHandleToEvent(InstanceHandle handle, InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { lock (this.ThisLock) { this.GetOwnerEventHelper(persistenceEvent, owner).PendingHandles.Add(handle); } }
internal InstancePersistenceEvent AddHandleToEvent(InstanceHandle handle, InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { lock (this.ThisLock) { InstanceNormalEvent ownerEventHelper = this.GetOwnerEventHelper(persistenceEvent, owner); ownerEventHelper.BoundHandles.Add(handle); ownerEventHelper.PendingHandles.Remove(handle); return(ownerEventHelper.IsSignaled ? ownerEventHelper : null); } }
// Must be called under ThisLock. Doesn't validate the InstanceOwner. InstanceNormalEvent GetOwnerEventHelper(InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { InstanceNormalEvent normal; if (!owner.Events.TryGetValue(persistenceEvent.Name, out normal)) { normal = new InstanceNormalEvent(persistenceEvent); owner.Events.Add(persistenceEvent.Name, normal); } return(normal); }
private InstanceNormalEvent GetOwnerEventHelper(InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { InstanceNormalEvent event2; if (!owner.Events.TryGetValue(persistenceEvent.Name, out event2)) { event2 = new InstanceNormalEvent(persistenceEvent); owner.Events.Add(persistenceEvent.Name, event2); } return(event2); }
internal void PendHandleToEvent(InstanceHandle handle, InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { lock (ThisLock) { Fx.Assert(this.owners.ContainsKey(owner.InstanceOwnerId), "InstanceHandle called PendHandleToEvent on wrong InstanceStore!!"); Fx.Assert(object.ReferenceEquals(this.owners[owner.InstanceOwnerId].Target, owner), "How did multiple of the same owner become simultaneously active?"); InstanceNormalEvent normal = GetOwnerEventHelper(persistenceEvent, owner); Fx.Assert(!normal.PendingHandles.Contains(handle), "Should not have already pended the handle."); Fx.Assert(!normal.BoundHandles.Contains(handle), "Should not be able to pend an already-bound handle."); normal.PendingHandles.Add(handle); } }
internal InstancePersistenceEvent AddHandleToEvent(InstanceHandle handle, InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { lock (ThisLock) { Fx.Assert(this.owners.ContainsKey(owner.InstanceOwnerId), "InstanceHandle called AddHandleToEvent on wrong InstanceStore!!"); Fx.Assert(object.ReferenceEquals(this.owners[owner.InstanceOwnerId].Target, owner), "How did multiple instances of the same owner become simultaneously active?"); InstanceNormalEvent normal = GetOwnerEventHelper(persistenceEvent, owner); Fx.Assert(normal.PendingHandles.Contains(handle), "Should have already pended the handle."); Fx.Assert(!normal.BoundHandles.Contains(handle), "Should not be able to add a handle to an event twice."); normal.BoundHandles.Add(handle); normal.PendingHandles.Remove(handle); return(normal.IsSignaled ? normal : null); } }
internal void EventReady(InstancePersistenceEvent persistenceEvent) { WaitForEventsAsyncResult waitResult = null; lock (this.ThisLock) { if (this.waitResult != null) { waitResult = this.waitResult; this.waitResult = null; } } if (waitResult != null) { waitResult.Signaled(persistenceEvent); } }
internal void EventReady(InstancePersistenceEvent persistenceEvent) { WaitForEventsAsyncResult resultToComplete = null; lock (ThisLock) { if (this.waitResult != null) { resultToComplete = this.waitResult; this.waitResult = null; } } if (resultToComplete != null) { resultToComplete.Signaled(persistenceEvent); } }
internal void BindOwnerEvent(InstancePersistenceEvent persistenceEvent) { lock (this.ThisLock) { if (this.IsValid && ((this.boundOwnerEvents == null) || !this.boundOwnerEvents.Contains(persistenceEvent.Name))) { if (this.pendingOwnerEvents == null) { this.pendingOwnerEvents = new HashSet <InstancePersistenceEvent>(); } else if (this.pendingOwnerEvents.Contains(persistenceEvent)) { goto Label_0085; } this.pendingOwnerEvents.Add(persistenceEvent); this.Store.PendHandleToEvent(this, persistenceEvent, this.Owner); } Label_0085 :; } }
protected void SignalEvent(InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { if (persistenceEvent == null) { throw Fx.Exception.ArgumentNull("persistenceEvent"); } if (owner == null) { throw Fx.Exception.ArgumentNull("owner"); } InstanceNormalEvent normal; InstanceHandle[] handlesToNotify = null; lock (ThisLock) { WeakReference ownerReference; if (!this.owners.TryGetValue(owner.InstanceOwnerId, out ownerReference) || !object.ReferenceEquals(ownerReference.Target, owner)) { throw Fx.Exception.Argument("owner", SRCore.OwnerBelongsToWrongStore); } normal = GetOwnerEventHelper(persistenceEvent, owner); if (!normal.IsSignaled) { normal.IsSignaled = true; if (normal.BoundHandles.Count > 0) { handlesToNotify = normal.BoundHandles.ToArray(); } } } if (handlesToNotify != null) { foreach (InstanceHandle handle in handlesToNotify) { handle.EventReady(normal); } } }
protected void SignalEvent(InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { InstanceNormalEvent ownerEventHelper; if (persistenceEvent == null) { throw Fx.Exception.ArgumentNull("persistenceEvent"); } if (owner == null) { throw Fx.Exception.ArgumentNull("owner"); } InstanceHandle[] handleArray = null; lock (this.ThisLock) { WeakReference reference; if (!this.owners.TryGetValue(owner.InstanceOwnerId, out reference) || !object.ReferenceEquals(reference.Target, owner)) { throw Fx.Exception.Argument("owner", SRCore.OwnerBelongsToWrongStore); } ownerEventHelper = this.GetOwnerEventHelper(persistenceEvent, owner); if (!ownerEventHelper.IsSignaled) { ownerEventHelper.IsSignaled = true; if (ownerEventHelper.BoundHandles.Count > 0) { handleArray = ownerEventHelper.BoundHandles.ToArray <InstanceHandle>(); } } } if (handleArray != null) { foreach (InstanceHandle handle in handleArray) { handle.EventReady(ownerEventHelper); } } }
internal void BindOwnerEvent(InstancePersistenceEvent persistenceEvent) { lock (ThisLock) { Fx.Assert(OperationPending, "Should only be called during an operation."); Fx.Assert(AcquirePending == null, "Should only be called after acquiring the transaction."); Fx.Assert(Owner != null, "Must be bound to owner to have an owner-scoped event."); if (IsValid && (this.boundOwnerEvents == null || !this.boundOwnerEvents.Contains(persistenceEvent.Name))) { if (this.pendingOwnerEvents == null) { this.pendingOwnerEvents = new HashSet <InstancePersistenceEvent>(); } else if (this.pendingOwnerEvents.Contains(persistenceEvent)) { return; } this.pendingOwnerEvents.Add(persistenceEvent); Store.PendHandleToEvent(this, persistenceEvent, Owner); } } }
protected void ResetEvent(InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { if (persistenceEvent == null) { throw Fx.Exception.ArgumentNull("persistenceEvent"); } if (owner == null) { throw Fx.Exception.ArgumentNull("owner"); } InstanceNormalEvent normal; lock (ThisLock) { WeakReference ownerReference; if (!this.owners.TryGetValue(owner.InstanceOwnerId, out ownerReference) || !object.ReferenceEquals(ownerReference.Target, owner)) { throw Fx.Exception.Argument("owner", SRCore.OwnerBelongsToWrongStore); } if (!owner.Events.TryGetValue(persistenceEvent.Name, out normal)) { return; } if (normal.IsSignaled) { normal.IsSignaled = false; if (normal.BoundHandles.Count == 0 && normal.PendingHandles.Count == 0) { owner.Events.Remove(persistenceEvent.Name); } } } }
// Returns null if an InstanceHandleConflictException should be thrown. internal InstanceView Commit(InstanceView newState) { Fx.Assert(newState != null, "Null view passed to Commit."); newState.MakeReadOnly(); View = newState; List <InstanceHandleReference> handlesPendingResolution = null; InstanceHandle handleToFree = null; List <InstancePersistenceEvent> normals = null; WaitForEventsAsyncResult resultToComplete = null; try { lock (ThisLock) { if (this.inProgressBind != null) { // If there's a Version, it should be committed. if (Version != -1) { if (!Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree)) { return(null); } } else { Fx.Assert(OperationPending, "Should have cancelled this bind in FinishOperation."); Fx.Assert(AcquirePending == null, "Should not be in Commit during AcquirePending."); Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution); } } if (this.pendingOwnerEvents != null && IsValid) { if (this.boundOwnerEvents == null) { this.boundOwnerEvents = new HashSet <XName>(); } foreach (InstancePersistenceEvent persistenceEvent in this.pendingOwnerEvents) { if (!this.boundOwnerEvents.Add(persistenceEvent.Name)) { Fx.Assert("Should not have conflicts between pending and bound events."); continue; } InstancePersistenceEvent normal = Store.AddHandleToEvent(this, persistenceEvent, Owner); if (normal != null) { if (normals == null) { normals = new List <InstancePersistenceEvent>(this.pendingOwnerEvents.Count); } normals.Add(normal); } } this.pendingOwnerEvents = null; if (normals != null && this.waitResult != null) { resultToComplete = this.waitResult; this.waitResult = null; } } return(View); } } finally { InstanceOwner.ResolveHandles(handlesPendingResolution); // This is a convenience, it is not required for correctness. if (handleToFree != null) { Fx.Assert(!object.ReferenceEquals(handleToFree, this), "Shouldn't have been told to free ourselves."); handleToFree.Free(); } if (resultToComplete != null) { resultToComplete.Signaled(normals); } } }
public void BindEvent(InstancePersistenceEvent persistenceEvent) { throw new NotImplementedException(); }
internal InstanceView Commit(InstanceView newState) { InstanceView view; newState.MakeReadOnly(); this.View = newState; List <InstanceHandleReference> handlesPendingResolution = null; InstanceHandle handleToFree = null; List <InstancePersistenceEvent> persistenceEvents = null; WaitForEventsAsyncResult waitResult = null; try { lock (this.ThisLock) { if (this.inProgressBind != null) { if (this.Version != -1L) { if (!this.Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree)) { return(null); } } else { this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution); } } if ((this.pendingOwnerEvents != null) && this.IsValid) { if (this.boundOwnerEvents == null) { this.boundOwnerEvents = new HashSet <XName>(); } foreach (InstancePersistenceEvent event2 in this.pendingOwnerEvents) { if (this.boundOwnerEvents.Add(event2.Name)) { InstancePersistenceEvent item = this.Store.AddHandleToEvent(this, event2, this.Owner); if (item != null) { if (persistenceEvents == null) { persistenceEvents = new List <InstancePersistenceEvent>(this.pendingOwnerEvents.Count); } persistenceEvents.Add(item); } } } this.pendingOwnerEvents = null; if ((persistenceEvents != null) && (this.waitResult != null)) { waitResult = this.waitResult; this.waitResult = null; } } view = this.View; } } finally { InstanceOwner.ResolveHandles(handlesPendingResolution); if (handleToFree != null) { handleToFree.Free(); } if (waitResult != null) { waitResult.Signaled(persistenceEvents); } } return(view); }
protected void SignalEvent(InstancePersistenceEvent persistenceEvent, InstanceOwner owner) { throw new NotImplementedException(); }
internal InstanceNormalEvent(InstancePersistenceEvent persistenceEvent) : base(persistenceEvent.Name) { }
internal InstanceNormalEvent(InstancePersistenceEvent persistenceEvent) : base(persistenceEvent.Name) { this.boundHandles = new HashSet <InstanceHandle>(); this.pendingHandles = new HashSet <InstanceHandle>(); }