Search in sources :

Example 1 with InterestUpdateChangeRecord

use of com.sun.messaging.jmq.jmsserver.multibroker.InterestUpdateChangeRecord in project openmq by eclipse-ee4j.

the class RaptorProtocol method receiveConfigChangeEvent.

public void receiveConfigChangeEvent(BrokerAddress sender, Long xidProp, byte[] eventData) {
    if (DEBUG) {
        logger.log(logger.INFO, "RaptorProtocol.receiveConfigChangeEvent(xid=" + xidProp + ") from " + sender);
    }
    int status = ProtocolGlobals.G_EVENT_LOG_SUCCESS;
    String reason = null;
    boolean nologstack = false;
    try {
        setConfigOpInProgressIfNotBlocked();
        try {
            BrokerAddress configServer = c.getConfigServer();
            if (configServer == null) {
                throw new BrokerException("Unexpected: there is no master broker");
            }
            if (!configServer.equals(selfAddress)) {
                String[] args = new String[] { ProtocolGlobals.getPacketTypeDisplayString(ProtocolGlobals.G_CONFIG_CHANGE_EVENT), sender.toString(), configServer.toString() };
                throw new BrokerException(br.getKString(br.X_CLUSTER_UNABLE_PROCESS_NOT_MASTER_BROKER, args), Status.PRECONDITION_FAILED);
            }
            ChangeRecord cr = ChangeRecord.makeChangeRecord(eventData);
            if (Globals.nowaitForMasterBroker()) {
                if (cr.getOperation() == ProtocolGlobals.G_REM_DESTINATION) {
                    if (DestType.isQueue(((DestinationUpdateChangeRecord) cr).getType())) {
                        HashSet bmas = new HashSet();
                        synchronized (brokerList) {
                            Iterator itr = brokerList.keySet().iterator();
                            while (itr.hasNext()) {
                                BrokerMQAddress bma = ((BrokerAddress) itr.next()).getMQAddress();
                                bmas.add(bma);
                            }
                        }
                        Iterator itr = Globals.getClusterManager().getConfigBrokers();
                        ClusteredBroker cb = null;
                        while (itr.hasNext()) {
                            cb = (ClusteredBroker) itr.next();
                            if (!bmas.contains(cb.getBrokerURL()) && !cb.isLocalBroker()) {
                                String[] args = { ((DestinationUpdateChangeRecord) cr).getName(), sender.toString(), ServiceRestriction.NO_SYNC_WITH_MASTERBROKER.toString(), cb.getBrokerURL().toString() };
                                nologstack = true;
                                throw new BrokerException(br.getKString(BrokerResources.X_SERVICE_RESTRICTION_DELETE_QUEUE, args));
                            }
                        }
                    }
                }
            }
            if (cr.getOperation() == ProtocolGlobals.G_REM_DURABLE_INTEREST) {
                inDSubToBrokerMap.remove(cr.getUniqueKey());
            } else if (cr.getOperation() == ProtocolGlobals.G_NEW_INTEREST) {
                Subscription sub = Subscription.findDurableSubscription(((InterestUpdateChangeRecord) cr).getSubscriptionKey());
                if (sub != null) {
                    inDSubToBrokerMap.remove(cr.getUniqueKey());
                    String emsg = br.getKString(br.I_RECORD_DURA_SUB_EXIST_ALREADY, "[" + cr.getUniqueKey() + "]" + sub.getDSubLongLogString(), sender);
                    logger.log(logger.INFO, emsg);
                    if (sub.getShared() != ((InterestUpdateChangeRecord) cr).getShared() || sub.getJMSShared() != ((InterestUpdateChangeRecord) cr).getJMSShared()) {
                        throw new BrokerException(emsg);
                    }
                } else {
                    synchronized (inDSubToBrokerMap) {
                        InterestUpdateChangeRecord existcr = (InterestUpdateChangeRecord) inDSubToBrokerMap.get(cr.getUniqueKey());
                        if (existcr != null) {
                            Object[] args = { "[" + cr.getUniqueKey() + "]", existcr.getBroker(), sender };
                            String emsg = br.getKString(br.I_RECORD_DURA_SUB_CONCURRENT, args) + "[" + existcr.getFlagString() + "]";
                            logger.log(logger.INFO, emsg);
                            if (((InterestUpdateChangeRecord) cr).getShared() != existcr.getShared() || ((InterestUpdateChangeRecord) cr).getJMSShared() != existcr.getJMSShared()) {
                                throw new BrokerException(emsg);
                            }
                        } else {
                            ((InterestUpdateChangeRecord) cr).setBroker(sender);
                            inDSubToBrokerMap.put(cr.getUniqueKey(), cr);
                        }
                    }
                }
            }
            try {
                store.storeConfigChangeRecord(System.currentTimeMillis(), eventData, false);
            } catch (Exception e) {
                inDSubToBrokerMap.remove(cr.getUniqueKey());
                throw e;
            }
        } finally {
            setConfigOpInProgress(false);
        }
    } catch (Exception e) {
        reason = e.getMessage();
        status = ProtocolGlobals.G_EVENT_LOG_FAILURE;
        if (e instanceof BrokerException) {
            status = ((BrokerException) e).getStatusCode();
        }
        if (nologstack) {
            logger.log(logger.ERROR, e.getMessage(), e);
        } else {
            logger.logStack(logger.ERROR, e.getMessage(), e);
        }
    }
    sendConfigChangeEventAck(sender, xidProp, status, reason);
}
Also used : InterestUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.InterestUpdateChangeRecord) HandshakeInProgressException(com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException) DestinationUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.DestinationUpdateChangeRecord) InterestUpdateChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.InterestUpdateChangeRecord) ChangeRecord(com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord)

Aggregations

ChangeRecord (com.sun.messaging.jmq.jmsserver.multibroker.ChangeRecord)1 DestinationUpdateChangeRecord (com.sun.messaging.jmq.jmsserver.multibroker.DestinationUpdateChangeRecord)1 HandshakeInProgressException (com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException)1 InterestUpdateChangeRecord (com.sun.messaging.jmq.jmsserver.multibroker.InterestUpdateChangeRecord)1