예제 #1
0
 /**
  * <summary>
  * Determines whether the cursor indicated by <c>cursorID</c> is still
  * a valid cursor, and has not been invalidated by other queue readers.
  * </summary>
  *
  * <param name="cursorID">  The cursor which should be be evaluated</param>
  *
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  *      <c>MQConnection.TestCursor(QueueHandle,CursorHandle)</c>
  *      for error codes.
  * </returns>
  *
  * <seealso cref="MQConnection.TestCursor(QueueHandle,CursorHandle)">MQConnection.TestCursor(QueueHandle,CursorHandle)</seealso>
  */
 public ErrorCode TestCursor(CursorHandle cursorID)
 {
     return(con.TestCursor(que, cursorID));
 }
예제 #2
0
 /**
  * <summary>
  * Advances the cursor to the next message in the queue.
  * </summary>
  *
  * <param name="cursorID">  The cursor to be advanced.</param>
  *
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  *      <c>MQConnection.AdvanceCursor(QueueHandle,CursorHandle)</c>
  *      for error codes.
  * </returns>
  * <seealso cref="MQConnection.AdvanceCursor(QueueHandle,CursorHandle)">MQConnection.AdvanceCursor(QueueHandle,CursorHandle)</seealso>
  */
 public ErrorCode AdvanceCursor(CursorHandle cursorID)
 {
     return(con.AdvanceCursor(que, cursorID));
 }
예제 #3
0
 /**
  * <summary>
  * Attempts to locate the messaged indicated by <c>id</c>.  If the message
  * is succesfully located, the cursor will point to the message idenfified
  * and the message may be retrieved there after.
  * </summary>
  *
  * <param name="id">The recipt UUID of the message to be located </param>
  * <param name="timeout">
  *                  The maximum number of seconds the call should be allowed
  *                  before resulting in a "timeout".</param>
  * <param name="cursorID">
  *                  The cursor which should be be assigned the position
  *                  of the message indicated by <c>id</c></param>
  *
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  *      <c>MQConnection.SeekID(QueueHandle,UUID,int,CursorHandle)</c>
  *      for error codes.
  * </returns>
  *
  * <seealso cref="MQConnection.SeekID(QueueHandle,UUID,int,CursorHandle)">MQConnection.SeekID(QueueHandle,UUID,int,CursorHandle)</seealso>
  */
 public ErrorCode SeekID(UUID id, int timeout, CursorHandle cursorID)
 {
     return(con.SeekID(que, id, timeout, cursorID));
 }
예제 #4
0
 /**
  * <summary>
  * Opens a cursor for sequential reading of the queue.  The newly opened
  * cursor points to the oldest, highest priority message in the queue.
  * </summary>
  *
  * <remarks>
  * <para>Cursors may be used to violate the priority FIFO nature of the queue
  * by scanning the queue and only retreiving messages which meet the
  * criteria of the reader.  Cursor access is sequential when used in conjunction
  * with <c>AdvanceCursor(CursorHandle)</c>, however specific messages may
  * be sought out by a call to <c>SeekID(UUID,int,CursorHandle)</c>.  </para>
  * </remarks>
  *
  * <param name="cursorID">
  *                  A previously allocated reference to a <c>CursorHandle</c>
  *                  which will receive the reference to the cursor.</param>
  *
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  *      <c>MQConnection.OpenCursor(QueueHandle,CursorHandle)</c>
  *      for error codes.
  * </returns>
  * <seealso cref="MQConnection.OpenCursor(QueueHandle,CursorHandle)">MQConnection.OpenCursor(QueueHandle,CursorHandle)</seealso>
  */
 public ErrorCode OpenCursor(CursorHandle cursorID)
 {
     return(con.OpenCursor(que, cursorID));
 }
예제 #5
0
 /**
  * <summary>
  * Closes a cursor when it is nolonger needed to access the queue.  The
  * cursor is invalidated after a call to <c>CloseCursor()</c> and
  * should not be used again.
  * </summary>
  *
  * <param name="cursorID">  The cursor to be closed.</param>
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  *      <c>MQConnection.CloseCursor(QueueHandle,CursorHandle)</c>
  *      for error codes.
  * </returns>
  * <seealso cref="MQConnection.CloseCursor(QueueHandle,CursorHandle)">MQConnection.CloseCursor(QueueHandle,CursorHandle)</seealso>
  */
 public ErrorCode CloseCursor(CursorHandle cursorID)
 {
     return(con.CloseCursor(que, cursorID));
 }
예제 #6
0
        /**
         * <summary>
         * Retrieves the message pointed to by <c>cursorID</c>. The results
         * are placed in the object <c>msg</c>.
         * </summary>
         *
         * <remarks>
         * <para>Note: Retrieved messages are removed from the queue.</para>
         * </remarks>
         *
         * <param name="qhandle">		A handle to a queue previously opened by a call to OpenQueue(string)</param>
         * <param name="retrievebody">	A flag indicating whether the body of the message should be retrieved</param>
         * <param name="cursorID">		The cursor indicating the current position in the queue to be Read from</param>
         * <param name="msg">			Receives the contents of the message.</param>
         *
         * <returns>Upon success a value of <c>ErrorCode.EC_NOERROR</c>, otherwise
         * 			errors such as but not limited to could occur: <br/>
         * <table border="0" cellpadding="3" cellspacing="0">
         * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td>
         *				<td>A networking error has occurred and the conneciton
         *					is nolonger valid.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_NOMOREMESSAGES</c></td>
         *				<td>The queue is empty and no more messages are
         *					available.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_ALREADYCLOSED</c></td>
         *				<td>The queue reference is not valid as it has
         *					been closed.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td>
         *				<td>The user is not authorized to Read messages from this
         *					queue.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_CURSORINVALIDATED</c></td>
         *				<td>The cursor nolonger points to a valid location in the
         *					queue.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td>
         *				<td>The queue specified has not been opened by this connection.
         *				</td></tr>
         * </table>
         * </returns>
         *
         * <seealso cref="OpenQueue(string, QueueHandle)"/>
         */
        public ErrorCode RetrieveCursor(QueueHandle qhandle, bool retrievebody, CursorHandle cursorID, QueueMessage msg)
        {
            ErrorCode ret = ErrorCode.EC_NOERROR;

            PEEK_CURSOR_RETRIEVE_CURSOR_PARAMS	parms = new PEEK_CURSOR_RETRIEVE_CURSOR_PARAMS();
            parms.queueID = qhandle;
            parms.retrievebody = (byte)(retrievebody?1:0);
            parms.cursorID = cursorID;

            try {
                output.Write(Safmq.CMD_RETRIEVE_CURSOR);
                parms.Write(output);
                output.Flush();
                ret = getResponseCode();
                if (ret == ErrorCode.EC_NOERROR) {
                    msg.Read(input,retrievebody);
                    ret = ackRetrieveCursor(qhandle,msg);
                }
            } catch (Exception) {
                ret = ErrorCode.EC_NETWORKERROR;
            }
            return ret;
        }
예제 #7
0
 /**
  * <summary>
  * Retrieves the message pointed to by <c>cursorID</c>. The results
  * are placed in the object <c>msg</c>.  The message retrieved is
  * <i>not</i> remvoed from the queue and is available for reading by other
  * queue readers.
  *
  * <para>Note: Retrieved messages are removed from the queue.</para>
  * </summary>
  *
  * <param name="retrievebody">  A flag indicating whether the body of the message should be retrieved</param>
  * <param name="cursorID">      The cursor indicating the current position in the queue to be read from</param>
  * <param name="msg">           Receives the contents of the message.</param>
  *
  * <returns>Upon success a value of <c>Safmq.EC_NOERROR</c>, otherwise
  *          see <c>MQConnection.PeekCursor()</c> for result codes.</returns>
  * <seealso cref="MQConnection.PeekCursor(QueueHandle,bool,CursorHandle,QueueMessage)">MQConnection.Retrieve(QueueHandle,bool,int,QueueMessage)</seealso>
  */
 public ErrorCode PeekCursor(bool retrievebody, CursorHandle cursorID, QueueMessage msg)
 {
     return(con.PeekCursor(que, retrievebody, cursorID, msg));
 }
예제 #8
0
 /**
  * <summary>
  * Retrieves the message pointed to by <c>cursorID</c>. The results
  * are placed in the object <c>msg</c>.
  *
  * <para>Note: Retrieved messages are removed from the queue.</para>
  * </summary>
  *
  * <param name="retrievebody">
  *                          A flag indicating whether the body of the message should be retrieved</param>
  * <param name="cursorID">  The cursor indicating the current position in the queue to be read from</param>
  * <param name="msg">       Receives the contents of the message.</param>
  *
  * <returns>Upon success a value of <c>Safmq.EC_NOERROR</c>, otherwise
  * 			see MQConnection.Retrieve() for result codes.</returns>
  * <seealso cref="MQConnection.RetrieveCursor(QueueHandle,bool,CursorHandle,QueueMessage)">MQConnection.Retrieve(QueueHandle,bool,int,QueueMessage)</seealso>
  */
 public ErrorCode RetrieveCursor(bool retrievebody, CursorHandle cursorID, QueueMessage msg)
 {
     return con.RetrieveCursor(que,retrievebody,cursorID,msg);
 }
예제 #9
0
 /**
  * <summary>
  * Attempts to locate the messaged indicated by <c>id</c>.  If the message
  * is succesfully located, the cursor will point to the message idenfified
  * and the message may be retrieved there after.
  * </summary>
  *
  * <param name="id">The recipt UUID of the message to be located </param>
  * <param name="timeout">
  *                  The maximum number of seconds the call should be allowed
  * 					before resulting in a "timeout".</param>
  * <param name="cursorID">
  *                  The cursor which should be be assigned the position
  * 					of the message indicated by <c>id</c></param>
  *
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  * 		<c>MQConnection.SeekID(QueueHandle,UUID,int,CursorHandle)</c>
  * 		for error codes.
  * </returns>
  *
  * <seealso cref="MQConnection.SeekID(QueueHandle,UUID,int,CursorHandle)">MQConnection.SeekID(QueueHandle,UUID,int,CursorHandle)</seealso>
  */
 public ErrorCode SeekID(UUID id, int timeout, CursorHandle cursorID)
 {
     return con.SeekID(que,id,timeout,cursorID);
 }
예제 #10
0
 /**
  * <summary>
  * Closes a cursor when it is nolonger needed to access the queue.  The
  * cursor is invalidated after a call to <c>CloseCursor()</c> and
  * should not be used again.
  * </summary>
  *
  * <param name="cursorID">  The cursor to be closed.</param>
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  * 		<c>MQConnection.CloseCursor(QueueHandle,CursorHandle)</c>
  * 		for error codes.
  * </returns>
  * <seealso cref="MQConnection.CloseCursor(QueueHandle,CursorHandle)">MQConnection.CloseCursor(QueueHandle,CursorHandle)</seealso>
  */
 public ErrorCode CloseCursor(CursorHandle cursorID)
 {
     return con.CloseCursor(que,cursorID);
 }
예제 #11
0
 /**
  * <summary>
  * Opens a cursor for sequential reading of the queue.  The newly opened
  * cursor points to the oldest, highest priority message in the queue.
  * </summary>
  *
  * <remarks>
  * <para>Cursors may be used to violate the priority FIFO nature of the queue
  * by scanning the queue and only retreiving messages which meet the
  * criteria of the reader.  Cursor access is sequential when used in conjunction
  * with <c>AdvanceCursor(CursorHandle)</c>, however specific messages may
  * be sought out by a call to <c>SeekID(UUID,int,CursorHandle)</c>.  </para>
  * </remarks>
  *
  * <param name="cursorID">
  *                  A previously allocated reference to a <c>CursorHandle</c>
  * 					which will receive the reference to the cursor.</param>
  *
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  * 		<c>MQConnection.OpenCursor(QueueHandle,CursorHandle)</c>
  * 		for error codes.
  * </returns>
  * <seealso cref="MQConnection.OpenCursor(QueueHandle,CursorHandle)">MQConnection.OpenCursor(QueueHandle,CursorHandle)</seealso>
  */
 public ErrorCode OpenCursor(CursorHandle cursorID)
 {
     return con.OpenCursor(que,cursorID);
 }
예제 #12
0
 /**
  * <summary>
  * Advances the cursor to the next message in the queue.
  * </summary>
  *
  * <param name="cursorID">  The cursor to be advanced.</param>
  *
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  * 		<c>MQConnection.AdvanceCursor(QueueHandle,CursorHandle)</c>
  * 		for error codes.
  * </returns>
  * <seealso cref="MQConnection.AdvanceCursor(QueueHandle,CursorHandle)">MQConnection.AdvanceCursor(QueueHandle,CursorHandle)</seealso>
  */
 public ErrorCode AdvanceCursor(CursorHandle cursorID)
 {
     return con.AdvanceCursor(que,cursorID);
 }
예제 #13
0
        /**
         * <summary>
         * Closes a cursor when it is nolonger needed to access the queue.  The
         * cursor is invalidated after a call to <c>CloseCursor()</c> and
         * should not be used again.
         * </summary>
         *
         * <param name="qhandle">   A handle to a queue previously opened by a call to OpenQueue(string)</param>
         * <param name="cursorID">  The cursor to be closed.</param>
         *
         * <returns><c>ErrorCode.EC_NOERROR</c> upon success, otherwise errors returned
         * could be but are not limited to:<br/>
         * <table border="0" cellpadding="3" cellspacing="0">
         * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td>
         *				<td>A networking error has occurred and the conneciton
         *					is nolonger valid.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td>
         *				<td>The user is not authorized to Read messages from this
         *					queue.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td>
         *				<td>The queue specified has not been opened by this connection.
         *				</td></tr>
         * </table>
         * </returns>
         *
         * <seealso cref="OpenQueue(string, QueueHandle)"/>
         */
        public ErrorCode CloseCursor(QueueHandle qhandle, CursorHandle cursorID)
        {
            ErrorCode ret = ErrorCode.EC_NOERROR;
            CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS	parms = new CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS();
            parms.queueID = qhandle;
            parms.cursorID = cursorID;

            try {
                output.Write(Safmq.CMD_CLOSE_CURSOR);
                parms.Write(output);
                output.Flush();
                ret = getResponseCode();
            } catch (Exception) {
                ret = ErrorCode.EC_NETWORKERROR;
            }
            return ret;
        }
예제 #14
0
        /**
         * <summary>
         * Attempts to locate the messaged indicated by <c>id</c>.  If the message
         * is succesfully located, the cursor will point to the message idenfified
         * and the message may be retrieved there after.
         * </summary>
         *
         * <param name="qhandle">		A handle to a queue previously opened by a call to OpenQueue(string)</param>
         * <param name="id">		    The recipt UUID of the message to be located </param>
         * <param name="timeoutseconds">The maximum number of seconds the call should be allowed
         *           					before resulting in a "timeout".</param>
         * <param name="cursorID">	    The cursor which should be be assigned the position
         *           					of the message indicated by <c>id</c></param>
         *
         * <returns><c>ErrorCode.EC_NOERROR</c> upon success, otherwise errors returned
         * could be but are not limited to:<br/>
         * <table border="0" cellpadding="3" cellspacing="0">
         * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td>
         *				<td>A networking error has occurred and the conneciton
         *					is nolonger valid.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td>
         *				<td>The user is not authorized to Read messages from this
         *					queue.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td>
         *				<td>The queue specified has not been opened by this connection.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_CURSORINVALIDATED</c></td>
         *				<td>The cursor is no longer valid.
         *				</td></tr>
         * </table>
         * </returns>
         *
         * <seealso cref="OpenQueue(string, QueueHandle)"/>
         */
        public ErrorCode SeekID(QueueHandle qhandle, UUID id, int timeoutseconds, CursorHandle cursorID)
        {
            ErrorCode ret = ErrorCode.EC_NOERROR;
            SEEK_ID_PARAMS	parms = new SEEK_ID_PARAMS();
            parms.queueID = qhandle;
            parms.cursorID = cursorID;
            parms.reciptID = id;
            parms.timeoutseconds = timeoutseconds;

            try {
                output.Write(Safmq.CMD_SEEK_ID);
                parms.Write(output);
                output.Flush();
                ret = getResponseCode();
            } catch (Exception) {
                ret = ErrorCode.EC_NETWORKERROR;
            }
            return ret;
        }
예제 #15
0
        public void test_PeekID_PeekFront_OpenCursor_PeekCursor_SeekID_RetrieveCursor_AdvanceCursor_TestCurosr_CloseCursor_RetrieveID()
        {
            MQConnection con = null;
            try {
                con = connectToServer(address, null, null);

                addAllGroups(con);
                addAllUsers(con);
                addAllQueues(con);

                QueueHandle handle = new QueueHandle();
                ErrorCode ec = con.OpenQueue(TEST_QUEUE[0], handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to open queue: " + TEST_QUEUE[0]);

                sendMessages(con, handle, 5, 0);
                QueueMessage msg = new QueueMessage();
                StreamWriter sw = new StreamWriter(msg.Stream);
                sw.WriteLine(SPECIAL_MESSAGE);
                sw.Close();

                byte[] b = { 0, 0, 0, 0, 0, 0, 0, 0 };
                UUID uuid = new UUID(new Guid(123456789,4321,1234,b));
                msg.ReciptID = uuid;
                //msg.ReciptID = ((UUID)uuid.Clone());

                ec = con.Enqueue(handle, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to write special message");

                sendMessages(con, handle, 5, 5);

                msg = new QueueMessage();
                ec = con.PeekID(handle, true, uuid, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekID:" + ec);

                string txt = (new StreamReader(msg.Stream)).ReadLine();
                Console.WriteLine("txt:\t\t\t" + txt);
                Console.WriteLine("uuid:\t\t\t" + (Guid)uuid);
                Console.WriteLine("msg.ReceiptID:\t" + (Guid)msg.ReciptID);
                Console.WriteLine("txt.Equals(SPECIAL_MESSAGE): " + txt.Equals(SPECIAL_MESSAGE));
                Console.WriteLine("uuid.Equals(msg.ReceiptID)): " + uuid.Equals(msg.ReciptID));
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE) && uuid.Equals(msg.ReciptID), "Incorrect PeekID Message: " + (Guid)msg.ReciptID);

                msg = new QueueMessage();
                ec = con.PeekFront(handle, true, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekFront");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("0"), "Incorrect PeekFront Message: body=" + txt);

                CursorHandle cur = new CursorHandle();

                ec = con.OpenCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to OpenCursor");

                ec = con.SeekID(handle, uuid, 0, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to SeekID");
                msg = new QueueMessage();
                ec = con.PeekCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekCursor");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE) && uuid.Equals(msg.ReciptID), "Incorrect PeekCursor Message: " + msg.ReciptID);

                ec = con.AdvanceCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to AdvanceCursor");
                msg = new QueueMessage();
                ec = con.PeekCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekCursor (after advance)");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("5"), "Incorrect PeekCursor (after advance) Message: " + msg.ReciptID);

                msg = new QueueMessage();
                ec = con.RetrieveCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("5"), "Incorrect PeekCursor (after RetrieveCursor) Message: " + msg.ReciptID);

                ec = con.TestCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to test Cursor, ec: " + ec);

                ec = con.CloseCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to CloseCursor, ec: " + ec);

                msg = new QueueMessage();
                ec = con.RetrieveID(handle, true, uuid, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveID");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE) && uuid.Equals(msg.ReciptID), "Incorrect RetrieveID Message: " + msg.ReciptID);

                int[] bodies = { 0, 1, 2, 3, 4, 6, 7, 8, 9 }; // 5 was retrieved above.
                for(int x=0; x<bodies.Length; x++) {
                    msg = new QueueMessage();
                    ec = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to retrieve message: " + x);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Console.WriteLine("txt: " + txt);
                    Assert.IsTrue(int.Parse(txt) == bodies[x], "Incorrect message: " + txt);
                }

                ec = con.CloseQueue(handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to Close queue");

            } finally {
                if (con != null)
                    con.Close();
            }
        }
예제 #16
0
 /**
  * <summary>
  * Determines whether the cursor indicated by <c>cursorID</c> is still
  * a valid cursor, and has not been invalidated by other queue readers.
  * </summary>
  *
  * <param name="cursorID">  The cursor which should be be evaluated</param>
  *
  * <returns><c>Safmq.EC_NOERROR</c> upon success, otherwise see
  * 		<c>MQConnection.TestCursor(QueueHandle,CursorHandle)</c>
  * 		for error codes.
  * </returns>
  *
  * <seealso cref="MQConnection.TestCursor(QueueHandle,CursorHandle)">MQConnection.TestCursor(QueueHandle,CursorHandle)</seealso>
  */
 public ErrorCode TestCursor(CursorHandle cursorID)
 {
     return con.TestCursor(que,cursorID);
 }
예제 #17
0
        public void test_Transactions()
        {
            MQConnection con = null;
            try {
                con = connectToServer(address, null, null);

                addAllGroups(con);
                addAllUsers(con);
                addAllQueues(con);

                QueueHandle handle = new QueueHandle();
                ErrorCode ec = con.OpenQueue(TEST_QUEUE[0], handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to open queue: " + TEST_QUEUE[0]);

                sendMessages(con, handle, 10, 0);

                ec = con.BeginTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to BeginTransaction:" + ec);
                CursorHandle cur = new CursorHandle();

                ec = con.OpenCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to OpenCursor:" + ec);

                ec = con.AdvanceCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to AdvanceCursor:" + ec);
                ec = con.AdvanceCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to AdvanceCursor:" + ec);

                QueueMessage msg = new QueueMessage();
                ec = con.RetrieveCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                string txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("2"), "Incorrect Message: " + txt + " should be 2");

                msg = new QueueMessage();
                ec = con.RetrieveCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("3"), "Incorrect Message: " + txt + " should be 3");

                msg = new QueueMessage();
                ec = con.Retrieve(handle, true, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("0"), "Incorrect Message: " + txt + " should be 0");

                int[] ids = { 1, 4, 5, 6, 7, 8, 9 };
                for(int x=0;x<ids.Length;x++) {
                    msg = new QueueMessage();
                    ec = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Console.WriteLine("txt: " + txt);
                    Assert.IsTrue(int.Parse(txt) == ids[x], "Incorrect Message: " + txt + " should be " + ids[x]);
                }

                ec = con.RollbackTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RollbackTransaction:" + ec);

                for(int x=0;x<8;x++) {
                    msg = new QueueMessage();
                    ec = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Assert.IsTrue(int.Parse(txt) == x, "Incorrect Message: " + txt + " should be " + x);
                }

                ec = con.CommitTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to CommitTransaction:" + ec);

                for(int x=0;x<2;x++) {
                    msg = new QueueMessage();
                    ec = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Assert.IsTrue(int.Parse(txt) == x + 8, "Incorrect Message: " + txt + " should be " + (x + 8));
                }

                ec = con.RollbackTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RollbackTransaction:" + ec);

                ec = con.EndTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RollbackTransaction:" + ec);

                for(int x=0;x<2;x++) {
                    msg = new QueueMessage();
                    ec = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Assert.IsTrue(int.Parse(txt) == x + 8, "Incorrect Message: " + txt + " should be " + (x + 8));
                }

                msg = new QueueMessage();
                ec = con.Retrieve(handle, true, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOMOREMESSAGES, "Able to RetrieveCursor:" + ec);

                ec = con.CloseQueue(handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to CloseQueue:" + ec);
            } finally {
                if (con != null)
                    con.Close();
            }
        }
예제 #18
0
        /**
         * <summary>
         * Opens a cursor for sequential reading of the queue.  The newly opened
         * cursor points to the oldest, highest priority message in the queue.
         * </summary>
         *
         * <remarks>
         * <para>Cursors may be used to violate the priority FIFO nature of the queue
         * by scanning the queue and only retreiving messages which meet the
         * criteria of the reader.  Cursor access is sequential when used in conjunction
         * with <c>AdvanceCursor(CursorHandle)</c>, however specific messages may
         * be sought out by a call to <c>SeekID(UUID,int,CursorHandle)</c>.  </para>
         * </remarks>
         *
         * <param name="qhandle">	A handle to a queue previously opened by a call to OpenQueue(string)</param>
         * <param name="cursorID"> 	A previously allocated reference to a <c>CursorHandle</c>
         *      					which will receive the reference to the cursor.</param>
         * <returns><c>ErrorCode.EC_NOERROR</c> upon success, otherwise errors returned
         * could be but are not limited to:<br/>
         * <table border="0" cellpadding="3" cellspacing="0">
         * <tr><td><c>ErrorCode.EC_NETWORKERROR</c></td>
         *				<td>A networking error has occurred and the conneciton
         *					is nolonger valid.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_NOTAUTHORIZED</c></td>
         *				<td>The user is not authorized to Read messages from this
         *					queue.
         *				</td></tr>
         * <tr><td><c>ErrorCode.EC_NOTOPEN</c></td>
         *				<td>The queue specified has not been opened by this connection.
         *				</td></tr>
         * </table>
         * </returns>
         *
         * <seealso cref="OpenQueue(string, QueueHandle)"/>
         */
        public ErrorCode OpenCursor(QueueHandle qhandle, CursorHandle cursorID)
        {
            ErrorCode ret = ErrorCode.EC_NOERROR;
            QUEUE_CLOSE_OPEN_CURSOR_PARAMS	parms = new QUEUE_CLOSE_OPEN_CURSOR_PARAMS();
            parms.queueID = qhandle;

            try {
                output.Write(Safmq.CMD_OPEN_CURSOR);
                parms.Write(output);
                output.Flush();
                ret = getResponseCode();
                if (ret == ErrorCode.EC_NOERROR) {
                    cursorID.handle = input.ReadInt32();
                }
            } catch (Exception) {
                ret = ErrorCode.EC_NETWORKERROR;
            }

            return ret;
        }