return (1);
}
}
BridgeServiceManager bridgeManager = null;
if (BridgeBaseContextAdapter.bridgeEnabled()) {
logger.log(Logger.INFO, BrokerResources.I_INIT_BRIDGE_SERVICE_MANAGER);
try {
Class c = Class.forName(BridgeBaseContextAdapter.getManagerClass());
bridgeManager = (BridgeServiceManager)c.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 (isHA) {
logger.log(Logger.INFO,
BrokerResources.I_STARTING_MONITOR);
try {
// OK, in HA if the configuration already exists in the
// store, getMQAddress reflects the old state (this
// is because we want to do some additional startup
// checks)
// pass the "requested" address into HAMonitorService
// who will handle any updates
haMonitor = new HAMonitorService(Globals.getClusterID(),
Globals.getMQAddress(), resetTakeoverThenExit);
if (resetTakeoverThenExit) {
return (0);
}
Globals.setHAMonitorService(haMonitor);
} catch (Exception ex) {
logger.logStack(Logger.ERROR,
BrokerResources.E_ERROR_STARTING_MONITOR, ex);
if (ex instanceof StoreBeingTakenOverException) {
return (BrokerStateHandler.getRestartCode());
}
return (1);
}
logger.log(Logger.INFO,
BrokerResources.I_STARTING_HEARTBEAT);
try {
Globals.registerHeartbeatService(new HeartbeatService());
} catch (Exception e) {
logger.log(Logger.ERROR,
BrokerResources.E_ERROR_STARTING_HB, e);
return (1);
}
}
// creates the ClusterBroadcast
NO_CLUSTER = !license.getBooleanProperty(
LicenseBase.PROP_ENABLE_CLUSTER, false);
int maxBrokers = license.getIntProperty(
LicenseBase.PROP_BROKER_CONNLIMIT, -1);
ClusterRouter cr = null;
if (NO_CLUSTER) {
mbus = new com.sun.messaging.jmq.jmsserver.core.NoCluster();
logger.log(Logger.FORCE,
Globals.getBrokerResources().getKString(
BrokerResources.I_FEATURE_UNAVAILABLE,
Globals.getBrokerResources().getString(
BrokerResources.M_CLUSTER_SERVICE_FEATURE)));
} else {
try {
Class c = Class.forName("com.sun.messaging.jmq.jmsserver"
+ ".core.cluster.ClusterBroadcaster");
Class[] paramTypes = { Integer.class, Integer.class };
Constructor cons = c.getConstructor(paramTypes);
Object[] paramArgs = { new Integer(maxBrokers),
new Integer(DEFAULT_CLUSTER_VERSION) };
mbus = (ClusterBroadcast)cons.newInstance(paramArgs);
cr = new com.sun.messaging.jmq.jmsserver.core.cluster.MultibrokerRouter(mbus);
} 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);
mbus = new com.sun.messaging.jmq.jmsserver.core.NoCluster();
NO_CLUSTER = true;
} catch (InvocationTargetException ite) {
Throwable ex = ite.getCause();
if (ex != null && 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.core.NoCluster();
NO_CLUSTER = true;
} catch (Exception ex) {
logger.logStack(Logger.INFO,
BrokerResources.E_INTERNAL_BROKER_ERROR,
"unable to use cluster broadcaster", ex);
logger.log(Logger.WARNING, BrokerResources.I_USING_NOCLUSTER);
mbus = new com.sun.messaging.jmq.jmsserver.core.NoCluster();
NO_CLUSTER = true;
}
}
Globals.setClusterBroadcast(mbus);
Globals.setClusterRouter(cr);
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(
license.getIntProperty(LicenseBase.PROP_CLIENT_CONNLIMIT, -1));
Globals.setConnectionManager(cmgr);
tlist = new TransactionList(store);
Globals.setTransactionList(tlist);
// get the persisted data
try {
Destination.init();
Subscription.initSubscriptions();
BrokerMonitor.init();
} catch (BrokerException ex) {
logger.logStack(Logger.WARNING,
BrokerResources.E_UNABLE_TO_RETRIEVE_DATA, ex);
}
// Initialize the JMX Agent
try {
Class c = 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));
// create the handlers - these handle the message
// processing
pktrtr = new PacketRouter();
Globals.setProtocol( new ProtocolImpl(pktrtr));
HelloHandler hello = new HelloHandler(cmgr);
GetLicenseHandler getLicense = new GetLicenseHandler();
GoodbyeHandler goodbye = new GoodbyeHandler(cmgr);
// XXX - REVISIT 2/25/00
// we may want to load these from properties in the future
//
StartStopHandler startstop = new StartStopHandler();
ConsumerHandler conhdlr = new ConsumerHandler();
ProducerHandler prodhandler = new ProducerHandler();
DestinationHandler desthandler = new DestinationHandler();
QBrowseHandler qbrowserhdlr = new QBrowseHandler();
AuthHandler authenticate = new AuthHandler(cmgr);
SessionHandler sessionhdlr = new SessionHandler();
PingHandler pinghandler = new PingHandler();
DataHandler datahdrl = new DataHandler(tlist);
AckHandler ackhandler = new AckHandler(tlist);
RedeliverHandler redeliverhdlr =
new RedeliverHandler();
DeliverHandler deliverhdlr = new DeliverHandler();
TransactionHandler thandler =
new TransactionHandler(tlist);
VerifyDestinationHandler vdhandler = new VerifyDestinationHandler();
ClientIDHandler clienthandler = new ClientIDHandler();
FlowHandler flowhdlr = new FlowHandler();
FlowPausedHandler fphandler = new FlowPausedHandler();
GenerateUIDHandler genUIDhandler = new GenerateUIDHandler();
InfoRequestHandler infohandler = new InfoRequestHandler();
VerifyTransactionHandler vthandler = new VerifyTransactionHandler(tlist);
// Map message handles -> messages
try {
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);
} catch (Exception ex) {
logger.logStack(Logger.WARNING,
BrokerResources.E_INTERNAL_BROKER_ERROR,
"adding packet handlers", ex);
}
// set up the admin packet router
admin_pktrtr = new PacketRouter();
AdminDataHandler admin_datahdrl = new
AdminDataHandler(tlist);
// Map message handles -> messages. For the admin service this
// is just like the regular JMS service except we have a specialized
// data handler
try {
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);
} catch (Exception ex) {
logger.logStack(Logger.WARNING,
BrokerResources.E_INTERNAL_BROKER_ERROR,
"adding packet handlers to admin packet router",
ex);
}
// 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 (mbus instanceof com.sun.messaging.jmq.jmsserver.core.cluster.ClusterBroadcaster) {
if (Globals.useSharedConfigRecord()) {
try {
((com.sun.messaging.jmq.jmsserver.core.cluster.ClusterBroadcaster)mbus).
getRealClusterBroadcaster().syncChangeRecordOnStartup();
} catch (Exception e) {
logger.logStack(Logger.ERROR, rb.getKString(
rb.E_SHARCC_SYNC_ON_STARTUP_FAILED, Globals.getClusterID(),
e.getMessage()), 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 /* pause */);
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);
} catch (BrokerException e) {
logger.logStack(Logger.ERROR, e.getMessage(), e);
}
} else {
logger.log(Logger.ERROR, rb.I_MBUS_PAUSING);
}
} else {
sm.updateServiceList(sm.getAllActiveServiceNames(),
ServiceType.NORMAL, false /* dont pause */);
}
// 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");
// Add the shutdownHook. The hook gets called when the VM exits
// and gives us a chance to cleanup. This is new in JDK1.3.
if (inProcess || noShutdownHook || (shutdownHook = addShutdownHook()) == 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.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) {
matchProps.setProperty(Globals.IMQ + ".cluster.ha",
Globals.getConfig().getProperty(Globals.IMQ +".cluster.ha")); //must true
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.getClusterManager().getMasterBroker() != null && Globals.nowaitForMasterBroker()) {
matchProps.setProperty(Globals.NOWAIT_MASTERBROKER_PROP, "true");
}
if (Globals.useMasterBroker() && Globals.dynamicChangeMasterBrokerEnabled()) {
matchProps.setProperty(Globals.DYNAMIC_CHANGE_MASTERBROKER_ENABLED_PROP, "true");
}
if (Globals.useSharedConfigRecord()) {
matchProps.setProperty(Globals.NO_MASTERBROKER_PROP, "true");
}
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()) + ":" +
String.valueOf(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) {