@Test public void bulkUnsubscribe() throws Exception { final ChannelMetaData ch1 = new ChannelMetaData( 0, "C1", 42, ChannelMetaData.FilterType.NONE, null, ChannelMetaData.CacheType.NONE, false, true ); final ChannelMetaData ch2 = new ChannelMetaData( 1, "C2", 42, ChannelMetaData.FilterType.NONE, null, ChannelMetaData.CacheType.NONE, false, true ); final ChannelMetaData[] channels = new ChannelMetaData[]{ ch1, ch2 }; final ChannelAddress address1 = new ChannelAddress( ch1.getChannelId(), ValueUtil.randomInt() ); final ChannelAddress address2 = new ChannelAddress( ch1.getChannelId(), ValueUtil.randomInt() ); final ChannelAddress address3 = new ChannelAddress( ch1.getChannelId(), ValueUtil.randomInt() ); final ChannelAddress address4 = new ChannelAddress( ch2.getChannelId(), ValueUtil.randomInt() ); final TestReplicantSessionManager sm = new TestReplicantSessionManager( channels ); final ReplicantSession session = createSession( sm ); { EntityMessageCacheUtil.removeSessionChanges(); with( session, () -> sm.subscribe( session, address1, null ) ); with( session, () -> sm.subscribe( session, address2, null ) ); with( session, () -> sm.subscribe( session, address4, null ) ); EntityMessageCacheUtil.removeSessionChanges(); assertChannelActionCount( 0 ); final ArrayList<Integer> subChannelIds = new ArrayList<>(); subChannelIds.add( address1.getSubChannelId() ); subChannelIds.add( address2.getSubChannelId() ); subChannelIds.add( address3.getSubChannelId() ); subChannelIds.add( address4.getSubChannelId() ); sm.bulkUnsubscribe( session, ch1.getChannelId(), subChannelIds ); assertChannelActionCount( 2 ); assertChannelAction( getChannelActions().get( 0 ), address1, ChannelAction.Action.REMOVE, null ); assertChannelAction( getChannelActions().get( 1 ), address2, ChannelAction.Action.REMOVE, null ); with( session, () -> assertNull( session.findSubscriptionEntry( address1 ) ) ); with( session, () -> assertNull( session.findSubscriptionEntry( address2 ) ) ); } }
@Override public void bulkUnsubscribe( @Nonnull final ReplicantSession session, final int channelId, @Nonnull final Collection<Integer> subChannelIds ) throws InterruptedException { final ReentrantLock lock = session.getLock(); lock.lockInterruptibly(); try { doBulkUnsubscribe( session, channelId, subChannelIds ); } finally { lock.unlock(); } }
ReplicantSessionManagerImpl implements EntityMessageEndpoint, ReplicantSessionManager { @Override public void bulkUnsubscribe( @Nonnull final ReplicantSession session, final int channelId, @Nonnull final Collection<Integer> subChannelIds ) throws InterruptedException { final ReentrantLock lock = session.getLock(); lock.lockInterruptibly(); try { doBulkUnsubscribe( session, channelId, subChannelIds ); } finally { lock.unlock(); } } }
ReplicantSessionManagerImpl implements EntityMessageEndpoint, ReplicantSessionManager { @Override public void bulkUnsubscribe( @Nonnull final ReplicantSession session, final int channelId, @Nonnull final Collection<Integer> subChannelIds ) throws InterruptedException { final ReentrantLock lock = session.getLock(); lock.lockInterruptibly(); try { doBulkUnsubscribe( session, channelId, subChannelIds ); } finally { lock.unlock(); } }  }
ReplicantSessionManagerImpl implements EntityMessageEndpoint, ReplicantSessionManager { @Override public void bulkUnsubscribe( @Nonnull final ReplicantSession session, final int channelId, @Nonnull final Collection<Integer> subChannelIds ) throws InterruptedException { final ReentrantLock lock = session.getLock(); lock.lockInterruptibly(); try { doBulkUnsubscribe( session, channelId, subChannelIds ); } finally { lock.unlock(); } }  @Override boolean invalidateSession( @Nonnull final ReplicantSession session ); @Override @Nullable ReplicantSession getSession( @Nonnull final String sessionId ); @Nonnull @Override Set<String> getSessionIDs(); @Override @Nonnull ReplicantSession createSession( @Nonnull final Session webSocketSession ); @SuppressWarnings( { "WeakerAccess", "unused" } ) void pingSessions(); @SuppressWarnings( "WeakerAccess" ) void removeAllSessions(); @SuppressWarnings( "WeakerAccess" ) void removeClosedSessions(); @Override boolean saveEntityMessages( @Nullable final String sessionId,
                                     @Nullable final Integer requestId,
                                     @Nonnull final Collection<EntityMessage> messages,
                                     @Nullable final ChangeSet sessionChanges ); @Override void sendChangeMessage( @Nonnull final ReplicantSession session,
                                 @Nullable final Integer requestId,
                                 @Nullable final String etag,
                                 @Nonnull final Collection<EntityMessage> messages,
                                 @Nonnull final ChangeSet changeSet ); @Override void bulkSubscribe( @Nonnull final ReplicantSession session,
                             final int channelId,
                             @Nonnull final Collection<Integer> subChannelIds,
                             @Nullable final Object filter ); @Override void subscribe( @Nonnull final ReplicantSession session,
                         @Nonnull final ChannelAddress address,
                         @Nullable final Object filter ); @Override void unsubscribe( @Nonnull final ReplicantSession session, @Nonnull final ChannelAddress address ); @Override void bulkUnsubscribe( @Nonnull final ReplicantSession session,
                               final int channelId,
                               @Nonnull final Collection<Integer> subChannelIds ); }
ReplicantSessionManagerImpl implements EntityMessageEndpoint, ReplicantSessionManager { @Override public void bulkUnsubscribe( @Nonnull final ReplicantSession session, final int channelId, @Nonnull final Collection<Integer> subChannelIds ) throws InterruptedException { final ReentrantLock lock = session.getLock(); lock.lockInterruptibly(); try { doBulkUnsubscribe( session, channelId, subChannelIds ); } finally { lock.unlock(); } }  @Override boolean invalidateSession( @Nonnull final ReplicantSession session ); @Override @Nullable ReplicantSession getSession( @Nonnull final String sessionId ); @Nonnull @Override Set<String> getSessionIDs(); @Override @Nonnull ReplicantSession createSession( @Nonnull final Session webSocketSession ); @SuppressWarnings( { "WeakerAccess", "unused" } ) void pingSessions(); @SuppressWarnings( "WeakerAccess" ) void removeAllSessions(); @SuppressWarnings( "WeakerAccess" ) void removeClosedSessions(); @Override boolean saveEntityMessages( @Nullable final String sessionId,
                                     @Nullable final Integer requestId,
                                     @Nonnull final Collection<EntityMessage> messages,
                                     @Nullable final ChangeSet sessionChanges ); @Override void sendChangeMessage( @Nonnull final ReplicantSession session,
                                 @Nullable final Integer requestId,
                                 @Nullable final String etag,
                                 @Nonnull final Collection<EntityMessage> messages,
                                 @Nonnull final ChangeSet changeSet ); @Override void bulkSubscribe( @Nonnull final ReplicantSession session,
                             final int channelId,
                             @Nonnull final Collection<Integer> subChannelIds,
                             @Nullable final Object filter ); @Override void subscribe( @Nonnull final ReplicantSession session,
                         @Nonnull final ChannelAddress address,
                         @Nullable final Object filter ); @Override void unsubscribe( @Nonnull final ReplicantSession session, @Nonnull final ChannelAddress address ); @Override void bulkUnsubscribe( @Nonnull final ReplicantSession session,
                               final int channelId,
                               @Nonnull final Collection<Integer> subChannelIds );  }