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

📄 messagehandlefactory.java

📁 实现了Jms的服务器源码,支持多种适配器,DB,FTP,支持多种数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                             MessageImpl message)
        throws JMSException {

        return new TransientMessageHandle(message);
    }

    /**
     * Create a transient message handle for a durable consumer
     *
     * @param durable the durable consumer endpoint
     * @param message the message
     * @return the message handle
     * @throws JMSException if the handle can't be created
     */
    public static MessageHandle createHandle(DurableConsumerEndpoint durable,
                                             MessageImpl message)
        throws JMSException {

        return new TransientMessageHandle(message);
    }

    /**
     * Create a transient message handle.
     *
     * @param destination the message destination
     * @param name the consumer name, can be null for JmsQueue type
     * @param message the message
     * @return the message handle
     * @throws JMSException if the handle can't be created
     */
    public static MessageHandle createHandle(JmsDestination dest, String name,
                                             MessageImpl message)
        throws JMSException {

        return new TransientMessageHandle(message);
    }

    /**
     * Create a {@link PersistentMessageHandle} from the specified
     * {@link TransientMessageHandle}. It does not fill in all the fields of a
     * persistent message handle.
     *
     * @param handle  the transient message handle
     * @return the persistent message handle
     * @throws JMSException if the handle can't be created
     */
    public static MessageHandle createPersistentHandle(
        TransientMessageHandle handle) throws JMSException {

        PersistentMessageHandle phandle = new PersistentMessageHandle();
        phandle.setMessageId(handle.getMessageId());
        phandle.setPriority(handle.getPriority());
        phandle.setDelivered(handle.getDelivered());
        phandle.setDestination(handle.getDestination());
        phandle.setAcceptedTime(handle.getAcceptedTime());
        phandle.setExpiryTime(handle.getExpiryTime());
        phandle.setSequenceNumber(handle.getSequenceNumber());
        phandle.setClientId(handle.getClientId());

        return phandle;
    }

    /**
     * Create a persistent message handle belonging to a queue.
     *
     * @param connection connection to the database
     * @param queue queue destination cache
     * @param message the message
     * @return the message handle
     * @throws JMSException if the handle can't be created
     * @throws PersistenceException if the handle cannot be made persistent
     */
    public static MessageHandle createPersistentHandle(
        Connection connection, QueueDestinationCache queue, 
        MessageImpl message) throws JMSException, PersistenceException {

        PersistentMessageHandle handle = new PersistentMessageHandle(message);

        // fill in the persistent related particulars
        handle.setConsumerName(queue.getDestination().getName());
        handle.setDestination(queue.getDestination());

        // make the handle persistent
        DatabaseService.getAdapter().addMessageHandle(connection, handle);

        return handle;
    }

    /**
     * Create a persistent handle for a message belonging to a particular
     * durable consumer
     *
     * @param connection the connection to use.
     * @param durable durable consumer endpoint
     * @param message the message
     * @return the message handle
     * @throws JMSException if the handle can't be created
     * @throws PersistenceException if the handle cannot be made persistent
     */
    public static MessageHandle createPersistentHandle(
        Connection connection, DurableConsumerEndpoint durable, 
        MessageImpl message) throws JMSException, PersistenceException {

        PersistentMessageHandle handle = new PersistentMessageHandle(message);

        // set the consumer and destination identity
        handle.setConsumerName(durable.getName());
        handle.setDestination(durable.getDestination());

        DatabaseService.getAdapter().addMessageHandle(connection, handle);

        return handle;
    }

    /**
     * Create a persistent message handle from the destination and consumer
     * name
     *
     * @param connection the connection to use
     * @param destination the message destination
     * @param name the consumer name, can be null for JmsQueue type
     * @param message the message
     * @return the message handle
     * @throws JMSException if the handle can't be created
     * @throws PersistenceException if the handle cannot be made persistent
     */
    public static MessageHandle createPersistentHandle(Connection connection, 
                                                       JmsDestination dest, 
                                                       String name, 
                                                       MessageImpl message) 
        throws JMSException, PersistenceException {

        PersistentMessageHandle handle = new PersistentMessageHandle(message);

        // set the consumer and destination identity
        handle.setDestination(dest);
        if (dest instanceof JmsQueue) {
            handle.setConsumerName(dest.getName());
        } else {
            handle.setConsumerName(name);
        }

        DatabaseService.getAdapter().addMessageHandle(connection, handle);
        return handle;
    }

    /**
     * Destroy the specified persistent handle.
     *
     * @param connection the connection to use
     * @param handle the persistent handle to destroy
     * @throws PersistenceExcetpion if there is a persistence-related error
     */
    public static void destroyPersistentHandle(Connection connection,
                                               PersistentMessageHandle handle)
        throws PersistenceException {
        DatabaseService.getAdapter().removeMessageHandle(connection, handle);

        // notify the message manager
        MessageMgr.instance().handleDestroyed(handle);
    }

    /**
     * Destroy a persistent handle associated with a destination, consumer
     * name and message
     *
     * @param connection the connection to use
     * @param destination the destination assoicated with the message
     * @param name the name of the consumer
     * @param message the message
     * @throws JMSException if the handle can't be created
     * @throws PersistentException if there is a persistence related error
     */
    public static void destroyPersistentHandle(Connection connection,
                                               JmsDestination destination,
                                               String name,
                                               MessageImpl message)
        throws JMSException, PersistenceException {

        if (message.isPersistent()) {
            PersistentMessageHandle handle =
                (PersistentMessageHandle) getHandle(destination, name,
                    message);
            destroyPersistentHandle(connection, handle);
        }
    }

    /**
     * Update the state of the persistent handle
     *
     * @param connection the connection to use
     * @param handle the handle to update
     * @throws PersistentException if there is a persistence related error
     */
    public static void updatePersistentHandle(Connection connection,
                                              PersistentMessageHandle handle)
        throws PersistenceException {
        DatabaseService.getAdapter().updateMessageHandle(connection, handle);
    }

} //-- MessageHandleFactory

⌨️ 快捷键说明

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