throw new IllegalArgumentException("Creation options provided for a remote topic."); topic = createRemoteTopic(givenContext, name); } else { start(); topic = lookupTopic(name); if (topic == null) { if (DestinationUtil.isJndiName(name)) { throw new IllegalArgumentException("topic " + name + " does not exist, and jndi names are lookup only."); } else { topic = createTopic(name); addCreatedDestination(DestinationUtil.fullName(name, JMSDestination.Type.TOPIC)); return topicWrapper(name, topic, this);
@Override public Context createContext(Map<CreateContextOption, Object> options) throws Exception { final Options<CreateContextOption> opts = new Options<>(options); JMSSpecificContext context; boolean xa = opts.getBoolean(CreateContextOption.XA); ConnectionFactory cf; if (opts.has(CreateContextOption.HOST)) { cf = createRemoteConnectionFactory(opts); } else { start(); cf = (ConnectionFactory)lookupJNDI(xa ? JNDI_XA_CF_NAME : JNDI_CF_NAME); } if (xa) { context = createXAContext((XAConnectionFactory)cf, opts); } else { context = createContext(cf, opts); } if (opts.has(CreateContextOption.CLIENT_ID)) { context.jmsConnection().setClientID(opts.getString(CreateContextOption.CLIENT_ID)); } return context; }
throw new IllegalArgumentException("Creation options provided for a remote queue."); queue = createRemoteQueue(givenContext, name); } else { start(); queue = lookupQueue(name); if (queue == null) { if (DestinationUtil.isJndiName(name)) { throw new IllegalArgumentException("queue " + name + " does not exist, and jndi names are lookup only."); } else { queue = createQueue(name, opts.getString(CreateQueueOption.SELECTOR, ""), opts.getBoolean(CreateQueueOption.DURABLE)); addCreatedDestination(DestinationUtil.fullName(name, JMSDestination.Type.QUEUE)); return queueWrapper(name, queue, this);
@Override public Listener listen(final MessageHandler handler, Codecs codecs, Map<ListenOption, Object> options) throws Exception { Options<ListenOption> opts = new Options<>(options); Context givenContext = (Context)opts.get(ListenOption.CONTEXT); if (givenContext != null && !givenContext.isRemote()) { throw new IllegalArgumentException("Listening only accepts a remote context."); } MessageHandler wrappedHandler = new MessageHandler() { @Override public Reply onMessage(Message msg, Context ctx) throws Exception { ((JMSSpecificContext)ctx).setLatestMessage((JMSMessage)msg); return handler.onMessage(msg, ctx); } }; final JMSSpecificContext context = context(givenContext); Listener listener = new JMSMessageHandlerGroup(context, wrappedHandler, codecs, this, opts).start(); if (givenContext != null) { givenContext.addCloseable(listener); } this.broker.addCloseableForDestination(this, listener); this.broker.addCloseable(listener); return listener; }
protected JMSSpecificContext context(final Object context) throws Exception { Context newContext; JMSSpecificContext threadContext = JMSContext.currentContext.get(); if (context != null) { newContext = ((JMSSpecificContext) context).asNonCloseable(); } else if (TransactionUtil.isTransactionActive()) { newContext = this.broker.createContext(new HashMap() {{ put(Messaging.CreateContextOption.XA, true); }}); } else if (threadContext != null) { newContext = threadContext; } else { newContext = this.broker.createContext(null); } newContext.enlist(); return (JMSSpecificContext)newContext; }
@Override public Listener subscribe(final String id, final MessageHandler handler, final Codecs codecs, final Map<SubscribeOption, Object> options) throws Exception { Options<SubscribeOption> opts = new Options<>(options); final JMSSpecificContext context = (JMSSpecificContext)context(id, opts.get(SubscribeOption.CONTEXT)); final TopicSubscriber subscriber = context .jmsSession() .createDurableSubscriber((javax.jms.Topic) jmsDestination(), id, opts.getString(SubscribeOption.SELECTOR), false); final Listener listener = new JMSListener(handler, codecs, this, context, subscriber).start(); Context parent = (Context)opts.get(SubscribeOption.CONTEXT); if (parent != null) { parent.addCloseable(listener); } broker().addCloseableForDestination(this, listener); return new Listener() { @Override public void close() throws Exception { listener.close(); context.close(); } }; }
protected JMSSpecificContext context(final String id, final Object context) throws Exception { if (context != null) { return ((JMSSpecificContext)context).asNonCloseable(); } else { return (JMSSpecificContext)broker() .createContext(new HashMap<Messaging.CreateContextOption, Object>() {{ put(Messaging.CreateContextOption.CLIENT_ID, id); }}); } }