Example #1
0
 public override bool Equals(object o)
 {
     if (o == null)
     {
         return(false);
     }
     if (this == o)
     {
         return(true);
     }
     if (!(o is RPC.Server.ProtoNameVer))
     {
         return(false);
     }
     RPC.Server.ProtoNameVer pv = (RPC.Server.ProtoNameVer)o;
     return((pv.protocol.Equals(this.protocol)) && (pv.version == this.version));
 }
Example #2
0
 /// <exception cref="Org.Apache.Hadoop.Ipc.RpcServerException"/>
 private static RPC.Server.ProtoClassProtoImpl GetProtocolImpl(RPC.Server server,
                                                               string protoName, long clientVersion)
 {
     RPC.Server.ProtoNameVer pv = new RPC.Server.ProtoNameVer(protoName, clientVersion
                                                              );
     RPC.Server.ProtoClassProtoImpl impl = server.GetProtocolImplMap(RPC.RpcKind.RpcProtocolBuffer
                                                                     )[pv];
     if (impl == null)
     {
         // no match for Protocol AND Version
         RPC.Server.VerProtocolImpl highest = server.GetHighestSupportedProtocol(RPC.RpcKind
                                                                                 .RpcProtocolBuffer, protoName);
         if (highest == null)
         {
             throw new RpcNoSuchProtocolException("Unknown protocol: " + protoName);
         }
         // protocol supported but not the version that client wants
         throw new RPC.VersionMismatch(protoName, clientVersion, highest.version);
     }
     return(impl);
 }
Example #3
0
                /// <exception cref="System.IO.IOException"/>
                /// <exception cref="Org.Apache.Hadoop.Ipc.RPC.VersionMismatch"/>
                public virtual IWritable Call(RPC.Server server, string protocolName, IWritable rpcRequest
                                              , long receivedTime)
                {
                    WritableRpcEngine.Invocation call = (WritableRpcEngine.Invocation)rpcRequest;
                    if (server.verbose)
                    {
                        Log("Call: " + call);
                    }
                    // Verify writable rpc version
                    if (call.GetRpcVersion() != writableRpcVersion)
                    {
                        // Client is using a different version of WritableRpc
                        throw new RpcServerException("WritableRpc version mismatch, client side version="
                                                     + call.GetRpcVersion() + ", server side version=" + writableRpcVersion);
                    }
                    long   clientVersion = call.GetProtocolVersion();
                    string protoName;

                    RPC.Server.ProtoClassProtoImpl protocolImpl;
                    if (call.declaringClassProtocolName.Equals(typeof(VersionedProtocol).FullName))
                    {
                        // VersionProtocol methods are often used by client to figure out
                        // which version of protocol to use.
                        //
                        // Versioned protocol methods should go the protocolName protocol
                        // rather than the declaring class of the method since the
                        // the declaring class is VersionedProtocol which is not
                        // registered directly.
                        // Send the call to the highest  protocol version
                        RPC.Server.VerProtocolImpl highest = server.GetHighestSupportedProtocol(RPC.RpcKind
                                                                                                .RpcWritable, protocolName);
                        if (highest == null)
                        {
                            throw new RpcServerException("Unknown protocol: " + protocolName);
                        }
                        protocolImpl = highest.protocolTarget;
                    }
                    else
                    {
                        protoName = call.declaringClassProtocolName;
                        // Find the right impl for the protocol based on client version.
                        RPC.Server.ProtoNameVer pv = new RPC.Server.ProtoNameVer(call.declaringClassProtocolName
                                                                                 , clientVersion);
                        protocolImpl = server.GetProtocolImplMap(RPC.RpcKind.RpcWritable)[pv];
                        if (protocolImpl == null)
                        {
                            // no match for Protocol AND Version
                            RPC.Server.VerProtocolImpl highest = server.GetHighestSupportedProtocol(RPC.RpcKind
                                                                                                    .RpcWritable, protoName);
                            if (highest == null)
                            {
                                throw new RpcServerException("Unknown protocol: " + protoName);
                            }
                            else
                            {
                                // protocol supported but not the version that client wants
                                throw new RPC.VersionMismatch(protoName, clientVersion, highest.version);
                            }
                        }
                    }
                    // Invoke the protocol method
                    long      startTime = Time.Now();
                    int       qTime     = (int)(startTime - receivedTime);
                    Exception exception = null;

                    try
                    {
                        MethodInfo method = protocolImpl.protocolClass.GetMethod(call.GetMethodName(), call
                                                                                 .GetParameterClasses());
                        server.rpcDetailedMetrics.Init(protocolImpl.protocolClass);
                        object value = method.Invoke(protocolImpl.protocolImpl, call.GetParameters());
                        if (server.verbose)
                        {
                            Log("Return: " + value);
                        }
                        return(new ObjectWritable(method.ReturnType, value));
                    }
                    catch (TargetInvocationException e)
                    {
                        Exception target = e.InnerException;
                        if (target is IOException)
                        {
                            exception = (IOException)target;
                            throw (IOException)target;
                        }
                        else
                        {
                            IOException ioe = new IOException(target.ToString());
                            ioe.SetStackTrace(target.GetStackTrace());
                            exception = ioe;
                            throw ioe;
                        }
                    }
                    catch (Exception e)
                    {
                        if (!(e is IOException))
                        {
                            Log.Error("Unexpected throwable object ", e);
                        }
                        IOException ioe = new IOException(e.ToString());
                        ioe.SetStackTrace(e.GetStackTrace());
                        exception = ioe;
                        throw ioe;
                    }
                    finally
                    {
                        int processingTime = (int)(Time.Now() - startTime);
                        if (Log.IsDebugEnabled())
                        {
                            string msg = "Served: " + call.GetMethodName() + " queueTime= " + qTime + " procesingTime= "
                                         + processingTime;
                            if (exception != null)
                            {
                                msg += " exception= " + exception.GetType().Name;
                            }
                            Log.Debug(msg);
                        }
                        string detailedMetricsName = (exception == null) ? call.GetMethodName() : exception
                                                     .GetType().Name;
                        server.rpcMetrics.AddRpcQueueTime(qTime);
                        server.rpcMetrics.AddRpcProcessingTime(processingTime);
                        server.rpcDetailedMetrics.AddProcessingTime(detailedMetricsName, processingTime);
                    }
                }