use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.
the class MsgRemovalEvent method readFromBytes.
@Override
public void readFromBytes(byte[] data) throws IOException, BrokerException {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
dis.skip(2);
String dest = dis.readUTF();
destUID = new DestinationUID(dest);
sysMessageID = new SysMessageID();
sysMessageID.readID(dis);
dis.close();
bais.close();
}
use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.
the class MultibrokerRouter method handleJMSMsg.
@Override
public void handleJMSMsg(Packet p, Map<ConsumerUID, Integer> consumers, BrokerAddress sender, boolean sendMsgDeliveredAck) throws BrokerException {
Map<ConsumerUID, Integer> deliveryCnts = consumers;
boolean hasflowcontrol = true;
ArrayList<Consumer> targetVector = new ArrayList<>();
ArrayList ignoreVector = new ArrayList();
// PART
PartitionedStore pstore = Globals.getStore().getPrimaryPartition();
Iterator<Map.Entry<ConsumerUID, Integer>> itr = consumers.entrySet().iterator();
Map.Entry<ConsumerUID, Integer> entry = null;
while (itr.hasNext()) {
entry = itr.next();
ConsumerUID uid = entry.getKey();
Consumer interest = Consumer.getConsumer(uid);
if (interest != null && interest.isValid()) {
// we need the interest for updating the ref
targetVector.add(interest);
ConsumerUID suid = interest.getStoredConsumerUID();
if ((suid == null || suid.equals(uid)) && interest.getSubscription() == null) {
hasflowcontrol = false;
}
} else {
ignoreVector.add(uid);
}
}
if (targetVector.isEmpty()) {
sendIgnoreAck(p.getSysMessageID(), null, sender, ignoreVector);
return;
}
boolean exists = false;
// PART
PacketReference ref = DL.get(null, p.getSysMessageID());
if (ref != null) {
BrokerAddress addr = ref.getBrokerAddress();
if (addr == null || !addr.equals(sender)) {
if (DEBUG) {
logger.log(Logger.INFO, "Remote message " + ref.getSysMessageID() + " home broker " + addr + " changed to " + sender);
}
DL.remoteCheckMessageHomeChange(ref, sender);
if (addr == null) {
Object[] args = { ref.getSysMessageID(), sender, targetVector };
logger.log(logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_IGNORE_REMOTE_MSG_SENT_FROM, args));
ignoreVector.addAll(targetVector);
targetVector.clear();
sendIgnoreAck(p.getSysMessageID(), ref, sender, ignoreVector);
return;
}
}
}
List dsts = null;
// PART
ref = DL.get(null, p.getSysMessageID());
boolean acquiredWriteLock = false;
try {
if (ref != null) {
ref.acquireDestroyRemoteWriteLock();
acquiredWriteLock = true;
if (ref.isInvalid() || ref.isDestroyed()) {
ref.clearDestroyRemoteWriteLock();
acquiredWriteLock = false;
// PART
ref = DL.get(null, p.getSysMessageID());
if (ref != null) {
ref.acquireDestroyRemoteWriteLock();
acquiredWriteLock = true;
}
}
}
if (ref != null) {
if (ref.getBrokerAddress() == null) {
ref.clearDestroyRemoteWriteLock();
acquiredWriteLock = false;
Object[] args = { ref.getSysMessageID(), sender, targetVector };
logger.log(logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_IGNORE_REMOTE_MSG_SENT_FROM, args));
ignoreVector.addAll(targetVector);
targetVector.clear();
sendIgnoreAck(p.getSysMessageID(), ref, sender, ignoreVector);
return;
} else {
exists = true;
ref.setBrokerAddress(sender);
if (p.getRedelivered()) {
ref.overrideRedeliver();
}
}
} else {
// PART
ref = PacketReference.createReference(pstore, p, null);
ref.setBrokerAddress(sender);
}
// consumer
if (sendMsgDeliveredAck) {
for (int i = 0; i < targetVector.size(); i++) {
Consumer c = targetVector.get(i);
// ref.addMessageDeliveredAck(c.getStoredConsumerUID());
ref.addMessageDeliveredAck(c.getConsumerUID());
}
}
try {
if (ref.getDestinationUID().isWildcard()) {
List[] dss = DL.findMatchingIDs(pstore, ref.getDestinationUID());
dsts = dss[0];
} else {
// ok, autocreate the destination if necessary
Destination[] ds = DL.getDestination(pstore, ref.getDestinationUID().getName(), ref.getDestinationUID().isQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC, true, true);
Destination d = ds[0];
if (d != null) {
dsts = new ArrayList();
dsts.add(d.getDestinationUID());
}
}
if (dsts == null || dsts.isEmpty()) {
ignoreVector.addAll(targetVector);
targetVector.clear();
} else {
if (!exists && !targetVector.isEmpty()) {
ref.setNeverStore(true);
// OK .. we dont need to route .. its already happened
ref.storeRemoteInterests(targetVector, deliveryCnts);
itr = dsts.iterator();
while (itr.hasNext()) {
DestinationUID did = (DestinationUID) itr.next();
Destination[] ds = DL.getDestination(pstore, did);
Destination d = ds[0];
if (DEBUG) {
logger.log(logger.INFO, "Route remote message " + ref + " sent from " + sender + " to destination(s) " + did + " for consumer(s) " + targetVector + " hasflowcontrol=" + hasflowcontrol + ", enforcelimit=" + ENFORCE_REMOTE_DEST_LIMIT);
}
// add to message count
d.acquireQueueRemoteLock();
try {
PacketReference newref = d.getMessage(p.getSysMessageID());
if (newref != null) {
ignoreVector.addAll(targetVector);
targetVector.clear();
Object[] args = { p.getSysMessageID(), "" + d.getDestinationUID(), sender, newref + "[" + newref.getBrokerAddress() + "]" };
logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_REMOTE_NEW_MSG_ROUTED_ALREADY, args));
break;
}
d.queueMessage(ref, false, ENFORCE_REMOTE_DEST_LIMIT);
} finally {
d.clearQueueRemoteLock();
}
}
} else if (exists) {
ref.addRemoteInterests(targetVector);
}
}
} catch (Exception ex) {
Object[] args = { "" + ref, sender, targetVector };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.W_EXCEPTION_PROCESS_REMOTE_MSG, args);
if (!(ex instanceof BrokerException)) {
logger.logStack(logger.WARNING, emsg, ex);
} else {
BrokerException be = (BrokerException) ex;
int status = be.getStatusCode();
if (status != Status.RESOURCE_FULL && status != Status.ENTITY_TOO_LARGE) {
logger.logStack(logger.WARNING, emsg, ex);
} else {
Object[] args1 = { sender, targetVector };
emsg = Globals.getBrokerResources().getKString(BrokerResources.W_PROCESS_REMOTE_MSG_DST_LIMIT, args1);
int level = Logger.DEBUG;
if (!loggedFullDestsOnHandleJMSMsg.contains(ref.getDestinationUID())) {
level = Logger.WARNING;
loggedFullDestsOnHandleJMSMsg.add(ref.getDestinationUID());
}
logger.log(level, emsg + (level == Logger.DEBUG ? ": " + ex.getMessage() : ""));
}
}
}
} finally {
if (ref != null && acquiredWriteLock) {
ref.clearDestroyRemoteWriteLock();
}
}
// Now deliver the message...
StringBuilder debugString = new StringBuilder();
debugString.append('\n');
int i;
for (i = 0; i < targetVector.size(); i++) {
Consumer interest = targetVector.get(i);
if (!interest.routeMessage(ref, false)) {
// it disappeard on us, take care of it
try {
if (ref.acknowledged(interest.getConsumerUID(), interest.getStoredConsumerUID(), true, false)) {
try {
if (dsts == null) {
continue;
}
itr = dsts.iterator();
while (itr.hasNext()) {
DestinationUID did = (DestinationUID) itr.next();
Destination[] ds = DL.getDestination(pstore, did);
Destination d = ds[0];
d.removeRemoteMessage(ref.getSysMessageID(), RemoveReason.ACKNOWLEDGED, ref);
}
} finally {
ref.postAcknowledgedRemoval();
}
}
} catch (Exception ex) {
logger.log(logger.INFO, "Internal error processing ack", ex);
} finally {
ref.removeRemoteConsumerUID(interest.getStoredConsumerUID(), interest.getConsumerUID());
}
}
if (DEBUG) {
debugString.append("\t" + interest.getConsumerUID() + "\n");
}
}
if (DEBUG) {
logger.log(logger.DEBUGHIGH, "MessageBus: Delivering message to : {0}", debugString.toString());
}
sendIgnoreAck(p.getSysMessageID(), ref, sender, ignoreVector);
}
use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.
the class DBTool method doBackup.
/**
* Backup the JDBC store to filebased backup files.
*/
private void doBackup() throws BrokerException {
if (!Globals.getHAEnabled()) {
throw new BrokerException(br.getKString(BrokerResources.I_HA_NOT_ENABLE, dbmgr.getBrokerID()));
}
// instantiate the file store.
Properties props = System.getProperties();
String clusterID = Globals.getClusterID();
String backupDir = (String) props.get(Globals.IMQ + ".backupdir") + File.separator + clusterID;
logger.logToAll(Logger.INFO, "Backup persistent store for HA cluster " + clusterID);
final FileStore fileStore = new FileStore(backupDir, false);
// for backup, need to clear the store before storing anything.
fileStore.clearAll(false);
JDBCStore jdbcStore = null;
try {
jdbcStore = (JDBCStore) StoreManager.getStore();
/*
* For data that are not broker specific, i.e. properties, change records, consumers, brokers, and sessions, we will
* store those data on the top level directory (a.k.a cluster filestore).
*/
// Properties table
Properties properties = jdbcStore.getAllProperties();
Iterator propItr = properties.entrySet().iterator();
while (propItr.hasNext()) {
Map.Entry entry = (Map.Entry) propItr.next();
fileStore.updateProperty((String) entry.getKey(), entry.getValue(), false);
}
propItr = null;
properties = null;
// Configuration Change Record table
List<ChangeRecordInfo> records = jdbcStore.getAllConfigRecords();
for (int i = 0, len = records.size(); i < len; i++) {
fileStore.storeConfigChangeRecord(records.get(i).getTimestamp(), records.get(i).getRecord(), false);
}
records = null;
// Consumer table
Consumer[] consumerArray = jdbcStore.getAllInterests();
for (int i = 0; i < consumerArray.length; i++) {
fileStore.storeInterest(consumerArray[i], false);
}
consumerArray = null;
// Broker & Session table - store all HABrokerInfo as a property
HashMap bkrMap = jdbcStore.getAllBrokerInfos(true);
List haBrokers = new ArrayList(bkrMap.values());
fileStore.updateProperty(STORE_PROPERTY_HABROKERS, haBrokers, true);
/*
* For each broker in the cluster, we will store broker specific data, destinations, messages, transactions,
* acknowledgements in their own filestore (a.k.a broker filestore).
*/
Iterator bkrItr = haBrokers.iterator();
while (bkrItr.hasNext()) {
// Backup data for each broker
HABrokerInfo bkrInfo = (HABrokerInfo) bkrItr.next();
String brokerID = bkrInfo.getId();
logger.logToAll(Logger.INFO, "Backup persistent data for broker " + brokerID);
FileStore bkrFS = null;
JMSBridgeStore jmsbridgeStore = null;
try {
String instanceRootDir = backupDir + File.separator + brokerID;
bkrFS = new FileStore(instanceRootDir, false);
bkrFS.clearAll(false);
// Destination table.
Destination[] dstArray = jdbcStore.getAllDestinations(brokerID);
for (int i = 0, len = dstArray.length; i < len; i++) {
DestinationUID did = dstArray[i].getDestinationUID();
Destination dst = bkrFS.getDestination(did);
if (dst == null) {
// Store the destination if not found
bkrFS.storeDestination(dstArray[i], false);
}
}
// Storing messages for each destination.
for (int i = 0, len = dstArray.length; i < len; i++) {
Enumeration e = jdbcStore.messageEnumeration(dstArray[i]);
try {
for (; e.hasMoreElements(); ) {
DestinationUID did = dstArray[i].getDestinationUID();
Packet message = (Packet) e.nextElement();
SysMessageID mid = message.getSysMessageID();
// Get interest states for the message; Consumer State table
HashMap stateMap = jdbcStore.getInterestStates(did, mid);
if (stateMap == null || stateMap.isEmpty()) {
bkrFS.storeMessage(did, message, false);
} else {
int size = stateMap.size();
ConsumerUID[] iids = new ConsumerUID[size];
int[] states = new int[size];
Iterator stateItr = stateMap.entrySet().iterator();
int j = 0;
while (stateItr.hasNext()) {
Map.Entry entry = (Map.Entry) stateItr.next();
iids[j] = (ConsumerUID) entry.getKey();
states[j] = ((Integer) entry.getValue()).intValue();
j++;
}
bkrFS.storeMessage(did, message, iids, states, false);
}
}
} finally {
jdbcStore.closeEnumeration(e);
}
}
// Transaction table
Collection txnList = jdbcStore.getTransactions(brokerID);
Iterator txnItr = txnList.iterator();
while (txnItr.hasNext()) {
TransactionUID tid = (TransactionUID) txnItr.next();
TransactionInfo txnInfo = jdbcStore.getTransactionInfo(tid);
TransactionAcknowledgement[] txnAck = jdbcStore.getTransactionAcks(tid);
bkrFS.storeTransaction(tid, txnInfo, false);
for (int i = 0, len = txnAck.length; i < len; i++) {
bkrFS.storeTransactionAck(tid, txnAck[i], false);
}
}
/**
************************************************
* JMSBridge
*************************************************
*/
Properties bp = new Properties();
bp.setProperty("instanceRootDir", instanceRootDir);
bp.setProperty("reset", "true");
bp.setProperty("logdomain", "imqdbmgr");
bp.setProperty("identityName", Globals.getIdentityName());
BridgeServiceManager.getExportedService(JMSBridgeStore.class, "JMS", bp);
List bnames = jdbcStore.getJMSBridgesByBroker(brokerID, null);
Collections.sort(bnames);
String bname = null;
String currbname = null;
Iterator itr = bnames.iterator();
while (itr.hasNext()) {
bname = (String) itr.next();
if (currbname == null || !currbname.equals(bname)) {
currbname = bname;
bp.setProperty("jmsbridge", bname);
if (jmsbridgeStore != null) {
jmsbridgeStore.closeJMSBridgeStore();
jmsbridgeStore = null;
}
logger.logToAll(logger.INFO, "Backup JMS bridge " + bname);
jmsbridgeStore = (JMSBridgeStore) BridgeServiceManager.getExportedService(JMSBridgeStore.class, "JMS", bp);
List lrs = jdbcStore.getLogRecordsByNameByBroker(bname, brokerID, null);
logger.logToAll(logger.INFO, "\tBackup JMS bridge " + bname + " with " + lrs.size() + " TM log records");
byte[] lr = null;
Iterator itr1 = lrs.iterator();
while (itr1.hasNext()) {
lr = (byte[]) itr1.next();
jmsbridgeStore.storeTMLogRecord(null, lr, currbname, true, null);
}
}
}
} finally {
bkrFS.close();
if (jmsbridgeStore != null) {
jmsbridgeStore.closeJMSBridgeStore();
}
}
}
logger.logToAll(Logger.INFO, "Backup persistent store complete.");
} catch (Throwable ex) {
ex.printStackTrace();
throw new BrokerException(ex.getMessage());
} finally {
assert fileStore != null;
try {
fileStore.close();
} catch (Exception e) {
e.printStackTrace();
}
StoreManager.releaseStore(true);
}
}
use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.
the class TransactionLogReplayer method replaySentMessage.
private void replaySentMessage(TransactionWorkMessage workMessage, Set dstLoadedSet) throws IOException, BrokerException {
// Reconstruct the message
Packet pkt = workMessage.getMessage();
SysMessageID mid = pkt.getSysMessageID();
if (Store.getDEBUG()) {
String msg = getPrefix() + " replaying sent message: " + workMessage + " dest= " + pkt.getDestination();
logger.log(Logger.INFO, msg);
}
// Make sure destination exists; auto-create if necessary
// TODO
// recreating destinations may cause a bug if a destination had been
// deleted by a command after the message was logged.
// It will now reappear - (as an auto destination?)
String dname = pkt.getDestination();
int dtype = (pkt.getIsQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC);
List[] dss = DestinationList.findMatchingIDs(msgStore.parent, DestinationUID.getUID(dname, dtype));
List dlist = dss[0];
DestinationUID did = null;
Iterator itr = dlist.iterator();
while (itr.hasNext()) {
did = (DestinationUID) itr.next();
Destination[] ds = DestinationList.getDestination(msgStore.parent, did, dtype, true, true);
Destination dst = ds[0];
did = dst.getDestinationUID();
// Load all msgs in order to verify if any msgs are missing
if (!dstLoadedSet.contains(dst)) {
dst.load();
// Keep track of what has been loaded
dstLoadedSet.add(dst);
}
// Check to see if the msg is in the store
boolean exists = msgStore.containsMessage(did, mid);
if (exists) {
if (Store.getDEBUG()) {
String msg = getPrefix() + " stored message exists " + mid;
logger.log(Logger.INFO, msg);
}
// check if stored interests are the same as logged interests
HashMap storedInterests = msgStore.getInterestStates(did, mid);
boolean matched = compareStoredConsumers(mid, workMessage.getStoredInterests(), storedInterests);
if (!matched) {
logger.log(Logger.FORCE, BrokerResources.I_REPLACE_MSG_TXNLOG, mid);
dst.removeMessage(mid, RemoveReason.REMOVED_OTHER);
if (msgStore.containsMessage(did, mid)) {
msgStore.removeMessage(did, mid, false);
}
rerouteMessage(pkt, mid, dst);
}
} else {
if (Store.getDEBUG()) {
String msg = getPrefix() + " stored message does not exist " + mid;
logger.log(Logger.INFO, msg);
}
rerouteMessage(pkt, mid, dst);
}
}
// while
}
use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.
the class TransactionLogReplayer method replayMessageRemoval.
public void replayMessageRemoval(MsgRemovalEvent event, Set dstLoadedSet) throws IOException, BrokerException {
DestinationUID did = event.destUID;
SysMessageID mid = event.sysMessageID;
// Make sure dst exists; autocreate if possible
Destination[] ds = Globals.getDestinationList().getDestination(msgStore.parent, did.getName(), did.isQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC, true, true);
Destination dst = ds[0];
// Load all msgs inorder to update consumer states
if (!dstLoadedSet.contains(dst)) {
dst.load();
// Keep track of what has been loaded
dstLoadedSet.add(dst);
}
logger.log(Logger.FORCE, Globals.getBrokerResources().getKString(BrokerResources.I_RM_MSG_ON_REPLAY_MSG_REMOVAL, mid, dst));
dst.removeMessage(mid, RemoveReason.REMOVED_OTHER);
if (msgStore.containsMessage(did, mid)) {
msgStore.removeMessage(did, mid, false);
}
}
Aggregations