KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > api > jms > MantaMessageProducer


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Nimo.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46 package org.mr.api.jms;
47
48 import javax.jms.*;
49 import javax.jms.IllegalStateException JavaDoc;
50
51 import java.io.Serializable JavaDoc;
52 import java.util.HashMap JavaDoc;
53 import java.util.Iterator JavaDoc;
54
55 import org.mr.MantaException;
56 import org.mr.kernel.services.MantaService;
57 import org.mr.kernel.services.ServiceProducer;
58 import org.mr.core.util.SystemTime;
59
60 import org.apache.commons.logging.Log;
61 import org.apache.commons.logging.LogFactory;
62
63
64 /**
65  * A client uses a <CODE>MessageProducer</CODE> object to send messages to a
66  * destination. A <CODE>MessageProducer</CODE> object is created by passing a
67  * <CODE>Destination</CODE> object to a message-producer creation method
68  * supplied by a session.
69  *
70  * <P>
71  * <CODE>MessageProducer</CODE> is the parent interface for all message
72  * producers.
73  *
74  * <P>
75  * A client also has the option of creating a message producer without
76  * supplying a destination. In this case, a destination must be provided with
77  * every send operation. A typical use for this kind of message producer is to
78  * send replies to requests using the request's <CODE>JMSReplyTo</CODE>
79  * destination.
80  *
81  * <P>
82  * A client can specify a default delivery mode, priority, and time to live for
83  * messages sent by a message producer. It can also specify the delivery mode,
84  * priority, and time to live for an individual message.
85  *
86  * <P>
87  * A client can specify a time-to-live value in milliseconds for each message
88  * it sends. This value defines a message expiration time that is the sum of
89  * the message's time-to-live and the GMT when it is sent (for transacted
90  * sends, this is the time the client sends the message, not the time the
91  * transaction is committed).
92  *
93  * <P>
94  * A JMS provider should do its best to expire messages accurately; however,
95  * the JMS API does not define the accuracy provided.
96  *
97  * @author Nimo
98  */

99 public class MantaMessageProducer implements Serializable JavaDoc, MessageProducer, TopicPublisher, QueueSender {
100
101     /**
102      * The constructor for the MantaMessageProducer creates a new consumer
103      * for use by a client.
104      *
105      * @param clientId - the client id supplied by the creating session.
106      * @param sess - the creating session.
107      * @param destination - the queue/topic on which the producer puts messages.
108      * @param service - the service object in the MantaAgent.
109      */

110     public MantaMessageProducer(String JavaDoc clientId, MantaSession sess,Destination destination, ServiceProducer service){
111
112         theDestination = destination;
113         creatingSession = sess;
114         this.clientId = clientId;
115         theService = service;
116         producers = new HashMap JavaDoc();
117         isClosed = false;
118         log = LogFactory.getLog("MantaMessageProducer");
119     } //MantaMessageProducer
120

121     /**
122      * Creates a producer that has no specific destination to produce to.
123      */

124     public MantaMessageProducer (String JavaDoc clientId, MantaSession sess) {
125         //next line added by lital - merge constructors
126
this(clientId, sess,null, null);
127     }
128
129     /**
130      * Sets whether message IDs are disabled.
131      *
132      * <P>
133      * Since message IDs take some effort to create and increase a message's
134      * size, some JMS providers may be able to optimize message overhead if
135      * they are given a hint that the message ID is not used by an application.
136      * By calling the <CODE>setDisableMessageID</CODE> method on this message
137      * producer, a JMS client enables this potential optimization for all
138      * messages sent by this message producer. If the JMS provider accepts this
139      * hint, these messages must have the message ID set to null; if the
140      * provider ignores the hint, the message ID must be set to its normal
141      * unique value.
142      *
143      * <P>
144      * Message IDs are enabled by default.
145      *
146      * @param value
147      * indicates if message IDs are disabled
148      *
149      * @exception JMSException
150      * if the JMS provider fails to set message ID to disabled
151      * due to some internal error.
152      */

153     public void setDisableMessageID(boolean value) throws JMSException{
154
155
156         if (creatingSession==null || creatingSession.isClosed || creatingSession.isClosing)
157             throw new IllegalStateException JavaDoc("MNJMS00063 : FAILED ON METHOD setDisableMessageID() - PARENT SESSION IS CLOSED.");
158
159         //The Manta system does not defer between having message ids or
160
//not. hence - this method does nothing.
161
}
162
163     /**
164      * Gets an indication of whether message IDs are disabled.
165      *
166      * @return an indication of whether message IDs are disabled
167      *
168      * @exception JMSException
169      * if the JMS provider fails to determine if message IDs are
170      * disabled due to some internal error.
171      */

172     public boolean getDisableMessageID() throws JMSException{
173
174         checkLegalOperation();
175         //since Manta alwayes uses the message ids - it will always
176
//return that they are enabled.
177
return false;
178     }
179
180     /**
181      * Sets whether message timestamps are disabled.
182      *
183      * <P>
184      * Since timestamps take some effort to create and increase a message's
185      * size, some JMS providers may be able to optimize message overhead if
186      * they are given a hint that the timestamp is not used by an application.
187      * By calling the <CODE>setDisableMessageTimestamp</CODE> method on this
188      * message producer, a JMS client enables this potential optimization for
189      * all messages sent by this message producer. If the JMS provider accepts
190      * this hint, these messages must have the timestamp set to zero; if the
191      * provider ignores the hint, the timestamp must be set to its normal
192      * value.
193      *
194      * <P>
195      * Message timestamps are enabled by default.
196      *
197      * @param value
198      * indicates if message timestamps are disabled
199      *
200      * @exception JMSException
201      * if the JMS provider fails to set timestamps to disabled
202      * due to some internal error.
203      */

204     public void setDisableMessageTimestamp(boolean value) throws JMSException{
205
206         if (creatingSession==null || creatingSession.isClosed || creatingSession.isClosing)
207             throw new IllegalStateException JavaDoc("MNJMS00064 : FAILED ON METHOD setDisableMTimeStamp() - PARENT SESSION IS CLOSED.");
208         //Manta always uses the message timestamps, so
209
//this method does nothing.
210
}
211
212     /**
213      * Gets an indication of whether message timestamps are disabled.
214      *
215      * @return an indication of whether message timestamps are disabled
216      *
217      * @exception JMSException
218      * if the JMS provider fails to determine if timestamps are
219      * disabled due to some internal error.
220      */

221     public boolean getDisableMessageTimestamp() throws JMSException{
222         checkLegalOperation();
223         //Since Manta always uses the timestamps, they are always enabled.
224
return false;
225     }
226
227     /**
228      * Sets the producer's default delivery mode.
229      *
230      * <P>
231      * Delivery mode is set to <CODE>PERSISTENT</CODE> by default.
232      *
233      * @param deliveryMode
234      * the message delivery mode for this message producer; legal
235      * values are <code>DeliveryMode.NON_PERSISTENT</code> and
236      * <code>DeliveryMode.PERSISTENT</code>
237      *
238      * @exception JMSException
239      * if the JMS provider fails to set the delivery mode due to
240      * some internal error.
241      *
242      * @see javax.jms.MessageProducer#getDeliveryMode
243      * @see javax.jms.DeliveryMode#NON_PERSISTENT
244      * @see javax.jms.DeliveryMode#PERSISTENT
245      * @see javax.jms.Message#DEFAULT_DELIVERY_MODE
246      */

247     public void setDeliveryMode(int newDeliveryMode) throws JMSException{
248         checkLegalOperation();
249         if (newDeliveryMode != MantaMessage.PERSISTENT &&
250             newDeliveryMode != MantaMessage.NON_PERSISTENT)
251
252             throw new JMSException("MNJMS00065 : ILLEGAL DELIVERY MODE SUPPLIED : "+newDeliveryMode+" FAILED ON METHOD setDeliveryMode()");
253
254
255         else
256             this.deliveryMode = newDeliveryMode;
257
258     }
259
260     /**
261      * Gets the producer's default delivery mode.
262      *
263      * @return the message delivery mode for this message producer
264      *
265      * @exception JMSException
266      * if the JMS provider fails to get the delivery mode due to
267      * some internal error.
268      *
269      * @see javax.jms.MessageProducer#setDeliveryMode
270      */

271     public int getDeliveryMode() throws JMSException{
272         checkLegalOperation();
273         return this.deliveryMode;
274     }
275
276     /**
277      * Sets the producer's default priority.
278      *
279      * <P>
280      * The JMS API defines ten levels of priority value, with 0 as the lowest
281      * priority and 9 as the highest. Clients should consider priorities 0-4 as
282      * gradations of normal priority and priorities 5-9 as gradations of
283      * expedited priority. Priority is set to 4 by default.
284      *
285      * @param defaultPriority
286      * the message priority for this message producer; must be a
287      * value between 0 and 9
288      *
289      *
290      * @exception JMSException
291      * if the JMS provider fails to set the priority due to some
292      * internal error.
293      *
294      * @see javax.jms.MessageProducer#getPriority
295      * @see javax.jms.Message#DEFAULT_PRIORITY
296      */

297     public void setPriority(int defaultPriority) throws JMSException{
298         if (defaultPriority>MantaMessage.MAX_PRIORITY ||
299             defaultPriority<MantaMessage.MIN_PRIORITY)
300
301             throw new JMSException("MNJMS00066 : ILLEGAL PRIORITY SPECIFIED : "+defaultPriority+ " IS OUT OF RANGE. FAILED ON METHOD setPriority()");
302
303         else{
304             checkLegalOperation();
305             this.messagePriority = defaultPriority;
306         }
307     }
308
309     /**
310      * Gets the producer's default priority.
311      *
312      * @return the message priority for this message producer
313      *
314      * @exception JMSException
315      * if the JMS provider fails to get the priority due to some
316      * internal error.
317      *
318      * @see javax.jms.MessageProducer#setPriority
319      */

320     public int getPriority() throws JMSException{
321         checkLegalOperation();
322         return messagePriority;
323     }
324
325     /**
326      * Sets the default length of time in milliseconds from its dispatch time
327      * that a produced message should be retained by the message system.
328      *
329      * <P>
330      * Time to live is set to zero by default, which means unlimited.
331      *
332      * @param timeToLive
333      * the message time to live in milliseconds; zero is unlimited
334      *
335      * @exception JMSException
336      * if the JMS provider fails to set the time to live due to
337      * some internal error.
338      *
339      * @see javax.jms.MessageProducer#getTimeToLive
340      * @see javax.jms.Message#DEFAULT_TIME_TO_LIVE
341      */

342     public void setTimeToLive(long timeToLive) throws JMSException{
343         if (timeToLive<0)
344             throw new JMSException("MNJMS00067 : INVALID TIME TO LIVE SUPPLIED. NEGATIVE VALUES NOT ALLOWED. FAILED ON METHOD setTimeToLive()");
345
346         else {
347             checkLegalOperation();
348             this.messageTTL = timeToLive;
349         }
350
351     }
352
353     /**
354      * Gets the default length of time in milliseconds from its dispatch time
355      * that a produced message should be retained by the message system.
356      *
357      * @return the message time to live in milliseconds; zero is unlimited
358      *
359      * @exception JMSException
360      * if the JMS provider fails to get the time to live due to
361      * some internal error.
362      *
363      * @see javax.jms.MessageProducer#setTimeToLive
364      */

365     public long getTimeToLive() throws JMSException{
366         checkLegalOperation();
367         return this.messageTTL;
368     }
369
370     /**
371      * Gets the destination associated with this <CODE>MessageProducer</CODE>.
372      *
373      * @return this producer's <CODE>Destination/ <CODE>
374      *
375      * @exception JMSException
376      * if the JMS provider fails to get the destination for this
377      * <CODE>MessageProducer</CODE> due to some internal
378      * error.
379      * @since 1.1
380      */

381     public Destination getDestination() throws JMSException{
382         checkLegalOperation();
383         return theDestination;
384     }
385
386     /**
387      * Closes the message producer.
388      *
389      * <P>
390      * Since a provider may allocate some resources on behalf of a <CODE>
391      * MessageProducer</CODE> outside the Java virtual machine, clients should
392      * close them when they are not needed. Relying on garbage collection to
393      * eventually reclaim these resources may not be timely enough.
394      *
395      * @exception JMSException
396      * if the JMS provider fails to close the producer due to
397      * some internal error.
398      */

399     public void close() throws JMSException{
400
401         if (isClosed)
402             return;
403
404         isClosed = true;
405
406         //tell the creating session to remove this producer. along with its
407
//service.
408
creatingSession.removeProducer(this);
409         Iterator JavaDoc producersToRemove = producers.keySet().iterator();
410         while (producersToRemove.hasNext()) {
411             ServiceProducer sp = (ServiceProducer) producers.get(producersToRemove.next());
412             try {
413                 if (log.isInfoEnabled()) {
414                     log.info("Recalling local producer "+sp);
415                 }
416                 creatingSession.owningConnection.getChannel().recallService(sp);
417             } catch (MantaException e) {
418                 if (log.isErrorEnabled())
419                     log.error("MNJMS00067 : FAILED ON METHOD close(). UNABLE TO REMOVE PRODUCER FROM SESSION.",e);
420             }
421         }
422
423         creatingSession = null;
424         theService = null;
425         clientId = null;
426         //theMessageListener = null;
427

428     }
429
430     /**
431      * Sends a message using the <CODE>MessageProducer</CODE>'s default
432      * delivery mode, priority, and time to live.
433      *
434      * @param message
435      * the message to send
436      *
437      * @exception JMSException
438      * if the JMS provider fails to send the message due to some
439      * internal error.
440      * @exception MessageFormatException
441      * if an invalid message is specified.
442      * @exception InvalidDestinationException
443      * if a client uses this method with a <CODE>
444      * MessageProducer</CODE> with an invalid destination.
445      * @exception java.lang.UnsupportedOperationException
446      * if a client uses this method with a <CODE>
447      * MessageProducer</CODE> that did not specify a
448      * destination at creation time.
449      *
450      * @see javax.jms.Session#createProducer
451      * @see javax.jms.MessageProducer
452      *
453      * @since 1.1
454      */

455     public void send(Message msg) throws JMSException{
456
457         //delegate to full method with the defaults:
458

459
460         send(theDestination,msg,deliveryMode,messagePriority,messageTTL);
461
462     }
463
464     /**
465      * Sends a message to the destination, specifying delivery mode, priority,
466      * and time to live.
467      *
468      * @param message
469      * the message to send
470      * @param deliveryMode
471      * the delivery mode to use
472      * @param priority
473      * the priority for this message
474      * @param timeToLive
475      * the message's lifetime (in milliseconds)
476      *
477      * @exception JMSException
478      * if the JMS provider fails to send the message due to some
479      * internal error.
480      * @exception MessageFormatException
481      * if an invalid message is specified.
482      * @exception InvalidDestinationException
483      * if a client uses this method with a <CODE>
484      * MessageProducer</CODE> with an invalid destination.
485      * @exception java.lang.UnsupportedOperationException
486      * if a client uses this method with a <CODE>
487      * MessageProducer</CODE> that did not specify a
488      * destination at creation time.
489      *
490      * @see javax.jms.Session#createProducer
491      * @since 1.1
492      */

493     public void send(Message msg, int msgDeliveryMode, int priority, long timeToLive) throws JMSException{
494
495         //delegate with default destination:
496
send(theDestination,msg,msgDeliveryMode,priority,timeToLive);
497
498     }
499
500     /**
501      * Sends a message to a destination for an unidentified message producer.
502      * Uses the <CODE>MessageProducer</CODE>'s default delivery mode,
503      * priority, and time to live.
504      *
505      * <P>
506      * Typically, a message producer is assigned a destination at creation
507      * time; however, the JMS API also supports unidentified message producers,
508      * which require that the destination be supplied every time a message is
509      * sent.
510      *
511      * @param destination
512      * the destination to send this message to
513      * @param message
514      * the message to send
515      *
516      * @exception JMSException
517      * if the JMS provider fails to send the message due to some
518      * internal error.
519      * @exception MessageFormatException
520      * if an invalid message is specified.
521      * @exception InvalidDestinationException
522      * if a client uses this method with an invalid destination.
523      * @exception java.lang.UnsupportedOperationException
524      * if a client uses this method with a <CODE>
525      * MessageProducer</CODE> that specified a destination at
526      * creation time.
527      *
528      * @see javax.jms.Session#createProducer
529      * @see javax.jms.MessageProducer
530      * @since 1.1
531      */

532     public void send(Destination destination, Message message) throws JMSException{
533
534         //call the full method with default values.
535
if (theDestination!=null)
536             throw new UnsupportedOperationException JavaDoc("MNJMS00068 : FAILED ON METHOD send(). DEFAULT DESTINATION IS NOT NULL.");
537
538         send(destination,message,deliveryMode,messagePriority,messageTTL);
539
540     }
541
542     /**
543      * Sends a message to a destination for an unidentified message producer,
544      * specifying delivery mode, priority and time to live.
545      *
546      * <P>
547      * Typically, a message producer is assigned a destination at creation
548      * time; however, the JMS API also supports unidentified message producers,
549      * which require that the destination be supplied every time a message is
550      * sent.
551      *
552      * @param destination
553      * the destination to send this message to
554      * @param message
555      * the message to send
556      * @param deliveryMode
557      * the delivery mode to use
558      * @param priority
559      * the priority for this message
560      * @param timeToLive
561      * the message's lifetime (in milliseconds)
562      *
563      * @exception JMSException
564      * if the JMS provider fails to send the message due to some
565      * internal error.
566      * @exception MessageFormatException
567      * if an invalid message is specified.
568      * @exception InvalidDestinationException
569      * if a client uses this method with an invalid destination.
570      *
571      * @see javax.jms.Session#createProducer
572      * @since 1.1
573      */

574
575     public void send(Destination destination, Message message, int delMode, int priority, long timeToLive) throws JMSException{
576
577         checkLegalOperation();
578         if (destination==null)
579             throw new UnsupportedOperationException JavaDoc("MNJMS00069 : FAILED ON METHOD send(). NULL DESTINATION SUPPLIED.");
580
581         if (message==null)
582            throw new JMSException("MNJMS0006A : FAILED ON METHOD send(). NULL MESSAGE SUPPLIED.");
583         if (theDestination!=null && !destination.toString().equals(theDestination.toString()))
584             throw new UnsupportedOperationException JavaDoc("MNJMS0006B : FAILED ON METHOD send(). PRODUCER HAS A PERMANANT DESTINATION.");
585
586         if (log.isDebugEnabled()) {
587             log.debug("A new message is ready to be published to "+destination.toString());
588         }
589
590         //if we are sending the message, then
591
//this is all ok.
592
((MantaMessage)message).setWriteableState(true);
593
594         message.setJMSDeliveryMode(delMode);
595         message.setJMSPriority(priority);
596         message.setJMSDestination(destination);
597         //Aviad set the JMSTimeStamp here on the orig copy and not the shallow copy
598
message.setJMSTimestamp(SystemTime.gmtCurrentTimeMillis());
599
600         //only if this our message:
601
if (message instanceof MantaMessage){
602             ((MantaMessage)message).setClientId(clientId);
603             //is used by a subscriber that askes for 'noLocal' on topic,to identify the connection.
604
String JavaDoc connId = creatingSession.owningConnection.getClientID();
605             ((MantaMessage)message).setConnId(connId);
606
607         }
608
609         //conform to the agent.
610
if (timeToLive==0){
611             message.setJMSExpiration(Long.MAX_VALUE);
612         }
613         else {
614             //sets the expiration time to be the current time in milliseconds+gmt offset
615
//Aviad - set the Expiration to be timeStamp +ttl instead of currentTimeMillis+ttl
616
message.setJMSExpiration(message.getJMSTimestamp()+timeToLive);
617         }
618
619         if (this.theDestination!=destination){
620
621             ServiceProducer producer = (ServiceProducer) producers.get(destination.toString());
622
623             if (producer==null){ //never advertised!
624

625
626                 MantaService ms;
627                 if(destination instanceof Queue){
628                     ms = creatingSession.owningConnection.getChannel().getService(
629                             destination.toString(),MantaService.SERVICE_TYPE_QUEUE);
630
631                 }else{
632                     ms = creatingSession.owningConnection.getChannel().getService(
633                             destination.toString(),MantaService.SERVICE_TYPE_TOPIC);
634
635                 }
636                 producer = ServiceProducer.createNew(ms);
637
638                 try {
639                     if (!(destination instanceof TemporaryQueue) &&
640                         !(destination instanceof TemporaryTopic)){
641 // no need to keep track of temp producers or advertise them
642
if (log.isInfoEnabled()) {
643                             log.info("Created local producer "+producer);
644                         }
645                         creatingSession.owningConnection.getChannel().advertiseService(producer);
646                         producers.put(destination.toString(),producer);
647                     }
648                     else {
649                         if (log.isDebugEnabled()) {
650                             log.debug("Created producer on temporary queue "+producer);
651                         }
652                     }
653
654
655                 } catch(MantaException me) {
656                     throw new JMSException("MNJMS0006C : FAILED ON METHOD send(). ERROR TEXT : "+me.getMessage());
657
658                 }
659
660             }
661
662             creatingSession.sendMessage(producer,message);
663
664         }else{
665             creatingSession.sendMessage(this.getService(),message);
666         }
667
668
669     }//send
670

671
672
673     /**
674      * This method will extruct the acknowledge mode from the JMS message and return it as a byte.
675      * in case of a JMS exception the default of CLIENT_ACKNOWLEDGE would be returned.
676      *
677      * @param message the message which contains the delivery mode.
678      * @return
679      */

680     protected byte getAcknowledgeMode(Message message){
681         byte result = 0;
682         try {
683             result = (byte)message.getJMSDeliveryMode();
684         }//try
685
catch(JMSException e){
686             result = MantaSession.CLIENT_ACKNOWLEDGE;
687         }//catch
688

689         return result;
690     }//getAcknowledgeMode
691

692
693     //implementations for queue/topic interfaces:
694

695     /**
696      * Get the queue this producer produces to.
697      */

698     public Queue getQueue() throws JMSException
699     {
700         checkLegalOperation();
701         return (Queue) getDestination();
702     }
703
704     /**
705      * Send a message on a queue
706      */

707     public void send(Queue queue, Message message, int qDeliveryMode, int priority, long timeToLive) throws JMSException
708     {
709
710         send((Destination)queue, message, qDeliveryMode, priority, timeToLive);
711     }
712
713     /**
714      * Send a message on a queue
715      */

716     public void send(Queue queue, Message message) throws JMSException
717     {
718         send((Destination)queue, message,deliveryMode,
719                 messagePriority, messageTTL);
720
721     }
722
723     /**
724      * Gets the topic this producer produces on.
725      */

726     public Topic getTopic() throws JMSException
727     {
728         return (Topic) getDestination();
729     }
730
731     /**
732      * Publish a message to the topic.
733      */

734     public void publish(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
735     {
736         send(theDestination, message, deliveryMode, priority, timeToLive);
737     }
738
739     /**
740      * Publish a message to the topic.
741      */

742     public void publish(Message message) throws JMSException
743     {
744         send(theDestination,message,deliveryMode,messagePriority,messageTTL);
745
746     }
747
748     /**
749      * Publish a message to the topic.
750      */

751     public void publish(Topic topic, Message message, int deliveryMode, int priority, long timeToLive)
752     throws JMSException
753     {
754         send((MantaDestination)topic, message, deliveryMode, priority, timeToLive);
755     }
756
757     /**
758      * Publish a message to the topic
759      */

760     public void publish(Topic topic, Message message) throws JMSException
761     {
762         send((Destination)topic, message,deliveryMode,messagePriority,
763             messageTTL);
764     }
765
766     /**
767      * Gets the client id.
768      *
769      */

770     protected String JavaDoc getClientId(){
771         return clientId;
772     }
773
774     protected ServiceProducer getService() {
775         return theService;
776     }
777
778     private void checkLegalOperation() throws JMSException {
779         if (isClosed)
780             throw new IllegalStateException JavaDoc("MNJMS0006D : OPERATION UNALLOWED. PRODUCER IS CLOSED. FAILED ON METHOD checkLegalOperation()");
781     }
782
783     //The Destination Object associated with the Producer
784
protected Destination theDestination = null;
785
786
787     //the delivery mode for the message. defaults to PERSISTENT
788
protected int deliveryMode = Message.DEFAULT_DELIVERY_MODE;
789
790     //the default priority for messages sent:
791
protected int messagePriority = Message.DEFAULT_PRIORITY;
792
793     //the default time to live for this producer:
794
protected long messageTTL = Message.DEFAULT_TIME_TO_LIVE;
795
796     //the session that created this client.
797
protected MantaSession creatingSession = null;
798
799     //The specific client id that the session assigns this producer.
800
protected String JavaDoc clientId;
801
802     //the service for this producer.
803
protected ServiceProducer theService;
804
805     protected boolean isClosed;
806
807     protected HashMap JavaDoc producers;
808
809     private Log log;
810 }
811
Popular Tags