use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class ClusterManagerImpl method lookupBrokerID.
/**
* Finds the brokerid associated with the given host/port.
*
* @param broker the MQAddress of the new broker
* @return the id associated with the broker or null if the broker does not exist
* @throws RuntimeException if the cluster has not be initialized (which occurs the first time the MQAddress is set)
* @see ClusterManagerImpl#setMQAddress
*/
@Override
public String lookupBrokerID(MQAddress broker) {
if (!initialized) {
throw new RuntimeException("Cluster not initialized");
}
// the safe thing to do is to iterate
synchronized (allBrokers) {
Iterator itr = allBrokers.values().iterator();
while (itr.hasNext()) {
ClusteredBroker cb = (ClusteredBroker) itr.next();
MQAddress addr = cb.getBrokerURL();
if (addr.equals(broker)) {
return cb.getBrokerName();
}
}
}
return null;
}
use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class ClusterManagerImpl method initialize.
/**
* Initializes the cluster (loading all configuration). This methods is called the first time setMQAddress is called
* after the broker is created.
*
* @param address the address of the local broker
* @throws BrokerException if the cluster can not be initialized
* @see ClusterManagerImpl#setMQAddress
*/
@Override
public String initialize(MQAddress address) throws BrokerException {
initialized = true;
allBrokers = initAllBrokers(address);
setupListeners();
config.addListener(DEBUG_ALL_PROP, this);
config.addListener(DEBUG_LOCK_PROP, this);
config.addListener(DEBUG_TXN_PROP, this);
config.addListener(DEBUG_TAKEOVER_PROP, this);
config.addListener(DEBUG_MSG_PROP, this);
config.addListener(DEBUG_CONN_PROP, this);
config.addListener(DEBUG_PING_PROP, this);
config.addListener(DEBUG_PKT_PROP, this);
// handle parsing transport
transport = config.getProperty(TRANSPORT_PROPERTY);
if (transport == null) {
transport = "tcp";
}
clusterhost = config.getProperty(HOST_PROPERTY);
// if not set, try imq.hostname
if (clusterhost == null) {
clusterhost = Globals.getHostname();
if (clusterhost != null && clusterhost.equals(Globals.HOSTNAME_ALL)) {
clusterhost = null;
}
}
clusterport = config.getIntProperty(PORT_PROPERTY, 0);
clusterPingInterval = config.getIntProperty(CLUSTER_PING_INTERVAL_PROP, CLUSTER_PING_INTERVAL_DEFAULT);
if (clusterPingInterval <= 0) {
clusterPingInterval = CLUSTER_PING_INTERVAL_DEFAULT;
}
LinkedHashSet s = null;
try {
s = parseBrokerList();
} catch (Exception ex) {
logger.logStack(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.X_BAD_ADDRESS_BROKER_LIST, ex.toString()), ex);
throw new BrokerException(ex.getMessage(), ex);
}
localBroker = addBroker(address, true, s.remove(address), new UID());
getLocalBroker().setStatus(BrokerStatus.ACTIVATE_BROKER, null);
setBrokerNextToMe(s);
// handle broker list
Iterator itr = s.iterator();
while (itr.hasNext()) {
MQAddress addr = (MQAddress) itr.next();
try {
// ok, are we the local broker ?
ClusteredBroker lcb = getLocalBroker();
if (addr.equals(getMQAddress())) {
if (lcb instanceof ClusteredBrokerImpl) {
((ClusteredBrokerImpl) lcb).setConfigBroker(true);
}
} else {
addBroker(addr, false, true, null);
}
} catch (NoSuchElementException ex) {
logger.logStack(Logger.ERROR, ex.getMessage() + ": " + "bad address in the broker list ", ex);
}
}
// handle master broker
String mbroker = config.getProperty(CONFIG_SERVER);
if (!allowMasterBroker()) {
if (DEBUG || logger.getLevel() <= Logger.DEBUG) {
logger.log(Logger.INFO, "This broker does not allow " + CONFIG_SERVER + " to be configured." + (mbroker == null ? "" : " Ignore " + CONFIG_SERVER + "=" + mbroker));
}
mbroker = null;
} else if (Globals.useSharedConfigRecord()) {
if (mbroker == null) {
logger.log(logger.INFO, br.getKString(br.I_USE_SHARECC_STORE));
} else {
logger.log(logger.WARNING, br.getKString(br.I_USE_SHARECC_STORE_IGNORE_MB, CONFIG_SERVER + "=" + mbroker));
}
mbroker = null;
}
if (mbroker != null) {
// ok, see if we exist
MQAddress addr = null;
try {
addr = BrokerMQAddress.createAddress(mbroker);
} catch (Exception ex) {
logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "bad address while parsing " + "the broker list ", ex);
}
masterBroker = lookupBrokerID(addr);
if (masterBroker == null) {
// wasnt in list, add it
logger.log(Logger.WARNING, BrokerResources.W_MB_UNSET, addr.toString());
masterBroker = addBroker(addr, false, true, null);
}
masterBroker = lookupBrokerID(addr);
}
if (DEBUG) {
logger.log(Logger.DEBUG, "Cluster is:" + toString());
}
return localBroker;
}
use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class HAClusteredBrokerImpl method setBrokerURL.
/**
* the URL to the portmapper of this broker
*/
@Override
public void setBrokerURL(MQAddress address) throws Exception {
if (!local) {
throw new UnsupportedOperationException("Only the local broker can have its url changed");
}
MQAddress oldaddress = this.address;
try {
updateEntry(HABrokerInfo.UPDATE_URL, null, address.toString());
this.address = address;
} catch (Exception ex) {
logger.logStack(logger.ERROR, ex.getMessage() + "[" + oldaddress + ", " + address + "]" + brokerid, ex);
throw ex;
}
parent.brokerChanged(ClusterReason.ADDRESS_CHANGED, this.getBrokerName(), oldaddress, this.address, null, null);
}
use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class HAClusteredBrokerImpl method update.
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;
}
version = Integer.valueOf(m.getVersion());
state = BrokerState.getState(m.getState());
session = new UID(m.getSessionID());
takeoverBroker = m.getTakeoverBrokerID();
heartbeat = m.getHeartbeat();
}
if (!oldaddr.equals(address)) {
parent.brokerChanged(ClusterReason.ADDRESS_CHANGED, this.getBrokerName(), oldaddr, this.address, null, null);
}
}
use of com.sun.messaging.jmq.io.MQAddress in project openmq by eclipse-ee4j.
the class BrokerMonitor method getLocalBrokerInfo.
private CompositeData getLocalBrokerInfo() {
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) {
return (null);
}
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) {
return (null);
}
return (cd);
}
Aggregations