use of com.sun.messaging.jmq.jmsserver.core.Destination in project openmq by eclipse-ee4j.
the class DebugHandler method getDestinationInfo.
private Hashtable getDestinationInfo(DestinationUID uid) throws Exception {
Destination[] ds = DL.getDestination(null, uid);
Destination d = ds[0];
if (d == null) {
throw new Exception("Can not find Destination " + uid);
}
return d.getDebugState();
}
use of com.sun.messaging.jmq.jmsserver.core.Destination in project openmq by eclipse-ee4j.
the class DebugHandler method getPktInfo.
private Hashtable getPktInfo(String target, String type, boolean full) throws Exception {
Hashtable ht = new Hashtable();
if (type == null || type.length() == 0 || type.equals("bkr")) {
Hashtable dest = new Hashtable();
Iterator[] itrs = DL.getAllDestinations(null);
Iterator itr = itrs[0];
while (itr.hasNext()) {
Destination d = (Destination) itr.next();
dest.put(d.getDestinationUID().toString(), d.getDebugMessages(full));
}
ht.put("Destinations", dest);
// XXX LKS 1/8/2004
// add entries for sessions, etc
//
} else if (type.equals("q") || type.equals("t")) {
boolean isQueue = false;
if (type.equals("t")) {
isQueue = false;
} else if (type.equals("q")) {
isQueue = true;
}
DestinationUID uid = DestinationUID.getUID(target, isQueue);
Destination[] ds = DL.getDestination(null, uid);
Destination d = ds[0];
if (d == null) {
throw new Exception("Unknown destination " + uid);
} else {
ht.putAll(d.getDebugMessages(full));
}
} else if (type.equals("con")) {
if (target == null) {
throw new Exception("Please specify consumerUID");
} else {
ConsumerUID uid = new ConsumerUID(Long.parseLong(target));
Consumer c = Consumer.getConsumer(uid);
if (c == null) {
throw new Exception("Unknown consumer " + uid);
} else {
ht.put(uid.toString(), c.getDebugMessages(full));
}
}
} else if (type.equals("cxn")) {
if (target == null) {
throw new Exception("Please specify connectionUID");
}
ConnectionUID uid = new ConnectionUID(Long.parseLong(target));
IMQConnection cxn = (IMQConnection) Globals.getConnectionManager().getConnection(uid);
if (cxn == null) {
throw new Exception("Can not find connection " + uid);
}
ht.put(target, cxn.getDebugMessages(full));
} else if (type.equals("ses")) {
ht.put("Dump acks ", target);
if (target == null) {
throw new Exception("Please specify SessionUID");
}
SessionUID uid = new SessionUID(Long.parseLong(target));
Session sess = Session.getSession(uid);
if (sess == null) {
throw new Exception("Can not find session " + uid);
}
ht.put(target, sess.getDebugMessages(full));
} else {
ht.put("Error", "Unknown pkt type " + type);
}
return ht;
}
use of com.sun.messaging.jmq.jmsserver.core.Destination in project openmq by eclipse-ee4j.
the class AckHandler method cleanUp.
public void cleanUp(List cleanList) {
if (cleanList == null || cleanList.isEmpty()) {
return;
}
try {
Iterator itr = cleanList.iterator();
while (itr.hasNext()) {
PacketReference ref = (PacketReference) itr.next();
if (ref == null) {
continue;
}
try {
Destination d = ref.getDestination();
try {
if (ref.isDead()) {
d.removeDeadMessage(ref);
} else {
d.removeMessage(ref.getSysMessageID(), RemoveReason.ACKNOWLEDGED);
}
} catch (Exception ex) {
Object[] eparam = { "" + ref.toString(), (d == null ? "null" : d.getUniqueName()), ex.getMessage() };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.E_CLEANUP_MSG_AFTER_ACK, eparam);
if (DEBUG) {
logger.logStack(Logger.INFO, emsg, ex);
} else {
logger.log(Logger.INFO, emsg);
}
}
} finally {
ref.postAcknowledgedRemoval();
itr.remove();
}
}
} finally {
if (!cleanList.isEmpty()) {
Iterator<PacketReference> itr = cleanList.iterator();
while (itr.hasNext()) {
PacketReference ref = itr.next();
if (ref != null) {
ref.postAcknowledgedRemoval();
}
}
}
}
}
use of com.sun.messaging.jmq.jmsserver.core.Destination 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.Destination 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);
}
}
}
}
Aggregations