KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > server > JMSDestination


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq.server;
23
24 import javax.jms.JMSException JavaDoc;
25
26 import org.jboss.logging.Logger;
27 import org.jboss.mq.SpyDestination;
28 import org.jboss.mq.SpyMessage;
29 import org.jboss.mq.Subscription;
30 import org.jboss.mq.pm.Tx;
31
32 /**
33  * This class is a message queue which is stored (hashed by Destination) on the
34  * JMS provider
35  *
36  * @author Norbert Lataille (Norbert.Lataille@m4x.org)
37  * @author Hiram Chirino (Cojonudo14@hotmail.com)
38  * @author David Maplesden (David.Maplesden@orion.co.nz)
39  * @author Adrian Brock (adrian@jboss.com)
40  * @created August 16, 2001
41  * @version $Revision: 45317 $
42  */

43 public abstract class JMSDestination
44 {
45    //the Destination of this queue
46
SpyDestination destination;
47    //If this is a temporaryDestination, temporaryDestination=ClientConsumer of the owner, otherwise it's null
48
ClientConsumer temporaryDestination;
49    //The JMSServer object
50
JMSDestinationManager server;
51
52    //Counter used to number incomming messages. (Used to order the messages.)
53
long nextMessageIdCounter = 0;
54    Object JavaDoc nextMessageIdLock = new Object JavaDoc();
55
56    static long nextSharedMessageIdCounter = 0;
57    static Object JavaDoc nextSharedMessageIdLock = new Object JavaDoc();
58
59    /** The basic queue parameters */
60    public BasicQueueParameters parameters;
61
62    static Logger cat = Logger.getLogger(JMSDestination.class);
63
64    JMSDestination(SpyDestination dest, ClientConsumer temporary, JMSDestinationManager server, BasicQueueParameters parameters) throws JMSException JavaDoc
65    {
66       destination = dest;
67       temporaryDestination = temporary;
68       this.server = server;
69       this.parameters = parameters;
70    }
71
72    public SpyDestination getSpyDestination()
73    {
74       return destination;
75    }
76
77    public abstract void addSubscriber(Subscription sub) throws JMSException JavaDoc;
78
79    public abstract void removeSubscriber(Subscription sub) throws JMSException JavaDoc;
80
81    public abstract void nackMessages(Subscription sub) throws JMSException JavaDoc;
82
83    public abstract SpyMessage receive(Subscription sub, boolean wait) throws JMSException JavaDoc;
84
85    public abstract void addReceiver(Subscription sub) throws JMSException JavaDoc;
86
87    public abstract void removeReceiver(Subscription sub);
88
89    public abstract void restoreMessage(MessageReference message);
90
91    public void restoreMessage(SpyMessage message)
92    {
93       restoreMessage(message, null, Tx.UNKNOWN);
94    }
95    
96    /**
97     * Restore a message
98     *
99     * @param message the message
100     * @param tx any transaction
101     * @param type the type of restoration
102     */

103    public abstract void restoreMessage(SpyMessage message, Tx tx, int type);
104
105    public abstract boolean isInUse();
106
107    public abstract void close() throws JMSException JavaDoc;
108    public abstract void removeAllMessages() throws JMSException JavaDoc;
109
110    /**
111     * @param req org.jboss.mq.AcknowledgementRequest
112     * @param sub org.jboss.mq.Subscription
113     * @param txId org.jboss.mq.pm.Tx
114     * @exception javax.jms.JMSException The exception description.
115     */

116    public abstract void acknowledge(
117       org.jboss.mq.AcknowledgementRequest req,
118       org.jboss.mq.Subscription sub,
119       org.jboss.mq.pm.Tx txId)
120       throws javax.jms.JMSException JavaDoc;
121
122    /**
123     * @param mes org.jboss.mq.SpyMessage
124     * @param txId org.jboss.mq.pm.Tx
125     * @exception javax.jms.JMSException The exception description.
126     */

127    public abstract void addMessage(org.jboss.mq.SpyMessage mes, org.jboss.mq.pm.Tx txId) throws javax.jms.JMSException JavaDoc;
128
129    public abstract MessageCounter[] getMessageCounter();
130
131    protected static long nextSharedMessageId()
132    {
133       synchronized (nextSharedMessageIdLock)
134       {
135          return nextSharedMessageIdCounter++;
136       }
137    }
138
139    protected static void updateSharedNextMessageId(SpyMessage message)
140    {
141       synchronized (nextSharedMessageIdLock)
142       {
143          nextSharedMessageIdCounter = Math.max(nextSharedMessageIdCounter, message.header.messageId+1);
144       }
145    }
146
147    protected long nextMessageId()
148    {
149       if (parameters.lateClone)
150          return nextSharedMessageId();
151
152       synchronized (nextMessageIdLock)
153       {
154          return nextMessageIdCounter++;
155       }
156    }
157
158    protected void updateNextMessageId(SpyMessage message)
159    {
160       if (parameters.lateClone)
161       {
162          updateSharedNextMessageId(message);
163          return;
164       }
165
166       synchronized (nextMessageIdLock)
167       {
168          nextMessageIdCounter = Math.max(nextMessageIdCounter, message.header.messageId+1);
169       }
170    }
171 }
172
Popular Tags