Search in sources :

Example 91 with BrokerException

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

the class DestinationUtil method checkCreateDestinationAttrs.

public static void checkCreateDestinationAttrs(String type, AttributeList attrs) throws BrokerException {
    String[] validAttrs = null;
    checkDestType(type);
    if (attrs == null) {
        return;
    }
    if (type.equals(DestinationType.QUEUE)) {
        validAttrs = queueCreateAttrs;
    } else if (type.equals(DestinationType.TOPIC)) {
        validAttrs = topicCreateAttrs;
    }
    for (Iterator i = attrs.iterator(); i.hasNext(); ) {
        Attribute attr = (Attribute) i.next();
        String name = attr.getName();
        if (!checkOneDestAttr(name, validAttrs)) {
            BrokerResources rb = Globals.getBrokerResources();
            String err;
            if (type.equals(DestinationType.QUEUE)) {
                err = rb.getString(rb.X_JMX_INVALID_CREATE_TIME_ATTR_SPEC_QUEUE, name);
            } else {
                err = rb.getString(rb.X_JMX_INVALID_CREATE_TIME_ATTR_SPEC_TOPIC, name);
            }
            throw new BrokerException(err);
        }
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Iterator(java.util.Iterator) SizeString(com.sun.messaging.jmq.util.SizeString) BrokerResources(com.sun.messaging.jmq.jmsserver.resources.BrokerResources)

Example 92 with BrokerException

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

the class StoreManager method getStore.

/**
 * Return a singleton instance of a Store object.
 * <p>
 * The type of store to use is defined in the property:<br>
 * {@literal jmq.persist.store=<type>}
 * <p>
 * The class to use for the specified type is defined in:<br>
 * {@literal jmq.persist.<type>.class=<classname>}
 * <p>
 * If the type property is not defined, the default file based store will be instantiated and returned. If 'jdbc' type
 * is defined, and no class is defined, the default jdbc based store will be instantiated and returned.
 * <p>
 * If the type property is defined but we fail to instantiate the correspoinding class, a BrokerException will be thrown
 *
 * @return a Store
 * @exception BrokerException if it fails to instantiate a Store instance
 */
public static synchronized Store getStore() throws BrokerException {
    Logger logger = Globals.getLogger();
    BrokerResources br = Globals.getBrokerResources();
    if (store == null) {
        // Can't open the store if we are shutting down
        if (BrokerStateHandler.isShuttingDown()) {
            throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER), BrokerResources.X_SHUTTING_DOWN_BROKER);
        }
        BrokerConfig config = Globals.getConfig();
        String type = config.getProperty(STORE_TYPE_PROP, DEFAULT_STORE_TYPE);
        if (Store.getDEBUG()) {
            logger.log(logger.DEBUG, STORE_TYPE_PROP + "=" + type);
        }
        String classname = config.getProperty(PERSIST_PROP_PREFIX + type + CLASS_PROP);
        isConfiguredFileStore = Boolean.FALSE;
        isConfiguredJDBCStore = Boolean.FALSE;
        if (classname == null || classname.equals("")) {
            if (type.equals(Store.FILE_STORE_TYPE)) {
                classname = DEFAULT_FILESTORE_CLASS;
                isConfiguredFileStore = Boolean.TRUE;
            } else if (type.equals(Store.JDBC_STORE_TYPE)) {
                classname = DEFAULT_JDBCSTORE_CLASS;
                isConfiguredJDBCStore = Boolean.TRUE;
            } else {
                classname = null;
            }
        }
        if (classname == null) {
            throw new BrokerException(br.getString(br.E_BAD_STORE_TYPE, type));
        } else {
            if (Store.getDEBUG()) {
                logger.log(logger.DEBUG, PERSIST_PROP_PREFIX + type + CLASS_PROP + "=" + classname);
            }
        }
        try {
            boolean reload = false;
            do {
                if (Globals.isNucleusManagedBroker()) {
                    store = Globals.getHabitat().getService(Store.class, classname);
                } else {
                    store = (Store) Class.forName(classname).getDeclaredConstructor().newInstance();
                }
                // store.init();
                txnLogEnabled = Boolean.valueOf(config.getBooleanProperty(TXNLOG_ENABLED_PROP, false));
                newTxnLogEnabled = Boolean.valueOf(config.getBooleanProperty(NEW_TXNLOG_ENABLED_PROP, NEW_TXNLOG_ENABLED_PROP_DEFAULT));
                if (!isConfiguredFileStore.booleanValue()) {
                    if (txnLogEnabled.booleanValue()) {
                        logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_IGNORE_PROP_SETTING, TXNLOG_ENABLED_PROP + "=true"));
                    }
                    if (newTxnLogEnabled.booleanValue()) {
                        logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_IGNORE_PROP_SETTING, NEW_TXNLOG_ENABLED_PROP + "=true"));
                    }
                    break;
                }
                // logging
                Globals.isMinimumPersistLevel2();
                if (Globals.isNewTxnLogEnabled()) {
                    // txn logger is now read during store.init
                    return store;
                }
                // broker didn't shutdown cleanly.
                if (reload) {
                    if (((TxnLoggingStore) store).initTxnLogger()) {
                        // Shouldn't happens
                        throw new BrokerException(br.getString(BrokerResources.E_RECONSTRUCT_STORE_FAILED));
                    }
                    break;
                } else {
                    // 1st time through the loop
                    reload = ((TxnLoggingStore) store).initTxnLogger();
                    if (reload) {
                        store.close();
                        store = null;
                    }
                }
            } while (reload);
        } catch (Exception e) {
            if (e instanceof BrokerException) {
                throw (BrokerException) e;
            } else {
                throw new BrokerException(br.getString(br.E_OPEN_STORE_FAILED), e);
            }
        }
    }
    return store;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ShareConfigChangeStore(com.sun.messaging.jmq.jmsserver.persist.api.sharecc.ShareConfigChangeStore) Logger(com.sun.messaging.jmq.util.log.Logger) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 93 with BrokerException

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

the class ShareConfigChangeStore method getStore.

/**
 * Return a singleton instance of a Store object.
 */
public static synchronized ShareConfigChangeStore getStore() throws BrokerException {
    if (store != null) {
        return store;
    }
    if (BrokerStateHandler.isShuttingDown()) {
        throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER), BrokerResources.X_SHUTTING_DOWN_BROKER);
    }
    BrokerConfig config = Globals.getConfig();
    String type = config.getProperty(STORE_TYPE_PROP, DEFAULT_STORE_TYPE);
    if (!type.equalsIgnoreCase(DEFAULT_STORE_TYPE)) {
        throw new BrokerException("Not supported" + STORE_TYPE_PROP + "=" + type);
    }
    String classprop = STORE_TYPE_PROP + "." + type + CLASS_PROP_SUFFIX;
    String classname = config.getProperty(classprop);
    if (classname == null || classname.equals("")) {
        classname = DEFAULT_JDBCSTORE_CLASS;
    } else if (!classname.equals(DEFAULT_JDBCSTORE_CLASS)) {
        throw new BrokerException("Not supported " + classprop + "=" + classname);
    }
    try {
        if (Globals.isNucleusManagedBroker()) {
            store = Globals.getHabitat().getService(ShareConfigChangeStore.class, classname);
            if (store == null) {
                throw new BrokerException("Class " + classname + " not found");
            }
        } else {
            store = (ShareConfigChangeStore) Class.forName(classname).getDeclaredConstructor().newInstance();
        }
    } catch (Exception e) {
        throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.E_FAIL_OPEN_SHARECC_STORE, e.getMessage()), e);
    }
    return store;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 94 with BrokerException

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

the class DirectSession method _createAndAddConsumer.

/**
 * Create a consumerId with the jmsservice and return a MessageConsumer object that can be returned by the JMS API
 * method.
 * <p>
 * This method is used by the methods implementing jakarta.jms.Session, jakarta.jms.QueueSession, and
 * jakarta.jms.TopicSession<br>
 * A successfully created DirectConsumer is added to the table of Consumer objects maintained by this DirectSession.<br>
 * A successfully created durable DirectConsumer is added to the table of durable Consumer objects maintained by the
 * DirectConnection of this DirectSession.
 *
 * @param methodName The JMS API method that was called.
 * @param destination The JMS Destination object identifying the destination on which the consumer is to be created.
 * @param selector The JMS Message selector to be used.
 * @param subscriptionName if dest is Topic and if either durable true or share true, the subscription name
 * @param durable if dest is Topic, if true, this is a durable subscription
 * @param share if dest is Topic, if true, this is a shared subscription
 * @param jmsshare if dest is Topic, if true and share true, this is a JMS 2.0 Shared Subscription if false and share
 * true, this is a MQ Shared Subscription
 *
 * MQ Shared Subscription: messages will be shared with other consumers in the same group that have the same
 * clientId+DurableName for Shared Durable Subscriptions
 * <p>
 * OR
 * <p>
 * clientId+TopicName+Selector for Shared Non-Durable Sunscriptions
 *
 * @param noLocal If {@code true} then this consumer does not want to messages produced on it'sconnection to be
 * delivered to it.
 *
 * @return The DirectConsumer object to be returned by the JMS API method.
 *
 * @throws JMSException if any JMS error occurred.
 */
private DirectConsumer _createAndAddConsumer(String methodName, Destination destination, String selector, String subscriptionName, boolean durable, boolean share, boolean jmsshare, boolean noLocal) throws JMSException {
    JMSServiceReply reply;
    long consumerId = 0L;
    com.sun.messaging.jmq.jmsservice.Destination jmsservice_dest;
    if (_logFINE) {
        _loggerJS.fine(_lgrMID_INF + "sessionId=" + this.sessionId + ":" + methodName + ":Destination=" + destination + ":Selector=" + selector + ":subscriptionName=" + subscriptionName + ":durable=" + durable + ":share=" + share + ":jmsshare=" + jmsshare + ":noLocal=" + noLocal);
    }
    this._checkIfClosed(methodName);
    jmsservice_dest = this._checkDestinationForConsumer(destination);
    String duraname = (durable ? subscriptionName : null);
    DirectConsumer consumer = new DirectConsumer(this, jmsservice, destination, jmsservice_dest, noLocal, selector, duraname);
    try {
        // adjusted for JMS 2.0
        reply = jmsservice.addConsumer(connectionId, sessionId, jmsservice_dest, selector, subscriptionName, durable, share, jmsshare, this.getConnection()._getClientID(), noLocal);
        /*
             * reply = jmsservice.addConsumer(connectionId, sessionId, jmsservice_dest, selector, durableName,
             * this.getConnection()._getClientID(), noLocal, //XXX:tharakan:using false for shared temporarily false, false);
             */
        try {
            // Set consumerId right away
            consumerId = reply.getJMQConsumerID();
            consumer._setConsumerId(consumerId);
        } catch (NoSuchFieldException nsfe) {
            String exerrmsg = _lgrMID_EXC + "JMSServiceException:Missing JMQConsumerID";
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(nsfe);
            _loggerJS.severe(exerrmsg);
            throw jmse;
        }
    } catch (JMSServiceException jse) {
        JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
        String failure_cause;
        JMSException jmsse = null;
        String exerrmsg = "createConsumer on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and sessionId:" + sessionId + " due to ";
        switch(status) {
            case FORBIDDEN:
                failure_cause = "client forbidden to receive messages from this destination.";
                exerrmsg = exerrmsg + failure_cause;
                jmsse = new JMSSecurityException(exerrmsg, jse.getJMSServiceReply().getErrorCode());
                break;
            case NOT_FOUND:
                failure_cause = "destination not found and cannot be auto-created.";
                break;
            case CONFLICT:
                failure_cause = "destination limit for number of consumers exceeded.";
                break;
            case BAD_REQUEST:
                failure_cause = "invalid selector=" + selector;
                exerrmsg = exerrmsg + failure_cause;
                jmsse = new InvalidSelectorException(exerrmsg);
                break;
            case PRECONDITION_FAILED:
                if (jse.getCause() != null && jse.getCause() instanceof BrokerException) {
                    failure_cause = jse.getCause().getMessage();
                    exerrmsg = exerrmsg + failure_cause;
                    jmsse = new IllegalStateException(exerrmsg, ((BrokerException) jse.getCause()).getErrorCode());
                    break;
                }
            default:
                failure_cause = "unknown JMSService server error.";
        }
        _loggerJS.severe(exerrmsg);
        if (jmsse == null) {
            exerrmsg = exerrmsg + failure_cause;
            jmsse = new JMSException(exerrmsg);
        }
        jmsse.initCause(jse);
        throw jmsse;
    }
    this.addConsumer(consumer);
    if (subscriptionName != null && durable) {
        this.dc.addDurableConsumer(consumer);
    }
    if (destination instanceof TemporaryDestination) {
        this.dc._incrementTemporaryDestinationUsage((TemporaryDestination) destination);
    }
    return consumer;
}
Also used : IllegalStateException(com.sun.messaging.jms.IllegalStateException) InvalidSelectorException(jakarta.jms.InvalidSelectorException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSSecurityException(jakarta.jms.JMSSecurityException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException)

Example 95 with BrokerException

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

the class TransactionLogManager method initTransactionLogOnStartUp.

private void initTransactionLogOnStartUp() throws BrokerException {
    if (Store.getDEBUG()) {
        String msg = getPrefix() + " initTransactionLogOnStartUp";
        logger.log(Logger.DEBUG, msg);
    }
    logger.log(Logger.INFO, "new transaction log enabled");
    logger.log(Logger.INFO, "sync writes to disk = " + Destination.PERSIST_SYNC);
    logger.log(Logger.INFO, "logNonTransactedMsgSend = " + logNonTransactedMsgSend);
    logger.log(Logger.INFO, "logNonTransactedMsgAck = " + logNonTransactedMsgAck);
    // create txn log writers
    String filename = null;
    try {
        BrokerConfig config = Globals.getConfig();
        SizeString filesize = config.getSizeProperty(TXNLOG_FILE_SIZE_PROP, DEFAULT_TXNLOG_FILE_SIZE_KB);
        filename = MSG_LOG_FILENAME;
        String mode = "rwd";
        boolean synch = true;
        if (!Destination.PERSIST_SYNC) {
            mode = "rw";
            synch = false;
        }
        logger.log(Logger.INFO, br.getKString(BrokerResources.I_OPEN_TXNLOG, mode, Long.valueOf(filesize.getBytes())));
        FileTransactionLogWriter ftlw = new FileTransactionLogWriter(rootDir, filename, filesize.getBytes(), mode, synch, isTxnLogGroupCommits, BaseTransaction.CURRENT_FORMAT_VERSION);
        long existingFormatVersion = ftlw.getExistingAppCookie();
        // so this is just a sanity check.
        if (existingFormatVersion != BaseTransaction.CURRENT_FORMAT_VERSION) {
            throw new BrokerException("Unexpected transaction log format. Format on file = " + existingFormatVersion + " Current software version = " + BaseTransaction.CURRENT_FORMAT_VERSION);
        }
        msgLogWriter = ftlw;
        msgLogWriter.setCheckPointListener(this);
        if (Store.getDEBUG()) {
            logger.log(Logger.DEBUG, "created txn log");
        }
    } catch (IOException ex) {
        logger.logStack(Logger.ERROR, BrokerResources.E_CREATE_TXNLOG_FILE_FAILED, filename, ex);
        throw new BrokerException(br.getString(BrokerResources.E_CREATE_TXNLOG_FILE_FAILED, filename), ex);
    }
}
Also used : SizeString(com.sun.messaging.jmq.util.SizeString) BrokerConfig(com.sun.messaging.jmq.jmsserver.config.BrokerConfig) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) FileTransactionLogWriter(com.sun.messaging.jmq.io.txnlog.file.FileTransactionLogWriter) SizeString(com.sun.messaging.jmq.util.SizeString) IOException(java.io.IOException)

Aggregations

BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)290 IOException (java.io.IOException)72 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)33 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)31 SizeString (com.sun.messaging.jmq.util.SizeString)31 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)29 Iterator (java.util.Iterator)26 ArrayList (java.util.ArrayList)25 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)24 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)23 HashMap (java.util.HashMap)22 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)21 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)21 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)21 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)18 List (java.util.List)18 Packet (com.sun.messaging.jmq.io.Packet)16 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)16 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)16 ConsumerAlreadyAddedException (com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException)15