⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mqconnection.java

📁 一个简单实用的开源C++消息中间件SAFMQ - [软件开发] - [开源 消息中间件 SAFMQ ] 2006-11-23 在很多网络应用中
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 * 
	 * @return	Upon success a value of <code>Safmq.EC_NOERROR</code>, otherwise 
	 * 			errors such as but not limited to could occur: <br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOMOREMESSAGES</code></td>
	 *				<td>The queue is empty and no more messages are
	 *					available.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_ALREADYCLOSED</code></td>
	 *				<td>The queue reference is not valid as it has 
	 *					been closed.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The user is not authorized to read messages from this
	 *					queue.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTOPEN</code></td>
	 *				<td>The queue specified has not been opened by this connection.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_TIMEDOUT</code></td>
	 *				<td>The operation timed out before a message became available.
	 *				</td></tr>
	 *</table>
	 * @see 	#OpenQueue(String, QueueHandle)
	 */
	public int PeekFront(QueueHandle qhandle, boolean retrievebody, int timeoutseconds, QueueMessage msg) {
		int	ret = Safmq.EC_NOERROR;

		RETRIEVE_PEEK_FRONT_PARAMS	params = new RETRIEVE_PEEK_FRONT_PARAMS();
		params.queueID = qhandle.handle;
		params.retrievebody = (byte)(retrievebody?1:0);
		params.timeoutseconds = timeoutseconds;

		try {
			out.write(Safmq.CMD_PEEK_FRONT);
			params.write(out);
			out.flush();
			ret = getResponseCode();
			if (ret == Safmq.EC_NOERROR)
				msg.read(in,retrievebody);
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}

	/**
	 * Gathers the message identified by <code>id</code> in the message's 
	 * recipt id, set prior to the message having been enqueued (See: 
	 * <code>Enqueue(QueueMessage)</code>. The results  are placed in the object
	 * <code>msg</code>.  The message retrieved is <i>not</i> remvoed from the 
	 * queue and is available for reading by other queue readers.
	 * 
	 * <p>Note: Message responsders will typically place the message id of the original
	 * message in the recipt id of the message being returned.  This round-trip
	 * message identification is provided by SAFMQ as a method for coordinated two-way
	 * communications.</p>
	 * 
	 * @param qhandle		A handle to a queue previously opened by a call to OpenQueue(String)
	 * @param retrievebody	A flag indicating whether the body of the message should be retrieved
	 * @param id			The UUID of the message to be retrieved.
	 * @param timeoutseconds	The number of seconds to wait before returning, a value of zero (0) will
	 * 						cause the method to return immediately if no messages are present on the queue,
	 * 						a value of (-1) will cause the method to wait until a message is placed on the queue.
	 * @param msg			Receives the contents of the message.
	 * 
	 * @return	Upon success a value of <code>Safmq.EC_NOERROR</code>, otherwise 
	 * 			errors such as but not limited to could occur: <br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOMOREMESSAGES</code></td>
	 *				<td>The queue is empty and no more messages are
	 *					available.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_ALREADYCLOSED</code></td>
	 *				<td>The queue reference is not valid as it has 
	 *					been closed.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The user is not authorized to read messages from this
	 *					queue.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTOPEN</code></td>
	 *				<td>The queue specified has not been opened by this connection.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_TIMEDOUT</code></td>
	 *				<td>The operation timed out before a message became available.
	 *				</td></tr>
	 *</table>
	 * @see #Enqueue(QueueHandle, QueueMessage) Enqueue(QueueMessage)
	 * @see #OpenQueue(String, QueueHandle)
	 */
	public int PeekID(QueueHandle qhandle, boolean retrievebody, UUID id, int timeoutseconds, QueueMessage msg) {
		int	ret = Safmq.EC_NOERROR;

		RETRIEVE_ID_PEEK_ID_PARAMS	params = new RETRIEVE_ID_PEEK_ID_PARAMS();
		params.queueID = qhandle.handle;
		params.retrievebody = (byte)(retrievebody?1:0);
		params.reciptID = id;
		params.timeoutseconds = timeoutseconds;
		
		try {
			out.write(Safmq.CMD_PEEK_ID);
			params.write(out);
			out.flush();
			ret = getResponseCode();
			if (ret == Safmq.EC_NOERROR)
				msg.read(in,retrievebody);
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}

	/**
	 * Retrieves the message pointed to by <code>cursorID</code>. The results  
	 * are placed in the object <code>msg</code>.  The message retrieved is 
	 * <i>not</i> remvoed from the queue and is available for reading by other 
	 * queue readers.
	 * 
	 * <p>Note: Retrieved messages are removed from the queue.</p>
	 * 
	 * @param qhandle		A handle to a queue previously opened by a call to OpenQueue(String)
	 * @param retrievebody	A flag indicating whether the body of the message should be retrieved
	 * @param cursorID		The cursor indicating the current position in the queue to be read from
	 * @param msg			Receives the contents of the message.
	 * 
	 * @return	Upon success a value of <code>Safmq.EC_NOERROR</code>, otherwise 
	 * 			errors such as but not limited to could occur: <br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOMOREMESSAGES</code></td>
	 *				<td>The queue is empty and no more messages are
	 *					available.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_ALREADYCLOSED</code></td>
	 *				<td>The queue reference is not valid as it has 
	 *					been closed.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The user is not authorized to read messages from this
	 *					queue.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTOPEN</code></td>
	 *				<td>The queue specified has not been opened by this connection.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_CURSORINVALIDATED</code></td>
	 *				<td>The cursor nolonger points to a valid location in the
	 *					queue.
	 *				</td></tr>
	 *</table>
	 * @see #OpenQueue(String, QueueHandle)
	 */
	public int PeekCursor(QueueHandle qhandle, boolean retrievebody, CursorHandle cursorID, QueueMessage msg) {
		int	ret = Safmq.EC_NOERROR;

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

		try {
			out.write(Safmq.CMD_PEEK_CURSOR);
			params.write(out);
			out.flush();
			ret = getResponseCode();
			if (ret == Safmq.EC_NOERROR) {
				msg.read(in,retrievebody);
			}
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}
	
	/**
	 * Opens a cursor for sequential reading of the queue.  The newly opened
	 * cursor points to the oldest, highest priority message in the queue.
	 * 
	 * <p>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 <code>AdvanceCursor(CursorHandle)</code>, however specific messages may
	 * be sought out by a call to <code>SeekID(UUID,int,CursorHandle)</code>.  </p>
	 * 
	 * @param qhandle		A handle to a queue previously opened by a call to OpenQueue(String)
	 * @param cursorID 	A previously allocated reference to a <code>CursorHandle</code>
	 * 					which will receive the reference to the cursor.
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The user is not authorized to read messages from this
	 *					queue.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTOPEN</code></td>
	 *				<td>The queue specified has not been opened by this connection.
	 *				</td></tr>
	 *</table>
	 *
	 *  @see #OpenQueue(String, QueueHandle)
	 */
	public int OpenCursor(QueueHandle qhandle, CursorHandle cursorID) {
		int ret = Safmq.EC_NOERROR;
		QUEUE_CLOSE_OPEN_CURSOR_PARAMS	params = new QUEUE_CLOSE_OPEN_CURSOR_PARAMS();
		params.queueID = qhandle.handle;
		
		try {
			out.write(Safmq.CMD_OPEN_CURSOR);
			params.write(out);
			out.flush();
			ret = getResponseCode();
			if (ret == Safmq.EC_NOERROR) {
				cursorID.handle = in.readInt();
			}
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}

		return ret;
	}
	
	/**
	 * Closes a cursor when it is nolonger needed to access the queue.  The
	 * cursor is invalidated after a call to <code>CloseCursor()</code> and
	 * should not be used again.
	 * 
	 * @param qhandle		A handle to a queue previously opened by a call to OpenQueue(String)
	 * @param cursorID The cursor to be closed.
	 * 
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The user is not authorized to read messages from this
	 *					queue.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTOPEN</code></td>
	 *				<td>The queue specified has not been opened by this connection.
	 *				</td></tr>
	 *</table>
	 *
	 *  @see #OpenQueue(String, QueueHandle)
	 */
	public int CloseCursor(QueueHandle qhandle, CursorHandle cursorID) {
		int ret = Safmq.EC_NOERROR;
		CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS	params = new CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS();
		params.queueID = qhandle.handle;
		params.cursorID = cursorID.handle;

		try {
			out.write(Safmq.CMD_CLOSE_CURSOR);
			params.write(out);
			out.flush();
			ret = getResponseCode();
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}
		return ret;
	}
	
	/**
	 * Advances the cursor to the next message in the queue.
	 * 
	 * @param qhandle		A handle to a queue previously opened by a call to OpenQueue(String)
	 * @param cursorID The cursor to be advanced.
	 * @return <code>Safmq.EC_NOERROR</code> upon success, otherwise errors returned
	 * could be but are not limited to:<br>
	 *<table border=0 cellpadding=3 cellspacing=0>
	 *<tr><td><code>Safmq.EC_NETWORKERROR</code></td>
	 *				<td>A networking error has occurred and the conneciton
	 *					is nolonger valid.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTAUTHORIZED</code></td>
	 *				<td>The user is not authorized to read messages from this
	 *					queue.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_NOTOPEN</code></td>
	 *				<td>The queue specified has not been opened by this connection.
	 *				</td></tr>
	 *<tr><td><code>Safmq.EC_CURSORINVALIDATED</code></td>
	 *				<td>The cursor is no longer valid.
	 *				</td></tr>
	 *</table>
	 *
	 *  @see #OpenQueue(String, QueueHandle)
	 */
	public int AdvanceCursor(QueueHandle qhandle, CursorHandle cursorID) {
		int ret = Safmq.EC_NOERROR;
		CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS	params = new CLOSE_CURSOR_ADVANCE_CURSOR_TEST_CURSOR_PARAMS();
		params.queueID = qhandle.handle;
		params.cursorID = cursorID.handle ;

		try {
			out.write(Safmq.CMD_ADVANCE_CURSOR);
			params.write(out);
			out.flush();
			ret = getResponseCode();
		} catch (IOException e) {
			ret = Safmq.EC_NETWORKERROR;
		}

		return ret;
	}

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

		try {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -