c.setCreator(consumerString);
newc = c;
newc.pause("Consumer: new consumer");
// OK, determine if we are a wildcard or not
Destination d = Destination.getDestination(dest_uid);
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 (durablename != null) {
// durable
// get the subscription ... this may throw
// an exception IF we cant
sub = Subscription.
findCreateDurableSubscription(clientid,
durablename, dest_uid, selector,
nolocal,
true);
sub.pause("Consumer attaching to durable");
sub.setShared(shared);
// add the consumer .. this may throw an
// exception IF
sub.attachConsumer(c, con);
c.localConsumerCreationReady();
List dests = Destination.findMatchingIDs(dest_uid);
Iterator itr = dests.iterator();
while (itr.hasNext()) {
DestinationUID c_duid = (DestinationUID) itr.next();
Destination dd = Destination.getDestination(c_duid);
Subscription oldsub = (Subscription)dd.addConsumer(sub, true, con);
if (oldsub != null) {
oldsub.purge();
}
}
sub.sendCreateSubscriptionNotification(c);
} else if ((wildcard || !d.isQueue()) && shared) {
// non-durable
if (clientid == null) {
throw new BrokerException(
Globals.getBrokerResources().getKString(
BrokerResources.X_NON_DURABLE_SHARED_NO_CLIENTID,d.toString()),
BrokerResources.X_NON_DURABLE_SHARED_NO_CLIENTID,
null,
Status.PRECONDITION_FAILED);
}
// shared
logger.log(Logger.DEBUG,"Creating shared non-durable "
+ c);
sub = Subscription.createAttachNonDurableSub(c, con);
c.localConsumerCreationReady();
if (sub != null) {
sub.pause("Consumer: attaching to nondurable");
sub.setShared(true);
List dests = Destination.findMatchingIDs(dest_uid);
Iterator itr = dests.iterator();
while (itr.hasNext()) {
DestinationUID c_duid = (DestinationUID) itr.next();
Destination dd = Destination.getDestination(c_duid);
dd.addConsumer(sub, true, con);
}
}
c.attachToConnection(con.getConnectionUID());
//c.sendCreateConsumerNotification();
if (sub != null)
sub.sendCreateSubscriptionNotification(c);
} else {
c.localConsumerCreationReady();
// non-durable
List dests = Destination.findMatchingIDs(dest_uid);
Iterator itr = dests.iterator();
while (itr.hasNext()) {
DestinationUID c_duid = (DestinationUID) itr.next();
Destination dd = Destination.getDestination(c_duid);
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);
Consumer[] retc = new Consumer[3];
retc[0]=c;
retc[1]=newc;
retc[2]=sub;
return retc;
} catch (Exception e) {
Object[] args = { (durablename==null ? "":"["+clientid+":"+durablename+"]"),
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);
} catch (Exception e1) {
try {
c.destroyConsumer((new HashSet()), null, true, false, true);
} catch (Exception e2) {}
};
}
List dests = Destination.findMatchingIDs(dest_uid);
Iterator itr = dests.iterator();
while (itr.hasNext()) {
DestinationUID c_duid = (DestinationUID) itr.next();
Destination dd = Destination.getDestination(c_duid);
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) {