Search in sources :

Example 1 with ChangeRecordInfo

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

the class RaptorProtocol method sendNewMasterBrokerPrepareAndWaitReply.

private String sendNewMasterBrokerPrepareAndWaitReply(BrokerAddress newmaster) throws Exception {
    if (DEBUG) {
        logger.log(logger.INFO, "RaptorProtocol.sendNewMasterBrokerPrepare, to = " + newmaster);
    }
    String uuid = null;
    List<ChangeRecordInfo> records = store.getConfigChangeRecordsSince(-1);
    // long now = System.currentTimeMillis();
    ArrayList<ChangeRecord> recordList = ChangeRecord.compressRecords(records);
    records.clear();
    records = new ArrayList<>();
    records.add(ChangeRecord.makeResetRecord(false));
    ChangeRecord cr = null;
    ChangeRecordInfo cri = null;
    for (int i = 0; i < recordList.size(); i++) {
        cr = recordList.get(i);
        if (!cr.isDiscard()) {
            cri = new ChangeRecordInfo();
            cri.setRecord(cr.getBytes());
            records.add(cri);
        }
    }
    Long xid = newMasterBrokerReplyTracker.addWaiter(new UnicastReplyWaiter(newmaster, ProtocolGlobals.G_NEW_MASTER_BROKER_PREPARE_REPLY));
    try {
        ClusterNewMasterBrokerPrepareInfo nmpi = ClusterNewMasterBrokerPrepareInfo.newInstance(newmaster, records, xid, c);
        GPacket gp = nmpi.getGPacket();
        logger.log(logger.INFO, br.getKString(br.I_CLUSTER_UNICAST, ProtocolGlobals.getPacketTypeDisplayString(gp.getType()) + "[" + nmpi + "]", newmaster.toString()));
        uuid = nmpi.getUUID();
        c.unicast(newmaster, gp);
        ReplyStatus reply = null;
        try {
            reply = newMasterBrokerReplyTracker.waitForReply(xid, changeMasterBrokerWaitTimeout);
        } catch (BrokerException e) {
            BrokerException e1 = e;
            if (e.getStatusCode() == Status.GONE) {
                e1 = new BrokerException(br.getKString(br.X_CLUSTER_BROKER_LINK_DOWN, newmaster.toString()), Status.GONE);
            } else if (e.getStatusCode() == Status.TIMEOUT) {
                String[] args = new String[] { String.valueOf(changeMasterBrokerWaitTimeout), ProtocolGlobals.getPacketTypeDisplayString(ProtocolGlobals.G_NEW_MASTER_BROKER_PREPARE_REPLY), newmaster.toString() };
                e1 = new BrokerException(br.getKString(br.X_CLUSTER_WAIT_REPLY_TIMEOUT, args), Status.TIMEOUT);
            }
            throw e1;
        }
        if (reply.getStatus() != Status.OK) {
            String[] args = new String[] { reply.getReason(), ProtocolGlobals.getPacketTypeDisplayString(ProtocolGlobals.G_NEW_MASTER_BROKER_PREPARE), newmaster.toString() };
            String emsg = br.getKString(br.E_CLUSTER_RECEIVED_ERROR_REPLY_FROM_BROKER, args);
            throw new BrokerException(emsg, reply.getStatus());
        }
    } finally {
        newMasterBrokerReplyTracker.removeWaiter(xid);
    }
    return uuid;
}
Also used : ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) DestinationUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.DestinationUpdateChangeRecord) InterestUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.InterestUpdateChangeRecord) ChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord)

Example 2 with ChangeRecordInfo

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

the class ClusterImpl method processFirstInfoPacket.

protected void processFirstInfoPacket(GPacket gp, BrokerLink link) {
    try {
        if (!Globals.useSharedConfigRecord()) {
            // should never happen
            throw new BrokerException("Unexpected " + ProtocolGlobals.getPacketTypeDisplayString(gp.getType()) + " packet from " + link.getRemote());
        }
        ClusterFirstInfoInfo cii = ClusterFirstInfoInfo.newInstance(gp);
        ChangeRecordInfo cri = cii.getLastStoredChangeRecord();
        if (cri == null) {
            return;
        }
        logger.log(logger.INFO, br.getKString(br.I_CLUSTER_RECEIVED_FIRST_INFO, ProtocolGlobals.getPacketTypeDisplayString(gp.getType()) + "[(sharecc)" + cri.toString() + "]", link.getRemote()));
        cb.syncChangeRecordOnJoin(link.getRemote(), cri);
    } catch (Exception e) {
        logger.logStack(logger.ERROR, e.getMessage(), e);
        if (e instanceof BrokerException) {
            if (((BrokerException) e).getStatusCode() == Status.PRECONDITION_FAILED) {
                link.shutdown();
                return;
            }
        }
        link.closeConn();
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) LoopbackAddressException(com.sun.messaging.jmq.jmsserver.util.LoopbackAddressException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ClusterFirstInfoInfo(com.sun.messaging.jmq.jmsserver.multibroker.raptor.ClusterFirstInfoInfo)

Example 3 with ChangeRecordInfo

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

the class ClusterConsumerInfo method getShareccInfo.

public ChangeRecordInfo getShareccInfo(int i) {
    if (pkt.getProp("shareccSeq" + i) == null) {
        return null;
    }
    ChangeRecordInfo cri = new ChangeRecordInfo();
    cri.setSeq((Long) pkt.getProp("shareccSeq" + i));
    cri.setUUID((String) pkt.getProp("shareccUUID" + i));
    cri.setResetUUID((String) pkt.getProp("shareccResetUUID" + i));
    cri.setType(pkt.getType());
    return cri;
}
Also used : ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)

Example 4 with ChangeRecordInfo

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

the class ClusterDestInfo method getGPacket.

public GPacket getGPacket(short protocol, boolean changeRecord) {
    assert (d != null);
    assert (protocol == ProtocolGlobals.G_REM_DESTINATION || protocol == ProtocolGlobals.G_UPDATE_DESTINATION);
    GPacket gp = GPacket.getInstance();
    gp.setType(protocol);
    gp.putProp("N", d.getDestinationName());
    gp.putProp("DT", Integer.valueOf(d.getType()));
    switch(protocol) {
        case ProtocolGlobals.G_REM_DESTINATION:
            ChangeRecordInfo cri = d.getCurrentChangeRecordInfo(ProtocolGlobals.G_REM_DESTINATION);
            if (cri != null) {
                gp.putProp("shareccSeq", cri.getSeq());
                gp.putProp("shareccUUID", cri.getUUID());
                gp.putProp("shareccResetUUID", cri.getResetUUID());
            }
            break;
        case ProtocolGlobals.G_UPDATE_DESTINATION:
            cri = d.getCurrentChangeRecordInfo(ProtocolGlobals.G_UPDATE_DESTINATION);
            if (cri != null) {
                gp.putProp("shareccSeq", cri.getSeq());
                gp.putProp("shareccUUID", cri.getUUID());
                gp.putProp("shareccResetUUID", cri.getResetUUID());
            }
            if (DestType.isTemporary(d.getType())) {
                ConnectionUID cuid = d.getConnectionUID();
                if (cuid != null) {
                    gp.putProp("connectionUID", Long.valueOf(cuid.longValue()));
                }
            }
            HashMap props = d.getDestinationProperties();
            if (props == null) {
                props = new HashMap();
            }
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            try {
                PacketProperties.write(props, bos);
                bos.flush();
            } catch (IOException e) {
            /* Ignore */
            }
            byte[] buf = bos.toByteArray();
            gp.setPayload(ByteBuffer.wrap(buf));
            break;
    }
    if (changeRecord) {
        gp.putProp("M", Boolean.TRUE);
    }
    return gp;
}
Also used : ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) GPacket(com.sun.messaging.jmq.io.GPacket)

Example 5 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