Search in sources :

Example 6 with ChangeRecordInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo 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);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ArrayList(java.util.ArrayList) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) GPacket(com.sun.messaging.jmq.io.GPacket)

Example 7 with ChangeRecordInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo 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");
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Logger(com.sun.messaging.jmq.util.log.Logger) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) BrokerResources(com.sun.messaging.jmq.jmsserver.resources.BrokerResources)

Example 8 with ChangeRecordInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.

the class ChangeRecord method makeResetRecord.

public static ChangeRecordInfo makeResetRecord(boolean withUUID) {
    if (DEBUG) {
        Globals.getLogger().log(Logger.INFO, "ChangeRecord.makeResetRecord(" + withUUID + ")");
    }
    ChangeRecordInfo cri = new ChangeRecordInfo();
    GPacket gp = GPacket.getInstance();
    gp.setType(ProtocolGlobals.G_RESET_PERSISTENCE);
    if (withUUID) {
        String uuid = UUID.randomUUID().toString();
        gp.putProp(ChangeRecord.UUID_PROPERTY, uuid);
        cri.setUUID(uuid);
    }
    cri.setTimestamp(System.currentTimeMillis());
    ChangeRecord cr = ChangeRecord.makeChangeRecord(gp);
    cri.setUKey(cr.getUniqueKey());
    try {
        cri.setRecord(cr.getBytes());
    } catch (Exception e) {
        Globals.getLogger().log(Logger.ERROR, "Unexpected exception in makeResetRecord(" + withUUID + "):" + e.toString());
    }
    return cri;
}
Also used : ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) GPacket(com.sun.messaging.jmq.io.GPacket) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 9 with ChangeRecordInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.

the class ChangeRecord method recordCreateSubscription.

public static void recordCreateSubscription(Subscription sub, ChangeRecordCallback cb) throws BrokerException {
    ClusterSubscriptionInfo csi = ClusterSubscriptionInfo.newInstance(sub);
    GPacket gp = csi.getGPacket(ProtocolGlobals.G_NEW_INTEREST, true);
    ChangeRecordInfo cri = storeChangeRecord(gp, cb);
    sub.setCurrentChangeRecordInfo(ProtocolGlobals.G_NEW_INTEREST, cri);
}
Also used : ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) GPacket(com.sun.messaging.jmq.io.GPacket) ClusterSubscriptionInfo(com.sun.messaging.jmq.jmsserver.multibroker.raptor.ClusterSubscriptionInfo)

Example 10 with ChangeRecordInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.

the class ClusterBroadcaster method syncChangeRecordOnJoin.

@Override
public void syncChangeRecordOnJoin(BrokerAddress remote, ChangeRecordInfo cri) throws BrokerException {
    String resetUUID = null;
    if (lastSyncedChangeRecord != null) {
        resetUUID = lastSyncedChangeRecord.getResetUUID();
    }
    if (resetUUID == null) {
        resetUUID = (lastStoredChangeRecord == null ? null : lastStoredChangeRecord.getResetUUID());
    }
    if (resetUUID != null && !resetUUID.equals(cri.getResetUUID())) {
        throw new BrokerException(br.getKString(br.X_SHARECC_RESETUID_MISMATCH_ON_JOIN, "[" + resetUUID + ", " + cri.getResetUUID() + "]", remote.toString()), Status.PRECONDITION_FAILED);
    }
    ChangeRecordInfo lastr = lastReceivedChangeRecord.get(remote);
    if (lastr == null || lastr.getSeq().longValue() < cri.getSeq().longValue() || !lastr.getResetUUID().equals(cri.getResetUUID())) {
        if (lastSyncedChangeRecord == null || lastSyncedChangeRecord.getSeq().longValue() < cri.getSeq().longValue()) {
            logger.log(logger.INFO, br.getKString(br.I_SHARECC_SYNC_ON_JOIN, remote + "[" + cri + "]"));
            ChangeRecord.syncChangeRecord(this, this, ((CommonProtocol) protocol).getRealProtocol(), false);
        }
    }
}
Also used : ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)

Aggregations

ChangeRecordInfo (com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)35 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)11 GPacket (com.sun.messaging.jmq.io.GPacket)9 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)3 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)3 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)3 JMSBridgeStore (com.sun.messaging.bridge.api.JMSBridgeStore)2 Packet (com.sun.messaging.jmq.io.Packet)2 ClusterManager (com.sun.messaging.jmq.jmsserver.cluster.api.ClusterManager)2 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)2 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)2 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)2 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)2 ChangeRecord (com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord)2 ClusterDestInfo (com.sun.messaging.jmq.jmsserver.multibroker.raptor.ClusterDestInfo)2 ClusterFirstInfoInfo (com.sun.messaging.jmq.jmsserver.multibroker.raptor.ClusterFirstInfoInfo)2 ClusterSubscriptionInfo (com.sun.messaging.jmq.jmsserver.multibroker.raptor.ClusterSubscriptionInfo)2 HABrokerInfo (com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo)2