I can not find how to implement executeActivate and executeDelete method.
Hello Everyone,
Here is FlushOnPublish.java
I can not find how to implement executeActivate and executeDelete method.
-executeActivate : the method to cache the content to cache when flushing on publish.
-executeDelete : the method to delete the content from cache when flushing on publish.
Can you teach me how to implement it?
---------------------------------------------------------------
public class FlushOnPublish {
private static Logger log = LoggerFactory.getLogger(FlushOnPublish.class);
public static void execute(BundleContext bundleContext, Event event) {
if (bundleContext != null && event != null) {
final ServiceReference rrServiceReference = bundleContext.getServiceReference(ResourceResolverFactory.class.getName());
final ResourceResolverFactory resolverFactory = (ResourceResolverFactory)bundleContext.getService(rrServiceReference);
final ResourceResolver resolver = AdminService.getResourceResolver(resolverFactory);
final ReplicationAction replicationAction = ReplicationEvent.fromEvent(event).getReplicationAction();
final ReplicationActionType replicationActionType = replicationAction.getType();
if (replicationActionType.equals(ReplicationActionType.ACTIVATE)) {
// make 2 requests:
// 1) request to delete cache
// 2) request to cache new content
executeCurlCommand(getDispatcherUris(resolver), replicationAction.getPaths(), ReplicationActionType.DELETE);
executeCurlCommand(getDispatcherUris(resolver), replicationAction.getPaths(), ReplicationActionType.ACTIVATE);
}
else if (replicationActionType.equals(ReplicationActionType.DEACTIVATE) ||
replicationActionType.equals(ReplicationActionType.DELETE)) {
// make 1 request: delete cache
executeCurlCommand(getDispatcherUris(resolver), replicationAction.getPaths(), ReplicationActionType.DEACTIVATE);
}
}
}
private static String[] getDispatcherUris(ResourceResolver resolver) {
final String DISPATCHER_FLUSH_PATH = "/etc/replication/agents.publish/flush/jcr:content";
Resource resource = resolver.getResource(DISPATCHER_FLUSH_PATH);
String[] dispatcherUris = null;
if (resource != null) {
ValueMap valueMap = resource.getValueMap();
if (valueMap.containsKey("dispatchers")) {
dispatcherUris = valueMap.get("dispatchers", "").split(",");
}
}
/**
* i.e. [{protocol}://{dispatcher-server-hostname:port}/dispatcher/invalidate.cache]
*/
return dispatcherUris;
}
private static void executeCurlCommand(String[] dispatchers, String[] paths, ReplicationActionType methodType) {
/**
*
* curl
* -H "CQ-Action:Flush"
* -H "CQ-Handle: /content/geometrixx/en/toolbar"
* -H "CQ-Path:/content/geometrixx/en/toolbar"
* -H "Content-Length: 0"
* -H "Content-Type: application/octet-stream"
* http://dispatcher-server-hostname:port/dispatcher/invalidate.cache
*
* In Newer version of dispatcher try this
*
* curl
* -H "CQ-Action: DELETE" -> methodType
* -H "CQ-Handle:/content/geometrixx/en/toolbar" -> path
* -H "CQ-Path:/content/geometrixx/en/toolbar" -> path
* -H "Content-Length: 0"
* -H "Content-Type: application/octet-stream"
* http://dispatcher-server-hostname:port/dispatcher/invalidate.cache -> path
*/
for (String path : paths) {
for (String dispatcher : dispatchers) {
// Execute dispatcher flush
// The HTTP request should be called without waiting for response (asynchronously)
if (methodType.equals(ReplicationActionType.ACTIVATE)) {
//issue a curl request to cache the content (which is: path)
executeActivate();
}
else if (methodType.equals(ReplicationActionType.DELETE)) {
//issue a curl request to delete the content (which is: path)
executeDelete();
}
}
}
}
private static void executeActivate() {
}
private static void executeDelete() {
}
}