use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.
the class ConsumerHandler method destroyConsumer.
public void destroyConsumer(IMQConnection con, Session session, ConsumerUID uid, String durableName, String clientID, SysMessageID lastid, boolean lastidInTransaction, boolean redeliverAll, boolean isIndemp) throws BrokerException {
if (durableName != null) {
Subscription usub = Subscription.unsubscribe(durableName, clientID);
if (usub == null) {
// already destroyed
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_UNKNOWN_DURABLE_INTEREST, Subscription.getDSubLogString(clientID, durableName)), Status.NOT_FOUND);
}
DestinationUID dest_uid = usub.getDestinationUID();
Destination[] ds = DL.getDestination(con.getPartitionedStore(), dest_uid);
Destination d = ds[0];
if (d != null) {
d.removeConsumer(uid, true);
}
} else {
boolean redeliver = false;
if (con.getClientProtocolVersion() < Connection.RAPTOR_PROTOCOL) {
redeliver = true;
}
if (session == null && !isIndemp) {
if (con.getConnectionState() >= Connection.STATE_CLOSED) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CONNECTION_CLOSING, con.getConnectionUID()), Status.NOT_FOUND);
} else {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CONSUMER_SESSION_NOT_FOUND, uid, con.getConnectionUID()), Status.NOT_FOUND);
}
}
if (session != null) {
// should only be null w/ indemp
Consumer c = (Consumer) session.detatchConsumer(uid, lastid, lastidInTransaction, redeliver, redeliverAll);
if (DEBUG) {
logger.log(Logger.INFO, "ConsumerHandler: closed consumer " + c + ", with {lastid=" + lastid + ", lastidInTransaction=" + lastidInTransaction + ", redeliver=" + redeliver + ", redeliverAll=" + redeliverAll + ", isindemp=" + isIndemp + "}");
}
DestinationUID dest_uid = c.getDestinationUID();
Destination[] ds = DL.getDestination(con.getPartitionedStore(), dest_uid);
Destination d = ds[0];
if (d != null) {
d.removeConsumer(uid, true);
}
}
}
}
use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.
the class GetDurablesHandler 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() + ": " + cmd_props);
}
String destination = (String) cmd_props.get(MessageType.JMQ_DESTINATION);
// Send reply
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(PacketType.OBJECT_MESSAGE);
int status = Status.OK;
Vector v = null;
String err = null;
try {
DestinationUID duid = null;
if (destination != null) {
duid = DestinationUID.getUID(destination, false);
}
Set s = Subscription.getAllSubscriptions(duid);
v = new Vector();
Iterator itr = s.iterator();
while (itr.hasNext()) {
Subscription sub = (Subscription) itr.next();
DurableInfo di = new DurableInfo();
di.isDurable = sub.isDurable();
di.isShared = sub.getShared();
di.isJMSShared = sub.getJMSShared();
if (di.isDurable) {
di.name = sub.getDurableName();
} else if (di.isJMSShared) {
di.name = sub.getNDSubscriptionName();
}
di.clientID = sub.getClientID();
di.isActive = sub.isActive();
di.uidString = String.valueOf(sub.getConsumerUID().longValue());
List children = sub.getChildConsumers();
di.activeCount = children.size();
di.activeConsumers = new LinkedHashMap<>();
Iterator itr1 = children.iterator();
while (itr1.hasNext()) {
Consumer c = (Consumer) itr1.next();
ConsumerInfo cinfo = new ConsumerInfo();
cinfo.connection = new ConnectionInfo();
cinfo.connection.uuid = c.getConsumerUID().getConnectionUID().longValue();
cinfo.uidString = String.valueOf(c.getConsumerUID().longValue());
ConsumerUID uid = c.getStoredConsumerUID();
if (uid != null) {
cinfo.subuidString = String.valueOf(uid.longValue());
}
BrokerAddress addr = c.getConsumerUID().getBrokerAddress();
if (addr != null) {
cinfo.brokerAddressShortString = addr.getMQAddress().getHostAddressNPort() + (addr.getBrokerID() == null ? "" : "[" + addr.getBrokerID() + "]");
}
di.activeConsumers.put(cinfo.uidString, cinfo);
}
di.nMessages = sub.numInProcessMsgs();
di.consumer = new ConsumerInfo();
// Ok, I'm not setting id because it really should be an int, maybe later
di.consumer.destination = sub.getDestinationUID().getName();
di.consumer.type = DestType.DEST_TYPE_TOPIC;
di.consumer.selector = sub.getSelectorStr();
// not bothering with the connection this time either
di.consumer.connection = null;
v.add(di);
}
} catch (BrokerException ex) {
err = ex.getMessage();
status = ex.getStatusCode();
}
setProperties(reply, MessageType.GET_DURABLES_REPLY, status, err);
setBodyObject(reply, v);
parent.sendReply(con, cmd_msg, reply);
return true;
}
use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.
the class PacketHandler method checkServiceRestriction.
public void checkServiceRestriction(Packet msg, IMQConnection con, ErrHandler defhandler) throws BrokerException, IOException, ClassNotFoundException {
Service service = con.getService();
if (service.getServiceType() != ServiceType.NORMAL) {
return;
}
int id = msg.getPacketType();
if (id != PacketType.CREATE_DESTINATION && id != PacketType.ADD_CONSUMER && id != PacketType.ADD_PRODUCER) {
return;
}
ServiceRestriction[] srs = service.getServiceRestrictions();
if (srs == null) {
return;
}
ServiceRestriction sr = null;
for (int i = 0; i < srs.length; i++) {
sr = srs[i];
if (sr == ServiceRestriction.NO_SYNC_WITH_MASTERBROKER) {
Hashtable prop = msg.getProperties();
String dest = (String) prop.get("JMQDestination");
int dtype = ((Integer) prop.get("JMQDestType")).intValue();
if (id == PacketType.CREATE_DESTINATION) {
if (!checkForAutoCreate(dtype)) {
return;
}
DestinationUID duid = DestinationUID.getUID(dest, DestType.isQueue(dtype));
DestinationSpi[] ds = coreLifecycle.getDestination(con.getPartitionedStore(), duid);
DestinationSpi d = ds[0];
if (d != null) {
return;
}
if (DestType.isQueue(dtype) && DestType.isTemporary(dtype)) {
return;
}
String[] args = { Thread.currentThread().getName(), dest, service.toString(), sr.toString(true) };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_SERVICE_RESTRICTION_AUTO_CREATE_DEST, args);
logger.log(logger.WARNING, emsg);
waitForMasterBrokerSync(con, msg, emsg, emsg, defhandler);
return;
} else if (DestType.isTopic(dtype)) {
if (id == PacketType.ADD_PRODUCER) {
String[] args = { Thread.currentThread().getName(), dest, service.toString(), sr.toString(true) };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_SERVICE_RESTRICTION_TOPIC_PRODUCER, args);
logger.log(logger.WARNING, emsg);
waitForMasterBrokerSync(con, msg, emsg, emsg, defhandler);
return;
} else {
String[] args = { Thread.currentThread().getName(), dest, service.toString(), sr.toString(true) };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_SERVICE_RESTRICTION_TOPIC_CONSUMER, args);
logger.log(logger.WARNING, emsg);
waitForMasterBrokerSync(con, msg, emsg, emsg, defhandler);
return;
}
}
} else {
throw new BrokerException(Globals.getBrokerResources().getString(BrokerResources.E_INTERNAL_BROKER_ERROR, "Unknown service restriction " + sr + " on service " + service));
}
}
}
use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.
the class RemoteTxnConverter method convert.
void convert(TransactionInformation txnInfo) throws BrokerException {
if (ToTxnLogConverter.DEBUG) {
logger.log(Logger.DEBUG, getPrefix() + " convert " + txnInfo);
}
// should be a prepared transaction
int state = txnInfo.getState().getState();
if (state != TransactionState.PREPARED) {
String msg = getPrefix() + " convert: unknown state " + state + " for " + txnInfo;
logger.log(Logger.ERROR, msg);
}
TransactionUID txid = txnInfo.getTID();
TransactionState newState = new TransactionState(txnInfo.getState());
RemoteTransactionAckEntry[] rtaes = transactionList.getRecoveryRemoteTransactionAcks(txid);
if (rtaes != null) {
ArrayList<TransactionAcknowledgement> al = new ArrayList<>();
for (int i = 0; i < rtaes.length; i++) {
RemoteTransactionAckEntry rtae = rtaes[i];
TransactionAcknowledgement[] txnAcks = rtae.getAcks();
for (int j = 0; j < txnAcks.length; j++) {
al.add(txnAcks[j]);
}
}
TransactionAcknowledgement[] txnAcks = al.toArray(new TransactionAcknowledgement[al.size()]);
DestinationUID[] destIds = new DestinationUID[txnAcks.length];
for (int i = 0; i < txnAcks.length; i++) {
SysMessageID sid = txnAcks[i].getSysMessageID();
PacketReference p = DL.get((PartitionedStore) store, sid);
DestinationUID destID = null;
if (p != null) {
destID = p.getDestinationUID();
} else {
logger.log(Logger.WARNING, "Could not find packet for " + sid);
}
destIds[i] = destID;
}
TransactionBroker txnBroker = transactionList.getRemoteTransactionHomeBroker(txid);
BrokerAddress txnHomeBroker = txnBroker.getBrokerAddress();
RemoteTransaction remoteTxn = new RemoteTransaction(txid, newState, txnAcks, destIds, txnHomeBroker);
store.logTxn(remoteTxn);
} else {
logger.log(Logger.ERROR, "Could not find RemoteTransactionAckEntry for " + txid);
}
}
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);
}
Aggregations