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

📄 adminconnection.java

📁 实现了Jms的服务器源码,支持多种适配器,DB,FTP,支持多种数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**
     * Check if the durable consumer exists.
     *
     * @param       name                name of the durable conusmer
     * @return      boolean             true if it exists and false otherwise
     */
    public boolean durableConsumerExists(String name) {
        return ConsumerManager.instance().durableConsumerExists(name);
    }

    /**
     * Return the collection of durable consumer names for a particular
     * topic destination.
     *
     * @param       topic               the topic name
     * @return      Vector              collection of strings
     */
    public Vector getDurableConsumers(String topic) {
        Enumeration iter = null;
        Vector result = new Vector();
        Connection connection = null;

        try {
            connection = DatabaseService.getConnection();

            iter = DatabaseService.getAdapter().getDurableConsumers(
                connection, topic);
            // copy the elements into the vector
            while (iter.hasMoreElements()) {
                result.addElement(iter.nextElement());
            }
            connection.commit();
        } catch (Exception exception) {
            _log.error("Failed on get durable consumers for topic=" + topic,
                exception);
            SQLHelper.rollback(connection);
        } finally {
            SQLHelper.close(connection);
        }

        return result;
    }

    /**
     * De-Activate an active persistent consumer.
     *
     * @param       name                name of the consumer
     * @return      boolean             true if successful
     */
    public boolean unregisterConsumer(String name) {
        boolean success = false;

        try {
            ConsumerManager.instance().deleteDurableConsumerEndpoint(name);
            success = true;
        } catch (JMSException exception) {
            //
        }

        return success;
    }

    /**
     * Check to see if the given consumer is currently connected to the
     * OpenJMSServer. This is only valid when in online mode.
     *
     * @param name The name of the onsumer.
     * @return boolean True if the consumer is connected.
     */
    public boolean isConnected(String name) {
        return ConsumerManager.instance().isDurableConsumerActive(name);
    }

    /**
     * Return a list of all registered destinations.
     *
     * @return      Vector     collection of strings
     */
    public Vector getAllDestinations() {
        Enumeration iter = null;
        Vector result = new Vector();
        Connection connection = null;
        TransactionManager tm = null;

        try {
            connection = DatabaseService.getConnection();

            iter = DatabaseService.getAdapter().getAllDestinations(connection);
            // copy the elements into the vector
            while (iter.hasMoreElements()) {
                result.addElement(iter.nextElement());
            }
            connection.commit();
        } catch (Exception exception) {
            _log.error("Failed to get all destinations", exception);
            SQLHelper.rollback(connection);
        } finally {
            SQLHelper.close(connection);
        }

        return result;
    }

    /**
     * Add an administered destination with the specified name
     *
     * @param       name                destination name
     * @param       queue               whether it is queue or a topic
     * @return      boolean             true if successful
     */
    public boolean addDestination(String name, Boolean queue) {

        boolean success = false;

        // create the appropriate destination object
        JmsDestination destination = (queue.booleanValue())
            ? (JmsDestination) new JmsQueue(name)
            : (JmsDestination) new JmsTopic(name);
        destination.setPersistent(true);

        // create the administered destination
        try {
            success = DestinationManager.instance().
                createAdministeredDestination(destination);
        } catch (JMSException exception) {
            _log.error("Failed to add destination=" + name, exception);
        }

        return success;
    }

    /**
     * Destroy the specified destination and all associated messsages and
     * consumers. This is a very dangerous operation to execute while there
     * are clients online
     *
     * @param       name         destination to destroy
     * @return      boolean             true if successful
     */
    public boolean removeDestination(String name) {

        boolean success = false;
        JmsDestination dest =
            DestinationManager.instance().destinationFromString(name);

        // ensure that the destination actually translates to a valid
        // object.
        if (dest != null) {
            try {
                DestinationManager.instance().deleteAdministeredDestination(dest);
                success = true;
            } catch (JMSException exception) {
                _log.error("Failed to remove destination=" + name, exception);
            }
        }

        return success;
    }

    /**
     * Check whether the specified destination exists
     *
     * @param  name - the name of the destination to check
     * @return boolean - true if it does and false otherwise
     */
    public boolean destinationExists(String name) {

        boolean exists = false;
        DestinationManager mgr = DestinationManager.instance();
        JmsDestination dest = mgr.destinationFromString(name);

        if (dest != null) {
            exists = mgr.destinationExists(dest);
        }

        return exists;
    }

    /**
     * Terminate the JMS Server. If it is running as a standalone application
     * then exit the application. It is running as an embedded application then
     * just terminate the thread
     */
    public void stopServer() {
        // todo perform neccesary clean up for a much nicer shutdown.
        // probably should inform all clients.

        _log.info("Stopping all services");
        ServiceManager.instance().removeAll();
        _log.info("Server Shutdown scheduled for 5 secs");
        Runnable r = new Runnable() {

            public void run() {
                try {
                    Thread.sleep(5000);
                    System.exit(0);
                } catch (Exception err) {
                    //
                }
            }
        };
        Thread t = new Thread(r);
        t.start();
    }

    /**
     * Purge all processed messages from the database
     *
     * @return      int         number of messages purged
     * @deprecated  no replacement
     */
    public int purgeMessages() {
        return 0;
    }

    /**
     * Add a user with the specified name
     *
     * @param username    the users name
     * @param password    the users password
     * @return <code>true</code> if the user is added
     * otherwise <code>false</code>
     */
    public boolean addUser(String username, String password) {
        return AuthenticationMgr.instance().addUser(
            new User(username, password));
    }

    /**
     * Change password for the specified user
     *
     * @param username    the users name
     * @param password    the users password
     * @return <code>true</code> if the password is changed
     * otherwise <code>false</code>
     */
    public boolean changePassword(String username, String password) {
        return AuthenticationMgr.instance().updateUser(
            new User(username, password));
    }

    /**
     * Remove the specified user
     *
     * @param username    the users name
     * @return <code>true</code> if the user is removed
     * otherwise <code>false</code>
     */
    public boolean removeUser(String username) {
        return AuthenticationMgr.instance().removeUser(
            new User(username, null));
    }

    /**
     * Return a list of all registered users.
     *
     * @return Vector of users
     */
    public Vector getAllUsers() {
        Enumeration iter = null;
        Vector result = new Vector();
        Connection connection = null;

        try {
            connection = DatabaseService.getConnection();

            iter = DatabaseService.getAdapter().getAllUsers(
                connection);
            // copy the elements into the vector
            while (iter.hasMoreElements()) {
                result.addElement(iter.nextElement());
            }
            connection.commit();
        } catch (Exception exception) {
            _log.error("Failed on get all users", exception);
            SQLHelper.rollback(connection);
        } finally {
            SQLHelper.close(connection);
        }

        return result;
    }

}

⌨️ 快捷键说明

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