2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-23 04:28:01 +00:00

Better server caching.

This commit is contained in:
Tux 2014-08-09 23:57:57 -04:00
parent d3b2f3f10b
commit 6df0a481e7
2 changed files with 12 additions and 7 deletions

View File

@ -22,7 +22,6 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
@ -40,7 +39,6 @@ public class DataManager implements Listener {
* Most of these are purged only based on size limits but are also invalidated on certain actions. * Most of these are purged only based on size limits but are also invalidated on certain actions.
*/ */
private final Cache<UUID, String> serverCache = CacheBuilder.newBuilder() private final Cache<UUID, String> serverCache = CacheBuilder.newBuilder()
.expireAfterWrite(5, TimeUnit.SECONDS)
.maximumSize(2000) .maximumSize(2000)
.concurrencyLevel(2) .concurrencyLevel(2)
.build(); .build();
@ -244,8 +242,12 @@ public class DataManager implements Listener {
if (message.getSource().equals(source)) if (message.getSource().equals(source))
return; return;
// For now we will just invalidate the caches. In a future version the action scope will be expanded ;) // For now we will just invalidate the caches, depending on what action occurred.
invalidate(message.getTarget()); if (message.getAction() == DataManagerMessage.Action.SERVER_CHANGE) {
serverCache.invalidate(message.getTarget());
} else {
invalidate(message.getTarget());
}
} }
@Getter @Getter
@ -253,7 +255,8 @@ public class DataManager implements Listener {
static class DataManagerMessage { static class DataManagerMessage {
enum Action { enum Action {
JOIN, JOIN,
LEAVE LEAVE,
SERVER_CHANGE
} }
private final UUID target; private final UUID target;

View File

@ -64,8 +64,10 @@ public class RedisBungeeConsumer implements Runnable {
pipeline.sync(); pipeline.sync();
} else if (event instanceof PlayerChangedServerConsumerEvent) { } else if (event instanceof PlayerChangedServerConsumerEvent) {
PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event; PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event;
// No use in pipelining this Pipeline pipeline = jedis.pipelined();
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName()); pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName());
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage(event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE)));
pipeline.sync();
} }
} }