Novell.Directory.Ldap.MessageAgent.getLdapMessage C# (CSharp) Method

getLdapMessage() private method

private getLdapMessage ( Integer32 msgId ) : Object
msgId Integer32
return System.Object
        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)
                {
                    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);
                        }
                        catch (System.Threading.ThreadInterruptedException ex)
                        {
                        }
                    } /* end while */
                } /* end synchronized */
            }
        }

Same methods

MessageAgent::getLdapMessage ( System msgId ) : Object

Usage Example

        /// <summary> Private implementation of getResponse.
        /// Has an Integer object as a parameter so we can distinguish
        /// the null and the message number case
        /// </summary>
//		private LdapMessage getResponse(System.Int32 msgid)
        private LdapMessage getResponse(Integer32 msgid)
        {
            System.Object  resp;
            RfcLdapMessage message;
            LdapMessage    response;

            if ((resp = agent.getLdapMessage(msgid)) == null)
            {
                // blocks
                return(null); // no messages from this agent
            }
            // Local error occurred, contains a LocalException
            if (resp is LdapResponse)
            {
                return((LdapMessage)resp);
            }
            // Normal message handling
            message = (RfcLdapMessage)resp;
            switch (message.Type)
            {
            case LdapMessage.SEARCH_RESPONSE:
                response = new LdapSearchResult(message);
                break;

            case LdapMessage.SEARCH_RESULT_REFERENCE:
                response = new LdapSearchResultReference(message);
                break;

            case LdapMessage.EXTENDED_RESPONSE:
                ExtResponseFactory fac = new ExtResponseFactory();
                response = ExtResponseFactory.convertToExtendedResponse(message);
                break;

            case LdapMessage.INTERMEDIATE_RESPONSE:
                response = IntermediateResponseFactory.convertToIntermediateResponse(message);
                break;

            default:
                response = new LdapResponse(message);
                break;
            }
            return(response);
        }