Search in sources :

Example 21 with ChangeRecordInfo

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

the class ChangeRecord method prepareRestoreRecords.

/**
 * Preparing for restoring change records.
 */
public static List<ChangeRecordInfo> prepareRestoreRecords(String fileName) throws Exception {
    Logger logger = Globals.getLogger();
    BrokerResources br = Globals.getBrokerResources();
    if (DEBUG) {
        logger.logToAll(Logger.INFO, "ChangeRecord.prepareRestoreRecords from file " + fileName);
    }
    FileInputStream fis = null;
    DataInputStream dis = null;
    try {
        // Make sure that the file does exist.
        File f = new File(fileName);
        if (!f.exists()) {
            String emsg = br.getKString(br.W_MBUS_CANCEL_RESTORE1, fileName);
            logger.log(Logger.WARNING, emsg);
            throw new BrokerException(emsg);
        }
        fis = new FileInputStream(f);
        dis = new DataInputStream(fis);
        // Version
        int curversion = dis.readInt();
        // Signature.
        String sig = dis.readUTF();
        if (!sig.equals(ProtocolGlobals.CFGSRV_BACKUP_PROPERTY)) {
            String emsg = br.getKString(br.W_MBUS_CANCEL_RESTORE2, fileName);
            logger.logToAll(Logger.WARNING, emsg);
            throw new BrokerException(emsg);
        }
        if (curversion < ProtocolGlobals.VERSION_350 || curversion > ProtocolGlobals.getCurrentVersion()) {
            String emsg = br.getKString(br.W_MBUS_CANCEL_RESTORE3, String.valueOf(curversion), String.valueOf(ProtocolGlobals.getCurrentVersion()));
            logger.logToAll(Logger.ERROR, emsg);
            throw new BrokerException(emsg);
        }
        ArrayList<ChangeRecordInfo> records = new ArrayList<>();
        while (true) {
            int recsize = dis.readInt();
            if (recsize == 0) {
                break;
            }
            byte[] rec = new byte[recsize];
            dis.readFully(rec, 0, recsize);
            ChangeRecordInfo cri = new ChangeRecordInfo();
            cri.setRecord(rec);
            ChangeRecord cr = makeChangeRecord(rec);
            cri.setType(cr.getPacketType());
            cri.setUKey(cr.getUniqueKey());
            cri.setDuraAdd(cr.isDuraAdd());
            if (Globals.useSharedConfigRecord()) {
                String uuid = cr.getUUID();
                if (uuid == null) {
                    uuid = UUID.randomUUID().toString();
                }
                cri.setUUID(uuid);
            }
            records.add(cri);
            if (DEBUG) {
                logger.logToAll(Logger.INFO, "ChangeRecord.prepareRestoreRecords restore record " + cri);
            }
        }
        dis.close();
        fis.close();
        logger.logToAll(Logger.INFO, br.getKString(br.I_CLUSTER_MB_RESTORE_PROCESS_RECORDS, String.valueOf(records.size()), fileName));
        return records;
    } catch (Exception e) {
        String emsg = br.getKString(br.W_MBUS_RESTORE_ERROR, fileName, e.getMessage());
        logger.logStack(Logger.ERROR, emsg, e);
        throw e;
    } finally {
        if (dis != null) {
            try {
                dis.close();
            } catch (Exception e) {
            /* ignore */
            }
        }
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
            /* ignore */
            }
        }
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ArrayList(java.util.ArrayList) 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 22 with ChangeRecordInfo

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

the class ChangeRecord method recordUpdateDestination.

public static synchronized void recordUpdateDestination(Destination d, ChangeRecordCallback cb) throws BrokerException {
    ClusterDestInfo cdi = ClusterDestInfo.newInstance(d);
    GPacket gp = cdi.getGPacket(ProtocolGlobals.G_UPDATE_DESTINATION, true);
    ChangeRecordInfo cri = storeChangeRecord(gp, cb);
    d.setCurrentChangeRecordInfo(ProtocolGlobals.G_UPDATE_DESTINATION, cri);
}
Also used : ClusterDestInfo(com.sun.messaging.jmq.jmsserver.multibroker.raptor.ClusterDestInfo) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) GPacket(com.sun.messaging.jmq.io.GPacket)

Example 23 with ChangeRecordInfo

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

the class ClusterConsumerInfo method getGPacket.

public GPacket getGPacket(short protocol, int subtype, BrokerAddress broker) {
    assert (consumers != null);
    assert (protocol == ProtocolGlobals.G_NEW_INTEREST || protocol == ProtocolGlobals.G_INTEREST_UPDATE);
    if (protocol == ProtocolGlobals.G_INTEREST_UPDATE) {
        assert (// not effectively used ?
        subtype == ProtocolGlobals.G_NEW_PRIMARY_INTEREST || subtype == ProtocolGlobals.G_REM_INTEREST || subtype == ProtocolGlobals.G_DURABLE_DETACH);
    }
    GPacket gp = GPacket.getInstance();
    gp.setType(protocol);
    gp.putProp("C", Integer.valueOf(consumers.size()));
    if (broker != null && pendingMsgs != null && pendingMsgs.size() > 0) {
        TransactionUID tid = null;
        LinkedHashMap mm = null;
        SysMessageID sysid = null;
        StringBuilder sb = null;
        StringBuilder sb45 = null;
        StringBuilder oldsb = null;
        Map m = (Map) pendingMsgs.get(broker);
        if (m != null) {
            oldsb = new StringBuilder();
            Map.Entry pair = null;
            Iterator itr0 = m.entrySet().iterator();
            while (itr0.hasNext()) {
                pair = (Map.Entry) itr0.next();
                tid = (TransactionUID) pair.getKey();
                mm = (LinkedHashMap) pair.getValue();
                sb = new StringBuilder();
                sb45 = new StringBuilder();
                Map.Entry entry = null;
                Iterator itr = mm.entrySet().iterator();
                while (itr.hasNext()) {
                    entry = (Map.Entry) itr.next();
                    sysid = (SysMessageID) entry.getKey();
                    Integer deliverCnt = (Integer) entry.getValue();
                    sb.append(sysid).append(MID_DCT_SEPARATOR).append(deliverCnt == null ? 0 : deliverCnt).append(' ');
                    sb45.append(sysid).append(' ');
                    oldsb.append(sysid).append(' ');
                }
                if (sb.length() > 0) {
                    gp.putProp(PROP_PREFIX_PENDING_TID_MID_DCT + (tid == null ? "" : tid), String.valueOf(sb.toString()));
                    gp.putProp(PROP_PREFIX_PENDING_TID + (tid == null ? "" : tid), String.valueOf(sb45.toString()));
                }
            }
            // To be removed when clustering the old protocol (< 500) broker no longer supported
            gp.putProp(PROP_PENDING_MESSAGES, oldsb.toString());
        }
    }
    if (cleanup) {
        gp.putProp("cleanup", Boolean.TRUE);
    }
    if (c != null) {
        c.marshalBrokerAddress(c.getSelfAddress(), gp);
    }
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    switch(protocol) {
        case ProtocolGlobals.G_NEW_INTEREST:
            try {
                ClusterManager cm = Globals.getClusterManager();
                int csize = 1;
                if (cm != null) {
                    csize = cm.getConfigBrokerCount();
                    if (csize <= 0) {
                        csize = 1;
                    }
                }
                int i = 0;
                Iterator itr = consumers.iterator();
                while (itr.hasNext()) {
                    i++;
                    Consumer c = (Consumer) itr.next();
                    int prefetch = c.getPrefetchForRemote() / csize;
                    if (prefetch <= 0) {
                        prefetch = 1;
                    }
                    gp.putProp(c.getConsumerUID().longValue() + ":" + Consumer.PREFETCH, Integer.valueOf(prefetch));
                    writeConsumer(c, dos);
                    if (!(c instanceof Subscription)) {
                        continue;
                    }
                    ChangeRecordInfo cri = ((Subscription) c).getCurrentChangeRecordInfo(ProtocolGlobals.G_NEW_INTEREST);
                    if (cri == null) {
                        continue;
                    }
                    gp.putProp("shareccSeq" + i, cri.getSeq());
                    gp.putProp("shareccUUID" + i, cri.getUUID());
                    gp.putProp("shareccResetUUID" + i, cri.getResetUUID());
                }
                dos.flush();
                bos.flush();
            } catch (IOException e) {
            /* Ignore */
            }
            gp.setPayload(ByteBuffer.wrap(bos.toByteArray()));
            break;
        case ProtocolGlobals.G_INTEREST_UPDATE:
            gp.putProp("T", Integer.valueOf(subtype));
            try {
                Iterator itr = consumers.iterator();
                while (itr.hasNext()) {
                    Consumer c = (Consumer) itr.next();
                    writeConsumerUID(c.getConsumerUID(), dos);
                }
                dos.flush();
                bos.flush();
            } catch (IOException e) {
            /* Ignore */
            }
            gp.setPayload(ByteBuffer.wrap(bos.toByteArray()));
            break;
    }
    return gp;
}
Also used : GPacket(com.sun.messaging.jmq.io.GPacket) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription) ClusterManager(com.sun.messaging.jmq.jmsserver.cluster.api.ClusterManager)

Example 24 with ChangeRecordInfo

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

the class InterestUpdateChangeRecord method getFlagString.

public String getFlagString() {
    ChangeRecordInfo cri = new ChangeRecordInfo();
    transferFlag(cri);
    return cri.getFlagString(cri.getFlag());
}
Also used : ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)

Example 25 with ChangeRecordInfo

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

the class RaptorProtocol method configServerRestore.

/**
 * Restore the config server database.
 */
private void configServerRestore(String fileName) {
    if (DEBUG) {
        logger.log(Logger.INFO, "RaptorProtocol.configServerRestore. fileName = " + fileName);
    }
    try {
        // Make sure that the file does exist.
        File f = new File(fileName);
        if (!f.exists()) {
            logger.log(Logger.WARNING, br.W_MBUS_CANCEL_RESTORE1, fileName);
            return;
        }
        masterBrokerBlockWait(ProtocolGlobals.getWaitReplyTimeout(), "[RESTORE]");
        try {
            List<ChangeRecordInfo> records = ChangeRecord.prepareRestoreRecords(fileName);
            store.clearAllConfigChangeRecords(false);
            Iterator itr = records.iterator();
            ChangeRecordInfo cri = null;
            while (itr.hasNext()) {
                cri = (ChangeRecordInfo) itr.next();
                store.storeConfigChangeRecord(System.currentTimeMillis(), cri.getRecord(), false);
            }
            logger.log(Logger.INFO, br.I_CLUSTER_MB_RESTORE_SUCCESS, fileName);
        } finally {
            masterBrokerUnBlock();
        }
    } catch (Exception e) {
        logger.logStack(Logger.WARNING, br.W_MBUS_RESTORE_ERROR, e);
        return;
    }
    if (DEBUG) {
        logger.log(Logger.INFO, "RaptorProtocol.configServerRestore complete.");
    }
}
Also used : ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) HandshakeInProgressException(com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException)

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