# File lib/mcollective/rpc/agent.rb, line 62
      def handlemsg(msg, connection)
        @request = RPC::Request.new(msg, @ddl)
        @reply = RPC::Reply.new(@request.action, @ddl)

        begin
          # Incoming requests need to be validated against the DDL thus reusing
          # all the work users put into creating DDLs and creating a consistent
          # quality of input validation everywhere with the a simple once off
          # investment of writing a DDL
          @request.validate!

          # Calls the authorization plugin if any is defined
          # if this raises an exception we wil just skip processing this
          # message
          authorization_hook(@request) if respond_to?("authorization_hook")

          # Audits the request, currently continues processing the message
          # we should make this a configurable so that an audit failure means
          # a message wont be processed by this node depending on config
          audit_request(@request, connection)

          before_processing_hook(msg, connection)

          if respond_to?("#{@request.action}_action")
            send("#{@request.action}_action")
          else
            raise UnknownRPCAction, "Unknown action '#{@request.action}' for agent '#{@request.agent}'"
          end
        rescue RPCAborted => e
          @reply.fail e.to_s, 1

        rescue UnknownRPCAction => e
          @reply.fail e.to_s, 2

        rescue MissingRPCData => e
          @reply.fail e.to_s, 3

        rescue InvalidRPCData, DDLValidationError => e
          @reply.fail e.to_s, 4

        rescue UnknownRPCError => e
          Log.error("%s#%s failed: %s: %s" % [@agent_name, @request.action, e.class, e.to_s])
          Log.error(e.backtrace.join("\n\t"))
          @reply.fail e.to_s, 5

        rescue Exception => e
          Log.error("%s#%s failed: %s: %s" % [@agent_name, @request.action, e.class, e.to_s])
          Log.error(e.backtrace.join("\n\t"))
          @reply.fail e.to_s, 5

        end

        after_processing_hook

        if @request.should_respond?
          return @reply.to_hash
        else
          Log.debug("Client did not request a response, surpressing reply")
          return nil
        end
      end