⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractmessagehandler.java

📁 OpenJMS是一个开源的Java Message Service API 1.0.2 规范的实现,它包含有以下特性: *. 它既支持点到点(point-to-point)(PTP)模型和发布/订
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright *    statements and notices.  Redistributions must also contain a *    copy of this document. * * 2. Redistributions in binary form must reproduce the *    above copyright notice, this list of conditions and the *    following disclaimer in the documentation and/or other *    materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote *    products derived from this Software without prior written *    permission of Exoffice Technologies.  For written permission, *    please contact info@exolab.org. * * 4. Products derived from this Software may not be called "Exolab" *    nor may "Exolab" appear in their names without prior written *    permission of Exoffice Technologies. Exolab is a registered *    trademark of Exoffice Technologies. * * 5. Due credit should be given to the Exolab Project *    (http://www.exolab.org/). * * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2005 (C) Exoffice Technologies Inc. All Rights Reserved. * * $Id: AbstractMessageHandler.java,v 1.2 2005/10/20 14:07:03 tanderson Exp $ */package org.exolab.jms.tools.migration.proxy;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.sql.Blob;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Enumeration;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import javax.jms.Destination;import javax.jms.JMSException;import javax.jms.Message;import org.exolab.jms.client.JmsDestination;import org.exolab.jms.persistence.PersistenceException;import org.exolab.jms.persistence.SQLHelper;/** * Abstract implementation of the  <code>MessageHandler</code> interface. * * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> * @version $Revision: 1.2 $ $Date: 2005/10/20 14:07:03 $ */abstract class AbstractMessageHandler implements MessageHandler, DBConstants {    /**     * The destination store.     */    private final DestinationStore _destinations;    /**     * The database connection.     */    private Connection _connection;    /**     * Construct a new <code>AbstractMessageHandler</code>.     *     * @param destinations the destination store     * @param connection   the database connection     */    public AbstractMessageHandler(DestinationStore destinations,                                  Connection connection) {        _destinations = destinations;        _connection = connection;    }    /**     * Add a message.     *     * @param message the message to add     * @throws JMSException         for any JMS error     * @throws PersistenceException for any persistence error     */    public void add(Message message) throws JMSException, PersistenceException {        add(message, getType());    }    /**     * Returns a message given its identifier.     *     * @param messageId the identifier of the message to retrieve     * @return the message corresponding to <code>messageId</code>     * @throws JMSException         for any JMS error     * @throws PersistenceException for any persistence error     */    public Message get(String messageId) throws JMSException,            PersistenceException {        Message message = newMessage();        get(messageId, message);        return message;    }    /**     * Returns the type of message that this handler supports.     *     * @return the type of message     */    protected abstract String getType();    /**     * Create a new message.     *     * @return a new message     * @throws JMSException for any JMS error     */    protected abstract Message newMessage() throws JMSException;    /**     * Populate the message body.     *     * @param body    the message body     * @param message the message to populate     * @throws JMSException         for any JMS error     * @throws PersistenceException for any persistence error     */    protected abstract void setBody(Object body, Message message)            throws JMSException, PersistenceException;    /**     * Returns the body of the message.     *     * @param message the message     * @return the body of the message     * @throws JMSException for any JMS error     */    protected abstract Object getBody(Message message) throws JMSException;    /**     * Populate a message.     *     * @param messageId the message identifier     * @param message   the message to populate     * @throws JMSException         for any JMS error     * @throws PersistenceException for any persistence error     */    protected void get(String messageId, Message message)            throws JMSException, PersistenceException {        PreparedStatement select = null;        ResultSet set = null;        try {            select = _connection.prepareStatement(                    "select * from " + MESSAGE_TABLE + " where message_id = ?");            select.setString(1, messageId);            set = select.executeQuery();            if (!set.next()) {                throw new PersistenceException(                        "Message not found, JMSMessageID=" + messageId);            }            String correlationId = set.getString("correlation_id");            int deliveryMode = set.getInt("delivery_mode");            long destinationId = set.getLong("destination_id");            long expiration = set.getLong("expiration");            int priority = set.getInt("priority");            boolean redelivered = set.getBoolean("redelivered");            long replyToId = set.getLong("reply_to_id");            long timestamp = set.getLong("timestamp");            String type = set.getString("type");            Destination destination = _destinations.get(destinationId);            message.setJMSMessageID(messageId);            message.setJMSCorrelationID(correlationId);            message.setJMSDeliveryMode(deliveryMode);            message.setJMSDestination(destination);            message.setJMSExpiration(expiration);            message.setJMSPriority(priority);            message.setJMSRedelivered(redelivered);            if (replyToId != 0) {                Destination replyTo = _destinations.get(replyToId);                message.setJMSReplyTo(replyTo);            }            message.setJMSTimestamp(timestamp);            message.setJMSType(type);            Blob blob = set.getBlob("body");            Object body;            try {                body = deserialize(blob);            } catch (Exception exception) {                throw new PersistenceException(                        "Failed to deserialize message body, JMSMessageID="                        + messageId, exception);            }            setBody(body, message);        } catch (SQLException exception) {            throw new PersistenceException(                    "Failed to populate message, JMSMessageID="                    + messageId, exception);        } finally {            SQLHelper.close(set);            SQLHelper.close(select);        }        getProperties(messageId, message);    }    /**     * Populate message properties.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -