use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class DestinationList method getAllDebugState.
public static Hashtable getAllDebugState() {
Hashtable ht = new Hashtable();
ht.put("TABLE", "All Destinations");
ht.put("maxMsgSize", (individual_max_size == null ? "null" : individual_max_size.toString()));
ht.put("maxTotalSize", (max_size == null ? "null" : max_size.toString()));
ht.put("maxCount", String.valueOf(message_max_count));
ht.put("totalBytes", String.valueOf(totalbytes));
ht.put("totalCnt", String.valueOf(totalcnt));
ht.put("totalCntNonPersist", String.valueOf(totalcntNonPersist));
ht.put("sync", String.valueOf(PERSIST_SYNC));
ht.put("noProducerFlow", String.valueOf(NO_PRODUCER_FLOW));
ht.put("autoCreateTopics", String.valueOf(ALLOW_TOPIC_AUTOCREATE));
ht.put("autoCreateQueue", String.valueOf(ALLOW_QUEUE_AUTOCREATE));
ht.put("messageExpiration", String.valueOf(MESSAGE_EXPIRE));
ht.put("producerBatch", String.valueOf(MAX_PRODUCER_BATCH));
ht.put("QueueSpecific", Queue.getAllDebugState());
ArrayList dls = null;
synchronized (destinationListList) {
dls = new ArrayList(destinationListList.keySet());
}
ht.put("partitionedStoreCnt", String.valueOf(dls.size()));
Iterator itr = dls.iterator();
PartitionedStore ps = null;
DestinationList dl = null;
while (itr.hasNext()) {
ps = (PartitionedStore) itr.next();
dl = destinationListList.get(ps);
ht.put(ps.toString(), dl.getDebugState());
}
return ht;
}
use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class Consumer method destroyConsumer.
public void destroyConsumer(Set delivered, Map remotePendings, boolean remoteCleanup, boolean destroyingDest, boolean notify) {
if (DEBUG) {
logger.log(logger.INFO, "destroyConsumer(" + delivered.size() + ", " + remotePendings + ", " + remoteCleanup + ", " + destroyingDest + ", " + notify + ")");
}
synchronized (destroyLock) {
if (!valid) {
// already removed
return;
}
// we are going into destroy, so we are invalid
valid = false;
}
Subscription sub = parent;
if (sub != null) {
sub.pause("Consumer.java: destroy " + this);
}
pause("Consumer.java: destroy ");
// clean up hooks to any parent list
if (parentListMap.size() > 0 && plistenerMap.size() > 0) {
Object pll = null;
for (Map.Entry<PartitionedStore, SubSet> pair : parentListMap.entrySet()) {
pll = plistenerMap.get(pair.getKey());
if (pll != null) {
pair.getValue().removeEventListener(pll);
plistenerMap.remove(pair.getKey());
}
}
}
List<Destination> ds = getDestinations();
Map<PartitionedStore, SubSet> oldParent = new LinkedHashMap<>();
synchronized (parentListMap) {
oldParent.putAll(parentListMap);
parentListMap.clear();
}
if (parent != null) {
parent.releaseConsumer(uid);
parent = null;
if (notify) {
try {
sendDestroyConsumerNotification(remotePendings, remoteCleanup);
} catch (Exception ex) {
logger.logStack(Logger.WARNING, "Sending detach notification for " + uid + " from " + parent, ex);
}
}
} else {
if ((ds == null || ds.isEmpty()) && !destroyingDest) {
// destination already gone
// can happen if the destination is destroyed
logger.log(Logger.DEBUG, "Removing consumer from non-existant destination" + dest);
} else if (!destroyingDest) {
Iterator itr = ds.iterator();
while (itr.hasNext()) {
Destination d = null;
try {
d = (Destination) itr.next();
d.removeConsumer(uid, remotePendings, remoteCleanup, notify);
} catch (Exception ex) {
logger.logStack(Logger.WARNING, "removing consumer " + uid + " from " + d, ex);
}
}
}
}
if (DEBUG) {
logger.log(Logger.DEBUG, "Destroying consumer " + this + "[" + delivered.size() + ":" + msgs.size() + "]");
}
// now clean up and/or requeue messages
// any consumed messages will stay on the session
// until we are done
Set<PacketReference> s = new LinkedHashSet<>(msgs);
Reason cleanupReason = (ackMsgsOnDestroy ? RemoveReason.ACKNOWLEDGED : RemoveReason.UNLOADED);
delivered.addAll(s);
// automatically ack any remote or ack On Destroy messages
Iterator itr = delivered.iterator();
while (itr.hasNext()) {
PacketReference r = (PacketReference) itr.next();
if (r == null) {
continue;
}
if (ackMsgsOnDestroy || !r.isLocal()) {
itr.remove();
try {
if (r.acknowledged(getConsumerUID(), getStoredConsumerUID(), !uid.isUnsafeAck(), r.isLocal())) {
try {
Destination[] dds = DestinationList.getDestination(r.getPartitionedStore(), r.getDestinationUID());
Destination d = null;
for (int i = 0; i < dds.length; i++) {
d = dds[i];
if (d == null) {
continue;
}
if (r.isLocal()) {
d.removeMessage(r.getSysMessageID(), RemoveReason.ACKNOWLEDGED);
} else {
d.removeRemoteMessage(r.getSysMessageID(), RemoveReason.ACKNOWLEDGED, r);
}
}
} finally {
r.postAcknowledgedRemoval();
}
}
} catch (Exception ex) {
logger.log(Logger.DEBUG, "Broker down Unable to acknowlege" + r.getSysMessageID() + ":" + uid, ex);
}
}
}
msgs.removeAll(s, cleanupReason);
if (!ackMsgsOnDestroy) {
Map<PartitionedStore, Set> map = new LinkedHashMap<>();
Set set = null;
PacketReference ref = null;
PartitionedStore pstore = null;
itr = delivered.iterator();
while (itr.hasNext()) {
ref = (PacketReference) itr.next();
if (ref.getDestinationUID().isQueue()) {
pstore = ref.getPartitionedStore();
} else {
pstore = new NoPersistPartitionedStoreImpl(getStoredConsumerUID());
}
set = map.get(pstore);
if (set == null) {
set = new LinkedHashSet();
map.put(pstore, set);
}
set.add(ref);
}
SubSet pl = null;
for (Map.Entry<PartitionedStore, Set> pair : map.entrySet()) {
pl = oldParent.get(pair.getKey());
if (pl != null) {
((Prioritized) pl).addAllOrdered(pair.getValue());
}
}
// help gc
delivered.clear();
}
destroy();
if (msgs != null && mlistener != null) {
msgs.removeEventListener(mlistener);
mlistener = null;
}
if (sub != null) {
sub.resume("Consumer.java: destroyConsumer " + this);
}
selstr = null;
selector = null;
}
use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class Consumer method getDebugState.
public Hashtable getDebugState() {
Hashtable ht = new Hashtable();
ht.put("ConsumerUID", String.valueOf(uid.longValue()));
ht.put("Broker", (uid.getBrokerAddress() == null ? "NONE" : uid.getBrokerAddress().toString()));
ht.put("msgsToConsumer", String.valueOf(msgsToConsumer));
ht.put("StoredConsumerUID", String.valueOf(getStoredConsumerUID().longValue()));
ht.put("ConnectionUID", (conuid == null ? "none" : String.valueOf(conuid.longValue())));
ht.put("type", "CONSUMER");
ht.put("valid", String.valueOf(valid));
ht.put("paused", String.valueOf(paused));
ht.put("pauseCnt", String.valueOf(pauseCnt));
ht.put("noLocal", String.valueOf(noLocal));
ht.put("destinationUID", dest.toString());
ht.put("busy", String.valueOf(busy));
if (parent != null) {
ht.put("Subscription", String.valueOf(parent.getConsumerUID().longValue()));
}
ht.put("isSpecialRemote", String.valueOf(isSpecialRemote));
ht.put("ackMsgsOnDestroy", String.valueOf(ackMsgsOnDestroy));
ht.put("position", String.valueOf(position));
ht.put("active", String.valueOf(active));
ht.put("flowCount", String.valueOf(flowCount));
ht.put("flowPaused", String.valueOf(flowPaused));
ht.put("pauseFlowCnt", String.valueOf(pauseFlowCnt));
ht.put("resumeFlowCnt", String.valueOf(resumeFlowCnt));
ht.put("useConsumerFlowControl", String.valueOf(useConsumerFlowControl));
ht.put("selstr", (selstr == null ? "none" : selstr));
ht.put("parentListMap", parentListMap.toString());
ht.put("plistenerMap", plistenerMap.toString());
ht.put("isParentListEmpty", Boolean.valueOf(isParentListEmpty(parentListMap)));
if (DestinationList.DEBUG_LISTS) {
Hashtable h = new Hashtable();
synchronized (parentListMap) {
for (Map.Entry<PartitionedStore, SubSet> pair : parentListMap.entrySet()) {
h.put(pair.getKey().toString(), pair.getValue().toDebugString());
}
}
ht.put("ParentListMap(detail)", h);
}
ht.put("prefetch", String.valueOf(prefetch));
ht.put("remotePrefetch", String.valueOf(remotePrefetch));
ht.put("parentBusy", String.valueOf(getParentBusy()));
ht.put("hasMessages", String.valueOf(!msgs.isEmpty()));
ht.put("msgsSize", String.valueOf(msgs.size()));
if (DestinationList.DEBUG_LISTS) {
ht.put("msgs", msgs.toDebugString());
}
ht.put("isFailover", String.valueOf(isFailover));
ht.put("localConsumerCreationReady", String.valueOf(localConsumerCreationReady));
Vector v1 = new Vector();
ArrayList vals = null;
synchronized (remotePendingResumes) {
vals = new ArrayList(remotePendingResumes);
}
Iterator itr = vals.iterator();
while (itr.hasNext()) {
PacketReference ref = (PacketReference) itr.next();
String val = ref.getBrokerAddress() + ": " + ref;
v1.add(val);
}
ht.put("remotePendingResumes", v1);
Vector v2 = new Vector();
synchronized (lastDestMetrics) {
itr = lastDestMetrics.keySet().iterator();
while (itr.hasNext()) {
DestinationUID did = (DestinationUID) itr.next();
long[] holder = (long[]) lastDestMetrics.get(did);
String val = did + ": " + "ins=" + holder[0] + "|outs=" + holder[1] + "|time=" + holder[2] + "|inr=" + holder[3] + "|outr=" + holder[4] + "|outt=" + holder[5];
v2.add(val);
}
}
ht.put("lastDestMetrics", v2);
return ht;
}
use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class SessionOp method close.
@Override
public void close(Connection conn) {
TransactionList[] tls = DL.getTransactionList(((IMQConnection) conn).getPartitionedStore());
TransactionList translist = tls[0];
// deal w/ old messages
synchronized (deliveredMessages) {
if (!deliveredMessages.isEmpty()) {
// get the list by IDs
HashMap openMsgs = new HashMap();
Iterator itr = deliveredMessages.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
ackEntry e = (ackEntry) entry.getValue();
ConsumerUID cuid = e.getConsumerUID();
ConsumerUID storeduid = (e.getStoredUID() == null ? cuid : e.getStoredUID());
// deal w/ orphan messages
TransactionUID tid = e.getTUID();
if (tid != null) {
JMQXid jmqxid = translist.UIDToXid(tid);
if (jmqxid != null) {
translist.addOrphanAck(tid, e.getSysMessageID(), storeduid, cuid);
itr.remove();
continue;
}
TransactionState ts = translist.retrieveState(tid, true);
if (ts != null && ts.getState() == TransactionState.PREPARED) {
translist.addOrphanAck(tid, e.getSysMessageID(), storeduid, cuid);
itr.remove();
continue;
}
if (ts != null && ts.getState() == TransactionState.COMMITTED) {
itr.remove();
continue;
}
if (ts != null && ts.getState() == TransactionState.COMPLETE && conn.getConnectionState() >= Connection.STATE_CLOSED) {
String[] args = { "" + tid, TransactionState.toString(ts.getState()), session.getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
translist.addOrphanAck(tid, e.getSysMessageID(), storeduid, cuid);
itr.remove();
continue;
}
}
PacketReference ref = e.getReference();
if (ref == null) {
// PART
ref = DL.get(null, e.getSysMessageID());
}
if (ref != null && !ref.isLocal()) {
itr.remove();
try {
if ((ref = e.acknowledged(false)) != null) {
try {
Destination d = ref.getDestination();
d.removeRemoteMessage(ref.getSysMessageID(), RemoveReason.ACKNOWLEDGED, ref);
} finally {
ref.postAcknowledgedRemoval();
}
}
} catch (Exception ex) {
logger.logStack(session.DEBUG_CLUSTER_MSG ? Logger.WARNING : Logger.DEBUG, "Unable to clean up remote message " + e.getDebugMessage(false), ex);
}
continue;
}
// we arent in a transaction ID .. cool
// add to redeliver list
Set s = (Set) openMsgs.get(cuid);
if (s == null) {
s = new LinkedHashSet();
openMsgs.put(cuid, s);
}
if (ref != null) {
ref.removeInDelivery(storeduid);
}
s.add(e);
}
// OK .. see if we ack or cleanup
itr = openMsgs.entrySet().iterator();
Map.Entry pair = null;
while (itr.hasNext()) {
pair = (Map.Entry) itr.next();
ConsumerUID cuid = (ConsumerUID) pair.getKey();
Map parentmp = (Map) cleanupList.get(cuid);
ConsumerUID suid = (ConsumerUID) storeMap.get(cuid);
if (parentmp == null || parentmp.size() == 0) {
Set s = (Set) pair.getValue();
Iterator sitr = s.iterator();
while (sitr.hasNext()) {
ackEntry e = (ackEntry) sitr.next();
try {
PacketReference ref = e.acknowledged(false);
if (ref != null) {
try {
Destination d = ref.getDestination();
try {
if (ref.isLocal()) {
d.removeMessage(ref.getSysMessageID(), RemoveReason.ACKNOWLEDGED);
} else {
d.removeRemoteMessage(ref.getSysMessageID(), RemoveReason.ACKNOWLEDGED, ref);
}
} catch (Exception ex) {
Object[] args = { ref, this, ex.getMessage() };
logger.logStack(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.X_CLEANUP_MSG_CLOSE_SESSION, args), ex);
}
} finally {
ref.postAcknowledgedRemoval();
}
}
} catch (Exception ex) {
// ignore
}
}
} else {
Map mp = new LinkedHashMap();
Set msgs = null;
PartitionedStore ps = null;
Set s = (Set) openMsgs.get(cuid);
Iterator sitr = s.iterator();
while (sitr.hasNext()) {
ackEntry e = (ackEntry) sitr.next();
PacketReference ref = e.getReference();
if (ref != null) {
try {
if (!e.hasMarkConsumed()) {
ref.consumed(suid, !session.isUnsafeAck(cuid), session.isAutoAck(cuid));
}
} catch (Exception ex) {
logger.logStack(Logger.WARNING, "Unable to consume " + suid + ":" + ref, ex);
}
ps = ref.getPartitionedStore();
if (!ref.getDestinationUID().isQueue()) {
ps = new NoPersistPartitionedStoreImpl(suid);
}
msgs = (Set) mp.get(ps);
if (msgs == null) {
msgs = new LinkedHashSet();
mp.put(ps, msgs);
}
msgs.add(ref);
} else {
sitr.remove();
}
}
SubSet pl = null;
itr = mp.entrySet().iterator();
pair = null;
while (itr.hasNext()) {
pair = (Map.Entry) itr.next();
ps = (PartitionedStore) pair.getKey();
pl = (SubSet) parentmp.get(ps);
if (pl != null) {
((Prioritized) pl).addAllOrdered((Set) pair.getValue());
} else {
logger.log(logger.WARNING, "Message(s) " + mp.get(ps) + "[" + suid + ", " + cuid + "] parentlist not found on session closing");
}
}
}
}
deliveredMessages.clear();
cleanupList.clear();
storeMap.clear();
}
}
if (!session.isXATransacted()) {
Iterator itr = null;
synchronized (detachedRConsumerUIDs) {
itr = (new LinkedHashSet(detachedRConsumerUIDs)).iterator();
}
while (itr.hasNext()) {
Consumer c = Consumer.newInstance((ConsumerUID) itr.next());
try {
Globals.getClusterBroadcast().destroyConsumer(c, null, true);
} catch (Exception e) {
logger.log(Logger.WARNING, "Unable to send consumer [" + c + "] cleanup notification for closing of SessionOp[" + this + "].");
}
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class Subscription method attachConsumer.
public void attachConsumer(Consumer consumer, Connection conn) throws BrokerException {
logger.log(Logger.DEBUG, "Attaching Consumer " + consumer + " to durable " + this + " with " + msgs.size() + " msgs " + getDestinationUID() + "[" + getConsumerUID() + "]");
synchronized (subLock) {
if (activeConsumers.get(consumer.getConsumerUID()) != null) {
throw new ConsumerAlreadyAddedException(Globals.getBrokerResources().getKString(BrokerResources.I_CONSUMER_ALREADY_ADDED, consumer.getConsumerUID(), consumer.getDestinationUID()));
}
if (maxNumActiveConsumers == 1) {
ConsumerUID kidc = consumer.getConsumerUID();
uid.setConnectionUID(kidc.getConnectionUID());
conuid = kidc.getConnectionUID();
} else {
if (!activeConsumers.isEmpty() && consumer.noLocal != noLocal) {
throw new IllegalStateException("nolocal must match on all consumers");
}
}
if (maxNumActiveConsumers != -1 && (activeConsumers.size() >= maxNumActiveConsumers)) {
String[] args = { getDestinations().toString(), this.toString(), String.valueOf(maxNumActiveConsumers), String.valueOf(activeConsumers.size()) };
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_TOO_MANY_SHARED, args), BrokerResources.X_TOO_MANY_SHARED, (Throwable) null, Status.CONFLICT);
}
boolean wasActive = isActive();
consumer.setStoredConsumerUID(getConsumerUID());
consumer.getConsumerUID().setShouldStore(true);
activeConsumers.put(consumer.getConsumerUID(), consumer);
if (msgsSubset == null) {
msgsSubset = msgs.subSet((Filter) null);
}
consumer.setParentList(new NoPersistPartitionedStoreImpl(getStoredConsumerUID()), msgsSubset);
consumer.setSubscription(this);
// OK - get all matching destinations
active = !activeConsumers.isEmpty();
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DestinationList.findMatchingDestinationMap(null, getDestinationUID());
LinkedHashSet dset = null;
for (Map.Entry<PartitionedStore, LinkedHashSet<Destination>> pair : dmap.entrySet()) {
dset = pair.getValue();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
Destination d = itr1.next();
if (d == null) {
continue;
}
if (isActive() && !wasActive) {
if (!d.isLoaded()) {
logger.log(Logger.DEBUG, "Loading " + d);
try {
d.load();
} catch (BrokerException e) {
logger.logStack(Logger.ERROR, e.getMessage() + " [" + pair.getKey() + "]", e);
}
}
}
d.notifyConsumerAdded(consumer, conn);
}
}
}
}
Aggregations