* </p>
* @param prop CbQueueProperty transports subject queue property as well
* TODO: we should have a clear named SubjectQueueProperty
*/
public final void setSubjectQueueProperty(CbQueueProperty prop) throws XmlBlasterException {
CbQueueProperty origProp = (CbQueueProperty)this.subjectQueue.getProperties();
if (origProp == null) {
log.severe(ME+": Existing subject queue properties are null");
return;
}
if (prop == null) prop = new CbQueueProperty(glob, Constants.RELATING_SUBJECT, glob.getId());
this.lock.lock();
try {
if (prop.getTypeVersion().equals(origProp.getTypeVersion())) {
this.subjectQueue.setProperties(prop);
return;
}
// TODO: Extend CACHE queue to handle reconfigurations hidden so we don't need to do anything here
if (!this.subjectQueue.isTransient()) {
I_Queue newQueue = createSubjectQueue(prop);
if (newQueue.isTransient()) {
log.info(ME+": Reconfiguring subject queue: Copying " + this.subjectQueue.getNumOfEntries() + " entries from old " + origProp.getType() + " queue to " + prop.getTypeVersion() + " queue");
List<I_Entry> list = null;
int lastSize = -99;
while (this.subjectQueue.getNumOfEntries() > 0) {
try {
list = this.subjectQueue.peek(-1, -1);
if (this.subjectQueue.getNumOfEntries() == lastSize) {
log.severe(ME+": PANIC: " + this.subjectQueue.getNumOfEntries() + " entries from old queue " + this.subjectQueue.getStorageId() + " can't be copied, giving up!");
break;
}
lastSize = (int)this.subjectQueue.getNumOfEntries();
}
catch (XmlBlasterException e) {
log.severe(ME+": PANIC: Can't copy from subject queue '" + this.subjectQueue.getStorageId() + "' with " + this.subjectQueue.getNumOfEntries() + " entries: " + e.getMessage());
e.printStackTrace();
continue;
}
MsgQueueEntry[] queueEntries = (MsgQueueEntry[])list.toArray(new MsgQueueEntry[list.size()]);
// On error we send them as dead letters, as we don't know what to do with them in our holdback queue
try {
newQueue.put(queueEntries, false);
}
catch (XmlBlasterException e) {
log.warning(ME+": flushHoldbackQueue() failed: " + e.getMessage());
// errorCode == "ONOVERFLOW"
getMsgErrorHandler().handleError(new MsgErrorInfo(glob, queueEntries, null, e));
}
try {
long num = this.subjectQueue.removeNum(list.size());
if (num != list.size()) {
log.severe(ME+": PANIC: Expected to remove from subject queue '" + this.subjectQueue.getStorageId() + "' with " + this.subjectQueue.getNumOfEntries() + " entries " + list.size() + " entries, but only " + num + " where removed");
}
}
catch (XmlBlasterException e) {
log.severe(ME+": PANIC: Expected to remove from subject queue '" + this.subjectQueue.getStorageId() + "' with " + this.subjectQueue.getNumOfEntries() + " entries " + list.size() + " entries: " + e.getMessage());
}
}
this.subjectQueue.clear();
this.subjectQueue.shutdown();
this.subjectQueue = newQueue;
return;
}
}
} // synchronized
finally {
this.lock.release();
}
log.severe(ME+": Can't reconfigure subject queue type '" + origProp.getTypeVersion() + "' to '" + prop.getTypeVersion() + "'");
return;
//throw new XmlBlasterException(glob, ErrorCode.USER_CONFIGURATION, ME+".setSubjectQueueProperty()", "Can't reconfigure subject queue type '" + origProps.getTypeVersion() + "' to '" + props.getTypeVersion() + "'");
}