@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()) && ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession())); }
/** * Constructor to create DTO from a local user subscription. */ public TransferSimpSubscription(SimpSubscription subscription) { this.id = subscription.getId(); this.session = new TransferSimpSession(); this.destination = subscription.getDestination(); }
@Test public void getUserFromRemoteRegistry() throws Exception { // Prepare broadcast message from remote server TestSimpUser testUser = new TestSimpUser("joe"); TestSimpSession testSession = new TestSimpSession("remote-sess"); testSession.addSubscriptions(new TestSimpSubscription("remote-sub", "/remote-dest")); testUser.addSessions(testSession); SimpUserRegistry testRegistry = mock(SimpUserRegistry.class); when(testRegistry.getUsers()).thenReturn(Collections.singleton(testUser)); Object registryDto = new MultiServerUserRegistry(testRegistry).getLocalRegistryDto(); Message<?> message = this.converter.toMessage(registryDto, null); // Add remote registry this.registry.addRemoteRegistryDto(message, this.converter, 20000); assertEquals(1, this.registry.getUserCount()); SimpUser user = this.registry.getUser("joe"); assertNotNull(user); assertTrue(user.hasSessions()); assertEquals(1, user.getSessions().size()); SimpSession session = user.getSession("remote-sess"); assertNotNull(session); assertEquals("remote-sess", session.getId()); assertSame(user, session.getUser()); assertEquals(1, session.getSubscriptions().size()); SimpSubscription subscription = session.getSubscriptions().iterator().next(); assertEquals("remote-sub", subscription.getId()); assertSame(session, subscription.getSession()); assertEquals("/remote-dest", subscription.getDestination()); }
@Test public void findSubscriptionsFromRemoteRegistry() throws Exception { // Prepare broadcast message from remote server TestSimpUser user1 = new TestSimpUser("joe"); TestSimpUser user2 = new TestSimpUser("jane"); TestSimpUser user3 = new TestSimpUser("jack"); TestSimpSession session1 = new TestSimpSession("sess1"); TestSimpSession session2 = new TestSimpSession("sess2"); TestSimpSession session3 = new TestSimpSession("sess3"); session1.addSubscriptions(new TestSimpSubscription("sub1", "/match")); session2.addSubscriptions(new TestSimpSubscription("sub1", "/match")); session3.addSubscriptions(new TestSimpSubscription("sub1", "/not-a-match")); user1.addSessions(session1); user2.addSessions(session2); user3.addSessions(session3); SimpUserRegistry userRegistry = mock(SimpUserRegistry.class); when(userRegistry.getUsers()).thenReturn(new HashSet<>(Arrays.asList(user1, user2, user3))); Object registryDto = new MultiServerUserRegistry(userRegistry).getLocalRegistryDto(); Message<?> message = this.converter.toMessage(registryDto, null); // Add remote registry this.registry.addRemoteRegistryDto(message, this.converter, 20000); assertEquals(3, this.registry.getUserCount()); Set<SimpSubscription> matches = this.registry.findSubscriptions(s -> s.getDestination().equals("/match")); assertEquals(2, matches.size()); Iterator<SimpSubscription> iterator = matches.iterator(); Set<String> sessionIds = new HashSet<>(2); sessionIds.add(iterator.next().getSession().getId()); sessionIds.add(iterator.next().getSession().getId()); assertEquals(new HashSet<>(Arrays.asList("sess1", "sess2")), sessionIds); }
@Override public boolean equals(Object other) { return (this == other || (other instanceof SimpSubscription && getId().equals(((SimpSubscription) other).getId()))); }
@Override public boolean match(SimpSubscription subscription) { return subscription.getDestination().equals("/match"); } });
@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); }
for(SimpSession simpSession : simpUser.getSessions()){ for(SimpSubscription simpSubscription : simpSession.getSubscriptions()){ if(StringUtils.startsWith(simpSubscription.getDestination(), "/user/queue/workbench")){ subscribedWebsocketId.add(simpSession.getId());
@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())); }
/** * Constructor to create DTO from a local user subscription. */ public TransferSimpSubscription(SimpSubscription subscription) { this.id = subscription.getId(); this.session = new TransferSimpSession(); this.destination = subscription.getDestination(); }
@Override public boolean equals(Object other) { return (this == other || (other instanceof SimpSubscription && getId().equals(((SimpSubscription) other).getId()))); }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof SimpSubscription)) { return false; } SimpSubscription otherSubscription = (SimpSubscription) other; return (ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession()) && this.id.equals(otherSubscription.getId())); }
/** * Constructor to create DTO from a local user subscription. */ public TransferSimpSubscription(SimpSubscription subscription) { this.id = subscription.getId(); this.session = new TransferSimpSession(); this.destination = subscription.getDestination(); }
@Override public boolean equals(Object other) { return (this == other || (other instanceof SimpSubscription && getId().equals(((SimpSubscription) other).getId()))); }
@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()) && ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession())); }
/** * Constructor to create DTO from a local user subscription. */ public TransferSimpSubscription(SimpSubscription subscription) { this.id = subscription.getId(); this.session = new TransferSimpSession(); this.destination = subscription.getDestination(); }
@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()) && ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession())); }
@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()) && ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession())); }
@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())); }
@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())); }