//[DebuggerStepThrough] ////[DebuggerHidden] public CompositeMethodInstance(InvocationHandler invoker, FragmentInvocationHandler handler, MethodInfo method, int mixinIndex) { this.invoker = invoker; this.mixinInvoker = handler; this.method = method; this.mixinIndex = mixinIndex; }
//[DebuggerStepThrough] ////[DebuggerHidden] public MethodSideEffectsInstance(IList<InvocationHandler> sideEffects, SideEffectInvocationHandlerResult resultInvocationHandler, ProxyReferenceInvocationHandler proxyHandler, InvocationHandler invoker) { this.sideEffects = sideEffects; this.resultInvocationHandler = resultInvocationHandler; this.proxyHandler = proxyHandler; this.invoker = invoker; }
//[DebuggerStepThrough] ////[DebuggerHidden] public Composite NewProxy(InvocationHandler invocationHandler) { // TODO: linqify var instance = Activator.CreateInstance(this.proxyType, invocationHandler) as Composite; return instance; }
//[DebuggerStepThrough] ////[DebuggerHidden] public static object NewProxyInstance(Type type, InvocationHandler handler) { Type proxyType = BuildProxyType(type); object instance = Activator.CreateInstance(proxyType, new object[] { handler }); return instance; }
//[DebuggerStepThrough] ////[DebuggerHidden] private static void InvokeSideEffect(object proxy, MethodInfo method, object[] args, Exception originalException, InvocationHandler sideEffect) { try { sideEffect.Invoke(proxy, method, args); } catch (Exception exception) { if (exception != originalException) { //exception.printStackTrace(); } } }
//[DebuggerStepThrough] ////[DebuggerHidden] public MethodSideEffectsInstance NewInstance(ModuleInstance moduleInstance, InvocationHandler invoker) { var proxyHandler = new ProxyReferenceInvocationHandler(); var result = new SideEffectInvocationHandlerResult(); var sideEffects = new List<InvocationHandler>(this.sideEffectModels.Count); foreach (MethodSideEffectModel sideEffectModel in this.sideEffectModels) { object sideEffect = sideEffectModel.NewInstance(moduleInstance, result, proxyHandler); if (sideEffectModel.IsGeneric) { sideEffects.Add((InvocationHandler)sideEffect); } else { sideEffects.Add(new TypedFragmentInvocationHandler(sideEffect)); } } return new MethodSideEffectsInstance(sideEffects, result, proxyHandler, invoker); }
public IDisposable On(string methodName, Type[] parameterTypes, Func <object[], object, Task> handler, object state) { Log.RegisteringHandler(_logger, methodName); CheckDisposed(); // It's OK to be disposed while registering a callback, we'll just never call the callback anyway (as with all the callbacks registered before disposal). var invocationHandler = new InvocationHandler(parameterTypes, handler, state); var invocationList = _handlers.AddOrUpdate(methodName, _ => new List <InvocationHandler> { invocationHandler }, (_, invocations) => { lock (invocations) { invocations.Add(invocationHandler); } return(invocations); }); return(new Subscription(invocationHandler, invocationList)); }
/// <summary>Stop the proxy.</summary> /// <remarks> /// Stop the proxy. Proxy must either implement /// <see cref="System.IDisposable"/> /// or must have /// associated /// <see cref="RpcInvocationHandler"/> /// . /// </remarks> /// <param name="proxy">the RPC proxy object to be stopped</param> /// <exception cref="Org.Apache.Hadoop.HadoopIllegalArgumentException"> /// if the proxy does not implement /// <see cref="System.IDisposable"/> /// interface or /// does not have closeable /// <see cref="Reflect.InvocationHandler"/> /// </exception> public static void StopProxy(object proxy) { if (proxy == null) { throw new HadoopIllegalArgumentException("Cannot close proxy since it is null"); } try { if (proxy is IDisposable) { ((IDisposable)proxy).Close(); return; } else { InvocationHandler handler = Proxy.GetInvocationHandler(proxy); if (handler is IDisposable) { ((IDisposable)handler).Close(); return; } } } catch (IOException e) { Log.Error("Closing proxy or invocation handler caused exception", e); } catch (ArgumentException e) { Log.Error("RPC.stopProxy called on non proxy: class=" + proxy.GetType().FullName, e); } // If you see this error on a mock object in a unit test you're // developing, make sure to use MockitoUtil.mockProtocol() to // create your mock. throw new HadoopIllegalArgumentException("Cannot close proxy - is not Closeable or " + "does not provide closeable invocation handler " + proxy.GetType()); }
private async void PayloadReceived(RPCPayload payload) { //See if the payload wants us to close the connection if (payload.MethodName == Globals.CloseConnection) { Exception ex = null; if (payload.Parameters.Count > 0) { ex = new OperationCanceledException(payload.Parameters[0]); } await _mClient.DisconnectAsync(ex).ConfigureAwait(false); return; } if (!_subs.ContainsKey(payload.MethodName)) { return; } InvocationHandler handler = _subs[payload.MethodName]; if (handler.Types == null || handler.Types.Count == 0) { handler.Invoke(null); } else { List <object> parameters = new List <object>(); for (int i = 0; i < payload.Parameters.Count; i++) { parameters.Add(Deserialize(payload.Parameters[i], handler.Types[i])); } handler.Invoke(parameters.ToArray()); } }
public async Task When_Disposed_Should_RemoveHandlerFromList() { // Arrange var result = 0; var invocationHandler = new InvocationHandler(args => Task.Run(() => result++)); var invocationHandlerList = new InvocationHandlerList(invocationHandler); var subscription = new Subscription(invocationHandler, invocationHandlerList); // Act await invocationHandlerList.InvokeAsync(null); await invocationHandlerList.InvokeAsync(null); await invocationHandlerList.InvokeAsync(null); subscription.Dispose(); await invocationHandlerList.InvokeAsync(null); await invocationHandlerList.InvokeAsync(null); // Assert Assert.Equal(3, result); }
public override async Task <object> Invoke(IMessage message) { Task <object> result = null; RemotingMessage remotingMessage = message as RemotingMessage; string operation = remotingMessage.operation; string className = this.DestinationSettings.Properties["source"] as string; //This property is provided for backwards compatibility. The best practice, however, is to not expose the underlying source of a //RemoteObject destination on the client and only one source to a destination. if (remotingMessage.source != null && remotingMessage.source != string.Empty) { if (className == "*") { className = remotingMessage.source; } if (className != remotingMessage.source) { string msg = __Res.GetString(__Res.Type_MismatchMissingSource, remotingMessage.source, this.DestinationSettings.Properties["source"] as string); throw new MessageException(msg, new TypeLoadException(msg)); } } if (className == null) { throw new TypeInitializationException("null", null); } //Cache check string source = className + "." + operation; IList parameterList = remotingMessage.body as IList; FactoryInstance factoryInstance = this.Destination.GetFactoryInstance(); factoryInstance.Source = className; object instance = factoryInstance.Lookup(); if (instance != null) { Type type = instance.GetType(); bool isAccessible = TypeHelper.GetTypeIsAccessible(type); if (!isAccessible) { string msg = __Res.GetString(__Res.Type_InitError, type.FullName); throw new MessageException(msg, new TypeLoadException(msg)); } try { MethodInfo mi = MethodHandler.GetMethod(type, operation, parameterList); if (mi != null) { ParameterInfo[] parameterInfos = mi.GetParameters(); object[] args = new object[parameterInfos.Length]; parameterList.CopyTo(args, 0); TypeHelper.NarrowValues(args, parameterInfos); InvocationHandler invocationHandler = new InvocationHandler(mi); result = (Task <object>)invocationHandler.Invoke(instance, args); await result; } else { throw new MessageException(new MissingMethodException(className, operation)); } } catch (TargetInvocationException exception) { MessageException messageException = null; if (exception.InnerException is MessageException) { messageException = exception.InnerException as MessageException;//User code throws MessageException } else { messageException = new MessageException(exception.InnerException); } throw messageException; } catch (Exception exception) { MessageException messageException = new MessageException(exception); throw messageException; } } else { throw new MessageException(new TypeInitializationException(className, null)); } return(result.Result); }
public OutsideReferenceClass(Func <Invocation, Task <object> > handler) { InvocationHandler = new InvocationHandler(handler); }
public void Handle(HttpApplication httpApplication) { object result = null; string url = null; bool debug = false; CompressionLevels compressionLevel = CompressionLevels.None; if (FluorineConfiguration.Instance.HttpCompressSettings.HandleRequest == HandleRequest.Swx || FluorineConfiguration.Instance.HttpCompressSettings.HandleRequest == HandleRequest.All) { compressionLevel = FluorineConfiguration.Instance.HttpCompressSettings.CompressionLevel; } bool allowDomain = FluorineConfiguration.Instance.SwxSettings.AllowDomain; try { NameValueCollection parameters; if (httpApplication.Request.RequestType == "GET") { parameters = httpApplication.Request.QueryString; } else { parameters = httpApplication.Request.Form; } string serviceClass = parameters["serviceClass"]; string operation = parameters["method"]; string args = parameters["args"]; url = parameters["url"]; debug = parameters["debug"] != null?FluorineFx.Util.Convert.ToBoolean(parameters["debug"]) : false; if (url != null) { url = HttpUtility.UrlDecode(url); // Firefox/Flash (at least, and tested only on a Mac), sends // file:/// (three slashses) in the URI and that fails the validation // so replacing that with two slashes instead. url = url.Replace("///", "//"); try { UriBuilder uriBuilder = new UriBuilder(url); } catch (UriFormatException) { if (log.IsWarnEnabled) { string msg = __Res.GetString(__Res.Swx_InvalidCrossDomainUrl, url); log.Warn(msg); } url = null; } } else { if (allowDomain && log.IsWarnEnabled) { string msg = "No referring URL received from Flash. Cross-domain will not be supported on this call regardless of allowDomain setting"; log.Warn(msg); } } // If the user did not pass an args array, treat it as // an empty args array. (Although this may be an error // on the client side, it may also be the user calling // a method that doesn't take arguments and we shouldn't // force the user to create an args parameter with an empty // array.) if (args == "undefined" || args == string.Empty) { args = "[]"; } // Massage special characters back args = args.Replace("\\t", "\t"); args = args.Replace("\\n", "\n"); args = args.Replace("\\'", "'"); FluorineFx.Json.JavaScriptArray argsArray = FluorineFx.Json.JavaScriptConvert.DeserializeObject(args) as FluorineFx.Json.JavaScriptArray; object[] arguments = argsArray.ToArray(); object instance = ObjectFactory.CreateInstance(serviceClass); MethodInfo mi = MethodHandler.GetMethod(instance.GetType(), operation, arguments); ParameterInfo[] parameterInfos = mi.GetParameters(); TypeHelper.NarrowValues(arguments, parameterInfos); InvocationHandler invocationHandler = new InvocationHandler(mi); result = invocationHandler.Invoke(instance, arguments); } catch (TargetInvocationException exception) { Hashtable resultObj = new Hashtable(); resultObj["error"] = true; resultObj["code"] = "SERVER.PROCESSING"; resultObj["message"] = exception.InnerException.Message; result = resultObj; } catch (Exception exception) { Hashtable resultObj = new Hashtable(); resultObj["error"] = true; resultObj["code"] = "SERVER.PROCESSING"; resultObj["message"] = exception.Message; result = resultObj; } SwxAssembler assembler = new SwxAssembler(); byte[] buffer = assembler.WriteSwf(result, debug, compressionLevel, url, allowDomain); httpApplication.Response.Clear(); httpApplication.Response.ClearHeaders(); httpApplication.Response.Buffer = true; httpApplication.Response.ContentType = "application/swf"; httpApplication.Response.AppendHeader("Content-Length", buffer.Length.ToString()); httpApplication.Response.AppendHeader("Content-Disposition", "attachment; filename=data.swf"); if (buffer.Length > 0) { httpApplication.Response.OutputStream.Write(buffer, 0, buffer.Length); } try { httpApplication.Response.Flush(); } catch (SecurityException) { } }
public void Handle(HttpApplication httpApplication) { object data = null; string str = null; Hashtable hashtable; bool debug = false; CompressionLevels none = CompressionLevels.None; if ((FluorineConfiguration.Instance.HttpCompressSettings.HandleRequest == HandleRequest.Swx) || (FluorineConfiguration.Instance.HttpCompressSettings.HandleRequest == HandleRequest.All)) { none = FluorineConfiguration.Instance.HttpCompressSettings.CompressionLevel; } bool allowDomain = FluorineConfiguration.Instance.SwxSettings.AllowDomain; try { NameValueCollection queryString; string str5; if (httpApplication.Request.RequestType == "GET") { queryString = httpApplication.Request.QueryString; } else { queryString = httpApplication.Request.Form; } string typeName = queryString["serviceClass"]; string methodName = queryString["method"]; string str4 = queryString["args"]; str = queryString["url"]; debug = (queryString["debug"] != null) ? Convert.ToBoolean(queryString["debug"]) : false; if (str != null) { str = HttpUtility.UrlDecode(str); str = str.Replace("///", "//"); try { UriBuilder builder = new UriBuilder(str); } catch (UriFormatException) { if (log.get_IsWarnEnabled()) { str5 = __Res.GetString("Swx_InvalidCrossDomainUrl", new object[] { str }); log.Warn(str5); } str = null; } } else if (allowDomain && log.get_IsWarnEnabled()) { str5 = "No referring URL received from Flash. Cross-domain will not be supported on this call regardless of allowDomain setting"; log.Warn(str5); } switch (str4) { case "undefined": case string.Empty: str4 = "[]"; break; } object[] arguments = (JavaScriptConvert.DeserializeObject(str4.Replace(@"\t", "\t").Replace(@"\n", "\n").Replace(@"\'", "'")) as JavaScriptArray).ToArray(); object obj3 = ObjectFactory.CreateInstance(typeName); MethodInfo methodInfo = MethodHandler.GetMethod(obj3.GetType(), methodName, arguments); ParameterInfo[] parameters = methodInfo.GetParameters(); TypeHelper.NarrowValues(arguments, parameters); data = new InvocationHandler(methodInfo).Invoke(obj3, arguments); } catch (TargetInvocationException exception) { hashtable = new Hashtable(); hashtable["error"] = true; hashtable["code"] = "SERVER.PROCESSING"; hashtable["message"] = exception.InnerException.Message; data = hashtable; } catch (Exception exception2) { hashtable = new Hashtable(); hashtable["error"] = true; hashtable["code"] = "SERVER.PROCESSING"; hashtable["message"] = exception2.Message; data = hashtable; } byte[] buffer = new SwxAssembler().WriteSwf(data, debug, none, str, allowDomain); httpApplication.Response.Clear(); httpApplication.Response.ClearHeaders(); httpApplication.Response.Buffer = true; httpApplication.Response.ContentType = "application/swf"; int length = buffer.Length; httpApplication.Response.AppendHeader("Content-Length", length.ToString()); httpApplication.Response.AppendHeader("Content-Disposition", "attachment; filename=data.swf"); if (buffer.Length > 0) { httpApplication.Response.OutputStream.Write(buffer, 0, buffer.Length); } try { httpApplication.Response.Flush(); } catch (SecurityException) { } }
public ReporterFactory(InvocationHandler handler) { this._handler = handler; }
//[DebuggerStepThrough] ////[DebuggerHidden] public MethodConcernsInstance(InvocationHandler firstConcern, FragmentInvocationHandler mixinInvocationHandler, ProxyReferenceInvocationHandler proxyHandler) { this.firstConcern = firstConcern; this.mixinInvocationHandler = mixinInvocationHandler; this.proxyHandler = proxyHandler; }
public InterfacePropertyClass(InvocationHandler invocationHandler) { InvocationHandler = invocationHandler; }
protected AbstractClass(InvocationHandler handler) { InvocationHandler = handler; }
public TestClass(Func<Invocation, Task<object>> handler) { InvocationHandler = new InvocationHandler(handler); }
public TestProxy(InvocationHandler invocationHandler) { InvocationHandler = invocationHandler; }
protected override void OnInvoke(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, Notify invoke) { IServiceCall serviceCall = invoke.ServiceCall; if ((serviceCall.ServiceMethodName == "_result") || (serviceCall.ServiceMethodName == "_error")) { if (serviceCall.ServiceMethodName == "_error") { serviceCall.Status = 0x13; } if (serviceCall.ServiceMethodName == "_result") { serviceCall.Status = 2; } base.HandlePendingCallResult(connection, invoke); } else if (serviceCall is IPendingServiceCall) { IPendingServiceCall call2 = serviceCall as IPendingServiceCall; MethodInfo methodInfo = MethodHandler.GetMethod(this._netConnection.Client.GetType(), serviceCall.ServiceMethodName, serviceCall.Arguments, false, false); if (methodInfo != null) { ParameterInfo[] parameters = methodInfo.GetParameters(); object[] array = new object[parameters.Length]; serviceCall.Arguments.CopyTo(array, 0); TypeHelper.NarrowValues(array, parameters); try { object obj2 = new InvocationHandler(methodInfo).Invoke(this._netConnection.Client, array); if (methodInfo.ReturnType == typeof(void)) { serviceCall.Status = 4; } else { serviceCall.Status = (obj2 == null) ? ((byte)3) : ((byte)2); call2.Result = obj2; } } catch (Exception exception) { serviceCall.Exception = exception; serviceCall.Status = 0x13; } } else { string message = __Res.GetString("Invocation_NoSuitableMethod", new object[] { serviceCall.ServiceMethodName }); serviceCall.Status = 0x11; serviceCall.Exception = new FluorineException(message); } if ((serviceCall.Status == 4) || (serviceCall.Status == 3)) { if (log.get_IsDebugEnabled()) { log.Debug("Method does not have return value, do not reply"); } } else { FluorineFx.Messaging.Rtmp.Event.Invoke invoke2 = new FluorineFx.Messaging.Rtmp.Event.Invoke { ServiceCall = serviceCall, InvokeId = invoke.InvokeId }; channel.Write(invoke2); } } }
public object NewProxyInstance(object instanceObject, Type objInterface, InvocationHandler handler) { switch (objInterface.Name) { case "CloudletFilter": return new Ufc.MpOS.Proxy.Temp.Proxy_CloudletFilter(instanceObject,handler); case "InternetFilter": return new Ufc.MpOS.Proxy.Temp.Proxy_InternetFilter(instanceObject,handler); } return null; }
/* * Constructs a new {@code Proxy} instance with the specified invocation * handler. * * @param h * the invocation handler for the newly created proxy */ protected Proxy(InvocationHandler h) { this.h = h; }
public Proxy_CloudletFilter(object instanceObject, InvocationHandler instanceHandler) { this.instanceObject = (CloudletFilter)instanceObject; this.instanceHandler = instanceHandler; }
//[DebuggerStepThrough] ////[DebuggerHidden] public MethodConcernsInstance(InvocationHandler firstConcern, FragmentInvocationHandler mixinInvocationHandler, ProxyReferenceInvocationHandler proxyHandler) { this.firstConcern = firstConcern; this.mixinInvocationHandler = mixinInvocationHandler; this.proxyHandler = proxyHandler; }
// Z:\jsc.svn\core\ScriptCoreLibJava\BCLImplementation\System\ServiceModel\ClientBase.cs public static object newProxyInstance(ClassLoader loader, Class[] interfaces, InvocationHandler invocationHandler) { return null; }
public void SendMessage(string handler, IList arguments) { string str; string str2; this.BeginUpdate(); try { this._so.SendMessage(handler, arguments); } finally { this.EndUpdate(); } int length = handler.LastIndexOf("."); if (length != -1) { str = handler.Substring(0, length); str2 = handler.Substring(length + 1); } else { str = string.Empty; str2 = handler; } object serviceHandler = this.GetServiceHandler(str); if ((serviceHandler == null) && base.HasParent) { IScopeContext context = this.Parent.Context; try { serviceHandler = ObjectFactory.CreateInstance(this._so.Name + "." + str); } catch (Exception) { log.Debug(__Res.GetString("Type_InitError", new object[] { this._so.Name + "." + str })); } } if (serviceHandler != null) { MethodInfo methodInfo = MethodHandler.GetMethod(serviceHandler.GetType(), str2, arguments); if (methodInfo != null) { ParameterInfo[] parameters = methodInfo.GetParameters(); object[] array = new object[parameters.Length]; arguments.CopyTo(array, 0); TypeHelper.NarrowValues(array, parameters); try { object obj3 = new InvocationHandler(methodInfo).Invoke(serviceHandler, array); } catch (Exception exception) { log.Error("Error while invoking method " + str2 + " on shared object handler " + handler, exception); } } } foreach (ISharedObjectListener listener in this._serverListeners) { listener.OnSharedObjectSend(this, handler, arguments); } }
public SimpleInvocationHandler(string[] methods) { this.methods = methods; InnerHandler = new InvocationHandler(); }
public void SetHandler(InvocationHandler handler) { }
public static Object NewProxyInstance(Type interfaze, InvocationHandler handler) { ConstructorInfo constructor = GetOrCreateConstructorInfo(interfaze); return constructor.Invoke(new object[] { handler }); }
public VoidAsyncInvocation(object proxy, InvocationHandler invocationHandler, MethodInfo method, PropertyInfo property, object[] arguments, Func<Invocation, Task> implementation) : base(proxy, invocationHandler, method, property, arguments) { this.implementation = implementation; }
public void SetHandler(InvocationHandler handler) { }
public HandWrittenProxy(IHandWritten target, InvocationHandler invocationHandler) { this.target = target; this.invocationHandler = invocationHandler; }
public TestProxy(InvocationHandler invocationHandler) { InvocationHandler = invocationHandler; }
/** * Constructs a new {@code Proxy} instance with the specified invocation * handler. * * @param h * the invocation handler for the newly created proxy */ protected Proxy(InvocationHandler h) { this.h = h; }
public object NewProxy(InvocationHandler invocationHandler, Type mixinType) { Type mixinProxyType = CreateProxyType(mixinType); object instance = Activator.CreateInstance(mixinProxyType, invocationHandler); return instance; }
/// <summary> /// Creates a new <see cref="APIOperation" /> proxy given a handler. /// </summary> protected APIOperation NewAPIOperationProxy(SafeType<APIOperation> api, InvocationHandler handler) { return (APIOperation)Proxy.NewProxyInstance(api.RawType, handler); }
public OutsideReferenceClass(Func<Invocation, Task<object>> handler) { InvocationHandler = new InvocationHandler(handler); }