private SendResult send0(final Message message, final byte[] encodedData, final long timeout, final TimeUnit unit)
throws InterruptedException, MetaClientException {
try {
final String topic = message.getTopic();
Partition partition = null;
String serverUrl = null;
// ����������ڣ���ʹ����һ�η�����Ϣʱѡ���broker
if (this.isInTransaction()) {
final LastSentInfo info = this.lastSentInfo.get();
if (info != null) {
serverUrl = info.serverUrl;
// ѡ���broker�ڵ�ij������
partition =
this.producerZooKeeper.selectPartition(topic, message, this.partitionSelector, serverUrl);
if (partition == null) {
// û�п��÷������׳��쳣
throw new MetaClientException("There is no partitions in `" + serverUrl
+ "` to send message with topic `" + topic + "` in a transaction");
}
}
}
if (partition == null) {
partition = this.selectPartition(message);
}
if (partition == null) {
throw new MetaClientException("There is no aviable partition for topic " + topic
+ ",maybe you don't publish it at first?");
}
if (serverUrl == null) {
serverUrl = this.producerZooKeeper.selectBroker(topic, partition);
}
if (serverUrl == null) {
throw new MetaClientException("There is no aviable server right now for topic " + topic
+ " and partition " + partition + ",maybe you don't publish it at first?");
}
if (this.isInTransaction() && this.lastSentInfo.get() == null) {
// ��һ�η��ͣ���Ҫ��������
this.beforeSendMessageFirstTime(serverUrl);
}
final int flag = MessageFlagUtils.getFlag(message);
final PutCommand putCommand =
new PutCommand(topic, partition.getPartition(), encodedData, flag, CheckSum.crc32(encodedData),
this.getTransactionId(), OpaqueGenerator.getNextOpaque());
final BooleanCommand resp = this.invokeToGroup(serverUrl, partition, putCommand, message, timeout, unit);
return this.genSendResult(message, partition, serverUrl, resp);
}
catch (final TimeoutException e) {