mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28:01 +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() {
|
public void onDisable() {
|
||||||
if (pool != null) {
|
if (pool != null) {
|
||||||
// Poison the PubSub listener
|
// Poison the PubSub listener
|
||||||
|
psl.poison();
|
||||||
getProxy().getScheduler().cancel(this);
|
getProxy().getScheduler().cancel(this);
|
||||||
|
|
||||||
getLogger().info("Waiting for all tasks to finish.");
|
getLogger().info("Waiting for all tasks to finish.");
|
||||||
|
|
||||||
service.shutdown();
|
service.shutdown();
|
||||||
@ -342,6 +344,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
pool.destroy();
|
pool.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -477,10 +480,13 @@ public final class RedisBungee extends Plugin {
|
|||||||
public void removeChannel(String... channel) {
|
public void removeChannel(String... channel) {
|
||||||
jpsh.unsubscribe(channel);
|
jpsh.unsubscribe(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void poison() {
|
||||||
|
jpsh.unsubscribe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JedisPubSubHandler extends JedisPubSub {
|
class JedisPubSubHandler extends JedisPubSub {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(final String s, final String s2) {
|
public void onMessage(final String s, final String s2) {
|
||||||
if (s2.trim().length() == 0) return;
|
if (s2.trim().length() == 0) return;
|
||||||
|
@ -7,7 +7,9 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee;
|
package com.imaginarycode.minecraft.redisbungee;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
@ -27,9 +29,15 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class RedisBungeeAPI {
|
public class RedisBungeeAPI {
|
||||||
private final RedisBungee plugin;
|
private final RedisBungee plugin;
|
||||||
|
private final List<String> reservedChannels;
|
||||||
|
|
||||||
RedisBungeeAPI(RedisBungee plugin) {
|
RedisBungeeAPI(RedisBungee plugin) {
|
||||||
this.plugin = 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
|
* @since 0.3
|
||||||
*/
|
*/
|
||||||
public final void unregisterPubSubChannels(String... channels) {
|
public final void unregisterPubSubChannels(String... channels) {
|
||||||
|
for (String channel : channels) {
|
||||||
|
Preconditions.checkArgument(!reservedChannels.contains(channel), "attempting to unregister internal channel");
|
||||||
|
}
|
||||||
|
|
||||||
RedisBungee.getPubSubListener().removeChannel(channels);
|
RedisBungee.getPubSubListener().removeChannel(channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user