Thomas Vachuska

Fixing cyclic component dependency issue.

Change-Id: I7951df92b4a81f09f8ec3c1ae376a7d1125655df
...@@ -119,15 +119,36 @@ public class DistributedClusterStore ...@@ -119,15 +119,36 @@ public class DistributedClusterStore
119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
120 protected MessagingService messagingService; 120 protected MessagingService messagingService;
121 121
122 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 122 + // This must be optional to avoid a cyclic dependency
123 + @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
123 protected ComponentConfigService cfgService; 124 protected ComponentConfigService cfgService;
124 125
125 - @Activate 126 + /**
126 - public void activate(ComponentContext context) { 127 + * Hook for wiring up optional reference to a service.
127 - cfgService.registerProperties(getClass()); 128 + *
129 + * @param service service being announced
130 + */
131 + protected void bindComponentConfigService(ComponentConfigService service) {
132 + if (cfgService == null) {
133 + cfgService = service;
134 + cfgService.registerProperties(getClass());
135 + }
136 + }
128 137
129 - modified(context); 138 + /**
139 + * Hook for unwiring optional reference to a service.
140 + *
141 + * @param service service being withdrawn
142 + */
143 + protected void unbindComponentConfigService(ComponentConfigService service) {
144 + if (cfgService == service) {
145 + cfgService.unregisterProperties(getClass(), false);
146 + cfgService = null;
147 + }
148 + }
130 149
150 + @Activate
151 + public void activate() {
131 localNode = clusterMetadataService.getLocalNode(); 152 localNode = clusterMetadataService.getLocalNode();
132 153
133 messagingService.registerHandler(HEARTBEAT_MESSAGE, 154 messagingService.registerHandler(HEARTBEAT_MESSAGE,
...@@ -143,7 +164,6 @@ public class DistributedClusterStore ...@@ -143,7 +164,6 @@ public class DistributedClusterStore
143 164
144 @Deactivate 165 @Deactivate
145 public void deactivate() { 166 public void deactivate() {
146 - cfgService.unregisterProperties(getClass(), false);
147 messagingService.unregisterHandler(HEARTBEAT_MESSAGE); 167 messagingService.unregisterHandler(HEARTBEAT_MESSAGE);
148 heartBeatSender.shutdownNow(); 168 heartBeatSender.shutdownNow();
149 heartBeatMessageHandler.shutdownNow(); 169 heartBeatMessageHandler.shutdownNow();
......
...@@ -29,7 +29,7 @@ public class DistributedClusterStoreTest { ...@@ -29,7 +29,7 @@ public class DistributedClusterStoreTest {
29 @Before 29 @Before
30 public void setUp() throws Exception { 30 public void setUp() throws Exception {
31 distributedClusterStore = new DistributedClusterStore(); 31 distributedClusterStore = new DistributedClusterStore();
32 - distributedClusterStore.activate(null); 32 + distributedClusterStore.activate();
33 } 33 }
34 34
35 @After 35 @After
......