Search in sources :

Example 31 with DestinationUID

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

the class IMQConnection method getDebugState.

/**
 * The debug state of this object
 */
@Override
public synchronized Hashtable getDebugState() {
    Hashtable ht = super.getDebugState();
    ht.put("pauseFlowCnt", String.valueOf(pauseFlowCnt));
    ht.put("resumeFlowCnt", String.valueOf(resumeFlowCnt));
    ht.put("producerCnt", String.valueOf(producers.size()));
    if (producers.size() > 0) {
        Vector v = new Vector();
        Iterator itr = producers.keySet().iterator();
        while (itr.hasNext()) {
            ProducerUID p = (ProducerUID) itr.next();
            v.add(p.toString());
        }
        ht.put("producers", v);
    }
    ht.put("msgsToConsumer", String.valueOf(msgsToConsumer));
    ht.put("sessionCnt", String.valueOf(sessions.size()));
    if (sessions.size() > 0) {
        Vector v = new Vector();
        Iterator itr = sessions.values().iterator();
        while (itr.hasNext()) {
            Session p = (Session) itr.next();
            v.add(p.getSessionUID().toString());
        }
        ht.put("sessions", v);
    }
    ht.put("busySessionCnt", String.valueOf(busySessions.size()));
    if (busySessions.size() > 0) {
        Vector v = new Vector();
        Iterator itr = busySessions.iterator();
        while (itr.hasNext()) {
            Session p = (Session) itr.next();
            v.add(p.getSessionUID().toString());
        }
        ht.put("busySessions", v);
    }
    ht.put("tempDestCnt", String.valueOf(tmpDestinations.size()));
    if (tmpDestinations.size() > 0) {
        Vector v = new Vector();
        Iterator itr = tmpDestinations.iterator();
        while (itr.hasNext()) {
            DestinationUID p = (DestinationUID) itr.next();
            v.add(p.toString());
        }
        ht.put("tempDestinations", v);
    }
    ht.put("runningMsgs", String.valueOf(runningMsgs));
    ht.put("paused", String.valueOf(paused));
    ht.put("waitingForResumeFlow", String.valueOf(waitingForResumeFlow));
    ht.put("flowCount", String.valueOf(flowCount));
    ht.put("sentCount", String.valueOf(sent_count));
    ht.put("userName", getUserName());
    ht.put("remoteString", getRemoteConnectionString());
    // ht.put("write_assigned", write_assigned.toString());
    return ht;
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) ProducerUID(com.sun.messaging.jmq.jmsserver.core.ProducerUID) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 32 with DestinationUID

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

the class BrokerConsumers method addConsumer.

public void addConsumer(Consumer c) throws BrokerException {
    if (getDEBUG()) {
        logger.log(logger.INFO, "BrokerConsumers.addConsumer: " + c);
    }
    com.sun.messaging.jmq.jmsserver.core.ConsumerUID cuid = c.getConsumerUID();
    if (consumers.get(cuid) != null) {
        String emsg = Globals.getBrokerResources().getKString(BrokerResources.I_CONSUMER_ALREADY_ADDED, cuid, c.getDestinationUID());
        logger.log(logger.INFO, emsg + " (CLUSTER_ROUTER)");
        throw new ConsumerAlreadyAddedException(emsg);
    }
    DL.acquirePartitionLock(true);
    try {
        if (!(c instanceof Subscription)) {
            consumers.put(cuid, c);
            pendingConsumerUIDs.put(cuid, null);
            listeners.put(cuid, c.addEventListener(this, EventType.BUSY_STATE_CHANGED, null));
        }
        DestinationUID duid = c.getDestinationUID();
        int type = (duid.isQueue() ? DestType.DEST_TYPE_QUEUE : DestType.DEST_TYPE_TOPIC);
        Destination d = null;
        try {
            if (!duid.isWildcard()) {
                for (int i = 0; i < 2; i++) {
                    Destination[] ds = DL.getDestination(Globals.getStore().getPrimaryPartition(), duid.getName(), type, true, true);
                    d = ds[0];
                    try {
                        // is not removed by autocreate prematurely
                        if (d != null) {
                            d.incrementRefCount();
                            // well we should break anyway, but
                            break;
                        // this makes it explicit
                        }
                    } catch (BrokerException ex) {
                        // incrementRefCount throws a BrokerException
                        // if the destination was destroyed
                        // if we are here then the destination went away
                        // try to get the destination again
                        d = null;
                    }
                }
                if (d == null) {
                    throw new BrokerException("Unable to attach to destination " + duid);
                }
            }
        } catch (IOException ex) {
            throw new BrokerException("Unable to autocreate destination " + duid, ex);
        }
        try {
            // before we exit (so cleanup can occur)
            if (!c.getDestinationUID().isQueue() && (!(c instanceof Subscription)) && c.getSubscription() == null) {
                // directly send messages
                c.setFalconRemote(true);
            } else {
                int mp = (d == null ? -1 : d.getMaxPrefetch());
                if (mp <= 0 || mp > BTOBFLOW) {
                    mp = BTOBFLOW;
                }
                int prefetch = c.getRemotePrefetch();
                if (prefetch <= 0 || prefetch > mp) {
                    prefetch = mp;
                }
                Subscription sub = c.getSubscription();
                if (sub != null && sub.getShared()) {
                    prefetch = 1;
                }
                c.setPrefetch(prefetch);
            }
            try {
                if (d == null && c.getSubscription() == null) {
                    // deal with wildcard subscription
                    Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, c.getDestinationUID());
                    LinkedHashSet dset = null;
                    Destination dd = null;
                    Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
                    while (itr.hasNext()) {
                        dset = itr.next();
                        if (dset == null) {
                            continue;
                        }
                        Iterator<Destination> itr1 = dset.iterator();
                        while (itr1.hasNext()) {
                            dd = itr1.next();
                            if (dd == null) {
                                continue;
                            }
                            try {
                                dd.addConsumer(c, false);
                            } catch (ConsumerAlreadyAddedException e) {
                                logger.log(logger.INFO, e.getMessage() + " (CLUSTER_ROUTER)");
                            }
                        }
                    }
                } else if (c.getSubscription() == null) {
                    Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, c.getDestinationUID());
                    LinkedHashSet dset = null;
                    Destination dd = null;
                    Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
                    while (itr.hasNext()) {
                        dset = itr.next();
                        if (dset == null) {
                            continue;
                        }
                        Iterator<Destination> itr1 = dset.iterator();
                        while (itr1.hasNext()) {
                            dd = itr1.next();
                            if (dd == null) {
                                continue;
                            }
                            try {
                                dd.addConsumer(c, false);
                            } catch (ConsumerAlreadyAddedException e) {
                                logger.log(logger.INFO, e.getMessage() + " (CLUSTER_ROUTER)");
                            }
                        }
                    }
                }
            } catch (SelectorFormatException ex) {
                throw new BrokerException("unable to add destination " + d, ex);
            }
            if (!(c instanceof Subscription)) {
                if (c.isBusy()) {
                    synchronized (activeConsumers) {
                        activeConsumers.add(c);
                        activeConsumers.notifyAll();
                    }
                }
            }
        } finally {
            // processing the add consumer
            if (d != null) {
                // not wildcard
                d.decrementRefCount();
            }
        }
    } finally {
        DL.releasePartitionLock(true);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) IOException(java.io.IOException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Iterator(java.util.Iterator) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PartitionedStore(com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)

Example 33 with DestinationUID

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

the class ClusterConsumerInfo method readConsumer.

public static Consumer readConsumer(DataInputStream dis) throws IOException {
    Logger logger = Globals.getLogger();
    ConsumerUID id = null;
    String destName = null;
    String clientID = null;
    String durableName = null;
    String selstr = null;
    boolean isQueue;
    boolean noLocalDelivery;
    // boolean consumerReady;
    int sharedcnt;
    int position;
    // version
    long ver = dis.readLong();
    if (ver != ConsumerVersionUID) {
        throw new IOException("Wrong Consumer Version " + ver + " expected " + ConsumerVersionUID);
    }
    destName = dis.readUTF();
    boolean hasId = dis.readBoolean();
    if (hasId) {
        id = readConsumerUID(dis);
    }
    boolean hasClientID = dis.readBoolean();
    if (hasClientID) {
        clientID = dis.readUTF();
    }
    boolean hasDurableName = dis.readBoolean();
    if (hasDurableName) {
        durableName = dis.readUTF();
    }
    boolean hasSelector = dis.readBoolean();
    if (hasSelector) {
        selstr = dis.readUTF();
    }
    isQueue = dis.readBoolean();
    noLocalDelivery = dis.readBoolean();
    // consumerReady = dis.readBoolean();
    dis.readBoolean();
    boolean sharedSet = false;
    sharedcnt = 1;
    try {
        sharedSet = dis.readBoolean();
        if (sharedSet == true) {
            sharedcnt = dis.readInt();
        }
    } catch (Exception ex) {
    // do nothing prevents failures with old brokers
    }
    position = -1;
    try {
        position = dis.readInt();
    } catch (Exception ex) {
    // do nothing prevents failures with old brokers
    }
    // 5.0
    boolean jmsshare = false;
    String ndsubname = null;
    try {
        jmsshare = dis.readBoolean();
        boolean hasndsubname = dis.readBoolean();
        if (hasndsubname) {
            ndsubname = dis.readUTF();
        }
    } catch (Exception ex) {
    // do nothing prevents failures with old brokers
    }
    try {
        DestinationUID dest = DestinationUID.getUID(destName, isQueue);
        if (durableName != null) {
            Subscription sub = Subscription.findCreateDurableSubscription(clientID, durableName, (sharedcnt != 1), jmsshare, dest, selstr, noLocalDelivery, false, id, Integer.valueOf(sharedcnt));
            return sub;
        } else {
            if (sharedSet) {
                /* non-durable subscriber */
                Subscription sub = Subscription.findCreateNonDurableSubscription(clientID, selstr, ndsubname, (sharedcnt != 1), jmsshare, dest, noLocalDelivery, id, Integer.valueOf(sharedcnt));
                return sub;
            } else {
                Consumer c = Consumer.newConsumer(dest, selstr, noLocalDelivery, id);
                c.setLockPosition(position);
                return c;
            }
        }
    } catch (SelectorFormatException ex) {
        logger.logStack(Logger.WARNING, "Got bad selector[" + selstr + "] ", ex);
        IOException ioe = new IOException(ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    } catch (BrokerException ex) {
        if (ex.getStatusCode() == Status.CONFLICT || ex instanceof ConsumerAlreadyAddedException) {
            logger.log(Logger.WARNING, ex.getMessage());
        } else {
            logger.logStack(Logger.WARNING, ex.getMessage(), ex);
        }
        IOException ioe = new IOException(ex.getMessage());
        ioe.initCause(ex);
        throw ioe;
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) Logger(com.sun.messaging.jmq.util.log.Logger) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) ConsumerAlreadyAddedException(com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription)

Example 34 with DestinationUID

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

the class InfoRequestHandler method handle.

/**
 * Method to handle INFO_REQUEST messages
 */
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
    Hashtable pktprops = null;
    try {
        pktprops = msg.getProperties();
    } catch (Exception ex) {
        logger.logStack(Logger.WARNING, "INFO-REQUEST Packet.getProperties()", ex);
        pktprops = new Hashtable();
    }
    Integer level = (Integer) pktprops.get("JMQRequestType");
    if (level == null) {
        logger.log(logger.INFO, "No JMQRequestType set ");
        // pick and invalid value
        level = Integer.valueOf(-1);
    }
    if (level.intValue() == REQUEST_CONSUMER_INFO) {
        String destName = (String) pktprops.get("JMQDestination");
        int destType = ((Integer) pktprops.get("JMQDestType")).intValue();
        Boolean offb = (Boolean) pktprops.get("JMQRequestOff");
        boolean off = (offb != null && offb.booleanValue());
        DestinationUID duid = DestinationUID.getUID(destName, destType);
        if (off) {
            con.removeConsumerInfoRequest(duid);
        } else {
            con.addConsumerInfoRequest(duid);
        }
        ConsumerInfoNotifyManager cm = Globals.getConnectionManager().getConsumerInfoNotifyManager();
        cm.consumerInfoRequested(con, duid, destType);
        return true;
    }
    sendInfoPacket(level.intValue(), con, msg.getConsumerID());
    return true;
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConsumerInfoNotifyManager(com.sun.messaging.jmq.jmsserver.service.ConsumerInfoNotifyManager)

Example 35 with DestinationUID

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

the class PacketHandler method checkPermission.

public void checkPermission(int id, String op, String destination, int destTypeInt, IMQConnection con) throws AccessControlException, BrokerException {
    // Temporary destination should return null
    String destTypeStr = DestType.queueOrTopic(destTypeInt);
    if (destTypeStr == null) {
        return;
    }
    Service service = con.getService();
    int serviceType = service.getServiceType();
    if (!checkIsNonAdminDest(con, service, serviceType, destination)) {
        return;
    }
    String acdestination = destination;
    // if autocreate false, return to normal path
    if (id == PacketType.CREATE_DESTINATION) {
        if (!checkForAutoCreate(destTypeInt)) {
            return;
        }
        DestinationUID duid = DestinationUID.getUID(destination, DestType.isQueue(destTypeInt));
        DestinationSpi[] ds = coreLifecycle.getDestination(con.getPartitionedStore(), duid);
        DestinationSpi d = ds[0];
        if (d != null && !d.isAutoCreated()) {
            return;
        }
        acdestination = null;
    }
    checkPermission(con, service, serviceType, op, acdestination, destTypeStr, destination);
    // audit logging for destination authorization
    Globals.getAuditSession().destinationAuth(con.getUserName(), con.remoteHostString(), destTypeStr, acdestination, op, true);
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) DestinationSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi)

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