use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class ClusterUtil method getBrokerAddress.
public static String getBrokerAddress(String brokerID) {
ClusterManager cmgr;
ClusteredBroker bkr;
MQAddress addr;
if (brokerID == null) {
return (null);
}
cmgr = Globals.getClusterManager();
if (cmgr == null) {
return (null);
}
bkr = cmgr.getBroker(brokerID);
if (bkr == null) {
return (null);
}
addr = bkr.getBrokerURL();
if (addr == null) {
return (null);
}
return (addr.toString());
}
use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class PortMapper method setHostname.
/**
* Change the portmapper service's host interface
*/
private synchronized void setHostname(String hostname, boolean initOnly) throws PropertyUpdateException {
MQAddress mqaddr = null;
try {
String h = hostname;
if (hostname != null && hostname.equals(Globals.HOSTNAME_ALL)) {
h = null;
}
mqaddr = MQAddress.getMQAddress(h, getPort());
} catch (Exception e) {
throw new PropertyUpdateException(hostname + ": " + e.toString(), e);
}
if (hostname == null || hostname.equals(Globals.HOSTNAME_ALL) || hostname.trim().length() == 0) {
// Bind to all
this.hostname = null;
this.bindAddr = null;
mqaddress = mqaddr;
if (!initOnly) {
PUService pu = Globals.getPUService();
if (pu != null) {
try {
pu.rebind(new InetSocketAddress(bindAddr, port), backlog);
} catch (IOException e) {
logger.logStack(logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.X_PU_SERVICE_REBIND, (bindAddr == null ? "" : bindAddr.getHostAddress()) + ":" + port), e);
}
}
}
return;
}
if (hostname.equals(this.hostname)) {
return;
}
try {
if (Globals.isConfigForCluster()) {
String hn = hostname;
if (hn.equals("localhost")) {
hn = null;
}
this.bindAddr = BrokerMQAddress.resolveBindAddress(hn, true);
mqaddr = MQAddress.getMQAddress(this.bindAddr.getHostAddress(), getPort());
} else {
this.bindAddr = InetAddress.getByName(hostname);
}
} catch (Exception e) {
throw new PropertyUpdateException(rb.getString(rb.E_BAD_HOSTNAME, hostname), e);
}
this.hostname = hostname;
this.mqaddress = mqaddr;
LockFile lf = LockFile.getCurrentLockFile();
try {
if (lf != null) {
lf.updateHostname(mqaddress.getHostName(), Globals.getUseFileLockForLockFile());
}
} catch (IOException e) {
logger.log(Logger.WARNING, rb.E_LOCKFILE_BADUPDATE, e);
}
if (serverSocket != null) {
// one with the new port
try {
serverSocket.close();
} catch (IOException e) {
}
}
if (!initOnly) {
PUService pu = Globals.getPUService();
if (pu != null) {
try {
pu.rebind(new InetSocketAddress(bindAddr, port), backlog);
} catch (IOException e) {
logger.logStack(logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.X_PU_SERVICE_REBIND, (bindAddr == null ? "" : bindAddr.getHostAddress()) + ":" + port), e);
}
}
}
}
use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class UpdateClusterBrokerListHandler 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) {
int status = Status.OK;
String msg = null;
if (DEBUG) {
logger.log(Logger.INFO, this.getClass().getName() + ": " + cmd_props);
}
if (Globals.getHAEnabled()) {
status = Status.ERROR;
msg = rb.getKString(rb.E_OP_NOT_APPLY_TO_HA_BROKER, MessageType.getString(MessageType.UPDATE_CLUSTER_BROKERLIST));
logger.log(Logger.ERROR, msg);
} else if (!Globals.isJMSRAManagedBroker()) {
status = Status.ERROR;
msg = rb.getKString(rb.E_BROKER_NOT_JMSRA_MANAGED_IGNORE_OP, MessageType.getString(MessageType.UPDATE_CLUSTER_BROKERLIST));
logger.log(Logger.ERROR, msg);
msg = "BAD REQUEST";
} else {
try {
ClusterManager cm = Globals.getClusterManager();
MQAddress self = cm.getMQAddress();
String brokerlist = (String) cmd_props.get(MessageType.JMQ_CLUSTER_BROKERLIST);
Set brokers = cm.parseBrokerList(brokerlist);
MQAddress master = (cm.getMasterBroker() == null ? null : cm.getMasterBroker().getBrokerURL());
logger.log(logger.INFO, rb.getKString(rb.I_UPDATE_BROKERLIST, self + (master == null ? "]" : "(" + cm.CONFIG_SERVER + "=" + master + ")"), "[" + brokerlist + "]"));
if (master != null && !brokers.contains(master)) {
msg = rb.getKString(rb.X_REMOVE_MASTERBROKER_NOT_ALLOWED, master.toString(), brokers.toString() + "[" + brokerlist + "]");
throw new BrokerException(msg);
}
if (!brokers.contains(self)) {
brokerlist = "";
}
Properties prop = new Properties();
prop.put(cm.AUTOCONNECT_PROPERTY, brokerlist);
BrokerConfig bcfg = Globals.getConfig();
bcfg.updateProperties(prop, true);
} catch (PropertyUpdateException e) {
status = Status.BAD_REQUEST;
msg = e.getMessage();
logger.log(Logger.WARNING, msg);
} catch (Exception e) {
status = Status.ERROR;
msg = e.toString();
logger.log(Logger.WARNING, msg);
}
}
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
setProperties(reply, MessageType.UPDATE_CLUSTER_BROKERLIST_REPLY, status, msg);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class ClusterConfig method getLocalBrokerInfo.
public CompositeData getLocalBrokerInfo() throws MBeanException {
ClusterManager cm = Globals.getClusterManager();
CompositeData cd = null;
if (cm == null) {
return (null);
}
MQAddress address = cm.getMQAddress();
String id = null;
try {
id = cm.lookupBrokerID(BrokerMQAddress.createAddress(address.toString()));
} catch (Exception e) {
handleGetterException(ClusterAttributes.LOCAL_BROKER_INFO, e);
}
if ((id == null) || (id.equals(""))) {
return (null);
}
try {
ClusteredBroker cb = cm.getBroker(id);
if (cb == null) {
return (null);
}
cd = ClusterUtil.getConfigCompositeData(cb);
} catch (Exception e) {
handleGetterException(ClusterAttributes.LOCAL_BROKER_INFO, e);
}
return (cd);
}
use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class SFSHAClusteredBrokerImpl method update.
@Override
public void update(HABrokerInfo m) {
MQAddress oldaddr = address;
synchronized (this) {
this.brokerid = m.getId();
String urlstr = m.getUrl();
try {
address = BrokerMQAddress.createAddress(urlstr);
} catch (Exception ex) {
logger.logStack(logger.WARNING, ex.getMessage(), ex);
address = oldaddr;
}
}
if (!oldaddr.equals(address)) {
parent.brokerChanged(ClusterReason.ADDRESS_CHANGED, this.getBrokerName(), oldaddr, this.address, null, null);
}
}
Aggregations