mirror of
				https://github.com/proxiodev/RedisBungee.git
				synced 2025-11-04 09:38:03 +00:00 
			
		
		
		
	Do not allow unsubscribing from RedisBungee internal channels and properly poison the PubSub handler this time.
This commit is contained in:
		
							parent
							
								
									8ac70e801f
								
							
						
					
					
						commit
						d438186682
					
				@ -320,7 +320,9 @@ public final class RedisBungee extends Plugin {
 | 
			
		||||
    public void onDisable() {
 | 
			
		||||
        if (pool != null) {
 | 
			
		||||
            // Poison the PubSub listener
 | 
			
		||||
            psl.poison();
 | 
			
		||||
            getProxy().getScheduler().cancel(this);
 | 
			
		||||
 | 
			
		||||
            getLogger().info("Waiting for all tasks to finish.");
 | 
			
		||||
 | 
			
		||||
            service.shutdown();
 | 
			
		||||
@ -342,6 +344,7 @@ public final class RedisBungee extends Plugin {
 | 
			
		||||
            } finally {
 | 
			
		||||
                pool.returnResource(tmpRsc);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            pool.destroy();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@ -477,10 +480,13 @@ public final class RedisBungee extends Plugin {
 | 
			
		||||
        public void removeChannel(String... channel) {
 | 
			
		||||
            jpsh.unsubscribe(channel);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void poison() {
 | 
			
		||||
            jpsh.unsubscribe();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    class JedisPubSubHandler extends JedisPubSub {
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public void onMessage(final String s, final String s2) {
 | 
			
		||||
            if (s2.trim().length() == 0) return;
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,9 @@
 | 
			
		||||
package com.imaginarycode.minecraft.redisbungee;
 | 
			
		||||
 | 
			
		||||
import com.google.common.base.Function;
 | 
			
		||||
import com.google.common.base.Preconditions;
 | 
			
		||||
import com.google.common.collect.Collections2;
 | 
			
		||||
import com.google.common.collect.ImmutableList;
 | 
			
		||||
import com.google.common.collect.ImmutableSet;
 | 
			
		||||
import com.google.common.collect.Multimap;
 | 
			
		||||
import lombok.NonNull;
 | 
			
		||||
@ -27,9 +29,15 @@ import java.util.UUID;
 | 
			
		||||
 */
 | 
			
		||||
public class RedisBungeeAPI {
 | 
			
		||||
    private final RedisBungee plugin;
 | 
			
		||||
    private final List<String> reservedChannels;
 | 
			
		||||
 | 
			
		||||
    RedisBungeeAPI(RedisBungee plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
        this.reservedChannels = ImmutableList.of(
 | 
			
		||||
                "redisbungee-allservers",
 | 
			
		||||
                "redisbungee-" + plugin.getServerId(),
 | 
			
		||||
                "redisbungee-data"
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -220,6 +228,10 @@ public class RedisBungeeAPI {
 | 
			
		||||
     * @since 0.3
 | 
			
		||||
     */
 | 
			
		||||
    public final void unregisterPubSubChannels(String... channels) {
 | 
			
		||||
        for (String channel : channels) {
 | 
			
		||||
            Preconditions.checkArgument(!reservedChannels.contains(channel), "attempting to unregister internal channel");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        RedisBungee.getPubSubListener().removeChannel(channels);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user