org.springframework.messaging.simp.user.SimpSubscription Java Examples

The following examples show how to use org.springframework.messaging.simp.user.SimpSubscription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSimpUserRegistry.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public Set<SimpSubscription> findSubscriptions(SimpSubscriptionMatcher matcher) {
	Set<SimpSubscription> result = new HashSet<>();
	for (LocalSimpSession session : this.sessions.values()) {
		for (SimpSubscription subscription : session.subscriptions.values()) {
			if (matcher.match(subscription)) {
				result.add(subscription);
			}
		}
	}
	return result;
}
 
Example #2
Source File: DefaultSimpUserRegistryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void findSubscriptions() throws Exception {

	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub1", "/match");
	SessionSubscribeEvent subscribeEvent = new SessionSubscribeEvent(this, message, user);
	registry.onApplicationEvent(subscribeEvent);

	message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub2", "/match");
	subscribeEvent = new SessionSubscribeEvent(this, message, user);
	registry.onApplicationEvent(subscribeEvent);

	message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub3", "/not-a-match");
	subscribeEvent = new SessionSubscribeEvent(this, message, user);
	registry.onApplicationEvent(subscribeEvent);

	Set<SimpSubscription> matches = registry.findSubscriptions(new SimpSubscriptionMatcher() {
		@Override
		public boolean match(SimpSubscription subscription) {
			return subscription.getDestination().equals("/match");
		}
	});

	assertEquals(2, matches.size());

	Iterator<SimpSubscription> iterator = matches.iterator();
	Set<String> sessionIds = new HashSet<>(2);
	sessionIds.add(iterator.next().getId());
	sessionIds.add(iterator.next().getId());
	assertEquals(new HashSet<>(Arrays.asList("sub1", "sub2")), sessionIds);
}
 
Example #3
Source File: DefaultSimpUserRegistry.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object other) {
	if (this == other) {
		return true;
	}
	if (other == null || !(other instanceof SimpSubscription)) {
		return false;
	}
	SimpSubscription otherSubscription = (SimpSubscription) other;
	return (getSession().getId().equals(otherSubscription.getSession().getId()) &&
			this.id.equals(otherSubscription.getId()));
}
 
Example #4
Source File: DefaultSimpUserRegistry.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object other) {
	if (this == other) {
		return true;
	}
	if (other == null || !(other instanceof SimpSubscription)) {
		return false;
	}
	return this.id.equals(((SimpSubscription) other).getId());
}
 
Example #5
Source File: DefaultSimpUserRegistry.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public Set<SimpSubscription> findSubscriptions(SimpSubscriptionMatcher matcher) {
	Set<SimpSubscription> result = new HashSet<SimpSubscription>();
	for (DefaultSimpSession session : this.sessions.values()) {
		for (SimpSubscription subscription : session.subscriptions.values()) {
			if (matcher.match(subscription)) {
				result.add(subscription);
			}
		}
	}
	return result;
}
 
Example #6
Source File: DefaultSimpUserRegistryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void findSubscriptions() throws Exception {
	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub1", "/match");
	SessionSubscribeEvent subscribeEvent = new SessionSubscribeEvent(this, message, user);
	registry.onApplicationEvent(subscribeEvent);

	message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub2", "/match");
	subscribeEvent = new SessionSubscribeEvent(this, message, user);
	registry.onApplicationEvent(subscribeEvent);

	message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub3", "/not-a-match");
	subscribeEvent = new SessionSubscribeEvent(this, message, user);
	registry.onApplicationEvent(subscribeEvent);

	Set<SimpSubscription> matches = registry.findSubscriptions(new SimpSubscriptionMatcher() {
		@Override
		public boolean match(SimpSubscription subscription) {
			return subscription.getDestination().equals("/match");
		}
	});

	assertEquals(2, matches.size());

	Iterator<SimpSubscription> iterator = matches.iterator();
	Set<String> sessionIds = new HashSet<>(2);
	sessionIds.add(iterator.next().getId());
	sessionIds.add(iterator.next().getId());
	assertEquals(new HashSet<>(Arrays.asList("sub1", "sub2")), sessionIds);
}
 
Example #7
Source File: DefaultSimpUserRegistry.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean equals(Object other) {
	if (this == other) {
		return true;
	}
	if (!(other instanceof SimpSubscription)) {
		return false;
	}
	SimpSubscription otherSubscription = (SimpSubscription) other;
	return (getId().equals(otherSubscription.getId()) &&
			getSession().getId().equals(otherSubscription.getSession().getId()));
}
 
Example #8
Source File: DefaultSimpUserRegistry.java    From java-technology-stack with MIT License 5 votes vote down vote up
public Set<SimpSubscription> findSubscriptions(SimpSubscriptionMatcher matcher) {
	Set<SimpSubscription> result = new HashSet<>();
	for (LocalSimpSession session : this.sessions.values()) {
		for (SimpSubscription subscription : session.subscriptions.values()) {
			if (matcher.match(subscription)) {
				result.add(subscription);
			}
		}
	}
	return result;
}
 
Example #9
Source File: DefaultSimpUserRegistryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void findSubscriptions() throws Exception {
	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub1", "/match");
	SessionSubscribeEvent subscribeEvent = new SessionSubscribeEvent(this, message, user);
	registry.onApplicationEvent(subscribeEvent);

	message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub2", "/match");
	subscribeEvent = new SessionSubscribeEvent(this, message, user);
	registry.onApplicationEvent(subscribeEvent);

	message = createMessage(SimpMessageType.SUBSCRIBE, "123", "sub3", "/not-a-match");
	subscribeEvent = new SessionSubscribeEvent(this, message, user);
	registry.onApplicationEvent(subscribeEvent);

	Set<SimpSubscription> matches = registry.findSubscriptions(new SimpSubscriptionMatcher() {
		@Override
		public boolean match(SimpSubscription subscription) {
			return subscription.getDestination().equals("/match");
		}
	});

	assertEquals(2, matches.size());

	Iterator<SimpSubscription> iterator = matches.iterator();
	Set<String> sessionIds = new HashSet<>(2);
	sessionIds.add(iterator.next().getId());
	sessionIds.add(iterator.next().getId());
	assertEquals(new HashSet<>(Arrays.asList("sub1", "sub2")), sessionIds);
}
 
Example #10
Source File: DefaultSimpUserRegistry.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean equals(Object other) {
	if (this == other) {
		return true;
	}
	if (!(other instanceof SimpSubscription)) {
		return false;
	}
	SimpSubscription otherSubscription = (SimpSubscription) other;
	return (getId().equals(otherSubscription.getId()) &&
			getSession().getId().equals(otherSubscription.getSession().getId()));
}
 
Example #11
Source File: DefaultSimpUserRegistry.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Set<SimpSubscription> getSubscriptions() {
	return new HashSet<>(this.subscriptions.values());
}
 
Example #12
Source File: DefaultSimpUserRegistry.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean equals(Object other) {
	return (this == other ||
			(other instanceof SimpSubscription && getId().equals(((SimpSubscription) other).getId())));
}
 
Example #13
Source File: MessageBrokerConfigurationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Set<SimpSubscription> findSubscriptions(SimpSubscriptionMatcher matcher) { return null; }
 
Example #14
Source File: DefaultSimpUserRegistry.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Set<SimpSubscription> getSubscriptions() {
	return new HashSet<SimpSubscription>(this.subscriptions.values());
}
 
Example #15
Source File: DefaultSimpUserRegistry.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean equals(Object other) {
	return (this == other ||
			(other instanceof SimpSubscription && getId().equals(((SimpSubscription) other).getId())));
}
 
Example #16
Source File: DefaultSimpUserRegistry.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Set<SimpSubscription> getSubscriptions() {
	return new HashSet<>(this.subscriptions.values());
}
 
Example #17
Source File: MessageBrokerConfigurationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Set<SimpSubscription> findSubscriptions(SimpSubscriptionMatcher matcher) { return null; }