KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001, 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.transport.jms;
18
19 import java.util.HashMap JavaDoc;
20
21 import javax.jms.Destination JavaDoc;
22 import javax.jms.MessageListener JavaDoc;
23 import javax.jms.Session JavaDoc;
24
25 /**
26  * JMSEndpoint encapsulates interactions w/ a JMS destination.
27  *
28  * @author Jaime Meritt (jmeritt@sonicsoftware.com)
29  * @author Richard Chung (rchung@sonicsoftware.com)
30  * @author Dave Chappell (chappell@sonicsoftware.com)
31  */

32 public abstract class JMSEndpoint
33 {
34     private JMSConnector m_connector;
35
36     protected JMSEndpoint(JMSConnector connector)
37     {
38         m_connector = connector;
39     }
40
41     abstract Destination JavaDoc getDestination(Session JavaDoc session)
42         throws Exception JavaDoc;
43
44     /**
45      * Send a message and wait for a response.
46      *
47      * @param message
48      * @param timeout
49      * @return
50      * @throws JMSException
51      */

52     public byte[] call(byte[] message, long timeout)throws Exception JavaDoc
53     {
54         return m_connector.getSendConnection().call(this, message, timeout, null);
55     }
56
57     /**
58      * Send a message and wait for a response.
59      *
60      * @param message
61      * @param timeout
62      * @param properties
63      * @return
64      * @throws JMSException
65      */

66     public byte[] call(byte[] message, long timeout, HashMap JavaDoc properties)
67         throws Exception JavaDoc
68     {
69         if(properties != null)
70             properties = (HashMap JavaDoc)properties.clone();
71         return m_connector.getSendConnection().call(this, message, timeout, properties);
72     }
73
74     /**
75      * Send a message w/o waiting for a response.
76      *
77      * @param message
78      * @throws JMSException
79      */

80     public void send(byte[] message)throws Exception JavaDoc
81     {
82         m_connector.getSendConnection().send(this, message, null);
83     }
84
85     /**
86      * Send a message w/o waiting for a response.
87      *
88      * @param message
89      * @param properties
90      * @throws JMSException
91      */

92     public void send(byte[] message, HashMap JavaDoc properties)
93         throws Exception JavaDoc
94     {
95         if(properties != null)
96             properties = (HashMap JavaDoc)properties.clone();
97         m_connector.getSendConnection().send(this, message, properties);
98     }
99
100     /**
101      * Register a MessageListener.
102      *
103      * @param listener
104      * @throws JMSException
105      */

106     public void registerListener(MessageListener JavaDoc listener)
107         throws Exception JavaDoc
108     {
109         m_connector.getReceiveConnection().subscribe(createSubscription(listener, null));
110     }
111
112     /**
113      * Register a MessageListener.
114      *
115      * @param listener
116      * @param properties
117      * @throws JMSException
118      */

119     public void registerListener(MessageListener JavaDoc listener, HashMap JavaDoc properties)
120         throws Exception JavaDoc
121     {
122         if(properties != null)
123             properties = (HashMap JavaDoc)properties.clone();
124         m_connector.getReceiveConnection().subscribe(createSubscription(listener, properties));
125     }
126
127     /**
128      * Unregister a message listener.
129      *
130      * @param listener
131      */

132     public void unregisterListener(MessageListener JavaDoc listener)
133     {
134         m_connector.getReceiveConnection().unsubscribe(createSubscription(listener, null));
135     }
136
137     /**
138      * Unregister a message listener.
139      *
140      * @param listener
141      * @param properties
142      */

143     public void unregisterListener(MessageListener JavaDoc listener, HashMap JavaDoc properties)
144     {
145         if(properties != null)
146             properties = (HashMap JavaDoc)properties.clone();
147         m_connector.getReceiveConnection().unsubscribe(createSubscription(listener, properties));
148     }
149
150     protected Subscription createSubscription(MessageListener JavaDoc listener,
151                                               HashMap JavaDoc properties)
152     {
153         return new Subscription(listener, this, properties);
154     }
155
156     public int hashCode()
157     {
158         return toString().hashCode();
159     }
160
161     public boolean equals(Object JavaDoc object)
162     {
163         if(object == null || !(object instanceof JMSEndpoint))
164             return false;
165         return true;
166     }
167 }
168
Popular Tags