private Dictionary<int, Tuple<IGrainExtension, IGrainExtensionMethodInvoker>> extensionMap; // key is the extension interface ID /// <summary> /// Try to add an extension for the specific interface ID. /// Fail and return false if there is already an extension for that interface ID. /// Note that if an extension invoker handles multiple interface IDs, it can only be associated /// with one of those IDs when added, and so only conflicts on that one ID will be detected and prevented. /// </summary> /// <param name="invoker"></param> /// <param name="handler"></param> /// <returns></returns> internal bool TryAddExtension(IGrainExtensionMethodInvoker invoker, IGrainExtension handler) { if (extensionMap == null) { extensionMap = new Dictionary<int, Tuple<IGrainExtension, IGrainExtensionMethodInvoker>>(1); } if (extensionMap.ContainsKey(invoker.InterfaceId)) return false; extensionMap.Add(invoker.InterfaceId, new Tuple<IGrainExtension, IGrainExtensionMethodInvoker>(handler, invoker)); return true; }
public bool TryAddExtension(IGrainExtension handler) { ExtensionInvoker extensionInvoker = GetCurrentExtensionInvoker(); var methodInvoker = TryGetExtensionMethodInvoker(this.typeManager, handler.GetType()); if (methodInvoker == null) { throw new InvalidOperationException("Extension method invoker was not generated for an extension interface"); } return(extensionInvoker.TryAddExtension(methodInvoker, handler)); }
/// <summary> /// Adds the specified extension handler to the currently running activation. /// This method must be called during an activation turn. /// </summary> /// <param name="handler"></param> /// <returns></returns> internal bool TryAddExtension(IGrainExtension handler) { var currentActivation = GetCurrentActivationData(); var invoker = TryGetExtensionInvoker(handler.GetType()); if (invoker == null) { throw new SystemException("Extension method invoker was not generated for an extension interface"); } return(currentActivation.TryAddExtension(invoker, handler)); }
/// <summary> /// Gets the extension from this instance if it is available. /// </summary> /// <param name="interfaceId">The interface id.</param> /// <param name="extension">The extension.</param> /// <returns> /// <see langword="true"/> if the extension is found, <see langword="false"/> otherwise. /// </returns> public bool TryGetExtension(int interfaceId, out IGrainExtension extension) { if (extensionMap != null && extensionMap.TryGetValue(interfaceId, out var value)) { extension = value.Item1; } else { extension = null; } return(extension != null); }
internal void RemoveExtension(IGrainExtension extension) { if (extensionInvoker != null) { if (extensionInvoker.Remove(extension)) { extensionInvoker = null; } } else { throw new InvalidOperationException("Grain extensions not installed."); } }
private Dictionary <int, Tuple <IGrainExtension, IGrainExtensionMethodInvoker> > extensionMap; // key is the extension interface ID /// <summary> /// Try to add an extension for the specific interface ID. /// Fail and return false if there is already an extension for that interface ID. /// Note that if an extension invoker handles multiple interface IDs, it can only be associated /// with one of those IDs when added, and so only conflicts on that one ID will be detected and prevented. /// </summary> /// <param name="invoker"></param> /// <param name="handler"></param> /// <returns></returns> internal bool TryAddExtension(IGrainExtensionMethodInvoker invoker, IGrainExtension handler) { if (extensionMap == null) { extensionMap = new Dictionary <int, Tuple <IGrainExtension, IGrainExtensionMethodInvoker> >(1); } if (extensionMap.ContainsKey(invoker.InterfaceId)) { return(false); } extensionMap.Add(invoker.InterfaceId, new Tuple <IGrainExtension, IGrainExtensionMethodInvoker>(handler, invoker)); return(true); }
/// <summary> /// Gets the extension from this instance if it is available. /// </summary> /// <param name="interfaceId">The interface id.</param> /// <param name="extension">The extension.</param> /// <returns> /// <see langword="true"/> if the extension is found, <see langword="false"/> otherwise. /// </returns> public bool TryGetExtension(int interfaceId, out IGrainExtension extension) { Tuple <IGrainExtension, IGrainExtensionMethodInvoker> value; if (extensionMap != null && extensionMap.TryGetValue(interfaceId, out value)) { extension = value.Item1; } else { extension = null; } return(extension != null); }
public bool TryGetExtensionHandler(Type extensionType, out IGrainExtension result) { result = null; if (extensionMap == null) return false; foreach (var ext in extensionMap.Values) if (extensionType == ext.Item1.GetType()) { result = ext.Item1; return true; } return false; }
/// <summary> /// Removes all extensions for the specified interface id. /// Returns true if the chained invoker no longer has any extensions and may be safely retired. /// </summary> /// <param name="extension"></param> /// <returns>true if the chained invoker is now empty, false otherwise</returns> public bool Remove(IGrainExtension extension) { int interfaceId = 0; foreach(int iface in extensionMap.Keys) if (extensionMap[iface].Item1 == extension) { interfaceId = iface; break; } if (interfaceId == 0) // not found throw new InvalidOperationException(String.Format("Extension {0} is not installed", extension.GetType().FullName)); extensionMap.Remove(interfaceId); return extensionMap.Count == 0; }
private bool TryInstallExtension(int interfaceId, IInvokable invokable, string genericGrainType, ref IGrainMethodInvoker invoker) { ActivationData activationData = GetCurrentActivationData(); IGrainExtension extension = activationData.ActivationServices.GetServiceByKey <int, IGrainExtension>(interfaceId); if (extension == null) { return(false); } if (!TryAddExtension(extension)) { return(false); } // Get the newly installed invoker for the grain extension. invoker = invokable.GetInvoker(typeManager, interfaceId, genericGrainType); return(true); }
public bool TryGetExtensionHandler(Type extensionType, out IGrainExtension result) { result = null; if (extensionMap == null) { return(false); } foreach (var ext in extensionMap.Values) { if (extensionType == ext.Item1.GetType()) { result = ext.Item1; return(true); } } return(false); }
/// <summary> /// Removes all extensions for the specified interface id. /// Returns true if the chained invoker no longer has any extensions and may be safely retired. /// </summary> /// <param name="extension"></param> /// <returns>true if the chained invoker is now empty, false otherwise</returns> public bool Remove(IGrainExtension extension) { int interfaceId = 0; foreach (int iface in extensionMap.Keys) { if (extensionMap[iface].Item1 == extension) { interfaceId = iface; break; } } if (interfaceId == 0) // not found { throw new InvalidOperationException(String.Format("Extension {0} is not installed", extension.GetType().FullName)); } extensionMap.Remove(interfaceId); return(extensionMap.Count == 0); }
internal bool TryAddExtension(IGrainExtensionMethodInvoker invoker, IGrainExtension extension) { if(extensionInvoker == null) extensionInvoker = new ExtensionInvoker(); return extensionInvoker.TryAddExtension(invoker, extension); }
/// <summary> /// Gets the extension from this instance if it is available. /// </summary> /// <param name="interfaceId">The interface id.</param> /// <param name="extension">The extension.</param> /// <returns> /// <see langword="true"/> if the extension is found, <see langword="false"/> otherwise. /// </returns> public bool TryGetExtension(int interfaceId, out IGrainExtension extension) { Tuple<IGrainExtension, IGrainExtensionMethodInvoker> value; if (extensionMap != null && extensionMap.TryGetValue(interfaceId, out value)) { extension = value.Item1; } else { extension = null; } return extension != null; }
internal bool TryGetExtensionHandler(Type extensionType, out IGrainExtension result) { result = null; return(extensionInvoker != null && extensionInvoker.TryGetExtensionHandler(extensionType, out result)); }
internal void RemoveExtension(IGrainExtension extension) { if (extensionInvoker != null) { if (extensionInvoker.Remove(extension)) extensionInvoker = null; } else throw new InvalidOperationException("Grain extensions not installed."); }
internal bool TryGetExtensionHandler(Type extensionType, out IGrainExtension result) { result = null; return extensionInvoker != null && extensionInvoker.TryGetExtensionHandler(extensionType, out result); }
public void RemoveExtension(IGrainExtension handler) { var currentActivation = GetCurrentActivationData(); currentActivation.RemoveExtension(handler); }
public void RemoveExtension(IGrainExtension handler) { GetCurrentExtensionInvoker().Remove(handler); }