Search in sources :

Example 11 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class VerifyDestinationHandler method handle.

/**
 * Method to handle Destination (create or delete) messages
 */
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
    int status = Status.OK;
    String reason = null;
    assert msg.getPacketType() == PacketType.VERIFY_DESTINATION;
    Packet pkt = new Packet(con.useDirectBuffers());
    pkt.setConsumerID(msg.getConsumerID());
    pkt.setPacketType(PacketType.VERIFY_DESTINATION_REPLY);
    Hashtable hash = new Hashtable();
    Hashtable props = null;
    String selectorstr = null;
    int type = 0;
    try {
        props = msg.getProperties();
        String destination = (String) props.get("JMQDestination");
        Integer inttype = (Integer) props.get("JMQDestType");
        // destination & type required
        assert destination != null;
        type = (inttype == null) ? 0 : inttype.intValue();
        selectorstr = (String) props.get("JMQSelector");
        if (selectorstr != null) {
            Selector.compile(selectorstr);
        }
        boolean notFound = false;
        DestinationSpi d = null;
        if (DestinationUID.isWildcard(destination)) {
            // retrieve the list of destinations
            pkt.setWildcard(true);
            // see if there are any destinations that match
            DestinationUID duid = DestinationUID.getUID(destination, type);
            List[] ll = coreLifecycle.findMatchingIDs(con.getPartitionedStore(), duid);
            List l = ll[0];
            if (l.isEmpty()) {
                notFound = true;
            }
        } else {
            DestinationSpi[] ds = coreLifecycle.getDestination(con.getPartitionedStore(), destination, DestType.isQueue(type));
            d = ds[0];
            notFound = (d == null);
        }
        if (notFound) {
            // not found
            status = Status.NOT_FOUND;
            reason = "destination not found";
            hash.put("JMQCanCreate", Boolean.valueOf(coreLifecycle.canAutoCreate(DestType.isQueue(type))));
        } else {
            if (d != null) {
                hash.put("JMQDestType", Integer.valueOf(d.getType()));
            }
        }
    } catch (SelectorFormatException ex) {
        reason = ex.getMessage();
        status = Status.BAD_REQUEST;
        logger.log(Logger.WARNING, BrokerResources.W_SELECTOR_PARSE, selectorstr, ex);
    } catch (IOException ex) {
        logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to verify destination - no properties", ex);
        reason = ex.getMessage();
        status = Status.ERROR;
    } catch (ClassNotFoundException ex) {
        logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to verify destination -bad class", ex);
        reason = ex.getMessage();
        status = Status.ERROR;
    } catch (BrokerException ex) {
        reason = ex.getMessage();
        status = ex.getStatusCode();
        logger.logStack(Logger.DEBUG, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to verify destination ", ex);
    } catch (SecurityException ex) {
        reason = ex.getMessage();
        status = Status.FORBIDDEN;
        logger.log(Logger.WARNING, ex.toString(), ex);
    }
    hash.put("JMQStatus", Integer.valueOf(status));
    if (reason != null) {
        hash.put("JMQReason", reason);
    }
    if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
        hash.put("JMQReqID", msg.getSysMessageID().toString());
    }
    pkt.setProperties(hash);
    con.sendControlMessage(pkt);
    return true;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DestinationSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID)

Example 12 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class DestinationMonitor method getProducerWildcards.

public String[] getProducerWildcards() throws MBeanException {
    ArrayList<String> al = new ArrayList<>();
    String[] list = null;
    int numProducers = getNumProducers().intValue();
    Iterator producers;
    if (numProducers <= 0) {
        return (null);
    }
    producers = d.getProducers();
    while (producers.hasNext()) {
        ProducerSpi oneProd = (ProducerSpi) producers.next();
        if (oneProd.isWildcard()) {
            DestinationUID id = oneProd.getDestinationUID();
            al.add(id.getName());
        }
    }
    if (al.size() > 0) {
        list = new String[al.size()];
        list = al.toArray(list);
    }
    return (list);
}
Also used : ProducerSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.ProducerSpi) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 13 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class DestinationMonitor method getWildcards.

public String[] getWildcards() throws MBeanException {
    ArrayList<String> al = new ArrayList<>();
    String[] list = null;
    int numConsumers = getNumConsumers().intValue(), numProducers = getNumProducers().intValue();
    if (numConsumers > 0) {
        Iterator consumers = d.getConsumers();
        while (consumers.hasNext()) {
            Consumer oneCon = (Consumer) consumers.next();
            if (oneCon.isWildcard()) {
                DestinationUID id = oneCon.getDestinationUID();
                al.add(id.getName());
            }
        }
    }
    if (numProducers > 0) {
        Iterator producers = d.getProducers();
        while (producers.hasNext()) {
            ProducerSpi oneProd = (ProducerSpi) producers.next();
            if (oneProd.isWildcard()) {
                DestinationUID id = oneProd.getDestinationUID();
                al.add(id.getName());
            }
        }
    }
    if (al.size() > 0) {
        list = new String[al.size()];
        list = al.toArray(list);
    }
    return (list);
}
Also used : ProducerSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.ProducerSpi) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 14 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class DestinationMonitor method getConsumerWildcards.

public String[] getConsumerWildcards() throws MBeanException {
    ArrayList<String> al = new ArrayList<>();
    String[] list = null;
    int numConsumers = getNumConsumers().intValue();
    Iterator consumers;
    if (numConsumers <= 0) {
        return (null);
    }
    consumers = d.getConsumers();
    while (consumers.hasNext()) {
        Consumer oneCon = (Consumer) consumers.next();
        if (oneCon.isWildcard()) {
            DestinationUID id = oneCon.getDestinationUID();
            al.add(id.getName());
        }
    }
    if (al.size() > 0) {
        list = new String[al.size()];
        list = al.toArray(list);
    }
    return (list);
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 15 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class DestinationMonitor method getNumWildcardConsumers.

public Integer getNumWildcardConsumers(String wildcard) throws MBeanException {
    int numConsumers = getNumConsumers().intValue();
    if (numConsumers <= 0) {
        return (Integer.valueOf(0));
    }
    Iterator consumers = d.getConsumers();
    if (consumers == null) {
        return (Integer.valueOf(0));
    }
    int count = 0;
    while (consumers.hasNext()) {
        Consumer oneCon = (Consumer) consumers.next();
        if (oneCon.isWildcard()) {
            /*
                 * If wildcard param is not null, check for matches If it is null, return total count of wildcards
                 */
            if (wildcard != null) {
                DestinationUID id = oneCon.getDestinationUID();
                if (id.getName().equals(wildcard)) {
                    count++;
                }
            } else {
                count++;
            }
        }
    }
    return (Integer.valueOf(count));
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) Iterator(java.util.Iterator)

Aggregations

DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)61 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)25 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)20 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)20 Iterator (java.util.Iterator)18 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)16 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)16 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)10 Producer (com.sun.messaging.jmq.jmsserver.core.Producer)9 ArrayList (java.util.ArrayList)9 Packet (com.sun.messaging.jmq.io.Packet)8 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)8 IOException (java.io.IOException)8 ProducerUID (com.sun.messaging.jmq.jmsserver.core.ProducerUID)6 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)6 HashMap (java.util.HashMap)6 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)5 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)5 Session (com.sun.messaging.jmq.jmsserver.core.Session)5 SessionUID (com.sun.messaging.jmq.jmsserver.core.SessionUID)5