else {  if (log.isTraceEnabled()) { log.trace("creating new non-durable subscription on " + destination); } subscription = new Subscription(topic, selector, ms); } }
}
	public ConsumerDelegate createConsumerDelegate(Destination jmsDestination,                                                  String selector,                                                  boolean noLocal,                                                  String subscriptionName,                                                  boolean isCC) throws JMSException   {      if (closed)      {         throw new IllegalStateException("Session is closed");      }            if ("".equals(selector))      {         selector = null;      }            JBossDestination d = (JBossDestination)jmsDestination;            if (log.isTraceEnabled()) { log.trace("creating consumer endpoint for " + d + ", selector " + selector + ", " + (noLocal ? "noLocal, " : "") + "subscription " + subscriptionName); }                  if (d.isTemporary())      {         // Can only create a consumer for a temporary destination on the same connection         // that created it         if (!this.connectionEndpoint.temporaryDestinations.contains(d))         {            String msg = "Cannot create a message consumer on a different connection " +                         "to that which created the temporary destination";            throw new IllegalStateException(msg);         }      }            // look-up destination      DestinationManagerImpl dm = serverPeer.getDestinationManager();      Distributor destination = dm.getCoreDestination(jmsDestination);      if (destination == null)      {         throw new InvalidDestinationException("No such destination: " + jmsDestination);      }                String consumerID = new GUID().toString();           if (callbackHandler == null)      {         throw new JMSException("null callback handler");      }            Subscription subscription = null;      if (d.isTopic())      {         MessageStore ms = connectionEndpoint.getServerPeer().getMessageStore();         Topic topic = (Topic)destination;         if (subscriptionName != null)         {            // look-up the durable subscription            String clientID = connectionEndpoint.getClientID();            if (clientID == null)            {               throw new JMSException("Cannot create durable subscriber without having set client ID");            }            // it's a durable subscription - have we already got one with that name?            DurableSubscriptionStoreDelegate dsd = serverPeer.getDurableSubscriptionStoreDelegate();            subscription = dsd.getDurableSubscription(clientID, subscriptionName);            if (subscription == null)            {               if (log.isTraceEnabled()) { log.trace("creating new durable subscription on " + destination); }               subscription = dsd.                  createDurableSubscription(d.getName(), clientID, subscriptionName, selector);            }            else            {               if (log.isTraceEnabled()) { log.trace("subscription " + subscriptionName + " already exists"); }               // From javax.jms.Session Javadoc:               // A client can change an existing durable subscription by creating a durable               // TopicSubscriber with the same name and a new topic and/or message selector.               // Changing a durable subscriber is equivalent to unsubscribing (deleting) the old               // one and creating a new one.               // has the selector changed?               boolean selectorChanged =                  (selector == null && subscription.getSelector() != null) ||                  (subscription.getSelector() == null && selector != null) ||                  (subscription.getSelector() != null && selector != null &&                  !subscription.getSelector().equals(selector));               if (log.isTraceEnabled()) { log.trace("selector " + (selectorChanged ? "has" : "has NOT") + " changed"); }               // has the Topic changed?               boolean topicChanged = subscription.getTopic() != destination;               if (log.isTraceEnabled()) { log.trace("topic " + (topicChanged ? "has" : "has NOT") + " changed"); }               if (selectorChanged || topicChanged)               {                  if (log.isTraceEnabled()) { log.trace("topic or selector changed so deleting old subscription"); }                  boolean removed = dsd.                     removeDurableSubscription(this.connectionEndpoint.clientID, subscriptionName);                  if (!removed)                  {                     throw new InvalidDestinationException("Cannot find durable subscription " +                                                           subscriptionName + " to unsubscribe");                  }                  subscription.unsubscribe();                  subscription = null;               }            }         }         else         {            // Non durable subscription            if (log.isTraceEnabled()) { log.trace("creating new non-durable subscription on " + destination); }            subscription = new Subscription(topic, selector, ms);             }      }             ServerConsumerEndpoint ep =         new ServerConsumerEndpoint(consumerID,                                    subscription == null ? (Channel)destination : subscription,                                    callbackHandler, this, selector, noLocal);             Dispatcher.singleton.registerTarget(consumerID, new ConsumerAdvised(ep));               ClientConsumerDelegate stub = new ClientConsumerDelegate(consumerID);            if (subscription != null)      {         subscription.subscribe();      }                  putConsumerDelegate(consumerID, ep);            connectionEndpoint.consumers.put(consumerID, ep);      log.debug("created and registered " + ep);      return stub;   }