javax.jms.IllegalStateException类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(279)

本文整理了Java中javax.jms.IllegalStateException类的一些代码示例,展示了IllegalStateException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IllegalStateException类的具体详情如下:
包路径:javax.jms.IllegalStateException
类名称:IllegalStateException

IllegalStateException介绍

[英]This exception is thrown when a method is invoked at an illegal or inappropriate time or if the provider is not in an appropriate state for the requested operation. For example, this exception must be thrown if Session.commit is called on a non-transacted session. This exception is also called when a domain inappropriate method is called, such as calling TopicSession.CreateQueueBrowser.
[中]如果在非法或不适当的时间调用方法,或者提供程序对于请求的操作不处于适当的状态,则会引发此异常。例如,如果会话失败,则必须引发此异常。在非事务性会话上调用commit。当调用域不适当的方法(例如调用TopicSession)时,也会调用此异常。创建队列浏览器。

代码示例

代码示例来源:origin: spring-projects/spring-framework

throw new javax.jms.IllegalStateException(
    "setClientID call not supported on proxy for shared Connection. " +
    "Set the 'clientId' property on the SingleConnectionFactory instead.");
  throw new javax.jms.IllegalStateException(
      "setExceptionListener call not supported on proxy for shared Connection. " +
      "Set the 'exceptionListener' property on the SingleConnectionFactory instead. " +
  String msg = "JMS Session does not implement specific domain: " + session;
  try {
    session.close();
  throw new javax.jms.IllegalStateException(msg);

代码示例来源:origin: wildfly/wildfly

@Override
public void unsubscribe(final String name) throws JMSException {
 // As per spec. section 4.11
 if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) {
   throw new IllegalStateException("Cannot unsubscribe using a QueueSession");
 }
 SimpleString queueName = ActiveMQDestination.createQueueNameForSubscription(true, connection.getClientID(), name);
 try {
   QueueQuery response = session.queueQuery(queueName);
   if (!response.isExists()) {
    throw new InvalidDestinationException("Cannot unsubscribe, subscription with name " + name +
                         " does not exist");
   }
   if (response.getConsumerCount() != 0) {
    throw new IllegalStateException("Cannot unsubscribe durable subscription " + name +
                      " since it has active subscribers");
   }
   session.deleteQueue(queueName);
 } catch (ActiveMQException e) {
   throw JMSExceptionHelper.convertFromActiveMQException(e);
 }
}

代码示例来源:origin: org.ow2.joram/joram-client-jms

public void setClientID(String clientID) {
 try {
  if (lockClientID)
   throw new IllegalStateException("ClientID is already set by the provider.");
  if (connection == null) throw new JMSException("Underlying connection is closed");
  connection.setClientID(clientID);
  lockClientID = true;
 } catch (InvalidClientIDException e) {
  throw new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
 } catch (IllegalStateException e) {
  throw new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
 } catch (JMSException e) {
  throw new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
 }
}

代码示例来源:origin: wildfly/wildfly

@Override
public void setClientID(final String clientID) throws JMSException {
 checkClosed();
 if (this.clientID != null) {
   throw new IllegalStateException("Client id has already been set");
 }
 if (!justCreated) {
   throw new IllegalStateException("setClientID can only be called directly after the connection is created");
 }
 validateClientID(initialSession, clientID);
 this.clientID = clientID;
 try {
   this.addSessionMetaData(initialSession);
 } catch (ActiveMQException e) {
   JMSException ex = new JMSException("Internal error setting metadata jms-client-id");
   ex.setLinkedException(e);
   ex.initCause(e);
   throw ex;
 }
 justCreated = false;
}

代码示例来源:origin: org.ow2.joram/joram-client-jms

public void commit() {
 connection.lockClientID();
 try {
  session.commit();
 } catch (IllegalStateException e) {
  throw new IllegalStateRuntimeException(e.getMessage());
 } catch (JMSException e) {
  throw new JMSRuntimeException(e.getMessage());
 }
}

代码示例来源:origin: org.jboss.genericjms/generic-jms-ra-jar

public Queue createQueue(String queueName) throws JMSException {
  if (info.getType() == JmsConnectionFactory.TOPIC) {
    throw new IllegalStateException("Cannot create browser or javax.jms.TopicSession");
  }
  Session session = getSession();
  if (trace)
    log.trace("createQueue " + session + " queueName=" + queueName);
  Queue result = session.createQueue(queueName);
  if (trace)
    log.trace("createdQueue " + session + " queue=" + result);
  return result;
}

代码示例来源:origin: wildfly/wildfly

ClientSession.AddressQuery query = clientSession.addressQuery(address);
        clientSession.createAddress(address, RoutingType.ANYCAST, true);
        if (destination.isTemporary()) {
         clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
        } else {
         createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
        clientSession.createAddress(address, RoutingType.MULTICAST, true);
      } else if ((destination.isQueue() && !query.isAutoCreateQueues()) || (!destination.isQueue() && !query.isAutoCreateAddresses())) {
        throw new InvalidDestinationException("Destination " + address + " does not exist");
  activeMQJmsMessage.doBeforeSend();
} catch (Exception e) {
  JMSException je = new JMSException(e.getMessage());
  je.initCause(e);
  JMSException jmsException = new JMSException(e.getMessage());
  jmsException.initCause(e);
  throw jmsException;
  throw JMSExceptionHelper.convertFromActiveMQException(e);
} catch (java.lang.IllegalStateException e) {
  JMSException je = new IllegalStateException(e.getMessage());
  je.setStackTrace(e.getStackTrace());
  je.initCause(e);

代码示例来源:origin: wildfly/wildfly

switch (me.getType()) {
  case CONNECTION_TIMEDOUT:
   je = new JMSException(me.getMessage());
   break;
   je = new javax.jms.IllegalStateException(me.getMessage());
   break;
   je = new JMSException(me.getMessage());
   break;
   je = new JMSException(me.getMessage());
   break;
   je = new javax.jms.IllegalStateException(me.getMessage());
   break;
   je = new InvalidDestinationException(me.getMessage());
   break;
   je = new InvalidDestinationException(me.getMessage());
   break;
   je = new javax.jms.IllegalStateException(me.getMessage());
   break;

代码示例来源:origin: wildfly/wildfly

public void deleteTemporaryTopic(final ActiveMQDestination tempTopic) throws JMSException {
 if (!tempTopic.isTemporary()) {
   throw new InvalidDestinationException("Not a temporary topic " + tempTopic);
 }
 try {
   AddressQuery response = session.addressQuery(tempTopic.getSimpleAddress());
   if (!response.isExists()) {
    throw new InvalidDestinationException("Cannot delete temporary topic " + tempTopic.getName() +
                         " does not exist");
   }
   if (response.getQueueNames().size() > 1) {
    throw new IllegalStateException("Cannot delete temporary topic " + tempTopic.getName() +
                      " since it has subscribers");
   }
   SimpleString address = tempTopic.getSimpleAddress();
   session.deleteQueue(address);
   connection.removeTemporaryQueue(address);
 } catch (ActiveMQException e) {
   throw JMSExceptionHelper.convertFromActiveMQException(e);
 }
}

代码示例来源:origin: org.ow2.joram/joram-client-jms

public javax.jms.JMSConsumer createSharedConsumer(Topic topic,
  String sharedSubscriptionName, String messageSelector) {
 connection.lockClientID();
 try {
  return new JMSConsumer(session.createSharedConsumer(topic, sharedSubscriptionName, messageSelector));
 } catch (InvalidDestinationException e) {
  throw new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
 } catch (InvalidSelectorException e) {
  throw new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
 } catch (IllegalStateException e) {
  throw new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
 } catch (JMSException e) {
  if (logger.isLoggable(BasicLevel.DEBUG))
   logger.log(BasicLevel.DEBUG, "Unable to crate shared consumer " + e.getMessage());
  throw new JMSRuntimeException("Unable to create shared consumer " + e.getMessage(), e.getErrorCode(), e);
 } finally {
  if (connection.getAutoStart())
   connection.start();
 }
}

代码示例来源:origin: org.ow2.joram/joram-client-jms

public void stop() {
 try {
  if (connection == null) throw new JMSException("Underlying connection is closed");
  connection.stop();
 } catch (IllegalStateException e) {
  throw new IllegalStateRuntimeException("Unable to close context", e.getMessage(), e);
 } catch (JMSException e) {
  throw new JMSRuntimeException("Cannot stop connection", e.getMessage(), e);
 }
}

代码示例来源:origin: org.jboss.genericjms/generic-jms-ra-jar

public Topic createTopic(String topicName) throws JMSException {
  if (info.getType() == JmsConnectionFactory.QUEUE) {
    throw new IllegalStateException("Cannot create topic for javax.jms.QueueSession");
  }
  Session session = getSession();
  if (trace)
    log.trace("createTopic " + session + " topicName=" + topicName);
  Topic result = session.createTopic(topicName);
  if (trace)
    log.trace("createdTopic " + session + " topic=" + result);
  return result;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public TopicConnection createTopicConnection(String username, String password) throws JMSException {
  throw new javax.jms.IllegalStateException(
      "SingleConnectionFactory does not support custom username and password");
}

代码示例来源:origin: org.jboss.genericjms/generic-jms-ra-jar

public void commit() throws JMSException {
  lock();
  try {
    Session session = getSession();
    if (info.isTransacted() == false)
      throw new IllegalStateException("Session is not transacted");
    if (trace)
      log.trace("Commit session " + this);
    session.commit();
  } finally {
    unlock();
  }
}

代码示例来源:origin: org.ow2.joram/joram-client-jms

public JMSConsumer createDurableConsumer(Topic topic, String name, String selector, boolean noLocal) {
 connection.lockClientID();
 try {
  MessageConsumer consumer = (MessageConsumer) session.createDurableConsumer(topic, name, selector, noLocal);
  return new JMSConsumer(consumer);
 } catch (InvalidDestinationException e) {
  throw new InvalidDestinationRuntimeException(e.getMessage());
 } catch (InvalidSelectorException e) {
  throw new InvalidSelectorRuntimeException(e.getMessage());
 } catch (IllegalStateException e) {
  throw new IllegalStateRuntimeException(e.getMessage());
 } catch (JMSException e) {
  if (logger.isLoggable(BasicLevel.DEBUG))
   logger.log(BasicLevel.DEBUG, "Unable to instantiate a JMSConsumer" + e.getMessage());
  throw new JMSRuntimeException("Unable to instantiate a JMSConsumer");
 } finally {
  if (connection.getAutoStart())
   connection.start();
 }
}

代码示例来源:origin: org.apache.activemq/activemq-all

try {
  getInternalSession().setMessageListener(null);
      getInternalSession().rollback();
    } catch (JMSException e) {
      invalidate = true;
    sessionPool.returnObject(key, sessionHolder);
  } catch (Exception e) {
    javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(e.toString());
    illegalStateException.initCause(e);
    throw illegalStateException;

代码示例来源:origin: wildfly/wildfly

public static JMSException convertFromActiveMQException(final ActiveMQInterruptedException me) {
 JMSException je = new javax.jms.IllegalStateException(me.getMessage());
 je.setStackTrace(me.getStackTrace());
 je.initCause(me);
 return je;
}

代码示例来源:origin: org.apache.qpid/qpid-jms-client

protected void checkClosed() throws IllegalStateException {
  if (closed.get()) {
    IllegalStateException jmsEx = null;
    if (failureCause.get() == null) {
      jmsEx = new IllegalStateException("The Session is closed");
    } else {
      jmsEx = new IllegalStateException("The Session was closed due to an unrecoverable error.");
      jmsEx.initCause(failureCause.get());
    }
    throw jmsEx;
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public TopicSubscriber createDurableSubscriber(final Topic topic,
                       final String name,
                       String messageSelector,
                       final boolean noLocal) throws JMSException {
 // As per spec. section 4.11
 if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) {
   throw new IllegalStateException("Cannot create a durable subscriber on a QueueSession");
 }
 checkTopic(topic);
 if (!(topic instanceof ActiveMQDestination)) {
   throw new InvalidDestinationException("Not an ActiveMQTopic:" + topic);
 }
 if ("".equals(messageSelector)) {
   messageSelector = null;
 }
 ActiveMQDestination jbdest = (ActiveMQDestination) topic;
 if (jbdest.isQueue()) {
   throw new InvalidDestinationException("Cannot create a subscriber on a queue");
 }
 return createConsumer(jbdest, name, messageSelector, noLocal, ConsumerDurability.DURABLE);
}

代码示例来源:origin: wildfly/wildfly

AddressQuery response = session.addressQuery(dest.getSimpleAddress());
    throw new InvalidDestinationException("Destination " + dest.getName() + " does not exist");
 consumer = session.createConsumer(dest.getSimpleAddress(), coreFilterString, false);
} else {
 AddressQuery response = session.addressQuery(dest.getSimpleAddress());
    session.createAddress(dest.getSimpleAddress(), RoutingType.MULTICAST, true);
   } else {
    throw new InvalidDestinationException("Topic " + dest.getName() + " does not exist");
    throw new RuntimeException("Subscription name must be null for non-durable topic consumer");
   if (connection.getClientID() == null) {
    throw new IllegalStateException("Cannot create durable subscription - client ID has not been set");
    throw new InvalidDestinationException("Cannot create a durable subscription on a temporary topic");
      throw new IllegalStateException("Cannot create a subscriber on the durable subscription since it already has subscriber(s)");

相关文章