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());
 }
Example #2
0
        /// <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));
        }