use of com.sun.messaging.jmq.jmsserver.BrokerStateHandler in project openmq by eclipse-ee4j.
the class BrokerConfig method takeover.
public void takeover(String brokerID) throws MBeanException {
BrokerStateHandler bsh = Globals.getBrokerStateHandler();
logger.log(Logger.INFO, "Request to takeover broker " + brokerID + " received by MBean " + getMBeanName());
try {
bsh.takeoverBroker(brokerID, null, true);
} catch (BrokerException e) {
handleOperationException(BrokerOperations.TAKEOVER, e);
}
}
use of com.sun.messaging.jmq.jmsserver.BrokerStateHandler in project openmq by eclipse-ee4j.
the class BrokerConfig method shutdown.
public void shutdown(Boolean noFailover, Long time) {
BrokerStateHandler bsh = Globals.getBrokerStateHandler();
boolean failover = (noFailover == null || !(noFailover.booleanValue()));
logger.log(Logger.INFO, "Shutdown request received by MBean " + getMBeanName());
bsh.initiateShutdown("jmx", (time == null ? 0 : time.longValue()) * 1000, failover, 0, true, Broker.isInProcess(), false);
}
use of com.sun.messaging.jmq.jmsserver.BrokerStateHandler in project openmq by eclipse-ee4j.
the class ShutdownHandler method handle.
/**
* Handle the incoming administration message.
*
* @param con The Connection the message came in on.
* @param cmd_msg The administration message
* @param cmd_props The properties from the administration message
*/
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Shutting down broker: " + cmd_props);
}
boolean shouldRestart = true;
Boolean noFailover;
Integer time = null;
// extract the properties from the administration message
Boolean kill = (Boolean) cmd_props.get(MessageType.JMQ_KILL);
noFailover = (Boolean) cmd_props.get(MessageType.JMQ_NO_FAILOVER);
boolean failover = (noFailover == null || !(noFailover.booleanValue()));
time = (Integer) cmd_props.get(MessageType.JMQ_TIME);
Boolean restart = (Boolean) cmd_props.get(MessageType.JMQ_RESTART);
// is this a restart?
shouldRestart = (restart != null && restart.booleanValue());
if (shouldRestart) {
failover = false;
}
// Prepare reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
// not allowed to shutdown an in-process broker that has direct connections
if (Broker.isInProcess() && !shouldRestart && hasDirectConnections()) {
// TODO COrrect this message
String error = rb.getString(BrokerResources.E_CANNOT_SHUTDOWN_IN_PROCESS);
setProperties(reply, MessageType.SHUTDOWN_REPLY, Status.ERROR, error);
parent.sendReply(con, cmd_msg, reply);
return true;
}
// not allowed to restart an in-process broker
if (Broker.isInProcess() && shouldRestart) {
String error = rb.getString(BrokerResources.E_CANNOT_RESTART_IN_PROCESS);
setProperties(reply, MessageType.SHUTDOWN_REPLY, Status.ERROR, error);
parent.sendReply(con, cmd_msg, reply);
return true;
}
// this could be done before the previous check if we wanted
if (kill != null && kill.booleanValue()) {
Broker.getBroker().removeBrokerShutdownHook();
System.exit(1);
}
// audit logging for broker restart/shutdown
Globals.getAuditSession().brokerOperation(con.getUserName(), con.remoteHostString(), shouldRestart ? MQAuditSession.BROKER_RESTART : MQAuditSession.BROKER_SHUTDOWN);
// now begin the shutdown sequence
try {
// stop taking new requests
Globals.getServiceManager().stopNewConnections(ServiceType.NORMAL);
if (time == null || time.intValue() == 0) {
Globals.getServiceManager().stopNewConnections(ServiceType.ADMIN);
}
} catch (Exception ex) {
logger.logStack(Logger.WARNING, BrokerResources.E_INTERNAL_BROKER_ERROR, "unable to shutdown", ex);
} finally {
// send a reply to the client that we received the request
// currently we return OK even if we had an error during the shutdown
setProperties(reply, MessageType.SHUTDOWN_REPLY, Status.OK, null);
parent.sendReply(con, cmd_msg, reply);
if (con instanceof IMQBasicConnection) {
IMQBasicConnection ipCon = (IMQBasicConnection) con;
ipCon.flushControl(1000);
}
BrokerStateHandler bsh = Globals.getBrokerStateHandler();
if (time == null || time.intValue() == 0) {
// stop new connections
// set the flag to notify everyone we are shutting down
BrokerStateHandler.setShuttingDown(true);
bsh.prepareShutdown(failover, false);
}
// if we aren't doing an unsafe exit, give us time to complete any operations
waitForHandlersToComplete(20);
// logging
if (shouldRestart) {
logger.log(Logger.INFO, BrokerResources.I_ADMIN_RESTART_REQUEST);
} else {
logger.log(Logger.INFO, BrokerResources.I_ADMIN_SHUTDOWN_REQUEST);
}
// shutdown the broker
bsh.initiateShutdown("admin", (time == null ? 0 : time.longValue()) * 1000, failover, (shouldRestart ? BrokerStateHandler.getRestartCode() : 0), true);
}
return true;
}
use of com.sun.messaging.jmq.jmsserver.BrokerStateHandler in project openmq by eclipse-ee4j.
the class TakeoverHandler method handle.
/**
* Handle the incomming administration message.
*
* @param con The Connection the message came in on.
* @param cmd_msg The administration message
* @param cmd_props The properties from the administration message
*/
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Taking over broker: " + cmd_props);
}
String brokerID = (String) cmd_props.get(MessageType.JMQ_BROKER_ID);
int status = Status.OK;
String errMsg = null;
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
status = Status.ERROR;
errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
} else {
/*
* Add takeover logic here
*/
logger.log(Logger.INFO, BrokerResources.I_ADMIN_TAKEOVER, brokerID);
try {
BrokerStateHandler bsh = Globals.getBrokerStateHandler();
bsh.takeoverBroker(brokerID, null, true);
} catch (Exception ex) {
logger.logStack(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.E_UNABLE_TO_TAKEOVER_BKR, brokerID, ex.getMessage()), ex);
status = Status.ERROR;
errMsg = ex.toString();
}
}
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
setProperties(reply, MessageType.TAKEOVER_BROKER_REPLY, status, errMsg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.jmsserver.BrokerStateHandler in project openmq by eclipse-ee4j.
the class UnquiesceHandler method handle.
/**
* Handle the incomming administration message.
*
* @param con The Connection the message came in on.
* @param cmd_msg The administration message
* @param cmd_props The properties from the administration message
*/
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
if (DEBUG) {
logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Unquiescing broker: " + cmd_props);
}
int status = Status.OK;
String errMsg = null;
HAMonitorService hamonitor = Globals.getHAMonitorService();
if (hamonitor != null && hamonitor.inTakeover()) {
status = Status.ERROR;
errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
} else {
try {
BrokerStateHandler bsh = Globals.getBrokerStateHandler();
bsh.stopQuiesce();
} catch (Exception ex) {
errMsg = ex.toString();
status = Status.ERROR;
}
}
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
setProperties(reply, MessageType.UNQUIESCE_BROKER_REPLY, status, errMsg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
Aggregations