How to Create a Cluster Aware OSGi Service

Problem

How do I create an OSGi service that is aware of whether it is running on a CQ5/CRX cluster slave node or a master node?

Resolution

In CQ5, you can use the ClusterAware interface which will automatically handle periodically checking the descriptor for you.  This makes things easier if the node is elected as master:

import com.day.cq.jcrclustersupport.ClusterAware;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype = false, policy = ConfigurationPolicy.IGNORE)
@Service(ClusterAware.class)
public class MyClusterAwareService implements ClusterAware {
  public void unbindRepository() {
    log.info("No Repository is bound or Repository is unbound");
  }

  public void bindRepository(String repositoryId, String clusterId, boolean isMaster) {
    log.info("Bound to Repository {} Node {} (Cluster: {})",
      new Object[] { (isMaster ? "Master" : "Slave"), repositoryId, clusterId });
    doSomethiing(isMaster);
  }

  private void doSomething(boolean isMaster) {
    //TODO: your code here
  }
}

Note: the ClusterAware feature only applies to CQ5.3 with Feature Pack 34071 installed, CQ5.4 or later version.

Applies to

CQ 5.3

CQ 5.4

CRX 2.1

CRX 2.2

** If you want to use this in CQ5.3 you need 5.3 Feature Pack 34071 and CRX hotfix 2.1.0.10+.  If you don't have these hotfixes then you can request them via daycare.

참고:

AEM 5.6.1 onward use new topology api. Details at http://helpx.adobe.com/cq/kb/create-cluster-aware-osgi-service.html

 Adobe

쉽고 빠르게 지원 받기

신규 사용자이신가요?

Adobe MAX 2024

Adobe MAX
크리에이티비티 컨퍼런스

10월 14~16일 마이애미 비치 및 온라인

Adobe MAX

크리에이티비티 컨퍼런스

10월 14~16일 마이애미 비치 및 온라인

Adobe MAX 2024

Adobe MAX
크리에이티비티 컨퍼런스

10월 14~16일 마이애미 비치 및 온라인

Adobe MAX

크리에이티비티 컨퍼런스

10월 14~16일 마이애미 비치 및 온라인