001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.transport.jms;
019:
020: import javax.jms.Destination;
021: import javax.jms.JMSException;
022: import javax.jms.MessageConsumer;
023: import javax.jms.MessageProducer;
024: import javax.jms.Session;
025: import javax.jms.TemporaryQueue;
026:
027: /**
028: * Encapsulates pooled session, unidentified producer, destination &
029: * associated consumer (certain elements may be null depending on the
030: * context).
031: * <p>
032: * Currently only the point-to-point domain is supported,
033: * though the intention is to genericize this to the pub-sub domain
034: * also.
035: *
036: * @author Eoghan Glynn
037: */
038: public class PooledSession {
039: private final Session theSession;
040: private Destination theDestination;
041: private final MessageProducer theProducer;
042: private MessageConsumer theConsumer;
043:
044: private String correlationID;
045:
046: /**
047: * Constructor.
048: */
049: PooledSession(Session session, Destination destination,
050: MessageProducer producer, MessageConsumer consumer) {
051: theSession = session;
052: theDestination = destination;
053: theProducer = producer;
054: theConsumer = consumer;
055: }
056:
057: /**
058: * @return the pooled JMS Session
059: */
060: Session session() {
061: return theSession;
062: }
063:
064: /**
065: * @return the destination associated with the consumer
066: */
067: Destination destination() {
068: return theDestination;
069: }
070:
071: /**
072: * @param destination the destination to encapsulate
073: */
074: void destination(Destination destination) {
075: theDestination = destination;
076: }
077:
078: /**
079: * @return the unidentified producer
080: */
081: MessageProducer producer() {
082: return theProducer;
083: }
084:
085: /**
086: * @return the per-destination consumer
087: */
088: MessageConsumer consumer() {
089: return theConsumer;
090: }
091:
092: /**
093: * @return messageSelector if any set.
094: */
095:
096: String getCorrelationID() throws JMSException {
097: if (correlationID == null && theConsumer != null) {
098: //Must be request/reply
099: String selector = theConsumer.getMessageSelector();
100:
101: if (selector != null
102: && selector.startsWith("JMSCorrelationID")) {
103: int i = selector.indexOf('\'');
104: correlationID = selector.substring(i + 1, selector
105: .length() - 1);
106: }
107: }
108:
109: return correlationID;
110: }
111:
112: /**
113: * @param consumer the consumer to encapsulate
114: */
115: void consumer(MessageConsumer consumer) {
116: theConsumer = consumer;
117: }
118:
119: void close() throws JMSException {
120: if (theProducer != null) {
121: theProducer.close();
122: }
123:
124: if (theConsumer != null) {
125: theConsumer.close();
126: }
127:
128: if (theDestination instanceof TemporaryQueue) {
129: ((TemporaryQueue) theDestination).delete();
130: }
131:
132: if (theSession != null) {
133: theSession.close();
134: }
135: }
136: }
|