use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class ChangeRecord method processChangeRecords.
private static void processChangeRecords(List<ChangeRecordInfo> records, ChangeRecordCallback cb, MessageBusCallback mbcb, RaptorProtocol proto) throws BrokerException {
Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CLUSTER_PROCESS_CHANGE_RECORDS, Integer.valueOf(records.size())));
boolean resetFlag = false;
if (records.size() > 0 && records.get(0).isSelectAll()) {
resetFlag = true;
}
String resetUUID = null;
try {
ArrayList l = new ArrayList();
for (int i = 0; i < records.size(); i++) {
ByteArrayInputStream bis = new ByteArrayInputStream(records.get(i).getRecord());
DataInputStream dis = new DataInputStream(bis);
GPacket gp = GPacket.getInstance();
gp.read(dis);
if (gp.getType() != records.get(i).getType()) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHARECC_RECORD_TYPE_CORRUPT, ProtocolGlobals.getPacketTypeString(gp.getType()), records.get(i).toString()));
}
if (gp.getType() == ProtocolGlobals.G_RESET_PERSISTENCE) {
String uuid = records.get(i).getUUID();
if (resetUUID != null && !resetUUID.equals(uuid)) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHARECC_RESET_RECORD_UUID_CORRUPT, ProtocolGlobals.getPacketTypeString(ProtocolGlobals.G_RESET_PERSISTENCE), "[" + resetUUID + ", " + uuid + "]"));
} else if (resetUUID == null) {
resetUUID = uuid;
}
}
if (resetFlag) {
l.add(gp);
} else {
proto.handleGPacket(mbcb, Globals.getMyAddress(), gp);
}
}
if (resetFlag) {
proto.applyPersistentStateChanges(Globals.getMyAddress(), l);
}
if (records.size() > 0) {
ChangeRecordInfo rec = records.get(records.size() - 1);
cb.setLastSyncedChangeRecord(rec);
storeLastSeq(rec.getSeq());
if (resetFlag && resetUUID != null) {
rec.setResetUUID(resetUUID);
storeLastResetUUID(resetUUID);
}
}
} catch (Throwable t) {
Globals.getLogger().logStack(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.E_FAIL_PROCESS_SHARECC_RECORDS, t.getMessage()), t);
if (t instanceof BrokerException) {
throw (BrokerException) t;
}
throw new BrokerException(t.getMessage(), t);
}
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class ChangeRecord method backupRecords.
/**
* Backup the change records.
*/
public static void backupRecords(List<ChangeRecordInfo> records, String fileName, boolean throwEx) throws BrokerException {
Logger logger = Globals.getLogger();
if (DEBUG) {
logger.logToAll(Logger.INFO, "ChangeRecord.backup(" + fileName + ")");
}
BrokerResources br = Globals.getBrokerResources();
int loglevel = (throwEx ? Logger.ERROR : Logger.WARNING);
FileOutputStream fos = null;
DataOutputStream dos = null;
try {
// Make sure that the file does not exist.
File f = new File(fileName);
if (!f.createNewFile()) {
String emsg = br.getKString(br.W_MBUS_CANCEL_BACKUP2, fileName);
logger.logToAll(loglevel, emsg);
if (throwEx) {
throw new BrokerException(emsg);
}
return;
}
fos = new FileOutputStream(f);
dos = new DataOutputStream(fos);
ArrayList<ChangeRecord> recordList = compressRecords(records);
dos.writeInt(ProtocolGlobals.getCurrentVersion());
// Signature.
dos.writeUTF(ProtocolGlobals.CFGSRV_BACKUP_PROPERTY);
// Write the RESET record here.
ChangeRecordInfo cri = makeResetRecord(true);
byte[] rst = cri.getRecord();
dos.writeInt(rst.length);
dos.write(rst, 0, rst.length);
if (DEBUG) {
logger.logToAll(Logger.INFO, "ChangeRecord.backupRecords backup record " + cri);
}
ChangeRecord cr = null;
for (int i = 0; i < recordList.size(); i++) {
cr = recordList.get(i);
if (!cr.isDiscard()) {
byte[] rec = cr.getBytes();
dos.writeInt(rec.length);
dos.write(rec, 0, rec.length);
if (DEBUG) {
logger.logToAll(Logger.INFO, "ChangeRecord.backupRecords() backup record " + cr);
}
}
}
dos.writeInt(0);
logger.logToAll(Logger.INFO, br.I_CLUSTER_MB_BACKUP_SUCCESS, fileName);
} catch (Exception e) {
String emsg = br.getKString(br.W_MBUS_BACKUP_ERROR, e.getMessage());
logger.logStack((throwEx ? Logger.ERROR : Logger.WARNING), emsg, e);
if (throwEx) {
throw new BrokerException(emsg);
}
} finally {
if (dos != null) {
try {
dos.close();
} catch (Exception e) {
/* ignore */
}
}
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
/* ignore */
}
}
}
if (DEBUG) {
logger.logToAll(Logger.INFO, "ChanageRecord.backup complete");
}
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException 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);
}
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class Destination method queueMessage.
public boolean queueMessage(PacketReference pkt, boolean trans, boolean enforcelimit) throws BrokerException {
if (!DL.isValid()) {
throw new BrokerException(br.getKString(BrokerResources.I_DST_SHUTDOWN_DESTROY, getName()));
}
synchronized (dmc) {
msgsIn += 1;
msgBytesIn += pkt.byteSize();
msgsInInternal += 1;
if (msgsInInternal >= Long.MAX_VALUE) {
msgsInOutLastResetTime = System.currentTimeMillis();
msgsInInternal = 0;
msgsOutInternal = 0;
}
}
PacketListDMPair dmp = null;
try {
try {
boolean check = !isAdmin() && !isInternal();
dmp = DL.addNewMessage((check && enforcelimit), pkt);
boolean ok = dmp.getReturn();
if (!ok && !isDMQ) {
// put on dead message queue
if (!isInternal()) {
pkt.setDestination(this);
markDead(pkt, RemoveReason.EXPIRED, null);
DL.removePacketList(pkt.getSysMessageID(), this.getDestinationUID(), pkt);
}
return false;
}
} catch (BrokerException ex) {
pkt.destroy();
throw ex;
}
pkt.setDestination(this);
try {
if (!DL.isValid()) {
pkt.destroy();
throw new BrokerException(br.getKString(BrokerResources.I_DST_SHUTDOWN_DESTROY, getName()));
}
if (overrideP) {
pkt.overridePersistence(overridePvalue);
}
putMessage(pkt, AddReason.QUEUED, false, enforcelimit);
if (overrideTTL) {
pkt.overrideExpireTime(System.currentTimeMillis() + overrideTTLvalue);
}
ExpirationInfo ei = pkt.getExpireInfo();
MessageDeliveryTimeInfo di = pkt.getDeliveryTimeInfo();
if (di != null && di.isDeliveryDue()) {
di = null;
}
MsgExpirationReaper er = null;
MessageDeliveryTimeTimer dt = null;
if (ei != null || di != null) {
er = expireReaper;
dt = deliveryTimeTimer;
}
if (er != null && ei != null) {
if (!DL.isValid()) {
String emsg = br.getKString(br.W_ADD_MSG_DEST_DESTROYED, pkt, "" + uid);
RuntimeException ex = new RuntimeException(emsg);
logger.log(Logger.WARNING, emsg);
removeMessage(pkt.getSysMessageID(), null);
throw ex;
}
er.addExpiringMessage(ei);
}
if (di != null) {
if (!DL.isValid()) {
String emsg = br.getKString(br.W_ADD_MSG_DEST_DESTROYED, pkt, "" + uid);
RuntimeException ex = new RuntimeException(emsg);
ex.fillInStackTrace();
logger.log(Logger.WARNING, emsg);
removeMessage(pkt.getSysMessageID(), null);
throw ex;
}
if (dt == null) {
String emsg = br.getKString(br.W_ADD_MSG_NO_DELIVERY_TIMER, pkt, uid + "[" + isValid() + "]");
RuntimeException ex = new RuntimeException(emsg);
ex.fillInStackTrace();
logger.log(Logger.WARNING, emsg);
throw ex;
}
dt.addMessage(di);
}
} catch (IllegalStateException ex) {
// message exists
throw new BrokerException(br.getKString(BrokerResources.X_MSG_EXISTS_IN_DEST, pkt.getSysMessageID(), this.toString()), BrokerResources.X_MSG_EXISTS_IN_DEST, ex, Status.NOT_MODIFIED);
} catch (OutOfLimitsException ex) {
removeMessage(pkt.getSysMessageID(), RemoveReason.OVERFLOW);
Object lmt = ex.getLimit();
boolean unlimited = false;
if (lmt == null) {
} else if (lmt instanceof Integer) {
unlimited = ((Integer) ex.getLimit()).intValue() <= 0;
} else if (lmt instanceof Long) {
unlimited = ((Long) ex.getLimit()).longValue() <= 0;
}
String[] args = { pkt.getSysMessageID().toString(), getName(), (unlimited ? br.getString(BrokerResources.M_UNLIMITED) : ex.getLimit().toString()), ex.getValue().toString() };
String id = BrokerResources.X_INTERNAL_EXCEPTION;
int status = Status.RESOURCE_FULL;
switch(ex.getType()) {
case OutOfLimitsException.CAPACITY_EXCEEDED:
id = BrokerResources.X_DEST_MSG_CAPACITY_EXCEEDED;
break;
case OutOfLimitsException.BYTE_CAPACITY_EXCEEDED:
id = BrokerResources.X_DEST_MSG_BYTES_EXCEEDED;
break;
case OutOfLimitsException.ITEM_SIZE_EXCEEDED:
id = BrokerResources.X_DEST_MSG_SIZE_EXCEEDED;
status = Status.ENTITY_TOO_LARGE;
break;
default:
}
throw new BrokerException(br.getKString(id, args), id, ex, status);
} catch (IllegalArgumentException ex) {
removeMessage(pkt.getSysMessageID(), RemoveReason.ERROR);
throw ex;
}
} finally {
if (dmp != null) {
dmp.nullRef();
}
}
return true;
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class Destination method addProducer.
@Override
public boolean addProducer(ProducerSpi producer) throws BrokerException {
if (isInternal()) {
throw new BrokerException(br.getKString(BrokerResources.X_MONITOR_PRODUCER, getName()));
}
if (maxProducerLimit != UNLIMITED && producers.size() >= maxProducerLimit) {
throw new BrokerException(br.getKString(BrokerResources.X_PRODUCER_LIMIT_EXCEEDED, getName(), String.valueOf(maxProducerLimit)), BrokerResources.X_PRODUCER_LIMIT_EXCEEDED, (Throwable) null, Status.CONFLICT);
}
synchronized (this) {
if (destReaper != null) {
destReaper.cancel();
destReaper = null;
}
}
// then we have to deal with ordering
if (!loaded) {
load();
}
try {
synchronized (producers) {
producers.put(producer.getProducerUID(), producer);
}
} catch (IndexOutOfBoundsException ex) {
throw new BrokerException(br.getKString(BrokerResources.X_PRODUCER_LIMIT_EXCEEDED, getName(), String.valueOf(maxProducerLimit)), BrokerResources.X_PRODUCER_LIMIT_EXCEEDED, ex, Status.CONFLICT);
}
producerFlow.addProducer((Producer) producer);
boolean active = producerFlow.checkResumeFlow((Producer) producer, false);
logger.log(Logger.DEBUGHIGH, "Producer " + producer + " is " + active);
return active;
}
Aggregations