/**
* Copyright (C) 2013 kangliqiang ,kangliq@163.com
*
* Licensed under the Apache License, Version 2.0 (the "License")=0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#if!defined __MQPRODUCER_H__
#define __MQPRODUCER_H__

#include <vector>
#include <string>
#include "MQAdmin.h"
#include "SendResult.h"
#include "RocketMQClient.h"

class MessageQueue;
class SendCallback;
class LocalTransactionExecuter;
class MessageQueueSelector;

/**
* ÏûÏ¢Éú²úÕß
*
*/
class ROCKETMQCLIENT_API MQProducer : public MQAdmin
{
public:
	MQProducer()
	{

	}

	virtual ~MQProducer()
	{

	}

	/**
	* Æô¶¯·þÎñ
	*
	* @throw( MQClientException
	*/
	virtual void start()=0;

	/**
	* ¹Ø±Õ·þÎñ£¬Ò»µ©¹Ø±Õ£¬´Ë¶ÔÏó½«²»¿ÉÓÃ
	*/
	virtual void shutdown()=0;

	/**
	* ¸ù¾Ýtopic»ñÈ¡¶ÔÓ¦µÄMessageQueue£¬Èç¹ûÊÇË³ÐòÏûÏ¢£¬Ôò°´ÕÕË³ÐòÏûÏ¢ÅäÖÃ·µ»Ø
	*
	* @param topic
	*            ÏûÏ¢Topic
	* @return ·µ»Ø¶ÓÁÐ¼¯ºÏ
	* @throw( MQClientException
	*/
	virtual std::vector<MessageQueue>* fetchPublishMessageQueues(const std::string& topic)=0;

	/**
	* ·¢ËÍÏûÏ¢£¬Í¬²½µ÷ÓÃ
	*
	* @param msg
	*            ÏûÏ¢
	* @return ·¢ËÍ½á¹û
	* @throw( InterruptedException
	* @throw( MQBrokerException
	* @throw( RemotingException
	* @throw( MQClientException
	*/
	virtual SendResult send(Message& msg)=0;

	/**
	* ·¢ËÍÏûÏ¢£¬Òì²½µ÷ÓÃ
	*
	* @param msg
	*            ÏûÏ¢
	* @param sendCallback
	*            ·¢ËÍ½á¹ûÍ¨¹ý´Ë½Ó¿Ú»Øµ÷
	* @throw( MQClientException
	* @throw( RemotingException
	* @throw( InterruptedException
	*/
	virtual void send(Message& msg, SendCallback* sendCallback)=0;

	/**
	* ·¢ËÍÏûÏ¢£¬OnewayÐÎÊ½£¬·þÎñÆ÷²»Ó¦´ð£¬ÎÞ·¨±£Ö¤ÏûÏ¢ÊÇ·ñ³É¹¦µ½´ï·þÎñÆ÷
	*
	* @param msg
	*            ÏûÏ¢
	* @throw( MQClientException
	* @throw( RemotingException
	* @throw( InterruptedException
	*/
	virtual void sendOneway(Message& msg)=0;

	/**
	* ÏòÖ¸¶¨¶ÓÁÐ·¢ËÍÏûÏ¢£¬Í¬²½µ÷ÓÃ
	*
	* @param msg
	*            ÏûÏ¢
	* @param mq
	*            ¶ÓÁÐ
	* @return ·¢ËÍ½á¹û
	* @throw( InterruptedException
	* @throw( MQBrokerException
	* @throw( RemotingException
	* @throw( MQClientException
	*/
	virtual SendResult send(Message& msg, MessageQueue& mq)=0;

	/**
	* ÏòÖ¸¶¨¶ÓÁÐ·¢ËÍÏûÏ¢£¬Òì²½µ÷ÓÃ
	*
	* @param msg
	*            ÏûÏ¢
	* @param mq
	*            ¶ÓÁÐ
	* @param sendCallback
	*            ·¢ËÍ½á¹ûÍ¨¹ý´Ë½Ó¿Ú»Øµ÷
	* @throw( InterruptedException
	* @throw( RemotingException
	* @throw( MQClientException
	*/
	virtual void send(Message& msg, MessageQueue& mq, SendCallback* sendCallback)=0;
	
	/**
	* ÏòÖ¸¶¨¶ÓÁÐ·¢ËÍÏûÏ¢£¬OnewayÐÎÊ½£¬·þÎñÆ÷²»Ó¦´ð£¬ÎÞ·¨±£Ö¤ÏûÏ¢ÊÇ·ñ³É¹¦µ½´ï·þÎñÆ÷
	*
	* @param msg
	*            ÏûÏ¢
	* @param mq
	*            ¶ÓÁÐ
	* @throw( MQClientException
	* @throw( RemotingException
	* @throw( InterruptedException
	*/
	virtual void sendOneway(Message& msg, MessageQueue& mq)=0;

	/**
	* ·¢ËÍÏûÏ¢£¬¿ÉÒÔ×Ô¶¨ÒåÑ¡Ôñ¶ÓÁÐ£¬¶ÓÁÐµÄ×ÜÊý¿ÉÄÜ»áÓÉÓÚBrokerµÄÆôÍ£±ä»¯<br>
	* Èç¹ûÒª±£Ö¤ÏûÏ¢ÑÏ¸ñÓÐÐò£¬ÔÚÏòÔËÎ¬ÈËÔ±ÉêÇëTopicÊ±£¬ÐèÒªÌØ±ðËµÃ÷<br>
	* Í¬²½µ÷ÓÃ
	*
	* @param msg
	*            ÏûÏ¢
	* @param selector
	*            ¶ÓÁÐÑ¡ÔñÆ÷£¬·¢ËÍÊ±»á»Øµ÷
	* @param arg
	*            »Øµ÷¶ÓÁÐÑ¡ÔñÆ÷Ê±£¬´Ë²ÎÊý»á´«Èë¶ÓÁÐÑ¡Ôñ·½·¨
	* @return ·¢ËÍ½á¹û
	* @throw( InterruptedException
	* @throw( MQBrokerException
	* @throw( RemotingException
	* @throw( MQClientException
	*/
	virtual SendResult send(Message& msg, MessageQueueSelector* selector, void* arg)=0;

	/**
	* ·¢ËÍÏûÏ¢£¬¿ÉÒÔ×Ô¶¨ÒåÑ¡Ôñ¶ÓÁÐ£¬¶ÓÁÐµÄ×ÜÊý¿ÉÄÜ»áÓÉÓÚBrokerµÄÆôÍ£±ä»¯<br>
	* Èç¹ûÒª±£Ö¤ÏûÏ¢ÑÏ¸ñÓÐÐò£¬ÔÚÏòÔËÎ¬ÈËÔ±ÉêÇëTopicÊ±£¬ÐèÒªÌØ±ðËµÃ÷<br>
	* Òì²½µ÷ÓÃ
	*
	* @param msg
	*            ÏûÏ¢
	* @param selector
	*            ¶ÓÁÐÑ¡ÔñÆ÷£¬·¢ËÍÊ±»á»Øµ÷
	* @param arg
	*            »Øµ÷¶ÓÁÐÑ¡ÔñÆ÷Ê±£¬´Ë²ÎÊý»á´«Èë¶ÓÁÐÑ¡Ôñ·½·¨
	* @param sendCallback
	*            ·¢ËÍ½á¹ûÍ¨¹ý´Ë½Ó¿Ú»Øµ÷
	* @throw( MQClientException
	* @throw( RemotingException
	* @throw( InterruptedException
	*/
	virtual void send(Message& msg, MessageQueueSelector* selector, void* arg, SendCallback* sendCallback)=0;

	/**
	* ·¢ËÍÏûÏ¢£¬¿ÉÒÔ×Ô¶¨ÒåÑ¡Ôñ¶ÓÁÐ£¬¶ÓÁÐµÄ×ÜÊý¿ÉÄÜ»áÓÉÓÚBrokerµÄÆôÍ£±ä»¯<br>
	* Èç¹ûÒª±£Ö¤ÏûÏ¢ÑÏ¸ñÓÐÐò£¬ÔÚÏòÔËÎ¬ÈËÔ±ÉêÇëTopicÊ±£¬ÐèÒªÌØ±ðËµÃ÷<br>
	* OnewayÐÎÊ½£¬·þÎñÆ÷²»Ó¦´ð£¬ÎÞ·¨±£Ö¤ÏûÏ¢ÊÇ·ñ³É¹¦µ½´ï·þÎñÆ÷
	*
	* @param msg
	*            ÏûÏ¢
	* @param selector
	*            ¶ÓÁÐÑ¡ÔñÆ÷£¬·¢ËÍÊ±»á»Øµ÷
	* @param arg
	*            »Øµ÷¶ÓÁÐÑ¡ÔñÆ÷Ê±£¬´Ë²ÎÊý»á´«Èë¶ÓÁÐÑ¡Ôñ·½·¨
	* @throw( MQClientException
	* @throw( RemotingException
	* @throw( InterruptedException
	*/
	virtual void sendOneway(Message& msg, MessageQueueSelector* selector, void* arg)=0;

	virtual TransactionSendResult sendMessageInTransaction(Message& msg,
															LocalTransactionExecuter* tranExecuter,
															void* arg)=0;
};

#endif
