1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
89
89
*/
90
90
public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations {
91
91
92
- /**
93
- * Timeout value indicating that a receive operation should
94
- * check if a message is immediately available without blocking.
95
- */
96
- public static final long RECEIVE_TIMEOUT_NO_WAIT = -1 ;
97
-
98
- /**
99
- * Timeout value indicating a blocking receive without timeout.
100
- */
101
- public static final long RECEIVE_TIMEOUT_INDEFINITE_WAIT = 0 ;
102
-
103
-
104
92
/** The JMS 2.0 MessageProducer.setDeliveryDelay method, if available */
105
93
private static final Method setDeliveryDelayMethod =
106
94
ClassUtils .getMethodIfAvailable (MessageProducer .class , "setDeliveryDelay" , long .class );
@@ -315,11 +303,13 @@ public boolean isPubSubNoLocal() {
315
303
* Set the timeout to use for receive calls (in milliseconds).
316
304
* <p>The default is {@link #RECEIVE_TIMEOUT_INDEFINITE_WAIT}, which indicates
317
305
* a blocking receive without timeout.
318
- * <p>Specify {@link #RECEIVE_TIMEOUT_NO_WAIT} to inidicate that a receive operation
319
- * should check if a message is immediately available without blocking.
306
+ * <p>Specify {@link #RECEIVE_TIMEOUT_NO_WAIT} (or any other negative value)
307
+ * to indicate that a receive operation should check if a message is
308
+ * immediately available without blocking.
309
+ * @see #receiveFromConsumer(MessageConsumer, long)
320
310
* @see javax.jms.MessageConsumer#receive(long)
321
- * @see javax.jms.MessageConsumer#receive()
322
311
* @see javax.jms.MessageConsumer#receiveNoWait()
312
+ * @see javax.jms.MessageConsumer#receive()
323
313
*/
324
314
public void setReceiveTimeout (long receiveTimeout ) {
325
315
this .receiveTimeout = receiveTimeout ;
@@ -800,7 +790,7 @@ protected Message doReceive(Session session, MessageConsumer consumer) throws JM
800
790
if (resourceHolder != null && resourceHolder .hasTimeout ()) {
801
791
timeout = Math .min (timeout , resourceHolder .getTimeToLiveInMillis ());
802
792
}
803
- Message message = doReceive (consumer , timeout );
793
+ Message message = receiveFromConsumer (consumer , timeout );
804
794
if (session .getTransacted ()) {
805
795
// Commit necessary - but avoid commit call within a JTA transaction.
806
796
if (isSessionLocallyTransacted (session )) {
@@ -821,25 +811,6 @@ else if (isClientAcknowledge(session)) {
821
811
}
822
812
}
823
813
824
- /**
825
- * Actually receive a message from the given consumer.
826
- * @param consumer the JMS MessageConsumer to receive with
827
- * @param timeout the receive timeout
828
- * @return the JMS Message received, or {@code null} if none
829
- * @throws JMSException if thrown by JMS API methods
830
- */
831
- private Message doReceive (MessageConsumer consumer , long timeout ) throws JMSException {
832
- if (timeout == RECEIVE_TIMEOUT_NO_WAIT ) {
833
- return consumer .receiveNoWait ();
834
- }
835
- else if (timeout > 0 ) {
836
- return consumer .receive (timeout );
837
- }
838
- else {
839
- return consumer .receive ();
840
- }
841
- }
842
-
843
814
844
815
//---------------------------------------------------------------------------------------
845
816
// Convenience methods for receiving auto-converted messages
@@ -952,7 +923,7 @@ protected Message doSendAndReceive(Session session, Destination destination, Mes
952
923
logger .debug ("Sending created message: " + requestMessage );
953
924
}
954
925
doSend (producer , requestMessage );
955
- return doReceive (consumer , getReceiveTimeout ());
926
+ return receiveFromConsumer (consumer , getReceiveTimeout ());
956
927
}
957
928
finally {
958
929
JmsUtils .closeMessageConsumer (consumer );
0 commit comments