Session implements com.hazelcast.nio.serialization.IdentifiedDataSerializable { public TopicSubscription matches(String topicName) { return TopicSubscription.NEXUS.topicFiltersOf(clientId).stream() .filter(topicFilter -> TopicMatcher.match(topicFilter, topicName)) .map(topicFilter -> TopicSubscription.NEXUS.getBy(topicFilter, clientId)) .max((p1, p2) -> p1.qos().compareTo(p2.qos())).orElse(null); } Session();  Session(String clientId, String ip, int port, int keepAliveSeconds, boolean cleanSession, Message will); @JsonSerialize(using = ChannelIdSerializer.class) @JsonProperty ChannelId channelId(); boolean isConnected(boolean checkOwnership); void setConnected(boolean isConnected); String clientId(); Message will(); void will(Message will); boolean cleanSession(); boolean isExpired(); void setLastIncomingTime(Date lastIncomingTime); TopicSubscription matches(String topicName); void send(MqttMessage message, GenericFutureListener<? extends Future<? super Void>> completeListener); void completeRemainedMessages(); int nextMessageId(); void dispose(boolean sendWill); @JsonIgnore @Override int getFactoryId(); @JsonIgnore @Override int getId(); @Override void writeData(ObjectDataOutput out); @Override void readData(ObjectDataInput in); static final Sessions NEXUS; static final int ID; }
@Test public void testMatches() throws Exception { String testTopic = "testTopic/test"; Session session = new Session("1", "1", 1, 50, true, null); TopicSubscription ts0 = new TopicSubscription(session.clientId(), "testTopic/#", MqttQoS.AT_MOST_ONCE); TopicSubscription ts1 = new TopicSubscription(session.clientId(), "testTopic/+", MqttQoS.AT_LEAST_ONCE); TopicSubscription ts2 = new TopicSubscription(session.clientId(), testTopic, MqttQoS.EXACTLY_ONCE); TopicSubscription.NEXUS.put(ts0); TopicSubscription.NEXUS.put(ts1); TopicSubscription.NEXUS.put(ts2); Assert.assertEquals(3, TopicSubscription.NEXUS.topicFiltersOf(session.clientId()).size()); TopicSubscription target = session.matches(testTopic); Assert.assertTrue(target.topicFilter().equals(testTopic)); }