// Path: components/caching-invalidator/org.wso2.carbon.caching.invalidator/src/main/java/org/wso2/carbon/caching/invalidator/amqp/ConfigurationManager.java
// public class ConfigurationManager {
//     private static final Log log = LogFactory.getLog(ConfigurationManager.class);
// 
//     private static String topicName = null;
//     private static String providerUrl = null;
//     private static String providerPort = null;
//     private static String providerUsername = null;
//     private static String providerPassword = null;
//     private static boolean subscribed = false;
// 
//     private static List<String> sentMsgBuffer;
// 
//     public static boolean init(){
//         boolean propertyExists = false;
//         providerUrl = null;
// 
//         String configFilePath = Paths.get(CarbonUtils.getCarbonConfigDirPath(), "cache.xml").toString();
//         try{
//             StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(new FileInputStream(configFilePath));
//             OMElement documentElement = stAXOMBuilder.getDocumentElement();
//             Iterator iterator;
// 
//             iterator = documentElement.getChildrenWithName(new QName("providerUrl"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 providerUrl = cache.getText();
//             }
// 
//             iterator = documentElement.getChildrenWithName(new QName("cacheInvalidateTopic"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 topicName = cache.getText();
//             }
// 
//             iterator = documentElement.getChildrenWithName(new QName("providerPort"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 providerPort = cache.getText();
//             }
// 
//             if(providerPort == null || providerPort.equals("")){
//                 providerPort="5672"; //default
//             }
// 
//             iterator = documentElement.getChildrenWithName(new QName("providerUsername"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 providerUsername = cache.getText();
//             }
// 
//             if(providerUsername == null || providerUsername.equals("")){
//                 providerUsername="guest"; //default
//             }
// 
//             iterator = documentElement.getChildrenWithName(new QName("providerPassword"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 providerPassword = cache.getText();
//             }
// 
//             if(providerPassword == null || providerPassword.equals("")){
//                 providerPassword="guest"; //default
//             }
// 
//             propertyExists = providerUrl != null && !providerUrl.equals("");
//             propertyExists &= topicName != null && !topicName.equals("");
// 
//             if(!propertyExists){
//                 log.info("Global cache invalidation is offline according to cache.xml configurations");
//             }
// 
//         }catch (Exception e){
//             log.info("Global cache invalidation is offline according to cache.xml configurations");
//         }
//         return propertyExists;
//     }
// 
//     public static String getTopicName() {
//         return topicName;
//     }
// 
//     public static String getProviderUrl() {
//         return providerUrl;
//     }
// 
//     public static String getProviderPort() {
//         return providerPort;
//     }
// 
//     public static String getProviderUsername() {
//         return providerUsername;
//     }
// 
//     public static String getProviderPassword() {
//         return providerPassword;
//     }
// 
//     public static List<String> getSentMsgBuffer() {
//         if(sentMsgBuffer == null){
//             sentMsgBuffer = new ArrayList<String>();
//         }
//         return sentMsgBuffer;
//     }
// 
//     public static boolean isSubscribed() {
//         return subscribed;
//     }
// 
//     public static void setSubscribed(boolean subscribed) {
//         ConfigurationManager.subscribed = subscribed;
//     }
// }


import org.wso2.carbon.utils.ConfigurationContextService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.wso2.carbon.caching.impl.CacheInvalidator;
import org.wso2.carbon.caching.invalidator.amqp.CacheInvalidationPublisher;
import org.wso2.carbon.caching.invalidator.amqp.CacheInvalidationSubscriber;
import org.wso2.carbon.caching.invalidator.amqp.ConfigurationManager;
import org.wso2.carbon.core.clustering.api.CoordinatedActivity;
/*
 * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.wso2.carbon.caching.invalidator.internal;


@Component(
        name = "org.wso2.carbon.caching.invalidator.internal.CacheInvalidationServiceComponent",
        immediate = true)
public class CacheInvalidationServiceComponent {

    private static Log log = LogFactory.getLog(CacheInvalidationServiceComponent.class);

    ServiceRegistration serviceRegistration;

    CacheInvalidationSubscriber subscriber;

    CacheInvalidationPublisher publisher;

    @Activate
    protected void activate(ComponentContext ctxt) {

        log.info("Initializing the CacheInvalidationServiceComponent...");
        try {
// Path: components/caching-invalidator/org.wso2.carbon.caching.invalidator/src/main/java/org/wso2/carbon/caching/invalidator/amqp/ConfigurationManager.java
// public class ConfigurationManager {
//     private static final Log log = LogFactory.getLog(ConfigurationManager.class);
// 
//     private static String topicName = null;
//     private static String providerUrl = null;
//     private static String providerPort = null;
//     private static String providerUsername = null;
//     private static String providerPassword = null;
//     private static boolean subscribed = false;
// 
//     private static List<String> sentMsgBuffer;
// 
//     public static boolean init(){
//         boolean propertyExists = false;
//         providerUrl = null;
// 
//         String configFilePath = Paths.get(CarbonUtils.getCarbonConfigDirPath(), "cache.xml").toString();
//         try{
//             StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(new FileInputStream(configFilePath));
//             OMElement documentElement = stAXOMBuilder.getDocumentElement();
//             Iterator iterator;
// 
//             iterator = documentElement.getChildrenWithName(new QName("providerUrl"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 providerUrl = cache.getText();
//             }
// 
//             iterator = documentElement.getChildrenWithName(new QName("cacheInvalidateTopic"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 topicName = cache.getText();
//             }
// 
//             iterator = documentElement.getChildrenWithName(new QName("providerPort"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 providerPort = cache.getText();
//             }
// 
//             if(providerPort == null || providerPort.equals("")){
//                 providerPort="5672"; //default
//             }
// 
//             iterator = documentElement.getChildrenWithName(new QName("providerUsername"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 providerUsername = cache.getText();
//             }
// 
//             if(providerUsername == null || providerUsername.equals("")){
//                 providerUsername="guest"; //default
//             }
// 
//             iterator = documentElement.getChildrenWithName(new QName("providerPassword"));
// 
//             if(iterator.hasNext()){
//                 OMElement cache = (OMElement) iterator.next();
//                 providerPassword = cache.getText();
//             }
// 
//             if(providerPassword == null || providerPassword.equals("")){
//                 providerPassword="guest"; //default
//             }
// 
//             propertyExists = providerUrl != null && !providerUrl.equals("");
//             propertyExists &= topicName != null && !topicName.equals("");
// 
//             if(!propertyExists){
//                 log.info("Global cache invalidation is offline according to cache.xml configurations");
//             }
// 
//         }catch (Exception e){
//             log.info("Global cache invalidation is offline according to cache.xml configurations");
//         }
//         return propertyExists;
//     }
// 
//     public static String getTopicName() {
//         return topicName;
//     }
// 
//     public static String getProviderUrl() {
//         return providerUrl;
//     }
// 
//     public static String getProviderPort() {
//         return providerPort;
//     }
// 
//     public static String getProviderUsername() {
//         return providerUsername;
//     }
// 
//     public static String getProviderPassword() {
//         return providerPassword;
//     }
// 
//     public static List<String> getSentMsgBuffer() {
//         if(sentMsgBuffer == null){
//             sentMsgBuffer = new ArrayList<String>();
//         }
//         return sentMsgBuffer;
//     }
// 
//     public static boolean isSubscribed() {
//         return subscribed;
//     }
// 
//     public static void setSubscribed(boolean subscribed) {
//         ConfigurationManager.subscribed = subscribed;
//     }
// }


// Path: components/caching-invalidator/org.wso2.carbon.caching.invalidator/src/main/java/org/wso2/carbon/caching/invalidator/internal/CacheInvalidationServiceComponent.java
import org.wso2.carbon.utils.ConfigurationContextService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.wso2.carbon.caching.impl.CacheInvalidator;
import org.wso2.carbon.caching.invalidator.amqp.CacheInvalidationPublisher;
import org.wso2.carbon.caching.invalidator.amqp.CacheInvalidationSubscriber;
import org.wso2.carbon.caching.invalidator.amqp.ConfigurationManager;
import org.wso2.carbon.core.clustering.api.CoordinatedActivity;

/*
 * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.wso2.carbon.caching.invalidator.internal;


@Component(
        name = "org.wso2.carbon.caching.invalidator.internal.CacheInvalidationServiceComponent",
        immediate = true)
public class CacheInvalidationServiceComponent {

    private static Log log = LogFactory.getLog(CacheInvalidationServiceComponent.class);

    ServiceRegistration serviceRegistration;

    CacheInvalidationSubscriber subscriber;

    CacheInvalidationPublisher publisher;

    @Activate
    protected void activate(ComponentContext ctxt) {

        log.info("Initializing the CacheInvalidationServiceComponent...");
        try {
            if (ConfigurationManager.init()) {