Search in sources :

Example 6 with ProducerUID

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

the class ProducerHandler method handle.

/**
 * Method to handle Producers
 */
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(msg.getPacketType() + 1);
    reply.setConsumerID(msg.getConsumerID());
    boolean isIndemp = msg.getIndempotent();
    int status = Status.OK;
    String reason = null;
    Hashtable props = null;
    try {
        props = msg.getProperties();
    } catch (Exception ex) {
        throw new RuntimeException("Can not load props", ex);
    }
    Hashtable returnprop = new Hashtable();
    Destination d = null;
    try {
        if (msg.getPacketType() == PacketType.ADD_PRODUCER) {
            String dest = (String) props.get("JMQDestination");
            Integer type = (Integer) props.get("JMQDestType");
            if (!con.isAdminConnection() && MemoryGlobals.getMEM_DISALLOW_PRODUCERS()) {
                status = Status.ERROR;
                reason = "Low memory";
                logger.log(Logger.WARNING, BrokerResources.W_LOW_MEM_REJECT_PRODUCER);
                throw new BrokerException(reason, status);
            }
            Long lsessionid = (Long) props.get("JMQSessionID");
            if (lsessionid != null) {
                // 3.5 protocol
                SessionUID sessionID = new SessionUID(lsessionid.longValue());
                // single threaded .. we dont have to worry about
                // someone else creating it
                Session session = con.getSession(sessionID);
                if (session == null) {
                    throw new BrokerException("Internal Error: client sent " + "invalid sessionUID w/ ADD_PRODUCER " + sessionID + " session does not exist");
                }
            }
            Destination[] ds = null;
            DestinationUID duid = null;
            if (dest != null && !DestinationUID.isWildcard(dest) && type != null) {
                while (true) {
                    ds = DL.getDestination(con.getPartitionedStore(), dest, type.intValue(), true, !con.isAdminConnection());
                    d = ds[0];
                    if (d != null) {
                        try {
                            d.incrementRefCount();
                        } catch (BrokerException ex) {
                            // try again
                            continue;
                        } catch (IllegalStateException ex) {
                            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER), BrokerResources.X_SHUTTING_DOWN_BROKER, ex, Status.ERROR);
                        }
                    }
                    // got a lock on the dest
                    break;
                }
                if (d == null) {
                    logger.log(Logger.DEBUG, "Unable to add " + "producer to " + dest + " :" + DestType.toString(type.intValue()) + " destination can not be autocreated ");
                    reason = "can not create destination";
                    status = Status.NOT_FOUND;
                    throw new BrokerException(reason, status);
                }
                duid = d.getDestinationUID();
            } else if (dest == null || type == null) {
                reason = "no destination passed [dest,type] = [" + dest + "," + type + "]";
                status = Status.ERROR;
                throw new BrokerException(reason, status);
            } else {
                duid = DestinationUID.getUID(dest, DestType.isQueue(type.intValue()));
            }
            String info = msg.getSysMessageID().toString();
            Producer p = addProducer(duid, con, info, isIndemp);
            ProducerUID pid = p.getProducerUID();
            assert pid != null;
            // LKS - XXX - REVISIT - WHAT ABOUT FLOW CONTROL
            boolean active = d == null || d.isProducerActive(pid);
            returnprop.put("JMQProducerID", Long.valueOf(pid.longValue()));
            returnprop.put("JMQDestinationID", duid.toString());
            if (d == null) {
                returnprop.put("JMQBytes", Long.valueOf(-1));
                returnprop.put("JMQSize", Integer.valueOf(-1));
            } else if (active) {
                returnprop.put("JMQBytes", Long.valueOf(d.getBytesProducerFlow()));
                returnprop.put("JMQSize", Integer.valueOf(d.getSizeProducerFlow()));
            } else {
                returnprop.put("JMQBytes", Long.valueOf(0));
                returnprop.put("JMQSize", Integer.valueOf(0));
            }
        } else {
            assert msg.getPacketType() == PacketType.DELETE_PRODUCER;
            Long pid_l = (Long) props.get("JMQProducerID");
            ProducerUID pid = new ProducerUID(pid_l == null ? 0 : pid_l.longValue());
            removeProducer(pid, isIndemp, con, "Producer closed requested:\n\tconnection: " + con.getConnectionUID() + "\n\tproducerID: " + pid + "\n\trequest sysmsgid message: " + msg.getSysMessageID());
        }
    } catch (BrokerException ex) {
        status = ex.getStatusCode();
        reason = ex.getMessage();
        logger.log(Logger.INFO, reason);
    } catch (Exception ex) {
        logger.logStack(Logger.INFO, BrokerResources.E_INTERNAL_BROKER_ERROR, "producer message ", ex);
        reason = ex.getMessage();
        status = Status.ERROR;
    } finally {
        if (d != null) {
            d.decrementRefCount();
        }
    }
    returnprop.put("JMQStatus", Integer.valueOf(status));
    if (reason != null) {
        returnprop.put("JMQReason", reason);
    }
    if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
        returnprop.put("JMQReqID", msg.getSysMessageID().toString());
    }
    reply.setProperties(returnprop);
    con.sendControlMessage(reply);
    return true;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) SessionUID(com.sun.messaging.jmq.jmsserver.core.SessionUID) ProducerUID(com.sun.messaging.jmq.jmsserver.core.ProducerUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Producer(com.sun.messaging.jmq.jmsserver.core.Producer) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 7 with ProducerUID

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

the class JMSServiceImpl method deleteProducer.

/**
 * Delete a producer.
 *
 * @param connectionId The Id of the connection in which to delete the producer
 * @param sessionId The Id of the session in which to delete the producer
 * @param producerId The Id of the producer to delete
 *
 * @return The JMSServiceReply of the request to delete a producer
 *
 * @throws JMSServiceException if the Status returned for the deleteProducer method is not
 * {@link JMSServiceReply.Status#OK}
 *
 * @see JMSServiceReply.Status#FORBIDDEN
 * @see JMSServiceReply.Status#NOT_FOUND
 * @see JMSServiceReply.Status#ERROR
 */
@Override
public JMSServiceReply deleteProducer(long connectionId, long sessionId, long producerId) throws JMSServiceException {
    JMSServiceReply reply;
    HashMap props = new HashMap();
    IMQConnection cxn;
    cxn = checkConnectionId(connectionId, "deleteProducer");
    try {
        protocol.removeProducer(new ProducerUID(producerId), cxn, new Object().toString());
    } catch (Exception e) {
        String errStr = "deleteProducer: Delete producer failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", producer ID: " + producerId;
        logger.logStack(Logger.ERROR, errStr, e);
        props.put("JMQStatus", getErrorReplyStatus(e));
        throw new JMSServiceException(errStr, e, props);
    }
    props.put("JMQStatus", JMSServiceReply.Status.OK);
    reply = new JMSServiceReply(props);
    return (reply);
}
Also used : ProducerUID(com.sun.messaging.jmq.jmsserver.core.ProducerUID) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) AccessControlException(java.security.AccessControlException)

Example 8 with ProducerUID

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

the class ServiceMonitor method getProducerIDs.

public String[] getProducerIDs() throws MBeanException {
    List producerIDs = ServiceUtil.getProducerIDs(service);
    String[] ids;
    if ((producerIDs == null) || (producerIDs.size() == 0)) {
        return (null);
    }
    ids = new String[producerIDs.size()];
    Iterator iter = producerIDs.iterator();
    int i = 0;
    while (iter.hasNext()) {
        ProducerUID pid = (ProducerUID) iter.next();
        long prdID = pid.longValue();
        String id;
        try {
            id = Long.toString(prdID);
            ids[i] = id;
        } catch (Exception ex) {
            handleOperationException(ServiceOperations.GET_PRODUCER_IDS, ex);
        }
        i++;
    }
    return (ids);
}
Also used : ProducerUID(com.sun.messaging.jmq.jmsserver.core.ProducerUID) Iterator(java.util.Iterator) List(java.util.List) MBeanException(javax.management.MBeanException)

Example 9 with ProducerUID

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

the class ProducerManagerMonitor method getProducerWildcards.

public String[] getProducerWildcards() throws MBeanException {
    ArrayList<String> al = new ArrayList<>();
    String[] list = null;
    int numWildcardProducers = Producer.getNumWildcardProducers();
    Iterator producers;
    if (numWildcardProducers <= 0) {
        return (null);
    }
    producers = Producer.getWildcardProducers();
    if (producers == null) {
        return (null);
    }
    while (producers.hasNext()) {
        ProducerUID pid = (ProducerUID) producers.next();
        Producer oneProd = (Producer) Producer.getProducer(pid);
        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 : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Producer(com.sun.messaging.jmq.jmsserver.core.Producer) ProducerUID(com.sun.messaging.jmq.jmsserver.core.ProducerUID) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 10 with ProducerUID

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

the class ConnectionMonitor method getProducerIDs.

public String[] getProducerIDs() throws MBeanException {
    List producerIDs = ConnectionUtil.getProducerIDs(id);
    String[] ids;
    if ((producerIDs == null) || (producerIDs.size() == 0)) {
        return (null);
    }
    ids = new String[producerIDs.size()];
    Iterator iter = producerIDs.iterator();
    int i = 0;
    while (iter.hasNext()) {
        ProducerUID pid = (ProducerUID) iter.next();
        long prdID = pid.longValue();
        String id;
        try {
            id = Long.toString(prdID);
            ids[i] = id;
        } catch (Exception ex) {
            handleOperationException(ConnectionOperations.GET_PRODUCER_IDS, ex);
        }
        i++;
    }
    return (ids);
}
Also used : ProducerUID(com.sun.messaging.jmq.jmsserver.core.ProducerUID) Iterator(java.util.Iterator) List(java.util.List) MBeanException(javax.management.MBeanException)

Aggregations

ProducerUID (com.sun.messaging.jmq.jmsserver.core.ProducerUID)12 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)6 Producer (com.sun.messaging.jmq.jmsserver.core.Producer)5 Iterator (java.util.Iterator)5 Session (com.sun.messaging.jmq.jmsserver.core.Session)3 SessionUID (com.sun.messaging.jmq.jmsserver.core.SessionUID)3 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)2 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)2 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)2 List (java.util.List)2 MBeanException (javax.management.MBeanException)2 FaultInjection (com.sun.messaging.jmq.jmsserver.FaultInjection)1 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)1 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)1 ConsumerSpi (com.sun.messaging.jmq.jmsserver.plugin.spi.ConsumerSpi)1 BrokerResources (com.sun.messaging.jmq.jmsserver.resources.BrokerResources)1 Service (com.sun.messaging.jmq.jmsserver.service.Service)1 IMQConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)1 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 CacheHashMap (com.sun.messaging.jmq.util.CacheHashMap)1