Пример #1
0
        internal System.Object getLdapMessage(Integer32 msgId)
        {
            System.Object rfcMsg;
            // If no messages for this agent, just return null
            if (messages.Count == 0)
            {
                return(null);
            }
            if (msgId != null)
            {
                // Request messages for a specific ID
                try
                {
                    // Get message for this ID
//					Message info = messages.findMessageById(msgId);
                    Message info = messages.findMessageById(msgId.intValue);
                    rfcMsg = info.waitForReply();                     // blocks for a response
                    if (!info.acceptsReplies() && !info.hasReplies())
                    {
                        // Message complete and no more replies, remove from id list
                        SupportClass.VectorRemoveElement(messages, info);
                        info.Abandon(null, null);                         // Get rid of resources
                    }
                    else
                    {
                    }
                    return(rfcMsg);
                }
                catch (System.FieldAccessException ex)
                {
                    // no such message id
                    return(null);
                }
            }
            else
            {
                // A msgId was NOT specified, any message will do
                lock (messages.SyncRoot)
                {
                    while (true)
                    {
                        int     next = indexLastRead + 1;
                        Message info;
                        for (int i = 0; i < messages.Count; i++)
                        {
                            if (next >= messages.Count)
                            {
                                next = 0;
                            }
                            info          = (Message)messages[next];
                            indexLastRead = next++;
                            rfcMsg        = info.Reply;
                            // Check this request is complete
                            if (!info.acceptsReplies() && !info.hasReplies())
                            {
                                // Message complete & no more replies, remove from id list
                                SupportClass.VectorRemoveElement(messages, info);         // remove from list
                                info.Abandon(null, null);                                 // Get rid of resources
                                // Start loop at next message that is now moved
                                // to the current position in the Vector.
                                i -= 1;
                            }
                            if (rfcMsg != null)
                            {
                                // We got a reply
                                return(rfcMsg);
                            }
                            else
                            {
                                // We found no reply here
                            }
                        }                         // end for loop */
                        // Messages can be removed in this loop, we we must
                        // check if any messages left for this agent
                        if (messages.Count == 0)
                        {
                            return(null);
                        }

                        // No data, wait for something to come in.
                        try
                        {
                            System.Threading.Monitor.Wait(messages.SyncRoot);
                        }
                        catch (System.Threading.ThreadInterruptedException ex)
                        {
                        }
                    }             /* end while */
                }                 /* end synchronized */
            }
        }
Пример #2
0
        /// <summary>
        ///     Returns a response queued, or waits if none queued.
        /// </summary>
        internal object GetLdapMessage(int?msgId)
        {
            object rfcMsg;

            // If no messages for this agent, just return null
            if (_messages.Count == 0)
            {
                return(null);
            }

            if (msgId.HasValue)
            {
                // Request messages for a specific ID
                try
                {
                    // Get message for this ID
                    var info = _messages.FindMessageById(msgId.Value);
                    rfcMsg = info.WaitForReply(); // blocks for a response
                    if (!info.AcceptsReplies() && !info.HasReplies())
                    {
                        // Message complete and no more replies, remove from id list
                        SupportClass.VectorRemoveElement(_messages, info);
                        info.Abandon(null, null); // Get rid of resources
                    }

                    return(rfcMsg);
                }
                catch (FieldAccessException)
                {
                    // no such message id
                    return(null);
                }
            }

            // A msgId was NOT specified, any message will do
            lock (_messages)
            {
                while (true)
                {
                    var     next = _indexLastRead + 1;
                    Message info;
                    for (var i = 0; i < _messages.Count; i++)
                    {
                        if (next >= _messages.Count)
                        {
                            next = 0;
                        }

                        info           = (Message)_messages[next];
                        _indexLastRead = next++;
                        rfcMsg         = info.Reply;

                        // Check this request is complete
                        if (!info.AcceptsReplies() && !info.HasReplies())
                        {
                            // Message complete & no more replies, remove from id list
                            SupportClass.VectorRemoveElement(_messages, info); // remove from list
                            info.Abandon(null, null);                          // Get rid of resources

                            // Start loop at next message that is now moved
                            // to the current position in the Vector.
                            i -= 1;
                        }

                        if (rfcMsg != null)
                        {
                            // We got a reply
                            return(rfcMsg);
                        }
                    } // end for loop */

                    // Messages can be removed in this loop, we we must
                    // check if any messages left for this agent
                    if (_messages.Count == 0)
                    {
                        return(null);
                    }

                    // No data, wait for something to come in.
                    Monitor.Wait(_messages);
                } /* end while */
            }     /* end synchronized */
        }