KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > transport > jms > JMSEndpoint


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis.transport.jms;
57
58 import javax.jms.Destination JavaDoc;
59 import javax.jms.JMSException JavaDoc;
60 import javax.jms.MessageListener JavaDoc;
61 import javax.jms.Session JavaDoc;
62 import java.util.HashMap JavaDoc;
63
64 /**
65  * JMSEndpoint encapsulates interactions w/ a JMS destination.
66  *
67  * @author Jaime Meritt (jmeritt@sonicsoftware.com)
68  * @author Richard Chung (rchung@sonicsoftware.com)
69  * @author Dave Chappell (chappell@sonicsoftware.com)
70  */

71 public abstract class JMSEndpoint
72 {
73    private JMSConnector m_connector;
74
75    protected JMSEndpoint(JMSConnector connector)
76    {
77       m_connector = connector;
78    }
79
80    abstract Destination JavaDoc getDestination(Session JavaDoc session)
81            throws Exception JavaDoc;
82
83    /**
84     * Send a message and wait for a response.
85     *
86     * @param message
87     * @param timeout
88     * @return
89     * @throws JMSException
90     */

91    public byte[] call(byte[] message, long timeout) throws Exception JavaDoc
92    {
93       return m_connector.getSendConnection().call(this, message, timeout, null);
94    }
95
96    /**
97     * Send a message and wait for a response.
98     *
99     * @param message
100     * @param timeout
101     * @param properties
102     * @return
103     * @throws JMSException
104     */

105    public byte[] call(byte[] message, long timeout, HashMap JavaDoc properties)
106            throws Exception JavaDoc
107    {
108       if (properties != null)
109          properties = (HashMap JavaDoc)properties.clone();
110       return m_connector.getSendConnection().call(this, message, timeout, properties);
111    }
112
113    /**
114     * Send a message w/o waiting for a response.
115     *
116     * @param message
117     * @throws JMSException
118     */

119    public void send(byte[] message) throws Exception JavaDoc
120    {
121       m_connector.getSendConnection().send(this, message, null);
122    }
123
124    /**
125     * Send a message w/o waiting for a response.
126     *
127     * @param message
128     * @param properties
129     * @throws JMSException
130     */

131    public void send(byte[] message, HashMap JavaDoc properties)
132            throws Exception JavaDoc
133    {
134       if (properties != null)
135          properties = (HashMap JavaDoc)properties.clone();
136       m_connector.getSendConnection().send(this, message, properties);
137    }
138
139    /**
140     * Register a MessageListener.
141     *
142     * @param listener
143     * @throws JMSException
144     */

145    public void registerListener(MessageListener JavaDoc listener)
146            throws Exception JavaDoc
147    {
148       m_connector.getReceiveConnection().subscribe(createSubscription(listener, null));
149    }
150
151    /**
152     * Register a MessageListener.
153     *
154     * @param listener
155     * @param properties
156     * @throws JMSException
157     */

158    public void registerListener(MessageListener JavaDoc listener, HashMap JavaDoc properties)
159            throws Exception JavaDoc
160    {
161       if (properties != null)
162          properties = (HashMap JavaDoc)properties.clone();
163       m_connector.getReceiveConnection().subscribe(createSubscription(listener, properties));
164    }
165
166    /**
167     * Unregister a message listener.
168     *
169     * @param listener
170     */

171    public void unregisterListener(MessageListener JavaDoc listener)
172    {
173       m_connector.getReceiveConnection().unsubscribe(createSubscription(listener, null));
174    }
175
176    /**
177     * Unregister a message listener.
178     *
179     * @param listener
180     * @param properties
181     */

182    public void unregisterListener(MessageListener JavaDoc listener, HashMap JavaDoc properties)
183    {
184       if (properties != null)
185          properties = (HashMap JavaDoc)properties.clone();
186       m_connector.getReceiveConnection().unsubscribe(createSubscription(listener, properties));
187    }
188
189    protected Subscription createSubscription(MessageListener JavaDoc listener,
190                                              HashMap JavaDoc properties)
191    {
192       return new Subscription(listener, this, properties);
193    }
194
195    public int hashCode()
196    {
197       return toString().hashCode();
198    }
199
200    public boolean equals(Object JavaDoc object)
201    {
202       if (object == null || !(object instanceof JMSEndpoint))
203          return false;
204       return true;
205    }
206 }
207
Popular Tags