Search in sources :

Example 1 with AdminDataHandler

use of com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler in project openmq by eclipse-ee4j.

the class CoreLifecycleImpl method initHandlers.

@Override
public void initHandlers(PacketRouter pktrtr, ConnectionManager cmgr, PacketRouter admin_pktrtr, AdminDataHandler admin_datahdrl) throws BrokerException {
    this.pktr = pktrtr;
    HelloHandler hello = new HelloHandler(cmgr);
    hello.setCoreLifecycle(this);
    GetLicenseHandler getLicense = new GetLicenseHandler();
    getLicense.setCoreLifecycle(this);
    GoodbyeHandler goodbye = new GoodbyeHandler();
    goodbye.setCoreLifecycle(this);
    StartStopHandler startstop = new StartStopHandler();
    startstop.setCoreLifecycle(this);
    ConsumerHandler conhdlr = new ConsumerHandler();
    conhdlr.setCoreLifecycle(this);
    ProducerHandler prodhandler = new ProducerHandler();
    prodhandler.setCoreLifecycle(this);
    DestinationHandler desthandler = new DestinationHandler();
    desthandler.setCoreLifecycle(this);
    QBrowseHandler qbrowserhdlr = new QBrowseHandler();
    qbrowserhdlr.setCoreLifecycle(this);
    AuthHandler authenticate = new AuthHandler();
    authenticate.setCoreLifecycle(this);
    SessionHandler sessionhdlr = new SessionHandler();
    sessionhdlr.setCoreLifecycle(this);
    PingHandler pinghandler = new PingHandler();
    pinghandler.setCoreLifecycle(this);
    DataHandler datahdrl = new DataHandler();
    datahdrl.setCoreLifecycle(this);
    AckHandler ackhandler = new AckHandler();
    ackhandler.setCoreLifecycle(this);
    RedeliverHandler redeliverhdlr = new RedeliverHandler();
    redeliverhdlr.setCoreLifecycle(this);
    DeliverHandler deliverhdlr = new DeliverHandler();
    deliverhdlr.setCoreLifecycle(this);
    TransactionHandler thandler = new TransactionHandler();
    thandler.setCoreLifecycle(this);
    VerifyDestinationHandler vdhandler = new VerifyDestinationHandler();
    vdhandler.setCoreLifecycle(this);
    ClientIDHandler clienthandler = new ClientIDHandler();
    clienthandler.setCoreLifecycle(this);
    FlowHandler flowhdlr = new FlowHandler();
    flowhdlr.setCoreLifecycle(this);
    FlowPausedHandler fphandler = new FlowPausedHandler();
    fphandler.setCoreLifecycle(this);
    GenerateUIDHandler genUIDhandler = new GenerateUIDHandler();
    genUIDhandler.setCoreLifecycle(this);
    InfoRequestHandler infohandler = new InfoRequestHandler();
    infohandler.setCoreLifecycle(this);
    VerifyTransactionHandler vthandler = new VerifyTransactionHandler();
    vthandler.setCoreLifecycle(this);
    pktrtr.addHandler(PacketType.HELLO, hello);
    pktrtr.addHandler(PacketType.AUTHENTICATE, authenticate);
    pktrtr.addHandler(PacketType.GET_LICENSE, getLicense);
    pktrtr.addHandler(PacketType.ADD_CONSUMER, conhdlr);
    pktrtr.addHandler(PacketType.DELETE_CONSUMER, conhdlr);
    pktrtr.addHandler(PacketType.ADD_PRODUCER, prodhandler);
    pktrtr.addHandler(PacketType.START, startstop);
    pktrtr.addHandler(PacketType.STOP, startstop);
    pktrtr.addHandler(PacketType.ACKNOWLEDGE, ackhandler);
    pktrtr.addHandler(PacketType.BROWSE, qbrowserhdlr);
    pktrtr.addHandler(PacketType.GOODBYE, goodbye);
    pktrtr.addHandler(PacketType.REDELIVER, redeliverhdlr);
    pktrtr.addHandler(PacketType.CREATE_DESTINATION, desthandler);
    pktrtr.addHandler(PacketType.DESTROY_DESTINATION, desthandler);
    pktrtr.addHandler(PacketType.VERIFY_DESTINATION, vdhandler);
    pktrtr.addHandler(PacketType.DELIVER, deliverhdlr);
    pktrtr.addHandler(PacketType.START_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.COMMIT_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.ROLLBACK_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.PREPARE_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.END_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.RECOVER_TRANSACTION, thandler);
    pktrtr.addHandler(PacketType.SET_CLIENTID, clienthandler);
    pktrtr.addHandler(PacketType.GENERATE_UID, genUIDhandler);
    pktrtr.addHandler(PacketType.MAP_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.BYTES_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.MESSAGE_SET, datahdrl);
    pktrtr.addHandler(PacketType.OBJECT_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.STREAM_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.TEXT_MESSAGE, datahdrl);
    pktrtr.addHandler(PacketType.RESUME_FLOW, flowhdlr);
    pktrtr.addHandler(PacketType.FLOW_PAUSED, fphandler);
    pktrtr.addHandler(PacketType.CREATE_SESSION, sessionhdlr);
    pktrtr.addHandler(PacketType.DELETE_PRODUCER, prodhandler);
    pktrtr.addHandler(PacketType.DESTROY_SESSION, sessionhdlr);
    pktrtr.addHandler(PacketType.PING, pinghandler);
    pktrtr.addHandler(PacketType.INFO_REQUEST, infohandler);
    pktrtr.addHandler(PacketType.VERIFY_TRANSACTION, vthandler);
    // Map message handles -> messages. For the admin service this
    // is just like the regular JMS service except we have a specialized
    // data handler
    admin_pktrtr.addHandler(PacketType.HELLO, hello);
    admin_pktrtr.addHandler(PacketType.AUTHENTICATE, authenticate);
    admin_pktrtr.addHandler(PacketType.GET_LICENSE, getLicense);
    admin_pktrtr.addHandler(PacketType.ADD_CONSUMER, conhdlr);
    admin_pktrtr.addHandler(PacketType.DELETE_CONSUMER, conhdlr);
    admin_pktrtr.addHandler(PacketType.ADD_PRODUCER, prodhandler);
    admin_pktrtr.addHandler(PacketType.START, startstop);
    admin_pktrtr.addHandler(PacketType.STOP, startstop);
    admin_pktrtr.addHandler(PacketType.ACKNOWLEDGE, ackhandler);
    admin_pktrtr.addHandler(PacketType.BROWSE, qbrowserhdlr);
    admin_pktrtr.addHandler(PacketType.GOODBYE, goodbye);
    admin_pktrtr.addHandler(PacketType.REDELIVER, redeliverhdlr);
    admin_pktrtr.addHandler(PacketType.CREATE_DESTINATION, desthandler);
    admin_pktrtr.addHandler(PacketType.DESTROY_DESTINATION, desthandler);
    admin_pktrtr.addHandler(PacketType.VERIFY_DESTINATION, vdhandler);
    admin_pktrtr.addHandler(PacketType.DELIVER, deliverhdlr);
    admin_pktrtr.addHandler(PacketType.START_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.COMMIT_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.ROLLBACK_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.PREPARE_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.END_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.RECOVER_TRANSACTION, thandler);
    admin_pktrtr.addHandler(PacketType.SET_CLIENTID, clienthandler);
    admin_pktrtr.addHandler(PacketType.GENERATE_UID, genUIDhandler);
    admin_pktrtr.addHandler(PacketType.MAP_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.BYTES_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.MESSAGE_SET, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.OBJECT_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.STREAM_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.TEXT_MESSAGE, admin_datahdrl);
    admin_pktrtr.addHandler(PacketType.RESUME_FLOW, flowhdlr);
    admin_pktrtr.addHandler(PacketType.FLOW_PAUSED, fphandler);
    admin_pktrtr.addHandler(PacketType.CREATE_SESSION, sessionhdlr);
    admin_pktrtr.addHandler(PacketType.DELETE_PRODUCER, prodhandler);
    admin_pktrtr.addHandler(PacketType.DESTROY_SESSION, sessionhdlr);
}
Also used : GetLicenseHandler(com.sun.messaging.jmq.jmsserver.common.handlers.GetLicenseHandler) AuthHandler(com.sun.messaging.jmq.jmsserver.common.handlers.AuthHandler) SessionHandler(com.sun.messaging.jmq.jmsserver.common.handlers.SessionHandler) VerifyDestinationHandler(com.sun.messaging.jmq.jmsserver.common.handlers.VerifyDestinationHandler) DestinationHandler(com.sun.messaging.jmq.jmsserver.data.handlers.DestinationHandler) PingHandler(com.sun.messaging.jmq.jmsserver.common.handlers.PingHandler) VerifyTransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.VerifyTransactionHandler) GoodbyeHandler(com.sun.messaging.jmq.jmsserver.common.handlers.GoodbyeHandler) ProducerHandler(com.sun.messaging.jmq.jmsserver.data.handlers.ProducerHandler) HelloHandler(com.sun.messaging.jmq.jmsserver.common.handlers.HelloHandler) DataHandler(com.sun.messaging.jmq.jmsserver.data.handlers.DataHandler) AdminDataHandler(com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler) InfoRequestHandler(com.sun.messaging.jmq.jmsserver.common.handlers.InfoRequestHandler) ConsumerHandler(com.sun.messaging.jmq.jmsserver.data.handlers.ConsumerHandler) ClientIDHandler(com.sun.messaging.jmq.jmsserver.common.handlers.ClientIDHandler) VerifyTransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.VerifyTransactionHandler) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler) VerifyDestinationHandler(com.sun.messaging.jmq.jmsserver.common.handlers.VerifyDestinationHandler) FlowPausedHandler(com.sun.messaging.jmq.jmsserver.common.handlers.FlowPausedHandler) RedeliverHandler(com.sun.messaging.jmq.jmsserver.data.handlers.RedeliverHandler) QBrowseHandler(com.sun.messaging.jmq.jmsserver.data.handlers.QBrowseHandler) GenerateUIDHandler(com.sun.messaging.jmq.jmsserver.common.handlers.GenerateUIDHandler) DeliverHandler(com.sun.messaging.jmq.jmsserver.data.handlers.DeliverHandler) FlowHandler(com.sun.messaging.jmq.jmsserver.common.handlers.FlowHandler) StartStopHandler(com.sun.messaging.jmq.jmsserver.common.handlers.StartStopHandler) AckHandler(com.sun.messaging.jmq.jmsserver.data.handlers.AckHandler)

Example 2 with AdminDataHandler

use of com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler in project openmq by eclipse-ee4j.

the class MessageManagerConfig method replaceMessage.

public String replaceMessage(String destinationType, String destinationName, String messageID, HashMap messageBody) throws MBeanException {
    String newMsgID = null;
    try {
        if (destinationType == null) {
            throw new BrokerException("Admin replaceMessage: destination name and type not specified", Status.BAD_REQUEST);
        }
        PacketRouter pr = Globals.getPacketRouter(1);
        if (pr == null) {
            throw new BrokerException("Admin deleteMessage: Could not locate Admin Packet Router");
        }
        AdminDataHandler dhd = (AdminDataHandler) pr.getHandler(PacketType.OBJECT_MESSAGE);
        ReplaceMessageHandler hd = (ReplaceMessageHandler) dhd.getHandler(com.sun.messaging.jmq.util.admin.MessageType.REPLACE_MESSAGE);
        newMsgID = hd.replaceMessage(messageID, destinationName, messageBody, destinationType.equals(DestinationType.QUEUE));
    } catch (Exception e) {
        boolean logstack = true;
        if (e instanceof BrokerException) {
            int status = ((BrokerException) e).getStatusCode();
            if (status == Status.NOT_ALLOWED || status == Status.NOT_FOUND || status == Status.CONFLICT || status == Status.BAD_REQUEST) {
                logstack = false;
            }
        }
        Object[] args = { messageID, destinationName, e.getMessage() };
        String emsg = rb.getKString(rb.X_ADMIN_DELETE_MSG, args);
        if (logstack) {
            logger.logStack(Logger.ERROR, emsg, e);
        } else {
            logger.log(Logger.ERROR, emsg, e);
        }
        handleOperationException("replaceMessage", e);
    }
    return (newMsgID);
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) PacketRouter(com.sun.messaging.jmq.jmsserver.data.PacketRouter) AdminDataHandler(com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler) ReplaceMessageHandler(com.sun.messaging.jmq.jmsserver.data.handlers.admin.ReplaceMessageHandler) MBeanException(javax.management.MBeanException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 3 with AdminDataHandler

use of com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler in project openmq by eclipse-ee4j.

the class MessageManagerConfig method deleteMessage.

public void deleteMessage(String destinationType, String destinationName, String messageID) throws MBeanException {
    try {
        if (destinationType == null) {
            throw new BrokerException("Admin deleteMessage: destination type not specified", Status.BAD_REQUEST);
        }
        PacketRouter pr = Globals.getPacketRouter(1);
        if (pr == null) {
            throw new BrokerException("Admin deleteMessage: Could not locate Admin Packet Router");
        }
        AdminDataHandler dhd = (AdminDataHandler) pr.getHandler(PacketType.OBJECT_MESSAGE);
        DeleteMessageHandler hd = (DeleteMessageHandler) dhd.getHandler(com.sun.messaging.jmq.util.admin.MessageType.DELETE_MESSAGE);
        hd.deleteMessage(messageID, destinationName, destinationType.equals(DestinationType.QUEUE));
    } catch (Exception e) {
        boolean logstack = true;
        if (e instanceof BrokerException) {
            int status = ((BrokerException) e).getStatusCode();
            if (status == Status.NOT_ALLOWED || status == Status.NOT_FOUND || status == Status.CONFLICT || status == Status.BAD_REQUEST) {
                logstack = false;
            }
        }
        Object[] args = { messageID, destinationName, e.getMessage() };
        String emsg = rb.getKString(rb.X_ADMIN_DELETE_MSG, args);
        if (logstack) {
            logger.logStack(Logger.ERROR, emsg, e);
        } else {
            logger.log(Logger.ERROR, emsg, e);
        }
        handleOperationException("deleteMessage", e);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) PacketRouter(com.sun.messaging.jmq.jmsserver.data.PacketRouter) DeleteMessageHandler(com.sun.messaging.jmq.jmsserver.data.handlers.admin.DeleteMessageHandler) AdminDataHandler(com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler) MBeanException(javax.management.MBeanException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 4 with AdminDataHandler

use of com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler in project openmq by eclipse-ee4j.

the class Broker method _start.

private int _start(boolean inProcess, Properties propsFromCommandLine, boolean initOnly, Throwable failStartThrowable) throws OutOfMemoryError, IllegalStateException, IllegalArgumentException {
    try {
        setIsInProcess(inProcess);
        // initialize the Global properties if any arguments are passed in
        // read properties (including passwords) from standard input (used when the broker is managed by JMSRA)
        Properties propsFromStdin = null;
        if (propsFromCommandLine != null && propsFromCommandLine.containsKey(Globals.IMQ + ".readstdin.enabled")) {
            propsFromStdin = readPropertiesFromStandardInput();
        }
        // Combine any properties specified using command-line parameters with any properties read from standard input
        // The properties loaded from standard input have precedence and so are loaded second
        Properties combinedProps = new Properties();
        if (propsFromCommandLine != null) {
            combinedProps.putAll(propsFromCommandLine);
        }
        if (propsFromStdin != null) {
            combinedProps.putAll(propsFromStdin);
        }
        Globals.init(combinedProps, clearProps, saveProps);
        if (!removeInstance) {
            BrokerStateHandler.setShuttingDown(false);
            BrokerStateHandler.setShutdownStarted(false);
        }
        haltLogString = Globals.getBrokerResources().getKString(BrokerResources.W_HALT_BROKER);
        logger = Globals.getLogger();
        String configdir = Globals.getInstanceDir();
        File f = new File(configdir);
        // 
        if (!f.exists()) {
            // check parent directory
            while (!f.exists()) {
                // loop up looking for the parent
                f = f.getParentFile();
                if (f == null) {
                    // now where else to go
                    break;
                }
                if (!f.exists()) {
                    continue;
                }
                if (!f.canWrite() || !f.canRead()) {
                    String emsg = rb.getKString(rb.E_CAN_NOT_WRITE, f, Globals.getConfigName());
                    if (!silent) {
                        printErr(emsg);
                    }
                    if (failStartThrowable != null) {
                        failStartThrowable.initCause(new Exception(emsg));
                    }
                    return (BrokerExitCode.NO_PERMISSION_ON_INSTANCE);
                }
            }
        } else if (!f.canWrite() || !f.canRead()) {
            String emsg = rb.getKString(rb.E_CAN_NOT_WRITE, f, Globals.getConfigName());
            if (!silent) {
                System.err.println(emsg);
            }
            if (failStartThrowable != null) {
                failStartThrowable.initCause(new Exception(emsg));
            }
            return (BrokerExitCode.NO_PERMISSION_ON_INSTANCE);
        }
        // OF CREATING AN INSTANCE BEFORE THIS CHECK
        if (removeInstance) {
            removeInstance();
        }
        // if a password file is specified, read it
        try {
            parsePassfile();
        } catch (IOException ex) {
            logger.log(Logger.FORCE, rb.E_OPTION_VALID_ERROR, ex);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(ex);
            }
            return (1);
        }
        // Initialize any possible debug settings
        try {
            com.sun.messaging.jmq.util.Debug.setDebug(Globals.getConfig(), Globals.IMQ + ".debug.");
        } catch (Exception e) {
            logger.log(Logger.WARNING, rb.W_BAD_DEBUG_CLASS, e);
        }
        // Initialize any diag settings
        try {
            com.sun.messaging.jmq.util.DiagManager.registerClasses(Globals.getConfig(), Globals.IMQ + ".diag.");
        } catch (Exception e) {
            logger.log(Logger.WARNING, rb.W_BAD_DIAG_CLASS, e);
        }
        BrokerConfig conf = Globals.getConfig();
        try {
            checkBrokerConfig(conf);
        } catch (Exception e) {
            logger.logToAll(logger.ERROR, e.getMessage());
            if (failStartThrowable != null) {
                failStartThrowable.initCause(e);
            }
            return 1;
        }
        if (!Globals.isJMSRAManagedSpecified() && Globals.isJMSRAManagedBroker()) {
            String emsg = Globals.getBrokerResources().getKString(BrokerResources.E_START_JMSRA_MANAGED_BROKER_NONMANAGED);
            logger.log(Logger.ERROR, emsg);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(new Exception(emsg));
            }
            return (1);
        }
        if (Globals.isJMSRAManagedBroker()) {
            try {
                conf.updateBooleanProperty(Globals.JMSRA_MANAGED_PROPERTY, true, true);
            } catch (Exception e) {
                logger.logStack(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.E_SET_BROKER_CONFIG_PROPERTY, Globals.JMSRA_MANAGED_PROPERTY + "=true", e.getMessage()), e);
                if (failStartThrowable != null) {
                    failStartThrowable.initCause(e);
                }
                return (1);
            }
        }
        CoreLifecycleSpi coreLifecycle = Globals.getCoreLifecycle();
        String banner = version.getBanner(false, Version.MINI_COPYRIGHT) + rb.getString(rb.I_JAVA_VERSION) + System.getProperty("java.version") + " " + System.getProperty("java.vendor") + " " + System.getProperty("java.home");
        logger.logToAll(Logger.INFO, rb.NL + banner);
        // Check to see if we have a version mismatch
        if (!version.isProductValid()) {
            // not valid - display an error
            // 
            String emsg = rb.getKString(BrokerResources.E_INVALID_PRODUCT_VERSION);
            logger.log(Logger.ERROR, emsg);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(new Exception(emsg));
            }
            return (1);
        }
        try {
            initializePasswdFile();
        } catch (IOException ex) {
            if (failStartThrowable != null) {
                failStartThrowable.initCause(ex);
            }
            return (1);
        }
        if (initOnly) {
            logger.log(Logger.INFO, BrokerResources.I_INIT_DONE);
            return 0;
        }
        try {
            AccessController.setSecurityManagerIfneed();
        } catch (Exception e) {
            logger.logStack(Logger.ERROR, e.getMessage(), e);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(e);
            }
            return (1);
        }
        if (!MQAuthenticator.authenticateCMDUserIfset()) {
            logger.log(Logger.INFO, BrokerResources.I_SHUTDOWN_BROKER);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(new Exception("MQAuthenticator failed"));
            }
            return (1);
        }
        // For printing out VM heap info
        DiagManager.register(new VMDiagnostics());
        if (Version.compareVersions(System.getProperty("java.specification.version"), MIN_JAVA_VERSION, true) < 0) {
            String emsg = rb.getKString(rb.E_BAD_JAVA_VERSION, System.getProperty("java.specification.version"), MIN_JAVA_VERSION);
            logger.logToAll(Logger.ERROR, emsg);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(new Exception(emsg));
            }
            return (1);
        }
        String hostname = conf.getProperty(Globals.IMQ + ".hostname");
        // Save value of imq.hostname. This may be null which is OK
        Globals.setHostname(hostname);
        /*
             * In a variety of places we need to know the name of the host the broker is running on, and its IP address. Typically
             * you get this by calling getLocalHost(). But if the broker is running on a multihomed machine, you may want to control
             * which interface (and IP address) the broker uses. Therefore we support the imq.hostname property to let the user
             * configure this.
             */
        if (hostname == null || hostname.equals(Globals.HOSTNAME_ALL)) {
            // No hostname specified. Get local host
            try {
                InetAddress ia = InetAddress.getLocalHost();
                Globals.setBrokerInetAddress(ia);
            } catch (UnknownHostException e) {
                logger.log(Logger.ERROR, rb.E_NO_LOCALHOST, e);
                logger.log(Logger.INFO, rb.M_BROKER_EXITING);
                if (failStartThrowable != null) {
                    failStartThrowable.initCause(e);
                }
                return (1);
            }
        } else {
            // machine. Look up the address now so we have its IP
            try {
                InetAddress ia = InetAddress.getByName(hostname);
                Globals.setBrokerInetAddress(ia);
            } catch (UnknownHostException e) {
                logger.log(Logger.ERROR, rb.getString(rb.E_BAD_HOSTNAME_PROP, hostname, Globals.IMQ + ".hostname"), e);
                logger.log(Logger.INFO, rb.M_BROKER_EXITING);
                if (failStartThrowable != null) {
                    failStartThrowable.initCause(e);
                }
                return (1);
            }
        }
        /*
             * Do the same thing for JMX hostname. On a multihome system, we may want to designate different IP addresses for the
             * broker and for JMX traffic. A new property imq.jmx.hostname is created for this. By default, it will be set to
             * whatever value imq.hostname is set to.
             */
        String jmxHostname = conf.getProperty(Globals.IMQ + ".jmx.hostname");
        // Save value of imq.jmx.hostname. This may be null which is OK
        Globals.setJMXHostname(jmxHostname);
        /*
             * Only check for the case where the JMX hostname is specified. If it is not, it will default to whatever value is
             * configured for the broker hostname (imq.hostname).
             */
        if (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL)) {
            // machine. Look up the address now so we have its IP
            try {
                InetAddress ia = InetAddress.getByName(jmxHostname);
                Globals.setJMXInetAddress(ia);
            } catch (UnknownHostException e) {
                logger.log(Logger.ERROR, rb.getString(rb.E_BAD_HOSTNAME_PROP, hostname, Globals.IMQ + ".jmx.hostname"), e);
                logger.log(Logger.INFO, rb.M_BROKER_EXITING);
                if (failStartThrowable != null) {
                    failStartThrowable.initCause(e);
                }
                return (1);
            }
        }
        try {
            logger.logToAll(Logger.INFO, "   IMQ_HOME=" + new File(Globals.getJMQ_HOME()).getCanonicalPath());
            logger.logToAll(Logger.INFO, "IMQ_VARHOME=" + new File(Globals.getJMQ_VAR_HOME()).getCanonicalPath());
        } catch (IOException e) {
        }
        logger.logToAll(Logger.INFO, System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch") + " " + Globals.getBrokerHostName() + " " + "(" + Runtime.getRuntime().availableProcessors() + " cpu) " + System.getProperty("user.name"));
        try {
            // Log ulimit -n values
            Rlimit.Limits limits = Rlimit.get(Rlimit.RLIMIT_NOFILE);
            logger.logToAll(Logger.INFO, rb.getString(rb.I_NOFILES), ((limits.current == Rlimit.RLIM_INFINITY) ? "unlimited" : String.valueOf(limits.current)), ((limits.maximum == Rlimit.RLIM_INFINITY) ? "unlimited" : String.valueOf(limits.maximum)));
        } catch (Exception e) {
        // This is OK. It just means we can't log ulimit values on
        // this platform.
        }
        // Log JVM heap size information
        logger.logToAll(Logger.INFO, rb.getString(rb.I_JAVA_HEAP), Long.toString(Runtime.getRuntime().maxMemory() / 1024), Long.toString(Runtime.getRuntime().totalMemory() / 1024));
        // Start of logging of the various sets of properties that have been supplied in various ways
        // log the actual broker command-line arguments
        logger.logToAll(Logger.INFO, rb.getString(rb.I_BROKER_ARGS), (propsFromCommandLine == null ? "" : propsFromCommandLine.get("BrokerArgs")));
        // if the broker is non-embedded and started by JMSRA
        // log any properties read from standard input
        logProperties("JMSRA BrokerProps: ", propsFromStdin);
        // log any properties supplied programmatically
        if (embeddedBrokerStartupMessages != null) {
            for (String thisMessage : embeddedBrokerStartupMessages) {
                // Log the embeddedBrokerStartupMessages here
                // These are typically used to log broker properties configured on an embedded broker
                // which is why we perform this logging at this point.
                // However they can also be used to log other information passed by the code that started the embedded broker
                logger.logToAll(Logger.INFO, thisMessage);
            }
        }
        // log all properties specified on the command line either explicity or via command-line arguments
        logProperties(rb.getString(rb.I_BROKER_PROPERTIES), propsFromCommandLine);
        if (inProcess) {
            logger.logToAll(Logger.INFO, rb.getString(rb.I_INPROCESS_BROKER));
        }
        // set up out of memory handler
        Globals.setGlobalErrorHandler(this);
        // Get admin key from the key file if any. This is only used by
        // the nt service to handle shutdown.
        String key = getAdminKey(adminKeyFile);
        String propname = Globals.IMQ + ".adminkey";
        if (key == null || key.length() == 0) {
            // Make sure property is not set
            conf.remove(propname);
        } else {
            try {
                conf.updateProperty(propname, key);
            } catch (Exception e) {
            }
        }
        /*
             * Hawk HA : retrieve ha properties and brokerid
             */
        boolean isHA = Globals.getHAEnabled();
        String brokerid = Globals.getBrokerID();
        String clusterid = Globals.getClusterID();
        if (Globals.getHAEnabled()) {
            if (brokerid == null) {
                String emsg = rb.getKString(rb.E_BID_MUST_BE_SET);
                logger.logToAll(Logger.ERROR, emsg);
                if (failStartThrowable != null) {
                    failStartThrowable.initCause(new Exception(emsg));
                }
                return (1);
            }
            logger.log(Logger.INFO, BrokerResources.I_RUNNING_IN_HA, brokerid, clusterid);
        } else if (brokerid != null) {
            logger.log(Logger.INFO, BrokerResources.I_STARTING_WITH_BID, brokerid);
        }
        PortMapper pm = Globals.getPortMapper();
        if (pm == null || (pm.getServerSocket() == null && pm.isDoBind() && Globals.getPUService() == null)) {
            // PortMapper failed to bind to port. Port is probably already
            // in use. An error message has already been logged so just exit
            String emsg = rb.getString(rb.E_PORTMAPPER_START);
            logger.logToAll(logger.ERROR, emsg);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(new Exception(emsg));
            }
            return (1);
        }
        /*
             * Store MQAddress in Globals so it can be accessed when needed One place this is used is the "brokerAddress" property
             * of monitoring messages.
             */
        MQAddress addr = null;
        try {
            addr = BrokerMQAddress.createAddress(Globals.getBrokerHostName(), pm.getPort());
        } catch (Exception e) {
            logger.logStack(Logger.INFO, BrokerResources.E_CANNOT_CREATE_MQADDRESS, "[" + Globals.getBrokerHostName() + "]:" + pm.getPort(), e);
        }
        boolean NO_CLUSTER;
        try {
            NO_CLUSTER = Globals.initClusterManager(addr);
            if (NO_CLUSTER) {
                logger.log(Logger.WARNING, BrokerResources.I_USING_NOCLUSTER);
            }
        } catch (Exception e) {
            logger.logStack(Logger.ERROR, BrokerResources.E_INITING_CLUSTER, e);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(e);
            }
            return (1);
        }
        if (Globals.useMasterBroker() && Globals.dynamicChangeMasterBrokerEnabled() && !Globals.isJMSRAManagedBroker()) {
            if (Globals.isMasterBrokerSpecified()) {
                String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_NO_CMDLINE_MASTERBROKER_WHEN_DYNAMIC, ClusterManager.CONFIG_SERVER, Globals.DYNAMIC_CHANGE_MASTERBROKER_ENABLED_PROP + "=true");
                logger.log(Logger.ERROR, emsg);
                if (failStartThrowable != null) {
                    failStartThrowable.initCause(new Exception(emsg));
                }
                return (1);
            }
        }
        pm.updateProperties();
        if (pm.isDoBind()) {
            if (Globals.getPUService() == null) {
                // start the PortMapper thread
                Thread portMapperThread = new MQThread(pm, "JMQPortMapper");
                portMapperThread.setDaemon(true);
                portMapperThread.start();
            } else {
                try {
                    pm.startPUService();
                } catch (Exception e) {
                    logger.logStack(logger.ERROR, e.getMessage(), e);
                    if (failStartThrowable != null) {
                        failStartThrowable.initCause(e);
                    }
                    return (1);
                }
            }
        }
        // Try to acquire the lock file. This makes sure no other copy
        // of the broker is running in the same instance directory as
        // we are.
        LockFile lf = null;
        try {
            lf = LockFile.getLock(conf.getProperty(Globals.JMQ_VAR_HOME_PROPERTY), Globals.getConfigName(), (pm.getHostname() == null || pm.getHostname().equals("") ? Globals.getMQAddress().getHostName() : pm.getMQAddress().getHostName()), pm.getPort(), Globals.getUseFileLockForLockFile());
        } catch (Exception e) {
            Object[] msgargs = { LockFile.getLockFilePath(conf.getProperty(Globals.JMQ_VAR_HOME_PROPERTY), Globals.getConfigName()), e.toString(), Globals.getConfigName() };
            logger.logStack(Logger.ERROR, rb.E_LOCKFILE_EXCEPTION, msgargs, e);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(e);
            }
            return (1);
        }
        // Make sure we got the lock
        if (!lf.isMyLock()) {
            Object[] msgargs = { lf.getFilePath(), lf.getHost() + ":" + lf.getPort(), Globals.getConfigName() };
            String emsg = rb.getKString(rb.E_LOCKFILE_INUSE, msgargs);
            logger.log(Logger.ERROR, emsg);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(new Exception(emsg));
            }
            return (1);
        }
        // audit logging for reset store
        if (resetStore) {
            Globals.getAuditSession().storeOperation(null, null, MQAuditSession.RESET_STORE);
            if (isHA) {
                logger.log(Logger.WARNING, BrokerResources.W_HA_NO_RESET);
            }
        }
        // interests to destinations
        try {
            // logging
            Globals.isMinimumPersist();
            store = Globals.getStore();
        } catch (BrokerException ex) {
            logger.logStack(Logger.ERROR, BrokerResources.E_PERSISTENT_OPEN, ex);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(ex);
            }
            return (1);
        }
        if (Globals.useSharedConfigRecord()) {
            try {
                Globals.getStore().getShareConfigChangeStore();
            } catch (BrokerException ex) {
                logger.logStack(Logger.ERROR, BrokerResources.E_SHARECC_STORE_OPEN, ex);
                if (failStartThrowable != null) {
                    failStartThrowable.initCause(ex);
                }
                return (1);
            }
        }
        BridgeServiceManager bridgeManager = null;
        if (BridgeBaseContextAdapter.bridgeEnabled() && !Globals.isNucleusManagedBroker()) {
            logger.log(Logger.INFO, BrokerResources.I_INIT_BRIDGE_SERVICE_MANAGER);
            try {
                Class c = Class.forName(BridgeBaseContextAdapter.getManagerClass());
                bridgeManager = (BridgeServiceManager) c.getDeclaredConstructor().newInstance();
                bridgeManager.init(new BridgeBaseContextAdapter(this, resetStore));
            } catch (Throwable t) {
                bridgeManager = null;
                logger.logStack(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_INIT_BRIDGE_SERVICE_MANAGER_FAILED), t);
            }
        }
        HAMonitorService haMonitor = null;
        if (Globals.getHAEnabled()) {
            try {
                String cname = "com.sun.messaging.jmq.jmsserver" + ".cluster.manager.ha.HAMonitorServiceImpl";
                if (Globals.getHAEnabled()) {
                    logger.log(Logger.INFO, BrokerResources.I_STARTING_MONITOR);
                    if (Globals.isNucleusManagedBroker()) {
                        haMonitor = Globals.getHabitat().getService(HAMonitorService.class, cname);
                        if (haMonitor == null) {
                            throw new BrokerException("Class " + cname + " not found");
                        }
                        haMonitor.init(Globals.getClusterID(), Globals.getMQAddress(), resetTakeoverThenExit);
                    } else {
                        Class c = Class.forName(cname);
                        Class[] paramTypes = { String.class, MQAddress.class, Boolean.class };
                        Object[] paramArgs = { Globals.getClusterID(), Globals.getMQAddress(), Boolean.valueOf(resetTakeoverThenExit) };
                        Constructor cons = c.getConstructor(paramTypes);
                        haMonitor = (HAMonitorService) cons.newInstance(paramArgs);
                    }
                    if (resetTakeoverThenExit) {
                        return (0);
                    }
                } else {
                    if (Globals.isNucleusManagedBroker()) {
                        haMonitor = Globals.getHabitat().getService(HAMonitorService.class, cname);
                        if (haMonitor == null) {
                            throw new BrokerException("Class " + cname + " not found");
                        }
                    } else {
                        Class c = Class.forName(cname);
                        haMonitor = (HAMonitorService) c.getDeclaredConstructor().newInstance();
                    }
                }
                Globals.setHAMonitorService(haMonitor);
            } catch (Exception ex) {
                logger.logStack(Logger.ERROR, BrokerResources.E_ERROR_STARTING_MONITOR, ex);
                if (ex instanceof StoreBeingTakenOverException) {
                    if (failStartThrowable != null) {
                        failStartThrowable.initCause(ex);
                    }
                    return (BrokerStateHandler.getRestartCode());
                }
                if (failStartThrowable != null) {
                    failStartThrowable.initCause(ex);
                }
                return (1);
            }
            if (Globals.getHAEnabled()) {
                logger.log(Logger.INFO, BrokerResources.I_STARTING_HEARTBEAT);
                try {
                    Class c = Class.forName("com.sun.messaging.jmq.jmsserver" + ".multibroker.heartbeat.HeartbeatService");
                    Object hbs = c.getDeclaredConstructor().newInstance();
                    Globals.registerHeartbeatService(hbs);
                } catch (Exception e) {
                    logger.logStack(Logger.ERROR, BrokerResources.E_ERROR_STARTING_HB, e);
                    if (failStartThrowable != null) {
                        failStartThrowable.initCause(e);
                    }
                    return (1);
                }
            }
        }
        try {
            store.addPartitionListener(Globals.getClusterManager());
            store.partitionsReady();
        } catch (Exception e) {
            logger.logStack(Logger.ERROR, e.getMessage(), e);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(e);
            }
            return (1);
        }
        if (NO_CLUSTER) {
            mbus = new com.sun.messaging.jmq.jmsserver.cluster.api.NoCluster();
            logger.log(Logger.FORCE, Globals.getBrokerResources().getKString(BrokerResources.I_FEATURE_UNAVAILABLE, Globals.getBrokerResources().getString(BrokerResources.M_CLUSTER_SERVICE_FEATURE)));
        } else {
            try {
                String cname = CLUSTER_BROADCASTER_SERVICE_NAME;
                if (Globals.isNucleusManagedBroker()) {
                    mbus = Globals.getHabitat().getService(ClusterBroadcast.class, cname);
                    if (mbus == null) {
                        String emsg = "Failed to init cluster service because class " + cname + " not found";
                        if (Globals.getHAEnabled() || Globals.getClusterManager().getConfigBrokerCount() > 0) {
                            logger.log(Logger.ERROR, emsg);
                            if (failStartThrowable != null) {
                                failStartThrowable.initCause(new Exception(emsg));
                            }
                            return (1);
                        } else {
                            throw new BrokerException(emsg);
                        }
                    }
                    mbus.init(DEFAULT_CLUSTER_VERSION);
                } else {
                    Class c = Class.forName(cname);
                    Class[] paramTypes = { Integer.class };
                    Constructor cons = c.getConstructor(paramTypes);
                    Object[] paramArgs = { Integer.valueOf(DEFAULT_CLUSTER_VERSION) };
                    mbus = (ClusterBroadcast) cons.newInstance(paramArgs);
                }
            } catch (ClassNotFoundException cnfe) {
                logger.logStack(Logger.DEBUG, BrokerResources.E_INTERNAL_BROKER_ERROR, "unable to use cluster broadcaster", cnfe);
                logger.log(Logger.WARNING, BrokerResources.I_USING_NOCLUSTER + ": " + cnfe);
                mbus = new com.sun.messaging.jmq.jmsserver.cluster.api.NoCluster();
            } catch (InvocationTargetException ite) {
                Throwable ex = ite.getCause();
                if (ex instanceof InvocationTargetException) {
                    ex = ex.getCause();
                }
                if (!(ex instanceof LoopbackAddressException)) {
                    logger.logStack(Logger.INFO, BrokerResources.X_INTERNAL_EXCEPTION, ex.getMessage(), ex);
                }
                logger.log(Logger.WARNING, BrokerResources.I_USING_NOCLUSTER);
                mbus = new com.sun.messaging.jmq.jmsserver.cluster.api.NoCluster();
            } catch (Exception ex) {
                logger.logStack(Logger.WARNING, "Unable to use cluster broadcaster", ex);
                logger.log(Logger.WARNING, BrokerResources.I_USING_NOCLUSTER);
                mbus = new com.sun.messaging.jmq.jmsserver.cluster.api.NoCluster();
            }
        }
        Globals.setClusterBroadcast(mbus);
        Globals.setMyAddress(mbus.getMyAddress());
        /*
             * HANDLE LDAP PROPERTIES XXX - this is not the cleanest way to handle this technically it should be better integrated
             * with the authentication interfaces ... but I'm close to code freeze XXX-REVISIT racer 4/10/02
             */
        String type = Globals.getConfig().getProperty(AccessController.PROP_AUTHENTICATION_TYPE);
        if (type != null) {
            String userrep = Globals.getConfig().getProperty(AccessController.PROP_AUTHENTICATION_PREFIX + type + AccessController.PROP_USER_REPOSITORY_SUFFIX);
            if (userrep.equals("ldap")) {
                String DN = Globals.getConfig().getProperty(AccessController.PROP_USER_REPOSITORY_PREFIX + userrep + ".principal");
                String pwd = Globals.getConfig().getProperty(AccessController.PROP_USER_REPOSITORY_PREFIX + userrep + ".password");
                if (DN != null && DN.trim().length() > 0) {
                    // we have a DN
                    if (pwd == null || pwd.trim().length() == 0) {
                        int retry = 0;
                        Password pw = null;
                        boolean setProp = pwd == null || pwd.equals("");
                        while ((pwd == null || pwd.trim().equals("")) && retry < 5) {
                            pw = new Password();
                            if (pw.echoPassword()) {
                                System.err.println(Globals.getBrokerResources().getString(BrokerResources.W_ECHO_PASSWORD));
                            }
                            System.err.print(Globals.getBrokerResources().getString(BrokerResources.M_ENTER_KEY_LDAP, DN));
                            System.err.flush();
                            pwd = pw.getPassword();
                            // Limit the number of times we try
                            // reading the passwd.
                            // If the VM is run in the background
                            // the readLine()
                            // will always return null and
                            // we'd get stuck in the loop
                            retry++;
                        }
                        if (pwd == null || pwd.trim().equals("")) {
                            logger.log(Logger.WARNING, BrokerResources.W_NO_LDAP_PASSWD, pwd);
                            Globals.getConfig().put(AccessController.PROP_USER_REPOSITORY_PREFIX + userrep + ".principal", "");
                        } else if (setProp) {
                            Globals.getConfig().put(AccessController.PROP_USER_REPOSITORY_PREFIX + userrep + ".password", pwd);
                        }
                    }
                }
            }
        }
        ConnectionManager cmgr = new ConnectionManager();
        Globals.setConnectionManager(cmgr);
        // get the persisted data
        try {
            coreLifecycle.getDestinationList().addPartitionListener(Globals.getClusterManager());
            coreLifecycle.initDestinations();
            coreLifecycle.initSubscriptions();
            BrokerMonitor.init();
        } catch (BrokerException ex) {
            logger.logStack(Logger.ERROR, BrokerResources.E_UNABLE_TO_RETRIEVE_DATA, ex);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(ex);
            }
            return 1;
        }
        // Initialize the JMX Agent
        try {
            Class.forName("javax.management.MBeanServer");
            Agent agent = new Agent();
            Globals.setAgent(agent);
            agent.start();
        } catch (Exception e) {
            logger.log(Logger.WARNING, "JMX classes not present - JMX Agent is not created.");
        }
        /*
             * Check if we should support old (pre 3.0.1SP2) selector type conversions (which violated the JMS spec).
             */
        Selector.setConvertTypes(conf.getBooleanProperty(Globals.IMQ + ".selector.convertTypes", false));
        /*
             * By default the selector code short circuits boolean expression evaluation. This is a back door to disable that in
             * case there is a flaw in the implementation.
             */
        Selector.setShortCircuit(conf.getBooleanProperty(Globals.IMQ + ".selector.shortCircuit", true));
        /*
             * When shortCircuit is true, by default at selector compile time do additional test for shortCircuit
             */
        Selector.setShortCircuitCompileTimeTest(conf.getBooleanProperty(Globals.IMQ + ".selector.shortCircuitCompileTimeTest", true));
        // create the handlers - these handle the message processing
        pktrtr = new PacketRouter();
        // set up the admin packet router
        admin_pktrtr = new PacketRouter();
        AdminDataHandler admin_datahdrl = new AdminDataHandler();
        Globals.setProtocol(new ProtocolImpl(pktrtr));
        try {
            coreLifecycle.initHandlers(pktrtr, cmgr, admin_pktrtr, admin_datahdrl);
        } catch (Exception e) {
            logger.logStack(Logger.ERROR, e.getMessage(), e);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(e);
            }
            return 1;
        }
        try {
            PacketRouter pkr = new PacketRouter();
            CoreLifecycleSpi clc = Globals.getCorePlugin(CoreLifecycleSpi.CHMP);
            if (clc != null) {
                Class.forName("com.oracle.coherence.patterns.messaging.DefaultMessagingSession");
                clc.initHandlers(pkr, cmgr, null, null);
            }
        } catch (Exception e) {
            logger.logStack(Logger.ERROR, e.getMessage(), e);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(e);
            }
            return 1;
        }
        // The admin message handlers may need to locate standard packet
        // handlers, so we give it a reference to the PacketRouter.
        admin_datahdrl.setPacketRouter(admin_pktrtr);
        PacketRouter[] routers = { pktrtr, admin_pktrtr };
        Globals.setPacketRouters(routers);
        if (Globals.useSharedConfigRecord()) {
            try {
                mbus.syncChangeRecordOnStartup();
            } catch (Exception e) {
                logger.logStack(Logger.ERROR, rb.getKString(rb.E_SHARCC_SYNC_ON_STARTUP_FAILED, Globals.getClusterID(), e.getMessage()), e);
                if (failStartThrowable != null) {
                    failStartThrowable.initCause(e);
                }
                return (1);
            }
        }
        TLSProtocol.init();
        ServiceManager sm = new ServiceManager(cmgr);
        Globals.setServiceManager(sm);
        sm.updateServiceList(sm.getAllActiveServiceNames(), ServiceType.ADMIN, false);
        /*
             * Check if we need to pause the normal services until MessageBus syncs with the config server. The services will be
             * resumed by the MessageManager when it gets a notification from the MessageBus
             */
        if (mbus.waitForConfigSync()) {
            sm.updateServiceList(sm.getAllActiveServiceNames(), ServiceType.NORMAL, true);
            if (Globals.nowaitForMasterBroker()) {
                sm.addServiceRestriction(ServiceType.NORMAL, ServiceRestriction.NO_SYNC_WITH_MASTERBROKER);
                logger.log(Logger.WARNING, rb.I_MBUS_LIMITEDJMS);
                try {
                    sm.resumeAllActiveServices(ServiceType.NORMAL, true);
                } catch (BrokerException e) {
                    logger.logStack(Logger.ERROR, e.getMessage(), e);
                }
            } else {
                logger.log(Logger.WARNING, rb.I_MBUS_PAUSING);
            }
        } else {
            sm.updateServiceList(sm.getAllActiveServiceNames(), ServiceType.NORMAL, false, /* dont pause */
            true);
        }
        // OK, create the BrokerStateHandler
        Globals.setBrokerStateHandler(new BrokerStateHandler());
        // provide an option not to add shutdown hook.
        // This makes it easier to test restarts after ungraceful exits
        boolean noShutdownHook = Boolean.getBoolean(Globals.IMQ + ".noShutdownHook");
        if (inProcess || noShutdownHook || (shutdownHook = addBrokerShutdownHook()) == null) {
            // Couldn't add shutdown hook. Probably because running against 1.2
            logger.log(Logger.DEBUG, rb.I_NO_SHUTDOWN_HOOK);
        } else {
            logger.log(Logger.DEBUG, rb.I_SHUTDOWN_HOOK);
        }
        // start the memory manager
        if (!inProcess) {
            Globals.getMemManager().startManagement();
        } else {
            Globals.setMemMgrOn(false);
        }
        // Initialize the metric manager. This is the module that
        // generates performance data reports
        MetricManager mm = new MetricManager();
        Globals.setMetricManager(mm);
        mm.setParameters(Globals.getConfig());
        /*
             * Set the list of properties that must be matched before accepting connections from other brokers.
             */
        Properties matchProps = new Properties();
        matchProps.setProperty(Globals.USE_FILELOCK_FOR_LOCKFILE_PROP, String.valueOf(Globals.getUseFileLockForLockFile()));
        matchProps.setProperty(Globals.IMQ + ".autocreate.queue", Globals.getConfig().getProperty(Globals.IMQ + ".autocreate.queue", "false"));
        matchProps.setProperty(Globals.IMQ + ".autocreate.topic", Globals.getConfig().getProperty(Globals.IMQ + ".autocreate.topic", "false"));
        // 
        // "imq.queue.deliverypolicy" was used as one of the
        // "matchProps" in the 3.0.1 clusters. So even if this
        // property is now obsolete we still need to pretend that it
        // exists for cluster protocol compatibility..
        // 
        int active = Queue.getDefaultMaxActiveConsumers();
        int failover = Queue.getDefaultMaxFailoverConsumers();
        if (active == 1 && failover == 0) {
            matchProps.setProperty(Globals.IMQ + ".queue.deliverypolicy", "single");
        }
        if (active == 1 && failover != 0) {
            matchProps.setProperty(Globals.IMQ + ".queue.deliverypolicy", "failover");
        }
        if ((active == Queue.UNLIMITED || active > 1) && failover == 0) {
            matchProps.setProperty(Globals.IMQ + ".queue.deliverypolicy", "round-robin");
        }
        if (Globals.getClusterID() != null) {
            matchProps.setProperty(Globals.IMQ + ".cluster.clusterid", Globals.getClusterID());
        }
        if (isHA) {
            // must true
            matchProps.setProperty(Globals.IMQ + ".cluster.ha", Globals.getConfig().getProperty(Globals.IMQ + ".cluster.ha"));
            matchProps.setProperty(StoreManager.STORE_TYPE_PROP, Globals.getConfig().getProperty(StoreManager.STORE_TYPE_PROP));
            if (Globals.getJDBCHAEnabled()) {
                matchProps.setProperty(Globals.IMQ + ".cluster.monitor.interval", String.valueOf(haMonitor.getMonitorInterval()));
                matchProps.setProperty(Globals.IMQ + ".cluster.heartbeat.class", Globals.getConfig().getProperty(Globals.IMQ + ".cluster.heartbeat.class"));
            }
            matchProps.setProperty(Globals.IMQ + ".service.activelist", Globals.getConfig().getProperty(Globals.IMQ + ".service.activelist"));
            matchProps.setProperty(Globals.IMQ + ".bridge.enabled", Globals.getConfig().getProperty(Globals.IMQ + ".bridge.enabled", "false"));
        } else if (Globals.isNewTxnLogEnabled()) {
            matchProps.setProperty(StoreManager.NEW_TXNLOG_ENABLED_PROP, "true");
        }
        if (Globals.getConfig().getProperty(Globals.AUTOCLUSTER_BROKERMAP_CLASS_PROP) != null) {
            matchProps.setProperty(Globals.AUTOCLUSTER_BROKERMAP_CLASS_PROP, Globals.getConfig().getProperty(Globals.AUTOCLUSTER_BROKERMAP_CLASS_PROP));
        }
        if (Globals.getClusterManager().getMasterBroker() != null && Globals.nowaitForMasterBroker()) {
            matchProps.setProperty(Globals.NOWAIT_MASTERBROKER_PROP, "true");
        }
        if (Globals.useMasterBroker()) {
            if (Globals.dynamicChangeMasterBrokerEnabled()) {
                matchProps.setProperty(Globals.DYNAMIC_CHANGE_MASTERBROKER_ENABLED_PROP, "true");
            }
        }
        if (Globals.useSharedConfigRecord()) {
            matchProps.setProperty(Globals.NO_MASTERBROKER_PROP, "true");
        }
        try {
            Map props = Globals.getStore().getClusterMatchProperties();
            Map.Entry<String, String> pair = null;
            Iterator<Map.Entry<String, String>> itr = props.entrySet().iterator();
            while (itr.hasNext()) {
                pair = itr.next();
                matchProps.setProperty(pair.getKey(), pair.getValue());
            }
        } catch (Exception e) {
            logger.logStack(logger.ERROR, e.getMessage(), e);
            if (failStartThrowable != null) {
                failStartThrowable.initCause(e);
            }
            return (1);
        }
        mbus.setMatchProps(matchProps);
        /*
             * Start talking to other brokers now that all the handlers are initialized and ready to process callbacks from
             * MessageBus
             */
        mbus.startClusterIO();
        /**
         * services are up and running (although we may be paused)
         */
        startupComplete = true;
        // audit logging of broker startup
        Globals.getAuditSession().brokerOperation(null, null, MQAuditSession.BROKER_STARTUP);
        Object[] sargs = { Globals.getConfigName() + "@" + (pm.getHostname() == null || pm.getHostname().equals("") ? Globals.getMQAddress().getHostName() : pm.getMQAddress().getHostName()) + ":" + pm.getPort() };
        logger.logToAll(Logger.INFO, rb.I_BROKER_READY, sargs);
        // Load MQ Mbeans in JMX agent
        Agent agent = Globals.getAgent();
        if (agent != null) {
            agent.loadMBeans();
        }
        if (BridgeBaseContextAdapter.bridgeEnabled() && bridgeManager != null) {
            try {
                logger.log(Logger.INFO, Globals.getBrokerResources().I_START_BRIDGE_SERVICE_MANAGER);
                bridgeManager.start();
                Globals.setBridgeServiceManager(bridgeManager);
                logger.log(Logger.INFO, Globals.getBrokerResources().I_STARTED_BRIDGE_SERVICE_MANAGER);
            } catch (Throwable t) {
                logger.logStack(Logger.WARNING, Globals.getBrokerResources().W_START_BRIDGE_SERVICE_MANAGER_FAILED, t);
            }
        }
    } catch (OutOfMemoryError err) {
        Globals.handleGlobalError(err, rb.getKString(rb.M_LOW_MEMORY_STARTUP), Integer.valueOf(1));
        if (failStartThrowable != null) {
            failStartThrowable.initCause(err);
        }
        return (1);
    }
    if (diagInterval > 0) {
        MQTimer timer = Globals.getTimer();
        int _interval = diagInterval * 1000;
        timer.schedule(new BrokerDiagTask(), _interval, _interval);
    } else if (diagInterval == 0) {
        logger.log(Logger.INFO, DiagManager.allToString());
    }
    // started OK
    return 0;
}
Also used : PacketRouter(com.sun.messaging.jmq.jmsserver.data.PacketRouter) MQThread(com.sun.messaging.jmq.util.MQThread) com.sun.messaging.jmq.jmsserver.cluster.api(com.sun.messaging.jmq.jmsserver.cluster.api) Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent) Rlimit(com.sun.messaging.jmq.util.Rlimit) AdminDataHandler(com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler) CoreLifecycleSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.CoreLifecycleSpi) MQTimer(com.sun.messaging.jmq.util.timer.MQTimer) BridgeServiceManager(com.sun.messaging.bridge.api.BridgeServiceManager) BridgeServiceManager(com.sun.messaging.bridge.api.BridgeServiceManager) Password(com.sun.messaging.jmq.util.Password) MQThread(com.sun.messaging.jmq.util.MQThread)

Aggregations

AdminDataHandler (com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler)4 PacketRouter (com.sun.messaging.jmq.jmsserver.data.PacketRouter)3 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)2 MBeanException (javax.management.MBeanException)2 BridgeServiceManager (com.sun.messaging.bridge.api.BridgeServiceManager)1 com.sun.messaging.jmq.jmsserver.cluster.api (com.sun.messaging.jmq.jmsserver.cluster.api)1 AuthHandler (com.sun.messaging.jmq.jmsserver.common.handlers.AuthHandler)1 ClientIDHandler (com.sun.messaging.jmq.jmsserver.common.handlers.ClientIDHandler)1 FlowHandler (com.sun.messaging.jmq.jmsserver.common.handlers.FlowHandler)1 FlowPausedHandler (com.sun.messaging.jmq.jmsserver.common.handlers.FlowPausedHandler)1 GenerateUIDHandler (com.sun.messaging.jmq.jmsserver.common.handlers.GenerateUIDHandler)1 GetLicenseHandler (com.sun.messaging.jmq.jmsserver.common.handlers.GetLicenseHandler)1 GoodbyeHandler (com.sun.messaging.jmq.jmsserver.common.handlers.GoodbyeHandler)1 HelloHandler (com.sun.messaging.jmq.jmsserver.common.handlers.HelloHandler)1 InfoRequestHandler (com.sun.messaging.jmq.jmsserver.common.handlers.InfoRequestHandler)1 PingHandler (com.sun.messaging.jmq.jmsserver.common.handlers.PingHandler)1 SessionHandler (com.sun.messaging.jmq.jmsserver.common.handlers.SessionHandler)1 StartStopHandler (com.sun.messaging.jmq.jmsserver.common.handlers.StartStopHandler)1 VerifyDestinationHandler (com.sun.messaging.jmq.jmsserver.common.handlers.VerifyDestinationHandler)1 AckHandler (com.sun.messaging.jmq.jmsserver.data.handlers.AckHandler)1