internal virtual RPC.Server.VerProtocolImpl GetHighestSupportedProtocol(RPC.RpcKind rpcKind, string protocolName) { long highestVersion = 0L; RPC.Server.ProtoClassProtoImpl highest = null; if (Log.IsDebugEnabled()) { Log.Debug("Size of protoMap for " + rpcKind + " =" + GetProtocolImplMap(rpcKind). Count); } foreach (KeyValuePair <RPC.Server.ProtoNameVer, RPC.Server.ProtoClassProtoImpl> pv in GetProtocolImplMap(rpcKind)) { if (pv.Key.protocol.Equals(protocolName)) { if ((highest == null) || (pv.Key.version > highestVersion)) { highest = pv.Value; highestVersion = pv.Key.version; } } } if (highest == null) { return(null); } return(new RPC.Server.VerProtocolImpl(highestVersion, highest)); }
private ProtocolInfoProtos.GetProtocolSignatureRequestProto CreateGetProtocolSigRequestProto (Type protocol, RPC.RpcKind rpcKind) { ProtocolInfoProtos.GetProtocolSignatureRequestProto.Builder builder = ProtocolInfoProtos.GetProtocolSignatureRequestProto .NewBuilder(); builder.SetProtocol(protocol.FullName); builder.SetRpcKind(rpcKind.ToString()); return((ProtocolInfoProtos.GetProtocolSignatureRequestProto)builder.Build()); }
/// <summary>Returns whether the given method is supported or not.</summary> /// <remarks> /// Returns whether the given method is supported or not. /// The protocol signatures are fetched and cached. The connection id for the /// proxy provided is re-used. /// </remarks> /// <param name="rpcProxy">Proxy which provides an existing connection id.</param> /// <param name="protocol">Protocol for which the method check is required.</param> /// <param name="rpcKind">The RpcKind for which the method check is required.</param> /// <param name="version">The version at the client.</param> /// <param name="methodName">Name of the method.</param> /// <returns>true if the method is supported, false otherwise.</returns> /// <exception cref="System.IO.IOException"/> public static bool IsMethodSupported(object rpcProxy, Type protocol, RPC.RpcKind rpcKind, long version, string methodName) { IPEndPoint serverAddress = RPC.GetServerAddress(rpcProxy); IDictionary <long, ProtocolSignature> versionMap = GetVersionSignatureMap(serverAddress , protocol.FullName, rpcKind.ToString()); if (versionMap == null) { Configuration conf = new Configuration(); RPC.SetProtocolEngine(conf, typeof(ProtocolMetaInfoPB), typeof(ProtobufRpcEngine) ); ProtocolMetaInfoPB protocolInfoProxy = GetProtocolMetaInfoProxy(rpcProxy, conf); ProtocolInfoProtos.GetProtocolSignatureRequestProto.Builder builder = ProtocolInfoProtos.GetProtocolSignatureRequestProto .NewBuilder(); builder.SetProtocol(protocol.FullName); builder.SetRpcKind(rpcKind.ToString()); ProtocolInfoProtos.GetProtocolSignatureResponseProto resp; try { resp = protocolInfoProxy.GetProtocolSignature(NullController, ((ProtocolInfoProtos.GetProtocolSignatureRequestProto )builder.Build())); } catch (ServiceException se) { throw ProtobufHelper.GetRemoteException(se); } versionMap = ConvertProtocolSignatureProtos(resp.GetProtocolSignatureList()); PutVersionSignatureMap(serverAddress, protocol.FullName, rpcKind.ToString(), versionMap ); } // Assuming unique method names. MethodInfo desiredMethod; MethodInfo[] allMethods = protocol.GetMethods(); desiredMethod = null; foreach (MethodInfo m in allMethods) { if (m.Name.Equals(methodName)) { desiredMethod = m; break; } } if (desiredMethod == null) { return(false); } int methodHash = ProtocolSignature.GetFingerprint(desiredMethod); return(MethodExists(methodHash, version, versionMap)); }
> GetProtocolImplMap(RPC.RpcKind rpcKind) { if (protocolImplMapArray.Count == 0) { // initialize for all rpc kinds for (int i = 0; i <= RPC.RpcKind.MaxIndex; ++i) { protocolImplMapArray.AddItem(new Dictionary <RPC.Server.ProtoNameVer, RPC.Server.ProtoClassProtoImpl >(10)); } } return(protocolImplMapArray[(int)(rpcKind)]); }
/// <exception cref="System.IO.IOException"/> public override Writable Call(RPC.RpcKind rpcKind, string protocol, Writable param , long receiveTime) { if (sleep) { try { Thread.Sleep(Random.Next(20)); } catch (Exception) { } } // sleep a bit return(param); }
/// <exception cref="System.TypeLoadException"/> private long[] GetProtocolVersionForRpcKind(RPC.RpcKind rpcKind, string protocol) { Type protocolClass = Runtime.GetType(protocol); string protocolName = RPC.GetProtocolName(protocolClass); RPC.Server.VerProtocolImpl[] vers = server.GetSupportedProtocolVersions(rpcKind, protocolName); if (vers == null) { return(null); } long[] versions = new long[vers.Length]; for (int i = 0; i < versions.Length; i++) { versions[i] = vers[i].version; } return(versions); }
// Register protocol and its impl for rpc calls internal virtual void RegisterProtocolAndImpl(RPC.RpcKind rpcKind, Type protocolClass , object protocolImpl) { string protocolName = RPC.GetProtocolName(protocolClass); long version; try { version = RPC.GetProtocolVersion(protocolClass); } catch (Exception) { Log.Warn("Protocol " + protocolClass + " NOT registered as cannot get protocol version " ); return; } GetProtocolImplMap(rpcKind)[new RPC.Server.ProtoNameVer(protocolName, version)] = new RPC.Server.ProtoClassProtoImpl(protocolClass, protocolImpl); Log.Debug("RpcKind = " + rpcKind + " Protocol Name = " + protocolName + " version=" + version + " ProtocolImpl=" + protocolImpl.GetType().FullName + " protocolClass=" + protocolClass.FullName); }
internal virtual RPC.Server.VerProtocolImpl[] GetSupportedProtocolVersions(RPC.RpcKind rpcKind, string protocolName) { RPC.Server.VerProtocolImpl[] resultk = new RPC.Server.VerProtocolImpl[GetProtocolImplMap (rpcKind).Count]; int i = 0; foreach (KeyValuePair <RPC.Server.ProtoNameVer, RPC.Server.ProtoClassProtoImpl> pv in GetProtocolImplMap(rpcKind)) { if (pv.Key.protocol.Equals(protocolName)) { resultk[i++] = new RPC.Server.VerProtocolImpl(pv.Key.version, pv.Value); } } if (i == 0) { return(null); } RPC.Server.VerProtocolImpl[] result = new RPC.Server.VerProtocolImpl[i]; System.Array.Copy(resultk, 0, result, 0, i); return(result); }
/// <exception cref="System.Exception"/> public override IWritable Call(RPC.RpcKind rpcKind, string protocol, IWritable rpcRequest , long receiveTime) { return(GetRpcInvoker(rpcKind).Call(this, protocol, rpcRequest, receiveTime)); }
/// <summary>Add a protocol to the existing server.</summary> /// <param name="protocolClass">- the protocol class</param> /// <param name="protocolImpl">- the impl of the protocol that will be called</param> /// <returns>the server (for convenience)</returns> public virtual RPC.Server AddProtocol(RPC.RpcKind rpcKind, Type protocolClass, object protocolImpl) { RegisterProtocolAndImpl(rpcKind, protocolClass, protocolImpl); return(this); }