use of com.sun.messaging.jmq.jmsserver.core.Subscription 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.Subscription 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.Subscription in project openmq by eclipse-ee4j.
the class ConsumerHandler method _createConsumer.
private Consumer[] _createConsumer(DestinationUID dest_uid, IMQConnection con, Session session, String selectorstr, String clientid, String subscriptionName, boolean durable, boolean shared, boolean jmsshare, boolean nolocal, int size, String consumerString, boolean isIndemp, boolean useFlowControl) throws BrokerException, SelectorFormatException, IOException {
Consumer c = null;
Consumer newc = null;
Subscription sub = null;
String selector = selectorstr;
if (selectorstr != null && selectorstr.trim().length() == 0) {
selector = null;
}
try {
int prefetch = -1;
if (isIndemp) {
// see if we already created it
c = Consumer.getConsumer(consumerString);
if (c != null) {
prefetch = c.getPrefetch();
}
}
if (c == null) {
c = new Consumer(dest_uid, selector, nolocal, con.getConnectionUID());
c.setCreator(consumerString);
newc = c;
newc.pause("Consumer: new consumer");
// OK, determine if we are a wildcard or not
Destination[] ds = DL.getDestination(con.getPartitionedStore(), dest_uid);
// PART
Destination d = ds[0];
boolean wildcard = dest_uid.isWildcard();
// NOTE: if d == null, wildcard == true
int cprefetch = size;
int dprefetch = (wildcard ? -1 : (!shared ? d.getMaxPrefetch() : d.getSharedConsumerFlowLimit()));
prefetch = (dprefetch == -1) ? cprefetch : (cprefetch == -1 ? cprefetch : (cprefetch > dprefetch ? dprefetch : cprefetch));
c.setPrefetch(prefetch, useFlowControl);
// actual subscription added to the destination
if (subscriptionName != null && durable) {
if (!shared) {
logger.log(Logger.INFO, br.getKString(br.I_CREATE_UNSHARED_DURA, Subscription.getDSubLogString(clientid, subscriptionName), dest_uid));
} else {
logger.log(Logger.INFO, br.getKString(br.I_CREATE_SHARED_DURA, Subscription.getDSubLogString(clientid, subscriptionName) + (jmsshare ? "jms" : "mq"), dest_uid));
}
// durable
// get the subscription ... this may throw
// an exception IF we cant
sub = Subscription.findCreateDurableSubscription(clientid, subscriptionName, shared, jmsshare, dest_uid, selector, nolocal, true);
sub.setCreator(consumerString);
sub.pause("Consumer attaching to durable");
// add the consumer .. this may throw an
// exception IF
sub.attachConsumer(c, con);
c.localConsumerCreationReady();
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
LinkedHashSet dset = null;
Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
boolean notify = true;
while (itr.hasNext()) {
dset = itr.next();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
Destination dd = itr1.next();
if (dd == null) {
continue;
}
Subscription oldsub = null;
try {
oldsub = (Subscription) dd.addConsumer(sub, notify, con);
} catch (ConsumerAlreadyAddedException e) {
logger.log(logger.INFO, e.getMessage());
}
if (oldsub != null) {
oldsub.purge();
}
}
notify = false;
}
sub.sendCreateSubscriptionNotification(c);
} else if ((wildcard || !d.isQueue()) && shared) {
logger.log(Logger.INFO, br.getKString(br.I_CREATE_SHARED_NONDURA_SUB, Subscription.getNDSubLongLogString(clientid, dest_uid, selectorstr, subscriptionName, nolocal), "" + dest_uid));
sub = Subscription.createAttachNonDurableSub(c, con, subscriptionName, shared, jmsshare);
c.localConsumerCreationReady();
if (sub != null) {
sub.pause("Consumer: attaching to nondurable");
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
LinkedHashSet dset = null;
Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
while (itr.hasNext()) {
dset = itr.next();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
Destination dd = itr1.next();
if (dd != null) {
dd.addConsumer(sub, true, con);
}
}
}
}
c.attachToConnection(con.getConnectionUID());
if (sub != null) {
sub.sendCreateSubscriptionNotification(c);
}
} else {
c.localConsumerCreationReady();
// non-durable
Destination dd = null;
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
LinkedHashSet dset = null;
Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
while (itr.hasNext()) {
dset = itr.next();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
dd = itr1.next();
if (dd != null) {
dd.addConsumer(c, true, con);
}
}
}
c.attachToConnection(con.getConnectionUID());
c.sendCreateConsumerNotification();
}
}
if (fi.FAULT_INJECTION) {
// e.g. imqcmd debug fault -n consumer.add.1 -o selector="mqDestinationName = 'T:t0.*'" -debug
HashMap fips = new HashMap();
fips.put(FaultInjection.DST_NAME_PROP, DestinationUID.getUniqueString(dest_uid.getName(), dest_uid.isQueue()));
fi.checkFaultAndSleep(FaultInjection.FAULT_CONSUMER_ADD_1, fips);
}
session.attachConsumer(c);
if (DEBUG) {
logger.log(logger.INFO, "Attached consumer " + c + "[prefetch=" + c.getPrefetch() + ", useConsumerFlowControl=" + useFlowControl + "] to session " + session);
}
Consumer[] retc = new Consumer[3];
retc[0] = c;
retc[1] = newc;
retc[2] = sub;
return retc;
} catch (Exception e) {
Object[] args = { (durable ? Subscription.getDSubLogString(clientid, subscriptionName) : (shared ? Subscription.getNDSubLongLogString(clientid, dest_uid, selector, subscriptionName, nolocal) : "")), con, dest_uid };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.W_ADD_AUTO_CONSUMER_FAILED, args);
logger.logStack(logger.ERROR, emsg, e);
try {
if (c != null) {
try {
session.detatchConsumer(c.getConsumerUID(), null, false, false, false);
} catch (Exception e1) {
try {
c.destroyConsumer((new HashSet()), null, true, false, true);
} catch (Exception e2) {
}
}
}
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
LinkedHashSet dset = null;
Destination dd = null;
Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
while (itr.hasNext()) {
dset = itr.next();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
dd = itr1.next();
if (dd == null) {
continue;
}
try {
if (c != null) {
dd.removeConsumer(c.getConsumerUID(), true);
}
if (sub != null) {
dd.removeConsumer(sub.getConsumerUID(), true);
}
} catch (Exception e1) {
}
}
}
try {
if (sub != null && c != null) {
sub.releaseConsumer(c.getConsumerUID());
}
} catch (Exception e1) {
}
if (subscriptionName != null && durable) {
if (sub != null && sub.getCreator() != null && sub.getCreator().equals(consumerString)) {
try {
Subscription.unsubscribe(subscriptionName, clientid);
} catch (Exception e1) {
}
}
}
} catch (Exception e3) {
}
if (e instanceof BrokerException) {
throw (BrokerException) e;
}
if (e instanceof IOException) {
throw (IOException) e;
}
if (e instanceof SelectorFormatException) {
throw (SelectorFormatException) e;
}
throw new BrokerException(emsg, e);
}
}
use of com.sun.messaging.jmq.jmsserver.core.Subscription 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.Subscription in project openmq by eclipse-ee4j.
the class ConsumerManagerConfig method purge.
public void purge(String consumerID) throws MBeanException {
ConsumerUID cid = null;
try {
cid = new ConsumerUID(Long.parseLong(consumerID));
} catch (Exception e) {
/*
* XXX - should send specific 'cannot parse consumerID' exception
*/
handleOperationException(ConsumerOperations.PURGE, e);
}
Consumer con = Consumer.getConsumer(cid);
if (!con.isDurableSubscriber()) {
logger.log(Logger.INFO, "Purge not supported for non durable subscribers.");
return;
}
if (con instanceof Subscription) {
Subscription sub = (Subscription) con;
try {
sub.purge();
} catch (Exception e) {
handleOperationException(ConsumerOperations.PURGE, e);
}
}
}
Aggregations