Skip to content

Commit

Permalink
Proper fix on MessageProducer
Browse files Browse the repository at this point in the history
  • Loading branch information
clebertsuconic committed Jul 9, 2013
1 parent 2ac88e0 commit 81183f0
Showing 1 changed file with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,16 @@ public void close() throws JMSException

public void send(final Message message) throws JMSException
{
send(defaultDestination, message, defaultDeliveryMode, defaultPriority, defaultTimeToLive);
checkDefaultDestination();
doSendx(defaultDestination, message, defaultDeliveryMode, defaultPriority, defaultTimeToLive, null);
}

public
void
send(final Message message, final int deliveryMode, final int priority, final long timeToLive)
throws JMSException
public void send(final Message message,
final int deliveryMode,
final int priority, final long timeToLive) throws JMSException
{
send(defaultDestination, message, deliveryMode, priority, timeToLive);
checkDefaultDestination();
doSendx(defaultDestination, message, deliveryMode, priority, timeToLive, null);
}

public void send(final Destination destination, final Message message) throws JMSException
Expand All @@ -194,19 +195,9 @@ public void send(final Destination destination, final Message message, final int
{
checkClosed();

if (destination != null && !(destination instanceof HornetQDestination))
{
throw new InvalidDestinationException("Not a HornetQ Destination:" + destination);
}
if (destination != null && defaultDestination != null)
{
throw new UnsupportedOperationException("Cannot specify destination if producer has a default destination");
}
message.setJMSDeliveryMode(deliveryMode);

message.setJMSPriority(priority);
checkDestination(destination);

doSend(message, timeToLive, (HornetQDestination)destination, null);
doSendx((HornetQDestination)destination, message, deliveryMode, priority, timeToLive, null);
}

@Override
Expand All @@ -231,7 +222,8 @@ public void send(Message message, CompletionListener completionListener) throws
public void send(Message message, int deliveryMode, int priority, long timeToLive,
CompletionListener completionListener) throws JMSException
{
send(defaultDestination, message, deliveryMode, priority, timeToLive, completionListener);
checkDefaultDestination();
doSendx(defaultDestination, message, deliveryMode, priority, timeToLive, completionListener);
}

@Override
Expand All @@ -246,19 +238,12 @@ public void send(Destination destination, Message message, int deliveryMode, int
CompletionListener completionListener) throws JMSException
{
checkClosed();
if (completionListener == null)
{
throw new IllegalArgumentException("Invalid completionListener used");
}
if (destination != null && !(destination instanceof HornetQDestination))
{
throw new InvalidDestinationException("Not a HornetQ Destination:" + destination);
}

message.setJMSDeliveryMode(deliveryMode);
checkCompletionListener(completionListener);

checkDestination(destination);

message.setJMSPriority(priority);
doSend(message, timeToLive, (HornetQDestination)destination, completionListener);
doSendx((HornetQDestination)destination, message, deliveryMode, priority, timeToLive, completionListener);
}

// TopicPublisher Implementation ---------------------------------
Expand All @@ -278,9 +263,7 @@ public void publish(final Topic topic, final Message message) throws JMSExceptio
send(topic, message);
}

public
void
publish(final Message message, final int deliveryMode, final int priority, final long timeToLive)
public void publish(final Message message, final int deliveryMode, final int priority, final long timeToLive)
throws JMSException
{
send(message, deliveryMode, priority, timeToLive);
Expand All @@ -289,7 +272,8 @@ public void publish(final Topic topic, final Message message) throws JMSExceptio
public void publish(final Topic topic, final Message message, final int deliveryMode, final int priority,
final long timeToLive) throws JMSException
{
send(topic, message, deliveryMode, priority, timeToLive);
checkDestination(topic);
doSendx((HornetQDestination) topic, message, deliveryMode, priority, timeToLive, null);
}

// QueueSender Implementation ------------------------------------
Expand All @@ -302,7 +286,8 @@ public void send(final Queue queue, final Message message) throws JMSException
public void send(final Queue queue, final Message message, final int deliveryMode, final int priority,
final long timeToLive) throws JMSException
{
send((Destination)queue, message, deliveryMode, priority, timeToLive);
checkDestination(queue);
doSendx((HornetQDestination) queue, message, deliveryMode, priority, timeToLive, null);
}

public Queue getQueue() throws JMSException
Expand All @@ -317,10 +302,51 @@ public String toString()
{
return "HornetQMessageProducer->" + clientProducer;
}
/**
* Check if the default destination has been set
*/
private void checkDefaultDestination()
{
if (defaultDestination == null)
{
throw new UnsupportedOperationException("Cannot specify destination if producer has a default destination");
}
}

private void doSend(final Message jmsMessage, final long timeToLive, HornetQDestination destination,
/**
* Check if the destination is sent correctly
*/
private void checkDestination(Destination destination) throws InvalidDestinationException
{
if (destination != null && !(destination instanceof HornetQDestination))
{
throw new InvalidDestinationException("Not a HornetQ Destination:" + destination);
}
if (destination != null && defaultDestination != null)
{
throw new UnsupportedOperationException("Cannot specify destination if producer has a default destination");
}
}

private void checkCompletionListener(CompletionListener completionListener)
{
if (completionListener == null)
{
throw new IllegalArgumentException("Invalid completionListener used");
}
}


private void doSendx(HornetQDestination destination, final Message jmsMessage, final int deliveryMode,
final int priority, final long timeToLive,
CompletionListener completionListener) throws JMSException
{

jmsMessage.setJMSDeliveryMode(deliveryMode);

jmsMessage.setJMSPriority(priority);


if (timeToLive == 0)
{
jmsMessage.setJMSExpiration(0);
Expand Down

0 comments on commit 81183f0

Please sign in to comment.