@Override public void stop() throws Exception { if (!this.stopped) { closeCloseables(); this.broker.destroyDestination(this); this.stopped = true; } }
protected boolean destroyDestination(JMSDestination dest) throws Exception { String fullName = dest.fullName(); if (this.closeablesForDestination.containsKey(fullName)) { for(AutoCloseable each : this.closeablesForDestination.get(fullName)) { each.close(); } this.closeablesForDestination.remove(fullName); } if (this.createdDestinations.contains(fullName)) { if (dest.type() == JMSDestination.Type.QUEUE) { destroyQueue(dest.name()); } else { destroyTopic(dest.name()); } this.createdDestinations.remove(fullName); return true; } return false; }
@Override public void publish(Object content, Codec codec, Map<MessageOpOption, Object> options) throws Exception { publish(content, codec, options, Collections.EMPTY_MAP); }
JMSSpecificContext context = context(opts.get(MessageOpOption.CONTEXT)); Session session = context.jmsSession(); javax.jms.Destination destination = jmsDestination(); MessageProducer producer = session.createProducer(destination); fillInProperties(jmsMessage, (Map<String, Object>) opts.get(PublishOption.PROPERTIES, Collections.emptyMap())); fillInProperties(jmsMessage, additionalProperties); jmsMessage.setStringProperty(JMSMessage.CONTENT_TYPE_PROPERTY, codec.contentType());
Options<MessageOpOption> opts = new Options<>(options); int timeout = opts.getInt(ReceiveOption.TIMEOUT); JMSSpecificContext context = context(opts.get(MessageOpOption.CONTEXT)); Session jmsSession = context.jmsSession(); javax.jms.Destination destination = jmsDestination(); String selector = opts.getString(ReceiveOption.SELECTOR); MessageConsumer consumer = jmsSession.createConsumer(destination, selector);
public void addCloseableForDestination(JMSDestination dest, AutoCloseable c) { String fullName = dest.fullName(); List<AutoCloseable> closeables = this.closeablesForDestination.get(fullName); if (closeables == null) { closeables = new ArrayList<>(); this.closeablesForDestination.put(fullName, closeables); } closeables.add(c); }
protected MessageConsumer createConsumer(final Destination destination, final Context context, final Options<Destination.ListenOption> options) throws JMSException { return ((JMSSpecificContext)context) .jmsSession() .createConsumer(((JMSDestination) destination).jmsDestination(), options.getString(Destination.ListenOption.SELECTOR)); } }
@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; }