001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)JMSServerConnection.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.proxy.jms;
030:
031: import com.sun.jbi.binding.proxy.LocalStringKeys;
032:
033: import com.sun.jbi.binding.proxy.util.Translator;
034:
035: import com.sun.jbi.binding.proxy.connection.ServerConnection;
036: import com.sun.jbi.binding.proxy.connection.ClientConnection;
037:
038: import java.util.logging.Logger;
039:
040: import javax.jms.BytesMessage;
041: import javax.jms.Destination;
042: import javax.jms.MessageConsumer;
043: import javax.jms.Queue;
044: import javax.jms.Session;
045:
046: /**
047: * Connection as a JMS Server.
048: * @author Sun Microsystems, Inc
049: */
050: public class JMSServerConnection implements ServerConnection {
051: private Logger mLog = Logger
052: .getLogger("com.sun.jbi.binding.proxy.jms");
053: private JMSConnectionManager mCM;
054: private Queue mQueue;
055: private Session mSession;
056: private MessageConsumer mConsumer;
057: private String mId;
058:
059: /**
060: * Creates a new instance of JMSServerConnection
061: * @param cm that owns this server connection
062: * @param session that should be used to create any JMS resources
063: * @param instance id for this server connection.
064: * @throws com.sun.jbi.binding.proxy.connection.ConnectionException for any JMS problems.
065: */
066: JMSServerConnection(JMSConnectionManager cm, Session session,
067: Queue queue)
068: throws com.sun.jbi.binding.proxy.connection.ConnectionException {
069: mCM = cm;
070: mSession = session;
071: mQueue = queue;
072: try {
073: mId = mQueue.getQueueName();
074: mConsumer = mSession.createConsumer(mQueue);
075: } catch (javax.jms.JMSException jEx) {
076: throw new com.sun.jbi.binding.proxy.connection.ConnectionException(
077: Translator
078: .translate(LocalStringKeys.CANT_CREATE_SERVERCONNECTION)
079: + ":" + jEx);
080: }
081: }
082:
083: /**
084: * Accept a new client connection.
085: * @return The ClientConnection.
086: * @throws com.sun.jbi.binding.proxy.connection.ConnectionException for any JMS problem.
087: */
088: public ClientConnection accept()
089: throws com.sun.jbi.binding.proxy.connection.ConnectionException {
090: ClientConnection cc = null;
091:
092: try {
093: BytesMessage bytes = (BytesMessage) mConsumer.receive();
094:
095: if (bytes != null) {
096: cc = mCM.getClientConnection(bytes);
097: }
098: return (cc);
099: } catch (javax.jms.JMSException jEx) {
100: throw new com.sun.jbi.binding.proxy.connection.ConnectionException(
101: Translator
102: .translate(LocalStringKeys.CANT_ACCEPT_SERVERCONNECTION)
103: + ":" + jEx.toString());
104: }
105: }
106:
107: /**
108: * Return the instance of the client.
109: * @return The instanceId of the client.
110: */
111: public String getInstanceId() {
112: return (mId);
113: }
114:
115: /**
116: * Return reply address.
117: * @return the JMS reply queue to use.
118: */
119: Queue getReplyQueue() {
120: return (mQueue);
121: }
122: }
|