示例#1
0
        protected internal virtual bool TryGetAllInfo(int timeout, out IEnumerable <HandleInfo> infos, ref Exception exception)
        {
            IList <HandleInfo> out_infos     = emptryhandleinfos;
            Exception          out_exception = null;

            try
            {
                if (timeout <= 0 && timeout != -1)
                {
                    out_exception = EventWaitHandle.NewTimeoutException();
                    return(false);
                }
                using (ManualResetEvent events = new ManualResetEvent(false))
                {
                    bool success = false;
                    bool abort   = false;
                    if (!MalockMessage.TryInvokeAsync(this, MalockNodeMessage.New(null, this.Identity,
                                                                                  MalockNodeMessage.CLIENT_COMMAND_GETALLINFO, timeout), timeout,
                                                      (errno, message, stream) =>
                    {
                        if (errno == MalockMessage.Mappable.ERROR_NOERROR)
                        {
                            if (message.Command == MalockNodeMessage.CLIENT_COMMAND_GETALLINFO)
                            {
                                out_infos = new List <HandleInfo>();
                                success = HandleInfo.Fill(out_infos, stream);
                            }
                        }
                        else if (errno == MalockMessage.Mappable.ERROR_ABORTED)
                        {
                            abort = true;
                        }
                        else if (errno == MalockMessage.Mappable.ERROR_TIMEOUT)
                        {
                            out_exception = EventWaitHandle.NewTimeoutException();
                        }
                        events.Set();
                    }, ref out_exception) || out_exception != null)
                    {
                        return(false);
                    }
                    events.WaitOne();
                    if (abort)
                    {
                        out_exception = EventWaitHandle.NewAbortedException();
                        return(false);
                    }
                    return(success);
                }
            }
            finally
            {
                infos     = out_infos;
                exception = out_exception;
            }
        }
示例#2
0
 protected internal virtual void GetAllInfoAsync(int timeout, Action <int, IEnumerable <HandleInfo> > state)
 {
     if (state == null)
     {
         throw new ArgumentNullException("callback");
     }
     if (timeout <= 0 && timeout != -1)
     {
         state(kERROR_TIMEOUT, emptryhandleinfos);
     }
     else
     {
         Exception exception = null;
         if (!MalockMessage.TryInvokeAsync(this,
                                           MalockNodeMessage.New(null, this.Identity, MalockNodeMessage.CLIENT_COMMAND_GETALLINFO, timeout), timeout,
                                           (errno, message, stream) =>
         {
             if (errno == MalockMessage.Mappable.ERROR_NOERROR)
             {
                 bool error = true;
                 if (message.Command == MalockNodeMessage.CLIENT_COMMAND_GETALLINFO)
                 {
                     IList <HandleInfo> results = new List <HandleInfo>();
                     if (HandleInfo.Fill(results, stream))
                     {
                         error = false;
                         state(kERROR_NOERROR, results);
                     }
                 }
                 if (error)
                 {
                     state(kERROR_ERRORNO, emptryhandleinfos);
                 }
             }
             else if (errno == MalockMessage.Mappable.ERROR_ABORTED)
             {
                 state(kERROR_ABORTED, emptryhandleinfos);
             }
             else if (errno == MalockMessage.Mappable.ERROR_TIMEOUT)
             {
                 state(kERROR_TIMEOUT, emptryhandleinfos);
             }
         }, ref exception))
         {
             state(kERROR_ABORTED, emptryhandleinfos);
         }
     }
 }
示例#3
0
 private MalockMessage NewMessage(string key, string identity, byte command, int sequence, int timeout)
 {
     return(MalockNodeMessage.New(key, identity, command, sequence, timeout));
 }
示例#4
0
 protected MalockMessage NewMesssage(byte command, int timeout)
 {
     return(MalockNodeMessage.New(this.Key, this.GetIdentity(), command, timeout));
 }
示例#5
0
        protected virtual void OnConnected(object sender, EventArgs e)
        {
            MalockMessage message = MalockNodeMessage.New(null, this.Identity, MalockNodeMessage.SERVER_COMMAND_SYN_LOADALLINFO, -1);

            MalockMessage.TrySendMessage(this, message);
        }