use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class MultibrokerRouter method sendIgnoreAck.
private void sendIgnoreAck(SysMessageID sysid, PacketReference ref, BrokerAddress sender, List ignoredConsumers) {
List ignoreVector = ignoredConsumers;
StringBuilder debugString = new StringBuilder();
debugString.append('\n');
Object o = null;
ConsumerUID cuid = null;
for (int i = 0; i < ignoreVector.size(); i++) {
try {
o = ignoreVector.get(i);
if (o instanceof Consumer) {
cuid = ((Consumer) o).getConsumerUID();
} else {
cuid = (ConsumerUID) o;
}
cb.acknowledgeMessage(sender, (ref == null ? sysid : ref.getSysMessageID()), cuid, ClusterBroadcast.MSG_IGNORED, null, false);
} catch (Exception e) {
logger.logStack(logger.WARNING, "sendMessageAck IGNORE failed to " + sender, e);
}
if (DEBUG) {
debugString.append("\t" + ignoreVector.get(i) + "\n");
}
}
if (DEBUG) {
if (ignoreVector.size() > 0) {
logger.log(logger.DEBUGHIGH, "MessageBus: Invalid targets : {0}", debugString.toString());
}
}
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID 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.ConsumerUID in project openmq by eclipse-ee4j.
the class ClusterConsumerInfo method writeConsumer.
public static void writeConsumer(Consumer consumer, DataOutputStream dos) throws IOException {
String destName = consumer.getDestinationUID().getName();
ConsumerUID id = consumer.getConsumerUID();
String durableName = null;
String clientID = null;
String selstr = consumer.getSelectorStr();
boolean noLocalDelivery = consumer.getNoLocal();
boolean isQueue = consumer.getDestinationUID().isQueue();
boolean isReady = true;
boolean setMaxCnt = false;
int position = consumer.getLockPosition();
int maxcnt = 1;
boolean jmsshare = false;
String ndsubname = null;
if (consumer instanceof Subscription) {
Subscription s = (Subscription) consumer;
maxcnt = s.getMaxNumActiveConsumers();
setMaxCnt = true;
jmsshare = s.getJMSShared();
durableName = s.getDurableName();
if (jmsshare && durableName == null) {
ndsubname = s.getNDSubscriptionName();
}
clientID = s.getClientID();
if (!s.isActive()) {
isReady = false;
}
}
// version
dos.writeLong(ConsumerVersionUID);
dos.writeUTF(destName);
dos.writeBoolean(id != null);
if (id != null) {
writeConsumerUID(id, dos);
}
dos.writeBoolean(clientID != null);
if (clientID != null) {
dos.writeUTF(clientID);
}
dos.writeBoolean(durableName != null);
if (durableName != null) {
dos.writeUTF(durableName);
}
dos.writeBoolean(selstr != null);
if (selstr != null) {
dos.writeUTF(selstr);
}
dos.writeBoolean(isQueue);
dos.writeBoolean(noLocalDelivery);
dos.writeBoolean(isReady);
dos.writeBoolean(setMaxCnt);
if (setMaxCnt) {
dos.writeInt(maxcnt);
}
dos.writeInt(position);
dos.writeBoolean(jmsshare);
dos.writeBoolean(ndsubname != null);
if (ndsubname != null) {
dos.writeUTF(ndsubname);
}
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ClusterMessageInfo method getGPacket.
public GPacket getGPacket() throws Exception {
assert (ref != null);
assert (consumers != null);
GPacket gp = GPacket.getInstance();
gp.setType(ProtocolGlobals.G_MESSAGE_DATA);
gp.putProp("D", Boolean.valueOf(sendMessageDeliveredAck));
gp.putProp("C", Integer.valueOf(consumers.size()));
if (Globals.getDestinationList().isPartitionMode()) {
gp.putProp("partitionID", Long.valueOf(ref.getPartitionedStore().getPartitionID().longValue()));
}
c.marshalBrokerAddress(c.getSelfAddress(), gp);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
Packet roPkt = null;
try {
for (int i = 0; i < consumers.size(); i++) {
ConsumerUID intid = consumers.get(i).getConsumerUID();
ClusterConsumerInfo.writeConsumerUID(intid, dos);
gp.putProp(PROP_PREFIX_CUID_DCT + intid.longValue(), deliveryCnts.get(i));
}
if (redelivered) {
gp.putProp(PROP_REDELIVERED, Boolean.valueOf(redelivered));
}
roPkt = ref.getPacket();
if (roPkt == null) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_NULL_PACKET_FROM_REF, ref.toString()));
}
roPkt.generateTimestamp(false);
roPkt.generateSequenceNumber(false);
roPkt.writePacket(dos);
dos.flush();
bos.flush();
} catch (Exception e) {
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_EXCEPTION_WRITE_PKT_ON_SEND_MSG_REMOTE, ref.toString(), e.getMessage());
if (e instanceof BrokerException) {
logger.log(Logger.WARNING, emsg);
throw e;
}
logger.logStack(Logger.WARNING, emsg, e);
throw e;
}
byte[] buf = bos.toByteArray();
gp.setPayload(ByteBuffer.wrap(buf));
return gp;
}
use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.
the class ClusterMessageInfo method toString.
@Override
public String toString() {
if (consumers == null || ref == null) {
return super.toString();
}
StringBuilder buf = new StringBuilder("\n");
for (int i = 0; i < consumers.size(); i++) {
ConsumerUID intid = consumers.get(i).getConsumerUID();
buf.append('\t').append(intid).append('\n');
}
return buf.toString();
}
Aggregations