use of com.sun.messaging.jmq.jmsserver.memory.MemoryManager in project openmq by eclipse-ee4j.
the class Destination method purgeDestination.
public void purgeDestination(boolean noerrnotfound) throws BrokerException {
if (!loaded) {
load(noerrnotfound);
}
try {
MemoryManager mm = Globals.getMemManager();
int maxpurge = destMessages.size();
long removedCount = 0L;
long indeliveryCount = 0L;
boolean do1 = false;
boolean oomed = false;
List<SysMessageID> list = null;
int count = 0;
while (maxpurge > 0 && count < maxpurge) {
do1 = false;
if (oomed) {
do1 = true;
oomed = false;
} else if (mm != null && mm.getCurrentLevel() > 0) {
do1 = true;
}
if (!do1) {
try {
list = new ArrayList<>(destMessages.getAllKeys());
count = maxpurge;
} catch (OutOfMemoryError oom) {
oomed = true;
continue;
}
} else {
list = destMessages.getFirstKeys(1);
}
if (list.isEmpty()) {
break;
}
count += list.size();
RemoveMessageReturnInfo ret = null;
SysMessageID sysid = null;
Iterator<SysMessageID> itr = list.iterator();
while (itr.hasNext()) {
sysid = itr.next();
ret = _removeMessage(sysid, RemoveReason.PURGED, null, null, true);
if (ret.removed) {
removedCount++;
} else if (ret.indelivery) {
indeliveryCount++;
}
}
}
// while maxpurge
logger.log(logger.INFO, br.getKString(br.I_NUM_MSGS_PURGED_FROM_DEST, removedCount, uid.getLocalizedName()));
if (indeliveryCount > 0) {
logger.log(logger.INFO, br.getKString(br.I_NUM_MSGS_INDELIVERY_NOT_PURGED_FROM_DEST, indeliveryCount, uid.getLocalizedName()));
}
Agent agent = Globals.getAgent();
if (agent != null) {
agent.notifyDestinationPurge(this);
}
} catch (Exception ex) {
if (BrokerStateHandler.isShuttingDown()) {
logger.log(Logger.INFO, BrokerResources.E_PURGE_DST_FAILED, getName(), ex);
} else {
logger.logStack(Logger.WARNING, BrokerResources.E_PURGE_DST_FAILED, getName(), ex);
}
if (ex instanceof BrokerException) {
throw (BrokerException) ex;
}
throw new BrokerException(br.getKString(BrokerResources.E_PURGE_DST_FAILED, getName()), ex);
}
}
Aggregations