#1225 - ENH: Extend L2 server cache (near caching) for clearing "near caches"

This commit is contained in:
Rob Bygrave committed 2017-12-13 02:09:10 +13:00
1 parent 69c045443c
commit c7f4b56dd1
23 files changed
+585 -65

No files matched your search

@@ -23,6 +23,7 @@ public class BinaryMessage {
public static final int TYPE_MSGCONTROL = 0;
public static final int TYPE_BEANIUD = 1;
public static final int TYPE_TABLEIUD = 2;
public static final int TYPE_CACHE = 3;
public static final int TYPE_MSGACK = 8;
public static final int TYPE_MSGRESEND = 9;
@@ -5,12 +5,10 @@ import java.util.List;
/**
* Holds a List of BinaryMessage's.
*
* @author rbygrave
*/
public class BinaryMessageList {
final ArrayList<BinaryMessage> list = new ArrayList<>();
final List<BinaryMessage> list = new ArrayList<>();
public void add(BinaryMessage msg) {
list.add(msg);
@@ -24,5 +24,4 @@ public interface ClusterBroadcast {
* Send a transaction event to all the members of the cluster.
*/
void broadcast(RemoteTransactionEvent remoteTransEvent);
}
@@ -1,6 +1,6 @@
package io.ebeaninternal.server.cluster;
import java.util.Properties;
import io.ebean.config.ContainerConfig;
/**
* Factory to create the cluster broadcast service.
@@ -10,5 +10,5 @@ public interface ClusterBroadcastFactory {
/**
* Create the cluster transport with the manager and deployment properties.
*/
ClusterBroadcast create(ClusterManager manager, Properties properties);
ClusterBroadcast create(ClusterManager manager, ContainerConfig config);
}
@@ -17,8 +17,6 @@ public class ClusterManager {
private static final Logger clusterLogger = LoggerFactory.getLogger("io.ebean.Cluster");
private static final Logger logger = LoggerFactory.getLogger(ClusterManager.class);
private final ConcurrentHashMap<String, EbeanServer> serverMap = new ConcurrentHashMap<>();
private final Object monitor = new Object();
@@ -27,12 +25,14 @@ public class ClusterManager {
private boolean started;
private boolean shutdown;
public ClusterManager(ContainerConfig config) {
if (!config.isClusterActive()) {
broadcast = null;
ClusterBroadcastFactory factory = createFactory();
if (factory != null) {
broadcast = factory.create(this, config);
} else {
ClusterBroadcastFactory factory = createFactory();
broadcast = factory.create(this, config.getProperties());
broadcast = null;
}
}
@@ -47,10 +47,6 @@ public class ClusterManager {
if (iterator.hasNext()) {
factory = iterator.next();
}
if (factory == null) {
throw new IllegalStateException("No ClusterTransportFactory found in classpath. "
+ " Probably need to add the avaje-ebeanorm-cluster dependency");
}
return factory;
}
@@ -76,6 +72,24 @@ public class ClusterManager {
}
}
/**
* Broadcast a cache clear all event to the cluster.
*/
public void cacheClearAll(String serverName) {
if (broadcast != null) {
broadcast.broadcast(new RemoteTransactionEvent(serverName).cacheClearAll());
}
}
/**
* Broadcast a cache clear event to the cluster.
*/
public void cacheClear(String serverName, Class<?> beanType) {
if (broadcast != null) {
broadcast.broadcast(new RemoteTransactionEvent(serverName).cacheClear(beanType));
}
}
/**
* Return true if clustering is on.
*/
@@ -99,8 +113,8 @@ public class ClusterManager {
* Shutdown the service and Deregister from the cluster.
*/
public void shutdown() {
if (broadcast != null) {
logger.info("ClusterManager shutdown ");
if (broadcast != null && !shutdown) {
shutdown = true;
broadcast.shutdown();
}
}