@SuppressWarnings("unchecked") private <T> void addTopicListener( String topic, Object inner, ByteArrayConverter<T> converter, TypedListener<T> listener) throws ConnectorException { synchronized (messageDispatcher) { MessageDispatcher<T> dispatcher = messageDispatcher.get(topic); if (dispatcher == null) { ConnectorSession session = connection.createSession(); ConnectorConsumer consumer = session.createConsumer(session.createTopic(topic)); messageDispatcher.put(topic, dispatcher = new MessageDispatcher<T>(consumer, converter)); } dispatcher.addListener(inner, listener); } }
private void removeTopicListener(String topic, Object inner) { synchronized (messageDispatcher) { MessageDispatcher dispatcher = messageDispatcher.get(topic); if (dispatcher != null) { dispatcher.removeListener(inner); if (!dispatcher.isListened()) { messageDispatcher.remove(topic); try { dispatcher.getConsumer().close(); } catch (ConnectorException e) { } } } } }