public override void Transition(LocalizedResource rsrc, ResourceEvent @event) { // Note: assumes that localizing container must succeed or fail ResourceReleaseEvent relEvent = (ResourceReleaseEvent)@event; rsrc.Release(relEvent.GetContainer()); }
/* * Synchronizing this method for avoiding races due to multiple ResourceEvent's * coming to LocalResourcesTracker from Public/Private localizer and * Resource Localization Service. */ public virtual void Handle(ResourceEvent @event) { lock (this) { LocalResourceRequest req = @event.GetLocalResourceRequest(); LocalizedResource rsrc = localrsrc[req]; switch (@event.GetType()) { case ResourceEventType.Localized: { if (useLocalCacheDirectoryManager) { Sharpen.Collections.Remove(inProgressLocalResourcesMap, req); } break; } case ResourceEventType.Request: { if (rsrc != null && (!IsResourcePresent(rsrc))) { Log.Info("Resource " + rsrc.GetLocalPath() + " is missing, localizing it again"); RemoveResource(req); rsrc = null; } if (null == rsrc) { rsrc = new LocalizedResource(req, dispatcher); localrsrc[req] = rsrc; } break; } case ResourceEventType.Release: { if (null == rsrc) { // The container sent a release event on a resource which // 1) Failed // 2) Removed for some reason (ex. disk is no longer accessible) ResourceReleaseEvent relEvent = (ResourceReleaseEvent)@event; Log.Info("Container " + relEvent.GetContainer() + " sent RELEASE event on a resource request " + req + " not present in cache."); return; } break; } case ResourceEventType.LocalizationFailed: { /* * If resource localization fails then Localized resource will be * removed from local cache. */ RemoveResource(req); break; } case ResourceEventType.Recovered: { if (rsrc != null) { Log.Warn("Ignoring attempt to recover existing resource " + rsrc); return; } rsrc = RecoverResource(req, (ResourceRecoveredEvent)@event); localrsrc[req] = rsrc; break; } } if (rsrc == null) { Log.Warn("Received " + @event.GetType() + " event for request " + req + " but localized resource is missing" ); return; } rsrc.Handle(@event); // Remove the resource if its downloading and its reference count has // become 0 after RELEASE. This maybe because a container was killed while // localizing and no other container is referring to the resource. // NOTE: This should NOT be done for public resources since the // download is not associated with a container-specific localizer. if (@event.GetType() == ResourceEventType.Release) { if (rsrc.GetState() == ResourceState.Downloading && rsrc.GetRefCount() <= 0 && rsrc .GetRequest().GetVisibility() != LocalResourceVisibility.Public) { RemoveResource(req); } } if (@event.GetType() == ResourceEventType.Localized) { if (rsrc.GetLocalPath() != null) { try { stateStore.FinishResourceLocalization(user, appId, BuildLocalizedResourceProto(rsrc )); } catch (IOException ioe) { Log.Error("Error storing resource state for " + rsrc, ioe); } } else { Log.Warn("Resource " + rsrc + " localized without a location"); } } } }