Search in sources :

Example 21 with PartitionedStore

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

the class DestinationList method assignStorePartition.

public static PartitionedStore assignStorePartition(int serviceType, ConnectionUID connid, UID storeSession) throws BrokerException {
    PartitionedStore pstore = null;
    DestinationList dl = null;
    if (partitionMode && serviceType == ServiceType.ADMIN) {
        synchronized (destinationListList) {
            if (destinationListList.size() == 0) {
                throw new BrokerException("IllegalStateException: DestinationList not inited !");
            }
            dl = destinationListList.get(Globals.getStore().getPrimaryPartition());
            dl.attachConnection(connid);
            return dl.getPartitionedStore();
        }
    }
    if (storeSession != null && Globals.getStore().getPartitionModeEnabled()) {
        PartitionedStore tmpps = new NoPersistPartitionedStoreImpl(storeSession);
        synchronized (destinationListList) {
            dl = destinationListList.get(tmpps);
            if (dl == null) {
                throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.I_CONN_REQUEST_PARTITION_NOT_FOUND, storeSession, connid), Status.NOT_FOUND);
            }
            dl.attachConnection(connid);
            pstore = dl.getPartitionedStore();
        }
        Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_ASSIGN_REQUESTED_PARTITION_TO_CONN, pstore, connid));
        return pstore;
    }
    while (!shutdown) {
        ArrayList<ConnToPartitionStrategyContext> dls = null;
        synchronized (destinationListList) {
            dls = new ArrayList<>(destinationListList.values());
        }
        if (dls.size() == 0) {
            throw new BrokerException("XXXIllegalState: DestinationList not inited !");
        }
        if (dls.size() == 1) {
            dl = (DestinationList) dls.get(0);
            synchronized (destinationListList) {
                dl.attachConnection(connid);
            }
            pstore = dl.getPartitionedStore();
            if (Globals.getStore().getPartitionModeEnabled()) {
                Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_ASSIGN_CONN_PARTITION, pstore, connid));
            }
            return pstore;
        }
        if (partitionStrategy != null) {
            pstore = partitionStrategy.chooseStorePartition(dls);
        } else {
            pstore = dls.get(0).getPartitionedStore();
        }
        synchronized (destinationListList) {
            dl = destinationListList.get(pstore);
            if (dl == null) {
                continue;
            }
            if (!dl.isValid()) {
                continue;
            }
            dl.attachConnection(connid);
        }
        pstore = dl.getPartitionedStore();
        Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_ASSIGN_CONN_PARTITION, pstore, connid));
        return pstore;
    }
    throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER), BrokerResources.X_SHUTTING_DOWN_BROKER);
}
Also used : NoPersistPartitionedStoreImpl(com.sun.messaging.jmq.jmsserver.persist.api.NoPersistPartitionedStoreImpl) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Example 22 with PartitionedStore

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

the class Consumer method getDestinations.

protected List<Destination> getDestinations() {
    List<Destination> snapshot = new ArrayList<>();
    synchronized (destinationMap) {
        if (destinationMap.size() == 0) {
            DestinationList DL = Globals.getDestinationList();
            if (!dest.isWildcard()) {
                Map<PartitionedStore, Destination> mp = DL.getDestinationMap(null, dest);
                LinkedHashSet set = null;
                for (Map.Entry<PartitionedStore, Destination> pair : mp.entrySet()) {
                    set = destinationMap.get(pair.getKey());
                    if (set == null) {
                        set = new LinkedHashSet<>();
                        destinationMap.put(pair.getKey(), set);
                    }
                    set.add(pair.getValue());
                }
            } else {
                Map<PartitionedStore, LinkedHashSet<Destination>> mp = DL.findMatchingDestinationMap(null, dest);
                destinationMap.putAll(mp);
            }
        }
        Iterator<LinkedHashSet<Destination>> itr = destinationMap.values().iterator();
        while (itr.hasNext()) {
            snapshot.addAll(itr.next());
        }
    }
    return snapshot;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Example 23 with PartitionedStore

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

the class PacketReference method replaceTest.

/**
 * TEST CASE FOR VERIFYING REPLACEMEMENT - MUST BE VALIDATED MANUALLY
 */
public static void replaceTest() {
    try {
        PartitionedStore ps = Globals.getDestinationList().assignStorePartition(ServiceType.NORMAL, new ConnectionUID(), null);
        DestinationUID duid = new DestinationUID("test", true);
        DestinationUID duid_t = new DestinationUID("test", false);
        ConsumerUID uid1 = new ConsumerUID(1);
        ConsumerUID uid2 = new ConsumerUID(2);
        // ConsumerUID[] uids = {uid1,uid2};
        Consumer consumer1 = new Consumer(duid, null, false, queueUID);
        ArrayList queues = new ArrayList();
        queues.add(consumer1);
        Consumer tconsumer1 = new Consumer(duid_t, null, false, uid1);
        Consumer tconsumer2 = new Consumer(duid_t, null, false, uid2);
        // simple Non-persistent
        ArrayList topics = new ArrayList();
        topics.add(tconsumer1);
        topics.add(tconsumer2);
        try {
            Globals.getDestinationList().createDestination(ps, "test", DestType.DEST_TYPE_QUEUE);
            Globals.getDestinationList().createDestination(ps, "test", DestType.DEST_TYPE_TOPIC);
        } catch (Exception ex) {
        }
        Packet p1 = new Packet();
        Hashtable props = new Hashtable();
        props.put("MyName", "MyValue");
        byte[] body1 = { 1 };
        p1.setProperties(props);
        p1.setMessageBody(body1);
        p1.updateTimestamp();
        p1.updateSequenceNumber();
        System.out.println("----------------------------------");
        System.out.println("Test1: non-persist No Properties");
        System.out.println("----------------------------------");
        System.out.print("Initial Packet " + p1.getSysMessageID());
        // USE CASE 1 basic replace
        // 
        // first create original packet
        // then create the packet reference
        // then store it
        // then replace the body
        // then check the contents
        // then clear out the reference and reload
        // then check the contents
        PacketReference ref = createReference(ps, p1, duid, null);
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        ref.store(queues);
        byte[] body2 = { 2 };
        try {
            SysMessageID newid = ref.replacePacket(null, body2);
            System.out.print("New ID " + newid);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        System.out.println("----------------------------------");
        System.out.println("Test2: persist No Properties");
        System.out.println("----------------------------------");
        p1 = new Packet();
        props = new Hashtable();
        props.put("MyName", "MyValue");
        byte[] body3 = { 3 };
        byte[] body4 = { 4 };
        p1.setMessageBody(body3);
        p1.setPersistent(true);
        p1.setProperties(props);
        p1.updateTimestamp();
        p1.updateSequenceNumber();
        System.out.print("Initial Packet " + p1.getSysMessageID());
        ref = createReference(ps, p1, duid, null);
        ref.store(queues);
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        try {
            SysMessageID newid = ref.replacePacket(null, body4);
            System.out.print("New ID " + newid);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        System.out.println("----------------------------------");
        System.out.println("Test3: Topic and 2 consumerUID");
        System.out.println("----------------------------------");
        p1 = new Packet();
        props = new Hashtable();
        props.put("MyName", "MyValue");
        byte[] body5 = { 5 };
        byte[] body6 = { 6 };
        p1.setMessageBody(body5);
        p1.setPersistent(true);
        p1.setIsQueue(false);
        p1.setProperties(props);
        p1.updateTimestamp();
        p1.updateSequenceNumber();
        System.out.print("Initial Packet " + p1.getSysMessageID());
        ref = createReference(ps, p1, duid, null);
        ref.store(topics);
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        try {
            SysMessageID newid = ref.replacePacket(null, body6);
            System.out.print("New ID " + newid);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        System.out.println("----------------------------------");
        System.out.println("Test4: Updating Properties");
        System.out.println("----------------------------------");
        p1 = new Packet();
        props = new Hashtable();
        props.put("MyName", "MyValue");
        byte[] body7 = { 7 };
        byte[] body8 = { 8 };
        p1.setMessageBody(body7);
        p1.setPersistent(true);
        p1.setIsQueue(false);
        p1.setProperties(props);
        p1.updateTimestamp();
        p1.updateSequenceNumber();
        Hashtable newProps = new Hashtable();
        newProps.put("MyNewName", "MyNewValue");
        newProps.put("MyName", "***REPLACE***");
        System.out.print("Initial Packet " + p1.getSysMessageID());
        ref = createReference(ps, p1, duid, null);
        System.out.println(ref.getProperties());
        ref.store(topics);
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        try {
            SysMessageID newid = ref.replacePacket(newProps, body8);
            System.out.print("New ID " + newid);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        System.out.println(ref.getProperties());
        System.out.println("----------------------------------");
        System.out.println("Test5: Message Delivered");
        System.out.println("----------------------------------");
        p1 = new Packet();
        props = new Hashtable();
        props.put("MyName", "MyValue");
        byte[] body9 = { 9 };
        byte[] body10 = { 10 };
        p1.setMessageBody(body9);
        p1.setPersistent(true);
        p1.setIsQueue(false);
        p1.setProperties(props);
        p1.updateTimestamp();
        p1.updateSequenceNumber();
        newProps = new Hashtable();
        newProps.put("MyNewName", "MyNewValue");
        newProps.put("MyName", "***REPLACE***");
        ref = createReference(ps, p1, duid, null);
        ref.store(topics);
        ref.delivered(uid2, uid2, false, false);
        System.out.print("Initial Packet " + p1.getSysMessageID());
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        try {
            SysMessageID newid = ref.replacePacket(newProps, body10);
            System.out.print("New ID " + newid);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println("\t[Body=" + ref.getPacket().getMessageBodyByteBuffer().get() + "]");
        System.out.println(ref.getProperties());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Example 24 with PartitionedStore

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

the class GetTransactionsHandler method getTransactionInfo.

private static Hashtable getTransactionInfo(TransactionList tl, TransactionUID id, int type, boolean showpartition) {
    Logger logger = Globals.getLogger();
    TransactionState ts = tl.retrieveState(id);
    if (type == LOCAL) {
        ts = tl.retrieveState(id, true);
    } else if (type == CLUSTER) {
        ts = tl.retrieveState(id, true);
    } else if (type == REMOTE) {
        ts = tl.getRemoteTransactionState(id);
    }
    if (ts == null) {
        return null;
    }
    JMQXid xid = tl.UIDToXid(id);
    Hashtable table = new Hashtable();
    table.put("type", Integer.valueOf(type));
    if (xid != null) {
        table.put("xid", xid.toString());
    }
    PartitionedStore pstore = tl.getPartitionedStore();
    table.put("txnid", Long.valueOf(id.longValue()) + (showpartition ? "[" + pstore.getPartitionID() + (pstore.isPrimaryPartition() ? "*]" : "]") : ""));
    if (ts.getUser() != null) {
        table.put("user", ts.getUser());
    }
    if (ts.getClientID() != null) {
        table.put("clientid", ts.getClientID());
    }
    table.put("timestamp", Long.valueOf(System.currentTimeMillis() - id.age()));
    table.put("connection", ts.getConnectionString());
    table.put("nmsgs", Integer.valueOf(tl.retrieveNSentMessages(id)));
    if (type != REMOTE) {
        table.put("nacks", Integer.valueOf(tl.retrieveNConsumedMessages(id)));
    } else {
        table.put("nacks", Integer.valueOf(tl.retrieveNRemoteConsumedMessages(id)));
    }
    table.put("state", Integer.valueOf(ts.getState()));
    ConnectionUID cuid = ts.getConnectionUID();
    if (cuid != null) {
        table.put("connectionid", Long.valueOf(cuid.longValue()));
    }
    TransactionBroker homeBroker = tl.getRemoteTransactionHomeBroker(id);
    String homeBrokerStr = "";
    if (homeBroker != null) {
        homeBrokerStr = homeBroker.getBrokerAddress().toString();
    }
    table.put("homebroker", homeBrokerStr);
    TransactionBroker[] brokers = null;
    if (type != REMOTE) {
        try {
            brokers = tl.getClusterTransactionBrokers(id);
        } catch (BrokerException be) {
            logger.log(Logger.WARNING, "Exception caught while obtaining list of brokers in transaction", be);
        }
    }
    StringBuilder allBrokers = new StringBuilder();
    StringBuilder pendingBrokers = new StringBuilder();
    if (brokers != null) {
        for (int i = 0; i < brokers.length; ++i) {
            TransactionBroker oneBroker = brokers[i];
            BrokerAddress addr = oneBroker.getBrokerAddress();
            if (allBrokers.length() != 0) {
                allBrokers.append(", ");
            }
            allBrokers.append(addr);
            if (oneBroker.isCompleted()) {
                continue;
            }
            if (pendingBrokers.length() != 0) {
                pendingBrokers.append(", ");
            }
            pendingBrokers.append(addr);
        }
    }
    table.put("allbrokers", allBrokers.toString());
    table.put("pendingbrokers", pendingBrokers.toString());
    return table;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) Hashtable(java.util.Hashtable) Logger(com.sun.messaging.jmq.util.log.Logger) JMQXid(com.sun.messaging.jmq.util.JMQXid) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Example 25 with PartitionedStore

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

the class GetDestinationsHandler method getDestinationInfo.

private static DestinationInfo getDestinationInfo(Destination d, DestinationInfo dinfo, boolean showpartition) {
    DestinationInfo di = dinfo;
    if (di == null || showpartition) {
        di = new DestinationInfo();
    }
    d.getSizeInfo(di);
    if (dinfo == null || showpartition) {
        di.nConsumers = d.getConsumerCount();
        di.nfConsumers = d.getFailoverConsumerCount();
        di.naConsumers = d.getActiveConsumerCount();
    }
    di.nProducers += d.getProducerCount();
    if (dinfo == null || showpartition) {
        di.autocreated = (d.isAutoCreated() || d.isInternal() || d.isDMQ() || d.isAdmin());
    }
    if (dinfo == null || showpartition) {
        di.destState = d.getState();
    }
    if (d.isAdmin() || !showpartition) {
        di.name = d.getDestinationName();
    } else {
        PartitionedStore pstore = d.getPartitionedStore();
        di.name = d.getDestinationName() + "[" + pstore.getPartitionID() + (pstore.isPrimaryPartition() ? "*]" : "]");
    }
    if (dinfo == null || showpartition) {
        di.type = d.getType() & ~(DestType.DEST_INTERNAL | DestType.DEST_AUTO | DestType.DEST_ADMIN);
        di.fulltype = d.getType();
    }
    di.maxMessages += d.getCapacity();
    if (di.maxMessages < 0) {
        di.maxMessages = 0;
    }
    SizeString bc = d.getByteCapacity();
    di.maxMessageBytes += (bc == null ? 0 : bc.getBytes());
    if (di.maxMessageBytes < 0) {
        di.maxMessageBytes = 0;
    }
    bc = d.getMaxByteSize();
    di.maxMessageSize += (bc == null ? 0 : bc.getBytes());
    if (di.maxMessageSize < 0) {
        di.maxMessageSize = 0;
    }
    if (dinfo == null || showpartition) {
        di.destScope = d.getScope();
        di.destLimitBehavior = d.getLimitBehavior();
        di.maxPrefetch = d.getMaxPrefetch();
        di.destCDP = d.getClusterDeliveryPolicy();
        di.maxActiveConsumers = d.getMaxActiveConsumers();
        di.maxFailoverConsumers = d.getMaxFailoverConsumers();
        di.maxProducers = d.getMaxProducers();
        di.maxNumSharedConsumers = d.getMaxNumSharedConsumers();
        di.sharedConsumerFlowLimit = d.getSharedConsumerFlowLimit();
        di.useDMQ = d.getUseDMQ();
        di.validateXMLSchemaEnabled = d.validateXMLSchemaEnabled();
        di.XMLSchemaUriList = d.getXMLSchemaUriList();
        di.reloadXMLSchemaOnFailure = d.reloadXMLSchemaOnFailure();
    }
    if (!d.isQueue()) {
        Hashtable<String, Integer> h = new Hashtable<>();
        if (dinfo == null || showpartition) {
            if (di.nConsumers > 0) {
                Iterator consumers = d.getConsumers();
                while (consumers.hasNext()) {
                    Consumer oneCon = (Consumer) consumers.next();
                    if (oneCon.isWildcard()) {
                        DestinationUID id = oneCon.getDestinationUID();
                        String wildcard = id.getName();
                        Integer count = h.get(wildcard), newCount;
                        if (count == null) {
                            newCount = Integer.valueOf(1);
                        } else {
                            newCount = Integer.valueOf(count.intValue() + 1);
                        }
                        h.put(wildcard, newCount);
                    }
                }
            }
            if (h.size() > 0) {
                di.consumerWildcards = h;
            }
        }
        h = di.producerWildcards;
        if (h == null) {
            h = new Hashtable<>();
        }
        if (di.nProducers > 0) {
            Iterator producers = d.getProducers();
            while (producers.hasNext()) {
                Producer oneProd = (Producer) producers.next();
                if (oneProd.isWildcard()) {
                    DestinationUID id = oneProd.getDestinationUID();
                    String wildcard = id.getName();
                    Integer count = h.get(wildcard), newCount;
                    if (count == null) {
                        newCount = Integer.valueOf(1);
                    } else {
                        newCount = Integer.valueOf(count.intValue() + 1);
                    }
                    h.put(wildcard, newCount);
                }
            }
        }
        if (h.size() > 0) {
            di.producerWildcards = h;
        }
    }
    return di;
}
Also used : SizeString(com.sun.messaging.jmq.util.SizeString) DestinationInfo(com.sun.messaging.jmq.util.admin.DestinationInfo) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) Producer(com.sun.messaging.jmq.jmsserver.core.Producer) Hashtable(java.util.Hashtable) Iterator(java.util.Iterator) SizeString(com.sun.messaging.jmq.util.SizeString) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Aggregations

PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)26 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)13 HashMap (java.util.HashMap)11 Map (java.util.Map)10 Iterator (java.util.Iterator)9 LinkedHashMap (java.util.LinkedHashMap)8 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)7 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)7 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)7 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)7 NoPersistPartitionedStoreImpl (com.sun.messaging.jmq.jmsserver.persist.api.NoPersistPartitionedStoreImpl)7 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)6 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)6 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)6 LinkedHashSet (java.util.LinkedHashSet)6 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)4 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)4