Search in sources :

Example 6 with ClusterManager

use of com.sun.messaging.jmq.jmsserver.cluster.api.ClusterManager 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)

Aggregations

ClusterManager (com.sun.messaging.jmq.jmsserver.cluster.api.ClusterManager)6 BrokerMQAddress (com.sun.messaging.jmq.jmsserver.core.BrokerMQAddress)3 GPacket (com.sun.messaging.jmq.io.GPacket)2 ClusteredBroker (com.sun.messaging.jmq.jmsserver.cluster.api.ClusteredBroker)2 ChangeRecordInfo (com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)2 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)2 Iterator (java.util.Iterator)2 MQAddress (com.sun.messaging.jmq.io.MQAddress)1 Packet (com.sun.messaging.jmq.io.Packet)1 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)1 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)1 Subscription (com.sun.messaging.jmq.jmsserver.core.Subscription)1 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 Properties (java.util.Properties)1 Set (java.util.Set)1