Search in sources :

Example 1 with ConflictException

use of com.sun.messaging.jmq.jmsserver.util.ConflictException in project openmq by eclipse-ee4j.

the class CreateDestinationHandler method handle.

/**
 * Handle the incomming administration message.
 *
 * @param con The Connection the message came in on.
 * @param cmd_msg The administration message
 * @param cmd_props The properties from the administration message
 */
@SuppressWarnings("deprecation")
@Override
public boolean handle(IMQConnection con, Packet cmd_msg, Hashtable cmd_props) {
    DestinationInfo info;
    info = (DestinationInfo) getBodyObject(cmd_msg);
    if (DEBUG) {
        logger.log(Logger.DEBUG, this.getClass().getName() + ": " + "Creating destination: " + cmd_props + ": " + info.toString());
    }
    Packet reply = new Packet(con.useDirectBuffers());
    reply.setPacketType(PacketType.OBJECT_MESSAGE);
    int status = Status.OK;
    String errMsg = null;
    // Default attributes of the destination
    int type = DestType.DEST_TYPE_QUEUE | DestType.DEST_FLAVOR_SINGLE;
    int maxMessages = -1;
    SizeString maxMessageBytes = null;
    SizeString maxMessageSize = null;
    HAMonitorService hamonitor = Globals.getHAMonitorService();
    if (hamonitor != null && hamonitor.inTakeover()) {
        status = Status.ERROR;
        errMsg = rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);
        logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
    } else if (MemoryGlobals.getMEM_DISALLOW_CREATE_DEST()) {
        status = Status.ERROR;
        errMsg = rb.W_LOW_MEM_REJECT_DEST;
    } else if (info.isModified(DestinationInfo.NAME)) {
        if (info.isModified(DestinationInfo.TYPE)) {
            type = info.type;
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGES)) {
            maxMessages = info.maxMessages;
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGE_BYTES)) {
            maxMessageBytes = new SizeString();
            maxMessageBytes.setBytes(info.maxMessageBytes);
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGE_SIZE)) {
            maxMessageSize = new SizeString();
            maxMessageSize.setBytes(info.maxMessageSize);
        }
    } else {
        status = Status.ERROR;
        errMsg = rb.X_NO_DEST_NAME_SET;
    }
    // XXX create destination
    if (status == Status.OK) {
        if (DestType.destNameIsInternal(info.name)) {
            status = Status.ERROR;
            errMsg = rb.getKString(rb.X_CANNOT_CREATE_INTERNAL_DEST, info.name, DestType.INTERNAL_DEST_PREFIX);
        } else {
            if (isValidDestinationName(info.name)) {
                try {
                    DL.createDestination(null, info.name, type);
                } catch (Exception ex) {
                    status = Status.ERROR;
                    errMsg = rb.getKString(rb.X_CREATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
                    if (ex instanceof ConflictException) {
                        logger.log(Logger.INFO, errMsg, ex);
                    } else {
                        logger.logStack(Logger.INFO, errMsg, ex);
                    }
                }
            } else {
                status = Status.ERROR;
                errMsg = rb.getKString(rb.X_DEST_NAME_INVALID, info.name);
            }
        }
    }
    if (status == Status.OK) {
        try {
            Destination[] ds = DL.getDestination(null, info.name, DestType.isQueue(type));
            Destination d = ds[0];
            d.setCapacity(maxMessages);
            d.setByteCapacity(maxMessageBytes);
            d.setMaxByteSize(maxMessageSize);
            if (info.isModified(info.DEST_SCOPE)) {
                int scope = info.destScope;
                d.setScope(scope);
            }
            if (info.isModified(info.DEST_LIMIT)) {
                int destlimit = info.destLimitBehavior;
                d.setLimitBehavior(destlimit);
            }
            if (info.isModified(info.DEST_PREFETCH)) {
                int prefetch = info.maxPrefetch;
                d.setMaxPrefetch(prefetch);
            }
            if (info.isModified(info.DEST_CDP)) {
                int clusterdeliverypolicy = info.destCDP;
                d.setClusterDeliveryPolicy(clusterdeliverypolicy);
            }
            if (info.isModified(info.MAX_ACTIVE_CONSUMERS)) {
                int maxcons = info.maxActiveConsumers;
                d.setMaxActiveConsumers(maxcons);
            }
            if (info.isModified(info.MAX_PRODUCERS)) {
                int maxp = info.maxProducers;
                d.setMaxProducers(maxp);
            }
            if (info.isModified(info.MAX_FAILOVER_CONSUMERS)) {
                int maxcons = info.maxFailoverConsumers;
                d.setMaxFailoverConsumers(maxcons);
            }
            if (info.isModified(info.MAX_SHARED_CONSUMERS)) {
                int maxsharedcons = info.maxNumSharedConsumers;
                d.setMaxSharedConsumers(maxsharedcons);
            }
            if (info.isModified(info.SHARE_FLOW_LIMIT)) {
                int sflowlimit = info.sharedConsumerFlowLimit;
                d.setSharedFlowLimit(sflowlimit);
            }
            if (info.isModified(info.USE_DMQ)) {
                boolean dmq = info.useDMQ;
                d.setUseDMQ(dmq);
            }
            if (info.isModified(info.VALIDATE_XML_SCHEMA_ENABLED)) {
                d.setValidateXMLSchemaEnabled(info.validateXMLSchemaEnabled);
            }
            if (info.isModified(info.XML_SCHEMA_URI_LIST)) {
                d.setXMLSchemaUriList(info.XMLSchemaUriList);
            }
            if (info.isModified(info.RELOAD_XML_SCHEMA_ON_FAILURE)) {
                d.setReloadXMLSchemaOnFailure(info.reloadXMLSchemaOnFailure);
            }
            d.update();
            // audit logging for create destination
            Globals.getAuditSession().destinationOperation(con.getUserName(), con.remoteHostString(), MQAuditSession.CREATE_DESTINATION, d.isQueue() ? MQAuditSession.QUEUE : MQAuditSession.TOPIC, d.getDestinationName());
        } catch (Exception ex) {
            // remove the destination
            try {
                DestinationUID duid = DestinationUID.getUID(info.name, DestType.isQueue(type));
                DL.removeDestination(null, duid, false, ex.toString());
            } catch (Exception ex1) {
            // if we cant destroy .. its ok .. ignore the exception
            }
            status = Status.ERROR;
            errMsg = rb.getString(rb.X_UPDATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
            logger.logStack(Logger.WARNING, errMsg, ex);
        }
    }
    // Send reply
    setProperties(reply, MessageType.CREATE_DESTINATION_REPLY, status, errMsg);
    parent.sendReply(con, cmd_msg, reply);
    return true;
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) SizeString(com.sun.messaging.jmq.util.SizeString) DestinationInfo(com.sun.messaging.jmq.util.admin.DestinationInfo) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) SizeString(com.sun.messaging.jmq.util.SizeString) HAMonitorService(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException)

Example 2 with ConflictException

use of com.sun.messaging.jmq.jmsserver.util.ConflictException in project openmq by eclipse-ee4j.

the class Subscription method subscribe.

/**
 * "public" for persist store internal test
 */
public static Subscription subscribe(String name, boolean share, boolean jmsshare, String clientID, String sel, DestinationUID duid, boolean nolocal, boolean notify, boolean autostore, /* false only in testing */
ConsumerUID requid, Integer sharecnt) throws BrokerException, SelectorFormatException {
    synchronized (Subscription.class) {
        Subscription s = findDurableSubscription(clientID, name);
        if (s != null) {
            String[] args = { getDSubLogString(clientID, name), duid.toString() };
            throw new ConflictException(Globals.getBrokerResources().getKString(BrokerResources.X_DURABLE_CONFLICT, args));
        }
        try {
            s = new Subscription(duid, sel, nolocal, name, share, jmsshare, clientID, notify, autostore, requid, sharecnt);
        } catch (IOException ex) {
            String[] args = { getDSubLogString(clientID, name), duid.toString() };
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.E_CREATE_DURABLE, args), ex);
        }
        durableList.put(getDSubKey(clientID, name), s);
        return s;
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException)

Example 3 with ConflictException

use of com.sun.messaging.jmq.jmsserver.util.ConflictException in project openmq by eclipse-ee4j.

the class DestinationList method createDestination.

// XXX : The public createDestination methods can be renamed so
// that it is easier to find the right variant. (e.g.
// createTempDestination, createAutoDestination,
// createClusterDestination etc...
private Destination createDestination(String name, int type, boolean store, boolean autocreated, ConnectionUID uid, boolean notify, boolean localOnly) throws BrokerException, IOException {
    DestinationUID duid = new DestinationUID(name, DestType.isQueue(type));
    if (!valid) {
        if (!DL.isPartitionMode()) {
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER), BrokerResources.X_SHUTTING_DOWN_BROKER, (Throwable) null, Status.ERROR);
        } else {
            throw new BrokerException(br.getKString(br.I_PARTITION_IS_CLOSING, logsuffix));
        }
    }
    if (destinationList.get(duid) != null) {
        throw new ConflictException(Globals.getBrokerResources().getKString(BrokerResources.X_DESTINATION_EXISTS, duid));
    }
    // OK, check the persistent store (required for HA)
    try {
        Destination d = pstore.getDestination(duid);
        if (d != null) {
            d.setDestinationList(this);
            addDestination(d, false);
            return d;
        }
    } catch (Exception ex) {
    // ignore we want to create it
    }
    ClusterBroadcast mbi = Globals.getClusterBroadcast();
    boolean clusterNotify = false;
    Destination d = null;
    try {
        if (DestType.isQueue(type)) {
            d = new Queue(name, type, store, uid, autocreated, this);
        } else {
            d = new Topic(name, type, store, uid, autocreated, this);
        }
        d.setClusterNotifyFlag(notify);
        try {
            synchronized (destinationList) {
                Destination newd = (Destination) destinationList.get(duid);
                if (newd != null) {
                    // updating existing
                    String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_DESTINATION_EXISTS, duid.getLongString());
                    throw new BrokerException(emsg, Status.CONFLICT);
                }
                if (!autocreated) {
                    d.setIsLocal(localOnly);
                }
                if (store) {
                    d.store();
                }
                destinationList.put(duid, d);
            }
        } catch (BrokerException ex) {
            // Conflict message
            if (ex.getStatusCode() != Status.CONFLICT) {
                throw new BrokerException(ex.getMessage(), ex, Status.CONFLICT);
            }
            throw ex;
        }
        clusterNotify = !d.isAutoCreated() && d.sendClusterUpdate() && notify;
        if (mbi != null && clusterNotify) {
            // dont worry about locking
            if (!mbi.lockDestination(duid, uid)) {
                throw new ConflictException("Internal Exception:" + " Destination " + duid + " is in the process" + " of being created");
            }
        }
        if (clusterNotify && mbi != null) {
            // we dont care about updating other brokers for
            // autocreated, internal or admin destinations
            // we may or may not update local dests (depends on version
            // of cluster)
            mbi.createDestination(d);
        }
    } finally {
        if (mbi != null && clusterNotify) {
            // only null in tonga test
            mbi.unlockDestination(duid, uid);
        }
    }
    // NOW ATTACH ANY WILDCARD PRODUCERS OR CONSUMERS
    Iterator itr = Consumer.getWildcardConsumers();
    while (itr.hasNext()) {
        ConsumerUID cuid = (ConsumerUID) itr.next();
        Consumer c = Consumer.getConsumer(cuid);
        if (c == null) {
            Globals.getLogger().log(Logger.INFO, "Consumer already destroyed");
            continue;
        }
        DestinationUID wuid = c.getDestinationUID();
        // compare the uids
        if (DestinationUID.match(d.getDestinationUID(), wuid)) {
            try {
                // attach the consumer
                if (c.getSubscription() != null) {
                    d.addConsumer(c.getSubscription(), false);
                } else {
                    d.addConsumer(c, false);
                }
            } catch (SelectorFormatException ex) {
            // LKS TBD
            }
        }
    }
    itr = Producer.getWildcardProducers();
    while (itr.hasNext()) {
        ProducerUID puid = (ProducerUID) itr.next();
        Producer p = (Producer) Producer.getProducer(puid);
        DestinationUID wuid = p.getDestinationUID();
        // compare the uids
        if (DestinationUID.match(d.getDestinationUID(), wuid)) {
            // attach the consumer
            d.addProducer(p);
        }
    }
    Agent agent = Globals.getAgent();
    if (agent != null) {
        agent.registerDestination(d);
        agent.notifyDestinationCreate(d);
    }
    return d;
}
Also used : Agent(com.sun.messaging.jmq.jmsserver.management.agent.Agent) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) SizeString(com.sun.messaging.jmq.util.SizeString) InvalidSysMessageIDException(com.sun.messaging.jmq.io.InvalidSysMessageIDException) PartitionNotFoundException(com.sun.messaging.jmq.jmsserver.util.PartitionNotFoundException) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) TransactionAckExistException(com.sun.messaging.jmq.jmsserver.util.TransactionAckExistException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) InvalidPacketException(com.sun.messaging.jmq.io.InvalidPacketException) ClusterBroadcast(com.sun.messaging.jmq.jmsserver.cluster.api.ClusterBroadcast)

Example 4 with ConflictException

use of com.sun.messaging.jmq.jmsserver.util.ConflictException in project openmq by eclipse-ee4j.

the class DestinationUtil method createDestination.

@SuppressWarnings("deprecation")
public static void createDestination(DestinationInfo info) throws BrokerException {
    String errMsg = null;
    int status = Status.OK;
    BrokerResources rb = Globals.getBrokerResources();
    Logger logger = Globals.getLogger();
    // Default attributes of the destination
    int type = DestType.DEST_TYPE_QUEUE | DestType.DEST_FLAVOR_SINGLE;
    int maxMessages = -1;
    SizeString maxMessageBytes = null;
    SizeString maxMessageSize = null;
    if (MemoryGlobals.getMEM_DISALLOW_CREATE_DEST()) {
        status = Status.ERROR;
        errMsg = rb.W_LOW_MEM_REJECT_DEST;
    } else if (info.isModified(DestinationInfo.NAME)) {
        if (info.isModified(DestinationInfo.TYPE)) {
            type = info.type;
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGES)) {
            maxMessages = info.maxMessages;
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGE_BYTES)) {
            maxMessageBytes = new SizeString();
            maxMessageBytes.setBytes(info.maxMessageBytes);
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGE_SIZE)) {
            maxMessageSize = new SizeString();
            maxMessageSize.setBytes(info.maxMessageSize);
        }
    } else {
        status = Status.ERROR;
        errMsg = rb.X_NO_DEST_NAME_SET;
    }
    // XXX create destination
    if (status == Status.OK) {
        if (DestType.destNameIsInternal(info.name)) {
            status = Status.ERROR;
            errMsg = rb.getKString(rb.X_CANNOT_CREATE_INTERNAL_DEST, info.name, DestType.INTERNAL_DEST_PREFIX);
        } else {
            if (CreateDestinationHandler.isValidDestinationName(info.name)) {
                try {
                    Globals.getDestinationList().createDestination(null, info.name, type);
                } catch (Exception ex) {
                    status = Status.ERROR;
                    errMsg = rb.getString(rb.X_CREATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
                    if (ex instanceof ConflictException) {
                        logger.log(Logger.INFO, errMsg, ex);
                    } else {
                        logger.logStack(Logger.INFO, errMsg, ex);
                    }
                }
            } else {
                status = Status.ERROR;
                errMsg = rb.getKString(rb.X_DEST_NAME_INVALID, info.name);
            }
        }
    }
    if (status == Status.OK) {
        try {
            Destination[] ds = Globals.getDestinationList().getDestination(null, info.name, DestType.isQueue(type));
            Destination d = ds[0];
            d.setCapacity(maxMessages);
            d.setByteCapacity(maxMessageBytes);
            d.setMaxByteSize(maxMessageSize);
            if (info.isModified(info.DEST_SCOPE)) {
                int scope = info.destScope;
                d.setScope(scope);
            }
            if (info.isModified(info.DEST_LIMIT)) {
                int destlimit = info.destLimitBehavior;
                d.setLimitBehavior(destlimit);
            }
            if (info.isModified(info.DEST_PREFETCH)) {
                int prefetch = info.maxPrefetch;
                d.setMaxPrefetch(prefetch);
            }
            if (info.isModified(info.DEST_CDP)) {
                int clusterdeliverypolicy = info.destCDP;
                d.setClusterDeliveryPolicy(clusterdeliverypolicy);
            }
            if (info.isModified(info.MAX_ACTIVE_CONSUMERS)) {
                int maxcons = info.maxActiveConsumers;
                d.setMaxActiveConsumers(maxcons);
            }
            if (info.isModified(info.MAX_PRODUCERS)) {
                int maxp = info.maxProducers;
                d.setMaxProducers(maxp);
            }
            if (info.isModified(info.MAX_FAILOVER_CONSUMERS)) {
                int maxcons = info.maxFailoverConsumers;
                d.setMaxFailoverConsumers(maxcons);
            }
            if (info.isModified(info.MAX_SHARED_CONSUMERS)) {
                int maxsharedcons = info.maxNumSharedConsumers;
                d.setMaxSharedConsumers(maxsharedcons);
            }
            if (info.isModified(info.SHARE_FLOW_LIMIT)) {
                int sflowlimit = info.sharedConsumerFlowLimit;
                d.setSharedFlowLimit(sflowlimit);
            }
            if (info.isModified(info.USE_DMQ)) {
                boolean dmq = info.useDMQ;
                d.setUseDMQ(dmq);
            }
            d.update();
        /*
                 * // audit logging for create destination Globals.getAuditSession().destinationOperation( con.getUserName(),
                 * con.remoteHostString(), MQAuditSession.CREATE_DESTINATION, d.isQueue()?MQAuditSession.QUEUE:MQAuditSession.TOPIC,
                 * d.getDestinationName());
                 */
        } catch (Exception ex) {
            // remove the destination
            try {
                DestinationUID duid = DestinationUID.getUID(info.name, DestType.isQueue(type));
                Globals.getDestinationList().removeDestination(null, duid, false, ex.toString());
            } catch (Exception ex1) {
            // if we cant destroy .. its ok .. ignore the exception
            }
            status = Status.ERROR;
            errMsg = rb.getString(rb.X_UPDATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
            logger.log(Logger.WARNING, errMsg, ex);
        }
    }
    if (status != Status.OK) {
        throw new BrokerException(errMsg);
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) SizeString(com.sun.messaging.jmq.util.SizeString) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) SizeString(com.sun.messaging.jmq.util.SizeString) Logger(com.sun.messaging.jmq.util.log.Logger) BrokerResources(com.sun.messaging.jmq.jmsserver.resources.BrokerResources) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Aggregations

ConflictException (com.sun.messaging.jmq.jmsserver.util.ConflictException)4 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)3 SizeString (com.sun.messaging.jmq.util.SizeString)3 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)2 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)2 InvalidPacketException (com.sun.messaging.jmq.io.InvalidPacketException)1 InvalidSysMessageIDException (com.sun.messaging.jmq.io.InvalidSysMessageIDException)1 ClusterBroadcast (com.sun.messaging.jmq.jmsserver.cluster.api.ClusterBroadcast)1 HAMonitorService (com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService)1 Agent (com.sun.messaging.jmq.jmsserver.management.agent.Agent)1 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)1 BrokerResources (com.sun.messaging.jmq.jmsserver.resources.BrokerResources)1 PartitionNotFoundException (com.sun.messaging.jmq.jmsserver.util.PartitionNotFoundException)1 TransactionAckExistException (com.sun.messaging.jmq.jmsserver.util.TransactionAckExistException)1 DestinationInfo (com.sun.messaging.jmq.util.admin.DestinationInfo)1 Logger (com.sun.messaging.jmq.util.log.Logger)1