@SuppressWarnings("unchecked") private synchronized <T> TopicHandler<T> getTopicHandler(String topic, Class<T> streamType) { TopicHandler<T> topicHandler = (TopicHandler<T>) topicHandlers.get(topic); if (topicHandler == null) { topicHandlers.put(topic, topicHandler = new TopicHandler<T>(streamType)); } else { topicHandler.checkClass(streamType); } return topicHandler; } }
@Override public void removeSubscriber(String topic, Consumer<?> subscriber) { TopicHandler<?> topicHandler; synchronized (this) { topicHandler = topicHandlers.get(topic); } if (topicHandler != null) { topicHandler.removeSubscriber(subscriber); } }
@Override public <T> void addSubscriber(String topic, Class<T> streamType, Consumer<T> subscriber) { getTopicHandler(topic, streamType).addSubscriber(subscriber); }
@Override public <T> void addSubscriber(String topic, Class<T> streamType, Consumer<T> subscriber) { getTopicHandler(topic, streamType).addSubscriber(subscriber); }
@SuppressWarnings("unchecked") private synchronized <T> TopicHandler<T> getTopicHandler(String topic, Class<T> streamType) { TopicHandler<T> topicHandler = (TopicHandler<T>) topicHandlers.get(topic); if (topicHandler == null) { topicHandlers.put(topic, topicHandler = new TopicHandler<T>(streamType)); } else { topicHandler.checkClass(streamType); } return topicHandler; } }
@Override public void removeSubscriber(String topic, Consumer<?> subscriber) { TopicHandler<?> topicHandler; synchronized (this) { topicHandler = topicHandlers.get(topic); } if (topicHandler != null) { topicHandler.removeSubscriber(subscriber); } }