use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class ConfigChangeRecord method getConfigChangeRecordsSince.
/**
* Retrieve all records in the store since timestamp.
*
* @return a list of ChangeRecordInfo, empty list of no records
*/
public ArrayList<ChangeRecordInfo> getConfigChangeRecordsSince(long timestamp) {
ArrayList records = new ArrayList();
synchronized (timeList) {
int size = timeList.size();
int i = 0;
for (; i < size; i++) {
Long stamp = (Long) timeList.get(i);
if (stamp.longValue() > timestamp) {
break;
}
}
for (; i < size; i++) {
records.add(new ChangeRecordInfo((byte[]) recordList.get(i), ((Long) timeList.get(i)).longValue()));
}
return records;
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class NewInterestHandler method handleNewInterest.
public void handleNewInterest(MessageBusCallback cb, BrokerAddress sender, GPacket pkt) {
if (DEBUG) {
logger.log(logger.INFO, "handleNewInterest from : " + sender);
}
ClusterConsumerInfo cci = ClusterConsumerInfo.newInstance(pkt, c);
if (ignoreNewInterest(cci, pkt)) {
return;
}
int count = cci.getConsumerCount();
if (DEBUG) {
logger.log(logger.INFO, "handleNewInterest count : " + count);
}
try {
int i = 0;
ChangeRecordInfo lastcri = null;
Iterator itr = cci.getConsumers();
while (itr.hasNext()) {
i++;
Consumer cons = null;
try {
cons = (Consumer) itr.next();
} catch (RuntimeException e) {
Throwable ex = e.getCause();
if (ex instanceof ConsumerAlreadyAddedException) {
logger.log(logger.WARNING, ex.getMessage() + " (" + ProtocolGlobals.getPacketTypeDisplayString(pkt.getType()) + ") " + sender);
continue;
}
throw e;
}
// Make sure that the destination exists...
DestinationUID duid = cons.getDestinationUID();
if (duid.isWildcard()) {
// we don't need to do anything here
// the logic below autocreates the destination
// and we need to do that.
} else {
// autocreate the destination if we need to
int type = (duid.isQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC);
Globals.getDestinationList().getDestination(null, duid.getName(), type, true, true);
}
cb.interestCreated(cons);
if (DEBUG) {
logger.log(logger.INFO, "Added newInterest(" + count + ")" + cons + " from " + sender);
}
ChangeRecordInfo cri = cci.getShareccInfo(i);
if (cri != null) {
if (lastcri == null) {
lastcri = cri;
} else if (cri.getSeq().longValue() > lastcri.getSeq().longValue()) {
lastcri = cri;
}
}
}
if (lastcri != null) {
cb.setLastReceivedChangeRecord(sender, lastcri);
}
} catch (Exception e) {
logger.logStack(logger.WARNING, e.getMessage() + " (" + ProtocolGlobals.getPacketTypeDisplayString(pkt.getType()) + ") " + sender + " " + pkt, e);
}
if (cci.needReply()) {
GPacket gp = ClusterConsumerInfo.getReplyGPacket(ProtocolGlobals.G_NEW_INTEREST_REPLY, ProtocolGlobals.G_SUCCESS);
try {
c.unicast(sender, gp);
} catch (IOException e) {
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class RemDurableHandler method handleRemDurableInterest.
public void handleRemDurableInterest(MessageBusCallback cb, BrokerAddress sender, GPacket pkt) {
ClusterSubscriptionInfo csi = ClusterSubscriptionInfo.newInstance(pkt);
if (p.getConfigSyncComplete() == false && !csi.isConfigSyncResponse()) {
// config sync is complete. Here is
if (DEBUG) {
logger.log(logger.DEBUG, "MessageBus: Dropping the G_REM_DURABLE_INTEREST " + "packet from {0}. Not ready yet.", sender);
}
return;
}
Iterator itr = csi.getSubscriptions();
try {
int i = 0;
ChangeRecordInfo lastcri = null;
while (itr.hasNext()) {
i++;
Subscription intr = (Subscription) itr.next();
if (intr != null) {
cb.unsubscribe(intr);
}
ChangeRecordInfo cri = csi.getShareccInfo(i);
if (cri != null) {
if (lastcri == null) {
lastcri = cri;
} else if (cri.getSeq().longValue() > lastcri.getSeq().longValue()) {
lastcri = cri;
}
}
}
if (lastcri != null) {
cb.setLastReceivedChangeRecord(sender, lastcri);
}
} catch (Exception e) {
logger.logStack(logger.DEBUG, "Exception processing packet ", e);
}
if (csi.needReply()) {
GPacket gp = ClusterSubscriptionInfo.getReplyGPacket(ProtocolGlobals.G_REM_DURABLE_INTEREST_REPLY, ProtocolGlobals.G_SUCCESS);
try {
c.unicast(sender, gp);
} catch (IOException e) {
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class DBTool method doBackupSharecc.
/**
* Backup the shared table for cluster config change record to a file
*/
private void doBackupSharecc() throws BrokerException {
Properties props = System.getProperties();
String clusterID = Globals.getClusterID();
String backupfile = (String) props.get(ShareConfigChangeStore.CLUSTER_SHARECC_PROP_PREFIX + ".backupfile");
logger.logToAll(Logger.INFO, br.getKString(br.I_SHARECC_BACKUP, clusterID, backupfile));
ShareConfigChangeDBManager mgr = ShareConfigChangeDBManager.getDBManager();
ShareConfigRecordDAO dao = mgr.getDAOFactory().getShareConfigRecordDAO();
try {
List<ChangeRecordInfo> records = null;
Util.RetryStrategy retry = null;
do {
try {
records = dao.getAllRecords(null, null);
break;
} catch (Exception e) {
if (retry == null) {
retry = new Util.RetryStrategy(mgr);
}
retry.assertShouldRetry(e);
}
} while (true);
Globals.getLogger().logToAll(Logger.INFO, br.getKString(br.I_SHARECC_BACKUP_RECORDS, String.valueOf(records.size()), dao.getTableName()));
ChangeRecord.backupRecords(records, backupfile, true);
Globals.getLogger().logToAll(Logger.INFO, br.getKString(br.I_SHARECC_BACKUP_RECORDS_SUCCESS, Globals.getClusterID(), backupfile));
} catch (BrokerException e) {
String emsg = br.getKString(br.E_SHARECC_BACKUP_RECORDS_FAIL, e.getMessage());
Globals.getLogger().logToAll(Logger.ERROR, emsg, e);
throw e;
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class DBTool method doBackup.
/**
* Backup the JDBC store to filebased backup files.
*/
private void doBackup() throws BrokerException {
if (!Globals.getHAEnabled()) {
throw new BrokerException(br.getKString(BrokerResources.I_HA_NOT_ENABLE, dbmgr.getBrokerID()));
}
// instantiate the file store.
Properties props = System.getProperties();
String clusterID = Globals.getClusterID();
String backupDir = (String) props.get(Globals.IMQ + ".backupdir") + File.separator + clusterID;
logger.logToAll(Logger.INFO, "Backup persistent store for HA cluster " + clusterID);
final FileStore fileStore = new FileStore(backupDir, false);
// for backup, need to clear the store before storing anything.
fileStore.clearAll(false);
JDBCStore jdbcStore = null;
try {
jdbcStore = (JDBCStore) StoreManager.getStore();
/*
* For data that are not broker specific, i.e. properties, change records, consumers, brokers, and sessions, we will
* store those data on the top level directory (a.k.a cluster filestore).
*/
// Properties table
Properties properties = jdbcStore.getAllProperties();
Iterator propItr = properties.entrySet().iterator();
while (propItr.hasNext()) {
Map.Entry entry = (Map.Entry) propItr.next();
fileStore.updateProperty((String) entry.getKey(), entry.getValue(), false);
}
propItr = null;
properties = null;
// Configuration Change Record table
List<ChangeRecordInfo> records = jdbcStore.getAllConfigRecords();
for (int i = 0, len = records.size(); i < len; i++) {
fileStore.storeConfigChangeRecord(records.get(i).getTimestamp(), records.get(i).getRecord(), false);
}
records = null;
// Consumer table
Consumer[] consumerArray = jdbcStore.getAllInterests();
for (int i = 0; i < consumerArray.length; i++) {
fileStore.storeInterest(consumerArray[i], false);
}
consumerArray = null;
// Broker & Session table - store all HABrokerInfo as a property
HashMap bkrMap = jdbcStore.getAllBrokerInfos(true);
List haBrokers = new ArrayList(bkrMap.values());
fileStore.updateProperty(STORE_PROPERTY_HABROKERS, haBrokers, true);
/*
* For each broker in the cluster, we will store broker specific data, destinations, messages, transactions,
* acknowledgements in their own filestore (a.k.a broker filestore).
*/
Iterator bkrItr = haBrokers.iterator();
while (bkrItr.hasNext()) {
// Backup data for each broker
HABrokerInfo bkrInfo = (HABrokerInfo) bkrItr.next();
String brokerID = bkrInfo.getId();
logger.logToAll(Logger.INFO, "Backup persistent data for broker " + brokerID);
FileStore bkrFS = null;
JMSBridgeStore jmsbridgeStore = null;
try {
String instanceRootDir = backupDir + File.separator + brokerID;
bkrFS = new FileStore(instanceRootDir, false);
bkrFS.clearAll(false);
// Destination table.
Destination[] dstArray = jdbcStore.getAllDestinations(brokerID);
for (int i = 0, len = dstArray.length; i < len; i++) {
DestinationUID did = dstArray[i].getDestinationUID();
Destination dst = bkrFS.getDestination(did);
if (dst == null) {
// Store the destination if not found
bkrFS.storeDestination(dstArray[i], false);
}
}
// Storing messages for each destination.
for (int i = 0, len = dstArray.length; i < len; i++) {
Enumeration e = jdbcStore.messageEnumeration(dstArray[i]);
try {
for (; e.hasMoreElements(); ) {
DestinationUID did = dstArray[i].getDestinationUID();
Packet message = (Packet) e.nextElement();
SysMessageID mid = message.getSysMessageID();
// Get interest states for the message; Consumer State table
HashMap stateMap = jdbcStore.getInterestStates(did, mid);
if (stateMap == null || stateMap.isEmpty()) {
bkrFS.storeMessage(did, message, false);
} else {
int size = stateMap.size();
ConsumerUID[] iids = new ConsumerUID[size];
int[] states = new int[size];
Iterator stateItr = stateMap.entrySet().iterator();
int j = 0;
while (stateItr.hasNext()) {
Map.Entry entry = (Map.Entry) stateItr.next();
iids[j] = (ConsumerUID) entry.getKey();
states[j] = ((Integer) entry.getValue()).intValue();
j++;
}
bkrFS.storeMessage(did, message, iids, states, false);
}
}
} finally {
jdbcStore.closeEnumeration(e);
}
}
// Transaction table
Collection txnList = jdbcStore.getTransactions(brokerID);
Iterator txnItr = txnList.iterator();
while (txnItr.hasNext()) {
TransactionUID tid = (TransactionUID) txnItr.next();
TransactionInfo txnInfo = jdbcStore.getTransactionInfo(tid);
TransactionAcknowledgement[] txnAck = jdbcStore.getTransactionAcks(tid);
bkrFS.storeTransaction(tid, txnInfo, false);
for (int i = 0, len = txnAck.length; i < len; i++) {
bkrFS.storeTransactionAck(tid, txnAck[i], false);
}
}
/**
************************************************
* JMSBridge
*************************************************
*/
Properties bp = new Properties();
bp.setProperty("instanceRootDir", instanceRootDir);
bp.setProperty("reset", "true");
bp.setProperty("logdomain", "imqdbmgr");
bp.setProperty("identityName", Globals.getIdentityName());
BridgeServiceManager.getExportedService(JMSBridgeStore.class, "JMS", bp);
List bnames = jdbcStore.getJMSBridgesByBroker(brokerID, null);
Collections.sort(bnames);
String bname = null;
String currbname = null;
Iterator itr = bnames.iterator();
while (itr.hasNext()) {
bname = (String) itr.next();
if (currbname == null || !currbname.equals(bname)) {
currbname = bname;
bp.setProperty("jmsbridge", bname);
if (jmsbridgeStore != null) {
jmsbridgeStore.closeJMSBridgeStore();
jmsbridgeStore = null;
}
logger.logToAll(logger.INFO, "Backup JMS bridge " + bname);
jmsbridgeStore = (JMSBridgeStore) BridgeServiceManager.getExportedService(JMSBridgeStore.class, "JMS", bp);
List lrs = jdbcStore.getLogRecordsByNameByBroker(bname, brokerID, null);
logger.logToAll(logger.INFO, "\tBackup JMS bridge " + bname + " with " + lrs.size() + " TM log records");
byte[] lr = null;
Iterator itr1 = lrs.iterator();
while (itr1.hasNext()) {
lr = (byte[]) itr1.next();
jmsbridgeStore.storeTMLogRecord(null, lr, currbname, true, null);
}
}
}
} finally {
bkrFS.close();
if (jmsbridgeStore != null) {
jmsbridgeStore.closeJMSBridgeStore();
}
}
}
logger.logToAll(Logger.INFO, "Backup persistent store complete.");
} catch (Throwable ex) {
ex.printStackTrace();
throw new BrokerException(ex.getMessage());
} finally {
assert fileStore != null;
try {
fileStore.close();
} catch (Exception e) {
e.printStackTrace();
}
StoreManager.releaseStore(true);
}
}
Aggregations