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);
}
}
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations