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

📄 jmsserver.java

📁 实现了Jms的服务器源码,支持多种适配器,DB,FTP,支持多种数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**
     * Print out information on running this sevice
     */
    protected static void usage() {
        PrintStream out = System.out;

        out.println("\n\n");
        out.println("=====================================================");
        out.println("Usage information for org.exolab.jms.server.JmsServer");
        out.println("=====================================================");
        out.println("\norg.exolab.jms.server.JmsServer");
        out.println("    [-config <xml config file> | -version | -help]\n");
        out.println("\t-config  file name of xml-based config file\n");
        out.println("\t-version displays OpenJMS version information\n");
        out.println("\t-help    displays this screen\n");
    }

    /**
     * Initialise the services
     */
    protected void registerServices() throws ServiceException {
        // add the thread pool manager
        _services.add(ThreadPoolManager.instance().getName(),
            ThreadPoolManager.instance());

        // add the event manager
        _services.add(BasicEventManager.instance().getName(),
            BasicEventManager.instance());

        // add the database service
        _services.add(DatabaseService.instance().getName(),
            DatabaseService.instance());

        // add the scheduler
        _services.add(Scheduler.createInstance().getName(),
            Scheduler.instance());

        // add the lease manager
        _services.add(LeaseManager.instance().getName(),
            LeaseManager.instance());

        // add the transaction manager
        //_services.add (TransactionService.instance().getName(),
        //                 TransactionService.instance());

        // add the garbage collection service
        _services.add(GarbageCollectionService.instance().getName(),
            GarbageCollectionService.instance());

        // add the authentication manager
        _services.add(AuthenticationMgr.createInstance().getName(),
            AuthenticationMgr.instance());

        // add the resource manager service
        //_services.add(ResourceManager.instance().getName(),
        //                ResourceManager.instance());

        // add the message manager
        _services.add(MessageMgr.createInstance().getName(),
            MessageMgr.instance());
    }

    /**
     * Creates an interface to the server for each configured connector
     *
     * @param context the initial context
     * @throws NamingException if administered objects cannot be bound in JNDI
     * @throws ServerException if an interface can't be created
     */
    protected void initConnectors(Context context)
        throws NamingException, ServerException {

        Connector[] connectors = _config.getConnectors().getConnector();
        _interfaces = new JmsServerIfc[connectors.length];

        for (int i = 0; i < connectors.length; ++i) {
            Connector connector = connectors[i];
            _interfaces[i] = initConnector(connector, context);
        }
    }

    /**
     * Create an interface to the server for the specified connector
     *
     * @param connector the connector
     * @param context the initial context
     * @return the interface corresponding to <code>connector</code>
     * @throws NamingException if administered objects cannot be bound in JNDI
     * @throws ServerException if the interface can't be created
     */
    protected JmsServerIfc initConnector(Connector connector, Context context)
        throws NamingException, ServerException {

        _log.info("Creating server interface for the " + connector.getScheme()
            + " connector");

        JmsServerIfc server;
        ConnectorResource resource = ConnectorHelper.getConnectorResource(
            connector.getScheme());

        String className = resource.getServer().getImplementationClass();
        Class clazz;
        try {
            clazz = Class.forName(className);
        } catch (ClassNotFoundException exception) {
            throw new FailedToCreateServerException(
                "Failed to load class " + className);
        }

        if (!JmsServerIfc.class.isAssignableFrom(clazz)) {
            throw new FailedToCreateServerException(
                "Class " + className + " does not implement JmsServerIfc");
        }
        try {
            server = (JmsServerIfc) clazz.newInstance();
            _log.debug("Created an instance of " + className
                + " as a server interface");
        } catch (Exception exception) {
            throw new FailedToCreateServerException(
                exception.getMessage(), exception);
        }

        // initialise the interface
        server.init();

        // bind any configured connection factories
        server.bindConnectionFactories(context);

        return server;
    }

    protected void createRegistry() throws ServerException {

        int port = _config.getRmiConfiguration().getRegistryPort();
        try {
            RmiRegistryService service = new RmiRegistryService(port);
            _services.add(service.getName(), service);
        } catch (Exception exception) {
            throw new FailedToCreateServerException(
                "Failed to start the RMI registry", exception);
        }
        _log.info("Embedded RMI registry running on port " + port);
    }

    /**
     * Creates a JNDI provider interface for each connector that supports it
     *
     * @param context the initial context
     * @throws NamingException if a provider can't be initialised
     * @throws ServerException if a provider can't be created
     */
    protected void initJNDIConnectors(Context context)
        throws NamingException, ServerException {

        Connector[] connectors = _config.getConnectors().getConnector();
        ArrayList interfaces = new ArrayList();

        for (int i = 0; i < connectors.length; ++i) {
            Connector connector = connectors[i];
            ConnectorResource resource = ConnectorHelper.getConnectorResource(
                connector.getScheme());
            if (resource.getJndi().getImplementationClass() != null) {
                JndiServerIfc provider = initJNDIConnector(resource, context);
                interfaces.add(provider);
            }
        }
        _jndiInterfaces = (JndiServerIfc[]) interfaces.toArray(
            new JndiServerIfc[0]);
    }

    /**
     * Creates a JNDI provider interface for the specified connector
     *
     * @param connector the connector
     * @param context the initial context
     * @return the JNDI provider interface
     * @throws NamingException if the provider can't be initialised
     * @throws ServerException if the provider can't be created
     */
    protected JndiServerIfc initJNDIConnector(
        ConnectorResource connector, Context context)
        throws NamingException, ServerException {

        _log.info("Creating JNDI interface for the " + connector.getScheme()
            + " connector");

        JndiServerIfc result;
        String className = connector.getJndi().getImplementationClass();
        Class clazz;
        try {
            clazz = Class.forName(className);
        } catch (ClassNotFoundException exception) {
            throw new FailedToCreateServerException(
                "Failed to load class " + className);
        }
        if (!JndiServerIfc.class.isAssignableFrom(clazz)) {
            throw new FailedToCreateServerException(
                "Class " + className + " does not implement JndiServerIfc");
        }
        try {
            Constructor constructor = clazz.getDeclaredConstructor(
                new Class[]{Context.class});
            result = (JndiServerIfc) constructor.newInstance(
                new Object[]{context});
            result.init();
            _log.debug("Created an instance of " + className
                + " as a JNDI provider interface");
        } catch (Exception exception) {
            throw new FailedToCreateServerException(
                exception.getMessage(), exception);
        }
        return result;
    }

    /**
     * Determines if the configuration has the specified connector
     *
     * @param scheme the connector scheme
     * @return <code>true<code> if the configuration has a connector
     * corresponding to <code>scheme</code>
     */
    private boolean hasConnector(SchemeType scheme) {
        boolean result = false;
        Connector[] connectors = _config.getConnectors().getConnector();
        for (int i = 0; i < connectors.length; ++i) {
            if (connectors[i].getScheme().equals(scheme)) {
                result = true;
                break;
            }
        }
        return result;
    }

    /**
     * Returns the value of the openjms.home environment variable
     */
    private static String getOpenJMSHome() {
        return System.getProperty("openjms.home",
            System.getProperty("user.dir"));
    }

} //-- JmsServer

⌨️ 快捷键说明

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