You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2013/07/11 07:18:11 UTC

[20/27] aplying 0001-Refactor-usage-module-to-apache-stratos.patch

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/RegistryUsageListener.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/RegistryUsageListener.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/RegistryUsageListener.java
deleted file mode 100644
index 2286516..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/RegistryUsageListener.java
+++ /dev/null
@@ -1,362 +0,0 @@
-/*
- * Copyright (c) 2008, 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.usage.agent.listeners;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.CarbonConstants;
-import org.wso2.carbon.base.ServerConfiguration;
-import org.wso2.carbon.registry.core.*;
-import org.wso2.carbon.registry.core.config.RegistryContext;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.registry.core.jdbc.handlers.Handler;
-import org.wso2.carbon.registry.core.jdbc.handlers.HandlerLifecycleManager;
-import org.wso2.carbon.registry.core.jdbc.handlers.HandlerManager;
-import org.wso2.carbon.registry.core.jdbc.handlers.RequestContext;
-import org.wso2.carbon.registry.core.jdbc.handlers.filters.Filter;
-import org.wso2.carbon.registry.core.jdbc.handlers.filters.URLMatcher;
-import org.wso2.carbon.registry.core.session.CurrentSession;
-import org.wso2.carbon.registry.core.utils.RegistryUtils;
-import org.wso2.carbon.stratos.common.constants.StratosConstants;
-import org.wso2.carbon.usage.agent.persist.RegistryUsagePersister;
-import org.wso2.carbon.usage.agent.util.MonitoredReader;
-import org.wso2.carbon.usage.agent.util.MonitoredWriter;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
-
-/**
- * Handler that intercept the registry calls
- */
-public class RegistryUsageListener extends Handler {
-
-    private static final Log log = LogFactory.getLog(RegistryUsageListener.class);
-
-    public void put(RequestContext context) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return;
-        }
-
-        // called only once per request
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-
-        ResourcePath path = context.getResourcePath();
-        Resource resource = context.getResource();
-        ((ResourceImpl) resource).setPath(path.getCompletePath());
-        if (resource instanceof CollectionImpl) {
-            return;
-        }
-        Object contentObj = resource.getContent();
-        if (contentObj == null) {
-            return;
-        }
-        int size;
-        if (contentObj instanceof String) {
-            size = ((String) contentObj).length();
-        } else if (contentObj instanceof byte[]) {
-            size = ((byte[]) contentObj).length;
-        } else {
-            String msg = "Unsupported type for the content.";
-            log.error(msg);
-            throw new RegistryException(msg);
-        }
-
-
-        // persisting bandwidth
-        //RegistryUsagePersister.storeIncomingBandwidth(tenantId, size);
-        //persisting to registry content addition
-        RegistryUsagePersister.storeAddContent(tenantId, size);
-
-        //we will pass through, so that normal registry operation will put the resource
-    }
-
-    public void importResource(RequestContext context) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return;
-        }
-        // called only once per request..
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-
-//        ResourcePath resourcePath = context.getResourcePath();
-        String sourceURL = context.getSourceURL();
-
-
-        // the import resource logic
-        URL url;
-        try {
-            if (sourceURL != null && sourceURL.toLowerCase().startsWith("file:")) {
-                String msg = "The source URL must not be file in the server's local file system";
-                throw new RegistryException(msg);
-            }
-            url = new URL(sourceURL);
-        } catch (MalformedURLException e) {
-            String msg = "Given source URL " + sourceURL + "is not valid.";
-            throw new RegistryException(msg, e);
-        }
-
-        try {
-            URLConnection uc = url.openConnection();
-            InputStream in = uc.getInputStream();
-            byte[] inByteArr = RegistryUtils.getByteArray(in);
-            int size = inByteArr.length;
-
-            // persisting bandwidth
-            //RegistryUsagePersister.storeIncomingBandwidth(tenantId, size);
-
-        } catch (IOException e) {
-
-            String msg = "Could not read from the given URL: " + sourceURL;
-            throw new RegistryException(msg, e);
-        }
-    }
-
-    public Resource get(RequestContext context) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return null;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return null;
-        }
-        // called only once per request..
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return null;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-
-
-        // get the resource
-        Resource resource = context.getResource();
-        if (resource == null) {
-            ResourcePath resourcePath = context.getResourcePath();
-            Registry registry = context.getRegistry();
-            if (registry.resourceExists(resourcePath.getPath())) {
-                resource = registry.get(resourcePath.getPath());
-                context.setResource(resource);
-                context.setProcessingComplete(true); // nothing else to do.
-            }
-        }
-        if (resource == null) {
-            return null;
-        }
-        if (resource instanceof CollectionImpl) {
-            return resource;
-        }
-        Object contentObj = resource.getContent();
-        if (contentObj == null) {
-            return resource;
-        }
-        int size;
-        if (contentObj instanceof String) {
-            size = ((String) contentObj).length();
-        } else if (contentObj instanceof byte[]) {
-            size = ((byte[]) contentObj).length;
-        } else {
-            String msg = "Unsupported type for the content.";
-            log.error(msg);
-            throw new RegistryException(msg);
-        }
-        // persisting bandwidth
-        //RegistryUsagePersister.storeOutgoingBandwidth(tenantId, size);
-        return resource;
-    }
-
-    public void dump(RequestContext requestContext) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return;
-        }
-        // called only once per request..
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-        long size = requestContext.getBytesWritten();
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-
-        if (size == 0) {
-            //Still not dumped
-            Registry registry = requestContext.getRegistry();
-            String path = requestContext.getResourcePath().getPath();
-            Writer writer = requestContext.getDumpingWriter();
-            // we wrap the writer with the monitored writer
-            MonitoredWriter monitoredWriter = new MonitoredWriter(writer);
-            registry.dump(path, monitoredWriter);
-            size = monitoredWriter.getTotalWritten();
-            requestContext.setProcessingComplete(true);
-        }
-
-        // persisting bandwidth
-        //RegistryUsagePersister.storeOutgoingBandwidth(tenantId, size);
-
-    }
-
-    public void restore(RequestContext requestContext) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return;
-        }
-        // called only once per request..
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-        long size = requestContext.getBytesRead();
-
-        if (size == 0) {
-            //not restored yet
-            Registry registry = requestContext.getRegistry();
-            String path = requestContext.getResourcePath().getPath();
-            Reader reader = requestContext.getDumpingReader();
-            // we wrap the reader with the monitored reader
-            MonitoredReader monitoredReader = new MonitoredReader(reader);
-            registry.restore(path, monitoredReader);
-            size = monitoredReader.getTotalRead();
-            requestContext.setProcessingComplete(true);
-        }
-        // persisting bandwidth
-        //RegistryUsagePersister.storeIncomingBandwidth(tenantId, size);
-
-    }
-
-    public static void registerRegistryUsagePersistingListener(RegistryContext registryContext)
-            throws RegistryException {
-
-        //If metering is disabled, we do not need to register the handler
-        if(!"true".equals(ServerConfiguration.getInstance().getFirstProperty("EnableMetering"))){
-            return;
-        }
-
-        HandlerManager handlerManager = registryContext.getHandlerManager();
-        RegistryUsageListener handler = new RegistryUsageListener();
-        URLMatcher anyUrlMatcher = new URLMatcher();
-        anyUrlMatcher.setPattern(".*");
-        String[] applyingFilters = new String[]{
-                Filter.PUT, Filter.IMPORT, Filter.GET, Filter.DUMP, Filter.RESTORE, Filter.DELETE};
-
-        handlerManager.addHandlerWithPriority(applyingFilters, anyUrlMatcher, handler,
-                HandlerLifecycleManager.DEFAULT_REPORTING_HANDLER_PHASE);
-    }
-
-    //===========================================================================================
-    public void delete(RequestContext context) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return;
-        }
-        // called only once per request
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-
-        ResourcePath path = context.getResourcePath();
-        Resource resource = context.getRegistry().get(path.getCompletePath());
-        Object contentObj = resource.getContent();
-        if (contentObj == null) {
-            return;
-        }
-        int size = 0;
-        if (contentObj instanceof String) {
-            size = ((String) contentObj).length();
-        } else if (contentObj instanceof byte[]) {
-            size = ((byte[]) contentObj).length;
-        } else if (contentObj instanceof String[]) {
-            // of type collection
-            for (String str : (String[]) contentObj) {
-                size += str.length();
-            }
-        } else {
-            String msg = "Unsupported type for the content.";
-            log.error(msg);
-            throw new RegistryException(msg);
-        }
-        RegistryUsagePersister.storeDeleteContent(tenantId, size);
-
-        //we will pass through, so that normal registry operation will put the resource
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/RegistryUsagePersistingListener.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/RegistryUsagePersistingListener.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/RegistryUsagePersistingListener.java
deleted file mode 100644
index 0e7e75a..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/RegistryUsagePersistingListener.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * Copyright (c) 2008, 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.usage.agent.listeners;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.CarbonConstants;
-import org.wso2.carbon.registry.core.*;
-import org.wso2.carbon.registry.core.config.RegistryContext;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.registry.core.jdbc.handlers.Handler;
-import org.wso2.carbon.registry.core.jdbc.handlers.HandlerLifecycleManager;
-import org.wso2.carbon.registry.core.jdbc.handlers.HandlerManager;
-import org.wso2.carbon.registry.core.jdbc.handlers.RequestContext;
-import org.wso2.carbon.registry.core.jdbc.handlers.filters.Filter;
-import org.wso2.carbon.registry.core.jdbc.handlers.filters.URLMatcher;
-import org.wso2.carbon.registry.core.session.CurrentSession;
-import org.wso2.carbon.registry.core.utils.RegistryUtils;
-import org.wso2.carbon.stratos.common.constants.StratosConstants;
-import org.wso2.carbon.usage.agent.persist.BandwidthPersistor;
-import org.wso2.carbon.usage.agent.util.MonitoredReader;
-import org.wso2.carbon.usage.agent.util.MonitoredWriter;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
-
-/**
- * Handler that intercept the registry calls
- * Currently this handler is not registered because there is a similar handler RegistryUsageHandler
- * After examining properly this class will be deleted.
- */
-public class RegistryUsagePersistingListener extends Handler {
-
-    private static final Log log = LogFactory.getLog(RegistryUsagePersistingListener.class);
-
-    public void put(RequestContext context) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return;
-        }
-
-        // called only once per request
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-
-        ResourcePath path = context.getResourcePath();
-        Resource resource = context.getResource();
-        ((ResourceImpl) resource).setPath(path.getCompletePath());
-        if (resource instanceof CollectionImpl) {
-            return;
-        }
-        Object contentObj = resource.getContent();
-        if (contentObj == null) {
-            return;
-        }
-        int size;
-        if (contentObj instanceof String) {
-            size = ((String) contentObj).length();
-        } else if (contentObj instanceof byte[]) {
-            size = ((byte[]) contentObj).length;
-        } else {
-            String msg = "Unsupported type for the content.";
-            log.error(msg);
-            throw new RegistryException(msg);
-        }
-
-
-        // persisting bandwidth
-        BandwidthPersistor.storeIncomingBandwidth(tenantId, size);
-
-        //we will pass through, so that normal registry operation will put the resource
-    }
-
-    public void importResource(RequestContext context) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return;
-        }
-        // called only once per request..
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-
-//        ResourcePath resourcePath = context.getResourcePath();
-        String sourceURL = context.getSourceURL();
-     
-
-        // the import resource logic
-        URL url;
-        try {
-            if (sourceURL != null && sourceURL.toLowerCase().startsWith("file:")) {
-                String msg = "The source URL must not be file in the server's local file system";
-                throw new RegistryException(msg);
-            }
-            url = new URL(sourceURL);
-        } catch (MalformedURLException e) {
-            String msg = "Given source URL " + sourceURL + "is not valid.";
-            throw new RegistryException(msg, e);
-        }
-
-        try {
-            URLConnection uc = url.openConnection();
-            InputStream in = uc.getInputStream();
-            byte[] inByteArr = RegistryUtils.getByteArray(in);
-            int size = inByteArr.length;
-
-            // persisting bandwidth
-            BandwidthPersistor.storeIncomingBandwidth(tenantId, size);
-
-        } catch (IOException e) {
-
-            String msg = "Could not read from the given URL: " + sourceURL;
-            throw new RegistryException(msg, e);
-        }
-    }
-
-    public Resource get(RequestContext context) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return null;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return null;
-        }
-        // called only once per request..
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return null;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-
-
-        // get the resource
-        Resource resource = context.getResource();
-        if (resource == null) {
-            ResourcePath resourcePath = context.getResourcePath();
-            Registry registry = context.getRegistry();
-            if (registry.resourceExists(resourcePath.getPath())) {
-                resource = registry.get(resourcePath.getPath());
-                context.setResource(resource);
-                context.setProcessingComplete(true); // nothing else to do.
-            }
-        }
-        if (resource == null) {
-            return null;
-        }
-        if (resource instanceof CollectionImpl) {
-            return resource;
-        }
-        Object contentObj = resource.getContent();
-        if (contentObj == null) {
-            return resource;
-        }
-        int size;
-        if (contentObj instanceof String) {
-            size = ((String) contentObj).length();
-        } else if (contentObj instanceof byte[]) {
-            size = ((byte[]) contentObj).length;
-        } else {
-            String msg = "Unsupported type for the content.";
-            log.error(msg);
-            throw new RegistryException(msg);
-        }
-        // persisting bandwidth
-        BandwidthPersistor.storeOutgoingBandwidth(tenantId, size);
-        return resource;
-    }
-
-    public void dump(RequestContext requestContext) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return;
-        }
-        // called only once per request..
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-        long size = requestContext.getBytesWritten();
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-
-        if (size == 0) {
-            //Still not dumped
-            Registry registry = requestContext.getRegistry();
-            String path = requestContext.getResourcePath().getPath();
-            Writer writer = requestContext.getDumpingWriter();
-            // we wrap the writer with the monitored writer
-            MonitoredWriter monitoredWriter = new MonitoredWriter(writer);
-            registry.dump(path, monitoredWriter);
-            size = monitoredWriter.getTotalWritten();
-            requestContext.setProcessingComplete(true);
-        }
-
-        // persisting bandwidth
-        BandwidthPersistor.storeOutgoingBandwidth(tenantId, size);
-
-    }
-
-    public void restore(RequestContext requestContext) throws RegistryException {
-        if (CurrentSession.getCallerTenantId() == MultitenantConstants.SUPER_TENANT_ID ||
-                CurrentSession.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) {
-            // no limitations for the super tenant
-            return;
-        }
-        if (CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(CurrentSession.getUser()) ||
-                CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(CurrentSession.getUser())) {
-            // skipping tracking for anonymous and system user
-            return;
-        }
-        // called only once per request..
-        if (CurrentSession.getAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR)
-                != null) {
-            return;
-        }
-        CurrentSession.setAttribute(StratosConstants.REGISTRY_USAGE_PERSISTED_SESSION_ATTR, true);
-
-        // pre triggering
-        int tenantId = CurrentSession.getTenantId();
-        long size = requestContext.getBytesRead();
-
-        if (size == 0) {
-            //not restored yet
-            Registry registry = requestContext.getRegistry();
-            String path = requestContext.getResourcePath().getPath();
-            Reader reader = requestContext.getDumpingReader();
-            // we wrap the reader with the monitored reader
-            MonitoredReader monitoredReader = new MonitoredReader(reader);
-            registry.restore(path, monitoredReader);
-            size = monitoredReader.getTotalRead();
-            requestContext.setProcessingComplete(true);
-        }
-        // persisting bandwidth
-        BandwidthPersistor.storeIncomingBandwidth(tenantId, size);
-
-    }
-
-    public static void registerRegistryUsagePersistingListener(RegistryContext registryContext)
-            throws RegistryException {
-
-        //This was commented out because there is a similar class RegistryUsageListener
-        //After examiming properly this class will be deleted
-        /*HandlerManager handlerManager = registryContext.getHandlerManager();
-        RegistryUsagePersistingListener handler = new RegistryUsagePersistingListener();
-        URLMatcher anyUrlMatcher = new URLMatcher();
-        anyUrlMatcher.setPattern(".*");
-        String[] applyingFilters = new String[]{
-                Filter.PUT, Filter.IMPORT, Filter.GET, Filter.DUMP, Filter.RESTORE,};
-
-        handlerManager.addHandlerWithPriority(applyingFilters, anyUrlMatcher, handler,
-                HandlerLifecycleManager.DEFAULT_REPORTING_HANDLER_PHASE);
-        */
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/StatisticsInHandler.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/StatisticsInHandler.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/StatisticsInHandler.java
deleted file mode 100644
index cd4d2d9..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/StatisticsInHandler.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.wso2.carbon.usage.agent.listeners;
-
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.engine.Handler;
-import org.apache.axis2.handlers.AbstractHandler;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.base.ServerConfiguration;
-import org.wso2.carbon.context.CarbonContext;
-import org.wso2.carbon.core.util.SystemFilter;
-import org.wso2.carbon.statistics.services.util.SystemStatistics;
-import org.wso2.carbon.usage.agent.util.PublisherUtils;
-import org.wso2.carbon.usage.agent.util.Util;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-public class StatisticsInHandler extends AbstractHandler{
-    private static Log log = LogFactory.getLog(StatisticsOutHandler.class);
-
-    public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
-        AxisService axisService =  messageContext.getAxisService();
-        if(axisService== null || SystemFilter.isFilteredOutService(axisService.getAxisServiceGroup()) ||
-                axisService.isClientSide()){
-            return InvocationResponse.CONTINUE;
-        }
-
-        if(Util.getSystemStatisticsUtil()==null){
-            return InvocationResponse.CONTINUE;
-        }
-
-        SystemStatistics systemStatistics = Util.getSystemStatisticsUtil().getSystemStatistics(messageContext);
-
-        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
-        tenantId = CarbonContext.getCurrentContext().getTenantId();
-
-        if(tenantId == MultitenantConstants.INVALID_TENANT_ID ||
-                tenantId == MultitenantConstants.SUPER_TENANT_ID) {
-            return Handler.InvocationResponse.CONTINUE;
-        }
-
-        try {
-            PublisherUtils.publish(systemStatistics, tenantId);
-        } catch (Exception e) {
-            //Logging the complete stacktrace in debug mode
-            if(log.isDebugEnabled()){
-                log.debug(e);
-            }
-
-            log.error("Error occurred while publishing request statistics. Full stacktrace available in debug logs. " + e.getMessage());
-        }
-
-        return InvocationResponse.CONTINUE;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/StatisticsOutHandler.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/StatisticsOutHandler.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/StatisticsOutHandler.java
deleted file mode 100644
index 9e21058..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/StatisticsOutHandler.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.wso2.carbon.usage.agent.listeners;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.engine.Handler;
-import org.apache.axis2.handlers.AbstractHandler;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.base.ServerConfiguration;
-import org.wso2.carbon.context.CarbonContext;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.core.init.CarbonServerManager;
-import org.wso2.carbon.core.util.SystemFilter;
-import org.wso2.carbon.statistics.services.util.SystemStatistics;
-import org.wso2.carbon.usage.agent.util.PublisherUtils;
-import org.wso2.carbon.usage.agent.util.Util;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-
-public class StatisticsOutHandler extends AbstractHandler{
-
-    private static Log log = LogFactory.getLog(StatisticsOutHandler.class);
-
-    public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
-
-
-        AxisService axisService =  messageContext.getAxisService();
-        if(axisService== null || SystemFilter.isFilteredOutService(axisService.getAxisServiceGroup()) ||
-                axisService.isClientSide()){
-
-            PrivilegedCarbonContext.destroyCurrentContext();
-            return InvocationResponse.CONTINUE;
-        }
-
-        if(Util.getSystemStatisticsUtil()==null){
-
-            PrivilegedCarbonContext.destroyCurrentContext();
-            return InvocationResponse.CONTINUE;
-        }
-        SystemStatistics systemStatistics = Util.getSystemStatisticsUtil().getSystemStatistics(messageContext);
-        
-        int tenantId = MultitenantConstants.INVALID_TENANT_ID;
-        tenantId = CarbonContext.getCurrentContext().getTenantId();
-
-        if(tenantId == MultitenantConstants.INVALID_TENANT_ID ||
-            tenantId == MultitenantConstants.SUPER_TENANT_ID) {
-
-            PrivilegedCarbonContext.destroyCurrentContext();
-            return Handler.InvocationResponse.CONTINUE;
-        }
-
-        try {
-            PublisherUtils.publish(systemStatistics, tenantId);
-        } catch (Exception e) {
-            //Logging the complete stacktrace in debug mode
-            if(log.isDebugEnabled()){
-                log.debug(e);
-            }
-
-            log.error("Error occurred while publishing request statistics. Full stacktrace available in debug logs. " + e.getMessage());
-        }
-
-        PrivilegedCarbonContext.destroyCurrentContext();
-        return InvocationResponse.CONTINUE;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/UsageStatsAxis2ConfigurationContextObserver.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/UsageStatsAxis2ConfigurationContextObserver.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/UsageStatsAxis2ConfigurationContextObserver.java
deleted file mode 100644
index 3c30ed3..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/UsageStatsAxis2ConfigurationContextObserver.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.wso2.carbon.usage.agent.listeners;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.description.AxisModule;
-import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver;
-
-
-public class UsageStatsAxis2ConfigurationContextObserver extends AbstractAxis2ConfigurationContextObserver {
-
-    private static final Log log = LogFactory.getLog(UsageStatsAxis2ConfigurationContextObserver.class);
-
-    @Override
-    public void createdConfigurationContext(ConfigurationContext configContext) {
-
-        AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();
-        int tenantId = PrivilegedCarbonContext.getCurrentContext().getTenantId(false);
-        try {
-            axisConfiguration.engageModule("metering");
-        } catch (AxisFault axisFault) {
-            log.error("Could not engage metering module for tenant: " + tenantId, axisFault);
-        }
-
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/axis2/RequestMeteringHandler.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/axis2/RequestMeteringHandler.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/axis2/RequestMeteringHandler.java
deleted file mode 100644
index 0eab461..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/axis2/RequestMeteringHandler.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
-*  Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-*  WSO2 Inc. licenses this file to you 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.usage.agent.listeners.axis2;
-
-import org.wso2.carbon.stratos.common.constants.StratosConstants;
-import org.wso2.carbon.core.transports.metering.MeteredServletRequest;
-import org.wso2.carbon.usage.agent.util.Util;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.handlers.AbstractHandler;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * this class is used to obtain tenant id from MeteredServletRequest or MessageContext
- */
-
-public class RequestMeteringHandler extends AbstractHandler {
-    private static final Log log = LogFactory.getLog(RequestMeteringHandler.class);
-
-    /**
-     * this method  invoke  MeteredServletRequest and return a InvocationResponse
-     * @param messageContext  MessageContext
-     * @return InvocationResponse
-     * @throws AxisFault
-     */
-
-    public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
-        if (log.isDebugEnabled()) {
-            log.debug("Staring metering handler invocation. Incoming message: " +
-                    messageContext.getEnvelope().toString());
-        }
-        AxisService service = messageContext.getAxisService();
-        Parameter param = service.getParameter("adminService");
-
-        Object obj = messageContext.getProperty("transport.http.servletRequest");
-        if (obj == null) {
-            // TODO: check for cause of the error.
-            log.debug("Servlet request is null. Skip monitoring.");
-            return InvocationResponse.CONTINUE;
-        }
-        if (!(obj instanceof MeteredServletRequest)) {
-            log.debug("HttpServletRequest is not of type MeteredServletRequest. Skip monitoring.");
-            return InvocationResponse.CONTINUE;
-        }
-
-        MeteredServletRequest servletRequest = (MeteredServletRequest) obj;
-
-        if (param != null && "true".equals(param.getValue())) {
-            servletRequest.setAttribute(StratosConstants.ADMIN_SERVICE_SERVLET_ATTR, "true");
-            return InvocationResponse.CONTINUE;
-        }
-        servletRequest.setAttribute(StratosConstants.SERVICE_NAME_SERVLET_ATTR, service.getName());
-
-        int tenantId = getTenantId(servletRequest);
-        servletRequest.setAttribute(StratosConstants.TENANT_ID_SERVLET_ATTR, tenantId);
-
-        return InvocationResponse.CONTINUE;
-    }
-
-    /**
-     * method to get tenant id from MeteredServletRequest
-     * @param servletRequest MeteredServletRequest
-     * @return tenant id
-     */
-
-    private int getTenantId(MeteredServletRequest servletRequest) {
-        String address = servletRequest.getRequestURI();
-        String servicesPrefix = "/services/t/";
-        if (address != null && address.contains(servicesPrefix)) {
-            int domainNameStartIndex =
-                    address.indexOf(servicesPrefix) + servicesPrefix.length();
-            int domainNameEndIndex = address.indexOf('/', domainNameStartIndex);
-            String domainName = address.substring(domainNameStartIndex,
-                    domainNameEndIndex == -1 ? address.length() : domainNameEndIndex);
-
-            // return tenant id if domain name is not null
-            if (domainName != null) {
-                try {
-                    return Util.getRealmService().getTenantManager().getTenantId(domainName);
-                } catch (org.wso2.carbon.user.api.UserStoreException e) {
-                    log.error("An error occurred while obtaining the tenant id.", e);
-                }
-            }
-        }
-
-        // return 0 if the domain name is null
-        return 0;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/axis2/RequestMeteringModule.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/axis2/RequestMeteringModule.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/axis2/RequestMeteringModule.java
deleted file mode 100644
index f45b8b5..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/listeners/axis2/RequestMeteringModule.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2008, 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.usage.agent.listeners.axis2;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.description.AxisDescription;
-import org.apache.axis2.description.AxisModule;
-import org.apache.axis2.modules.Module;
-import org.apache.neethi.Assertion;
-import org.apache.neethi.Policy;
-
-public class RequestMeteringModule implements Module {
-
-    public void init(ConfigurationContext configurationContext, AxisModule axisModule)
-            throws AxisFault {
-    }
-
-    public void engageNotify(AxisDescription axisDescription) throws AxisFault {
-    }
-
-    public boolean canSupportAssertion(Assertion assertion) {
-        return true;
-    }
-
-    public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault {
-    }
-
-    public void shutdown(ConfigurationContext configurationContext) throws AxisFault {
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/BandwidthPersistor.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/BandwidthPersistor.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/BandwidthPersistor.java
deleted file mode 100644
index e52384d..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/BandwidthPersistor.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2008, 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.usage.agent.persist;
-
-import org.wso2.carbon.stratos.common.constants.UsageConstants;
-import org.wso2.carbon.usage.agent.beans.BandwidthUsage;
-import org.wso2.carbon.usage.agent.util.Util;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-/**
- * this class is used to store incoming and outgoing bandwidth
- */
-
-public class BandwidthPersistor {
-
-    /**
-     * method to store incoming bandwidth
-     * @param tenantId tenant id
-     * @param size value of the incoming bandwidth
-     */
-
-    public static void storeIncomingBandwidth(int tenantId, long size) {
-        if ((MultitenantConstants.SUPER_TENANT_ID!=tenantId) && (size > 0)) {
-            BandwidthUsage usage = new BandwidthUsage(
-                    tenantId, UsageConstants.REGISTRY_INCOMING_BW, size);
-            Util.addToPersistingControllerQueue(usage);
-        }
-    }
-
-    /**
-     * method to store outgoingBandwidth
-     * @param tenantId tenant id
-     * @param size value of the outgoing bandwidth
-     */
-    public static void storeOutgoingBandwidth(int tenantId, long size) {
-        if ((MultitenantConstants.SUPER_TENANT_ID!=tenantId) && (size > 0)) {
-            BandwidthUsage usage = new BandwidthUsage(
-                    tenantId, UsageConstants.REGISTRY_OUTGOING_BW, size);
-            Util.addToPersistingControllerQueue(usage);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/BandwidthUsageDataRetrievalTask.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/BandwidthUsageDataRetrievalTask.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/BandwidthUsageDataRetrievalTask.java
deleted file mode 100644
index 7824fe8..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/BandwidthUsageDataRetrievalTask.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2011, 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.usage.agent.persist;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.CarbonConstants;
-import org.wso2.carbon.base.ServerConfiguration;
-import org.wso2.carbon.core.init.CarbonServerManager;
-import org.wso2.carbon.stratos.common.constants.UsageConstants;
-import org.wso2.carbon.stratos.common.util.StratosConfiguration;
-import org.wso2.carbon.usage.agent.beans.BandwidthUsage;
-import org.wso2.carbon.usage.agent.config.UsageAgentConfiguration;
-import org.wso2.carbon.tomcat.ext.transport.statistics.TransportStatisticsContainer;
-import org.wso2.carbon.tomcat.ext.transport.statistics.TransportStatisticsEntry;
-import org.wso2.carbon.usage.agent.util.UsageAgentConstants;
-import org.wso2.carbon.usage.agent.util.Util;
-import org.wso2.carbon.user.api.UserStoreException;
-import org.wso2.carbon.utils.CarbonUtils;
-
-import java.util.Queue;
-
-public class BandwidthUsageDataRetrievalTask implements Runnable {
-    private static final Log log = LogFactory.getLog(BandwidthUsageDataRetrievalTask.class);
-
-    private Queue<TransportStatisticsEntry> transportStats;
-    private UsageAgentConfiguration configuration;
-
-    //This will be decided based on whether a BAM Server URL is provided or not
-    private boolean isBamAvailable=false;
-
-    public BandwidthUsageDataRetrievalTask(UsageAgentConfiguration configuration) {
-        transportStats = TransportStatisticsContainer.getTransportStatistics();
-        this.configuration = configuration;
-
-        //Checking for the BAM Server URL
-        String bamServerUrl = ServerConfiguration.getInstance().getFirstProperty("BamServerURL");
-        if(bamServerUrl != null){
-            this.isBamAvailable = true;
-        }
-    }
-
-    public void run() {
-        /*if (log.isDebugEnabled()) {
-            log.debug("Retrieving Service and Web App bandwidth usage statistics.");
-        }*/
-
-        if (!transportStats.isEmpty()) {
-            for (int i = 0; i < configuration.getUsageTasksNumberOfRecordsPerExecution() && !transportStats.isEmpty(); i++) {
-                TransportStatisticsEntry entry = transportStats.remove();
-                try {
-                    if(!isBamAvailable){
-                        return;
-                    }
-
-                    int tenantId = getTenantID(entry.getTenantName());
-                    //if the tenant does not exist, no need and no way of updating the usage data
-                    //therefore ignore it
-                    if(tenantId<0){
-                        return;
-                    }
-                    if (inferMeasurement(entry).equals(UsageConstants.SERVICE_BANDWIDTH)) {
-                        if (entry.getRequestSize() > 0) {
-                            Util.addToPersistingControllerQueue(new BandwidthUsage(getTenantID(entry.getTenantName()), UsageConstants.SERVICE_INCOMING_BW, entry.getRequestSize()));
-                        }
-                        if (entry.getResponseSize() > 0) {
-                            Util.addToPersistingControllerQueue(new BandwidthUsage(getTenantID(entry.getTenantName()), UsageConstants.SERVICE_OUTGOING_BW, entry.getResponseSize()));
-                        }
-                    } else if (inferMeasurement(entry).equals(UsageConstants.WEBAPP_BANDWIDTH)) {
-                        if (entry.getRequestSize() > 0) {
-                            Util.addToPersistingControllerQueue(new BandwidthUsage(getTenantID(entry.getTenantName()), UsageConstants.WEBAPP_INCOMING_BW, entry.getRequestSize()));
-                        }
-                        if (entry.getResponseSize() > 0) {
-                            Util.addToPersistingControllerQueue(new BandwidthUsage(getTenantID(entry.getTenantName()), UsageConstants.WEBAPP_OUTGOING_BW, entry.getResponseSize()));
-                        }
-                    }
-                } catch (UserStoreException e) {
-                    log.error("Error persisting bandwidth usage statistics.", e);
-                }
-
-            }
-        }
-    }
-
-
-    private String inferMeasurement(TransportStatisticsEntry entry) {
-        if (entry.getContext() != null) {
-            if (entry.getContext().equals(UsageAgentConstants.BANDWIDTH_USAGE_SERVICES_CONTEXT)) {
-                return UsageConstants.SERVICE_BANDWIDTH;
-            } else if (entry.getContext().equals(UsageAgentConstants.BANDWIDTH_USAGE_WEBAPPS_CONTEXT)) {
-                return UsageConstants.WEBAPP_BANDWIDTH;
-            }
-        }
-
-        return UsageAgentConstants.BANDWIDTH_CARBON;
-    }
-
-    private int getTenantID(String tenantDomain) throws UserStoreException {
-        return Util.getRealmService().getTenantManager().getTenantId(tenantDomain);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/RegistryUsagePersister.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/RegistryUsagePersister.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/RegistryUsagePersister.java
deleted file mode 100644
index 0bd7ab1..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/RegistryUsagePersister.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2008, 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.usage.agent.persist;
-
-import org.wso2.carbon.stratos.common.constants.UsageConstants;
-import org.wso2.carbon.usage.agent.beans.BandwidthUsage;
-import org.wso2.carbon.usage.agent.util.Util;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-import java.lang.System;
-
-/**
- * this class is used to store incoming and outgoing bandwidth
- */
-
-public class RegistryUsagePersister {
-
-    /**
-     * method to store incoming bandwidth
-     * @param tenantId tenant id
-     * @param size value of the incoming bandwidth
-     */
-
-    public static void storeIncomingBandwidth(int tenantId, long size) {
-        if ((MultitenantConstants.SUPER_TENANT_ID!=tenantId) && (size > 0)) {
-            BandwidthUsage usage = new BandwidthUsage(
-                    tenantId, UsageConstants.REGISTRY_INCOMING_BW, size);
-            Util.addToPersistingControllerQueue(usage);
-        }
-    }
-    //=============================================================
-
-    public static void storeAddContent(int tenantId, long size) {
-        if ((MultitenantConstants.SUPER_TENANT_ID!=tenantId) && (size > 0)) {
-            BandwidthUsage usage = new BandwidthUsage(
-                    tenantId, "ContentBandwidth-In", size);
-            Util.addToPersistingControllerQueue(usage);
-        }
-    }
-    public static void storeDeleteContent(int tenantId, long size) {
-        if ((MultitenantConstants.SUPER_TENANT_ID!=tenantId) && (size > 0)) {
-            BandwidthUsage usage = new BandwidthUsage(
-                    tenantId, "ContentBandwidth-Out", size);
-            Util.addToPersistingControllerQueue(usage);
-        }
-    }
-   //=============================================================
-    /**
-     * method to store outgoingBandwidth
-     * @param tenantId tenant id
-     * @param size value of the outgoing bandwidth
-     */
-    public static void storeOutgoingBandwidth(int tenantId, long size) {
-        if ((MultitenantConstants.SUPER_TENANT_ID!=tenantId) && (size > 0)) {
-            BandwidthUsage usage = new BandwidthUsage(
-                    tenantId, UsageConstants.REGISTRY_OUTGOING_BW, size);
-            Util.addToPersistingControllerQueue(usage);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/ServiceDataPersistor.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/ServiceDataPersistor.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/ServiceDataPersistor.java
deleted file mode 100644
index 9b0902c..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/ServiceDataPersistor.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2008, 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.usage.agent.persist;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.core.transports.metering.MeteredServletRequest;
-import org.wso2.carbon.core.transports.metering.MeteredServletResponse;
-import org.wso2.carbon.core.transports.metering.RequestDataPersister;
-import org.wso2.carbon.stratos.common.constants.StratosConstants;
-import org.wso2.carbon.stratos.common.constants.UsageConstants;
-import org.wso2.carbon.usage.agent.beans.BandwidthUsage;
-import org.wso2.carbon.usage.agent.util.Util;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-/**
- * this class is used to persist service data
- */
-public class ServiceDataPersistor implements RequestDataPersister {
-    private static final Log log = LogFactory.getLog(ServiceDataPersistor.class);
-
-    /**
-     * this method get tenant id, inDataSize and outDataSize from the wrappedRequest, construct a
-     * BandwidthUsage object and add it to PersistingControllerQueue
-     * @param wrappedRequest  MeteredServletRequest
-     * @param wrappedResponse MeteredServletResponse
-     */
-    public void persist(MeteredServletRequest wrappedRequest, MeteredServletResponse wrappedResponse) {
-        if ("true".equals(wrappedRequest.getAttribute(StratosConstants.SERVICE_NAME_SERVLET_ATTR))) {
-            return;
-        }
-
-        Integer tenantId = (Integer) wrappedRequest.getAttribute(
-                StratosConstants.TENANT_ID_SERVLET_ATTR);
-        if (tenantId == null || tenantId == MultitenantConstants.SUPER_TENANT_ID) {
-            return;
-        }
-        long inDataSize = wrappedRequest.getReadSize();
-        long outDataSize = wrappedResponse.getWrittenSize();
-
-        if(log.isTraceEnabled()){
-            log.trace("Persisting service bandwidth usage for tenant " + tenantId + " in size: " + inDataSize + " out size: " + outDataSize);
-        }
-        // add the job to queue
-        if (inDataSize > 0) {
-            BandwidthUsage usage = new BandwidthUsage(tenantId,
-                    UsageConstants.SERVICE_INCOMING_BW, inDataSize);
-            Util.addToPersistingControllerQueue(usage);
-        }
-        if (outDataSize > 0) {
-            BandwidthUsage usage = new BandwidthUsage(tenantId,
-                    UsageConstants.SERVICE_OUTGOING_BW, outDataSize);
-            Util.addToPersistingControllerQueue(usage);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/UsageDataPersistenceManager.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/UsageDataPersistenceManager.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/UsageDataPersistenceManager.java
deleted file mode 100644
index 5cf4491..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/UsageDataPersistenceManager.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2011, 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.usage.agent.persist;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.usage.agent.beans.BandwidthUsage;
-import org.wso2.carbon.usage.agent.config.UsageAgentConfiguration;
-
-import java.util.Queue;
-import java.util.concurrent.*;
-
-public class UsageDataPersistenceManager {
-    private static final Log log = LogFactory.getLog(UsageDataPersistenceManager.class);
-
-    // queue to store Bandwidth usage statistics.
-    // usage of  LinkedBlockingQueue ensures operations on the queue to wait for the queue to be non
-    // empty when retrieving and wait for space when storing element.
-    private Queue<BandwidthUsage> persistenceJobs = new LinkedBlockingQueue<BandwidthUsage>();
-
-    private final ScheduledExecutorService scheduler;
-
-    private UsageAgentConfiguration configuration;
-
-    public UsageDataPersistenceManager(UsageAgentConfiguration configuration) {
-        scheduler = Executors.newScheduledThreadPool(2, new UsageDataPersistenceThreadFactory());
-        this.configuration = configuration;
-    }
-
-    /**
-     * this method add bandwidth usage entries to the jobQueue
-     *
-     * @param usage Bandwidth usage
-     */
-
-    public void addToQueue(BandwidthUsage usage) {
-        persistenceJobs.add(usage);
-    }
-
-    public void scheduleUsageDataPersistenceTask() {
-        //we will schedule the usage data persistence task only if interval is not -1
-        if(configuration.getUsageTasksExecutionIntervalInMilliSeconds()>0){
-            scheduler.scheduleWithFixedDelay(new UsageDataPersistenceTask(persistenceJobs, configuration),
-                    configuration.getUsageTasksStartupDelayInMilliSeconds(),
-                    configuration.getUsageTasksExecutionIntervalInMilliSeconds(),
-                    TimeUnit.MILLISECONDS);
-            log.debug("Usage data persistence task was scheduled");
-        }else{
-            log.debug("Usage data persistence task is disabled");
-        }
-    }
-
-
-    public void scheduleBandwidthUsageDataRetrievalTask() {
-        //we will schedule the usage data retrieval task only if interval is not -1
-        if(configuration.getUsageTasksExecutionIntervalInMilliSeconds()>0){
-            scheduler.scheduleWithFixedDelay(new BandwidthUsageDataRetrievalTask(configuration),
-                    configuration.getUsageTasksStartupDelayInMilliSeconds(),
-                    configuration.getUsageTasksExecutionIntervalInMilliSeconds(),
-                    TimeUnit.MILLISECONDS);
-            log.debug("Bandwidth Usage data retrieval task was scheduled");
-        }else {
-            log.debug("Bandwidth Usage data retrieval task was disabled");
-        }
-    }
-
-    class UsageDataPersistenceThreadFactory implements ThreadFactory {
-        private int counter = 0;
-
-        public Thread newThread(Runnable r) {
-            return new Thread(r, "UsageDataPersistenceThread-" + counter++);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/UsageDataPersistenceTask.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/UsageDataPersistenceTask.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/UsageDataPersistenceTask.java
deleted file mode 100644
index 64f3b0a..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/persist/UsageDataPersistenceTask.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2011, 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.usage.agent.persist;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.base.MultitenantConstants;
-import org.wso2.carbon.usage.agent.beans.BandwidthUsage;
-import org.wso2.carbon.usage.agent.config.UsageAgentConfiguration;
-import org.wso2.carbon.usage.agent.exception.UsageException;
-import org.wso2.carbon.usage.agent.util.PublisherUtils;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Queue;
-
-public class UsageDataPersistenceTask implements Runnable {
-
-    private static final Log log = LogFactory.getLog(UsageDataPersistenceTask.class);
-
-    private Queue<BandwidthUsage> usagePersistenceJobs;
-    private UsageAgentConfiguration configuration;
-
-    public UsageDataPersistenceTask(Queue<BandwidthUsage> jobs, UsageAgentConfiguration configuration) {
-        usagePersistenceJobs = jobs;
-        this.configuration = configuration;
-    }
-
-    public void run() {
-        if (!usagePersistenceJobs.isEmpty()) {
-            if (log.isDebugEnabled()) {
-                log.debug("Persisting Service and Web App bandwidth usage statistics");
-            }
-            try {
-                persistUsage(usagePersistenceJobs);
-            } catch (UsageException e) {
-                log.error("Error when persisting usage statistics.", e);
-            }
-        }
-    }
-
-    /**
-     * this method create a Summarizer object for each tenant and call accumulate() method to
-     * accumulate usage statistics
-     *
-     * @param jobQueue usage data persistence jobs
-     * @throws org.wso2.carbon.usage.agent.exception.UsageException
-     *
-     */
-
-    public void persistUsage(Queue<BandwidthUsage> jobQueue) throws UsageException {
-
-        // create a map to hold summarizer objects against tenant id
-        HashMap<Integer, Summarizer> summarizerMap = new HashMap<Integer, Summarizer>();
-
-        // if the jobQueue is not empty
-        for (int i = 0; i < configuration.getUsageTasksNumberOfRecordsPerExecution() && !jobQueue.isEmpty(); i++) {
-
-            // get the first element from the queue, which is a BandwidthUsage object
-            BandwidthUsage usage = jobQueue.poll();
-
-            // get the tenant id
-            int tenantId = usage.getTenantId();
-
-            //get the Summarizer object corresponds to the tenant id
-            Summarizer summarizer = summarizerMap.get(tenantId);
-
-            // when tenant invoke service for the first time, no corresponding summarizer object in
-            // the map
-            if (summarizer == null) {
-                //create a Summarizer object and put to the summarizerMap
-                summarizer = new Summarizer();
-                summarizerMap.put(tenantId, summarizer);
-            }
-
-            //  now accumulate usage
-            summarizer.accumulate(usage);
-        }
-
-        //Finished accumulating. Now publish the events
-
-        // get the collection view of values in summarizerMap
-        Collection<Summarizer> summarizers = summarizerMap.values();
-
-        // for each summarizer object call the publish method
-        for (Summarizer summarizer : summarizers) {
-            summarizer.publish();
-        }
-    }
-
-    /**
-     * inner class Summarizer
-     * this class is used to accumulate and publish usage statistics.
-     * for each tenant this keeps a map to store BandwidthUsage values
-     */
-    private static class Summarizer {
-        private HashMap<String, BandwidthUsage> usageMap;
-
-        public Summarizer() {
-            usageMap = new HashMap<String, BandwidthUsage>();
-        }
-
-        /**
-         * the method to accumulate usage data
-         *
-         * @param usage BandwidthUsage
-         */
-
-        public void accumulate(BandwidthUsage usage) {
-            // get the measurement name of usage entry
-            String key = usage.getMeasurement();
-
-            // get the existing value of measurement
-            BandwidthUsage existingUsage = usageMap.get(key);
-
-            // if this measurement is metered earlier add the new value to the existing value
-            if (existingUsage != null) {
-                existingUsage.setValue(existingUsage.getValue() + usage.getValue());
-            } else {
-                // if this measurement is not metered previously we need to add it to the usageMap
-                usageMap.put(key, usage);
-            }
-        }
-
-        /**
-         * this method reads usage items from the usageMap and call publish method to publish to
-         * the BAM
-         *
-         * @throws UsageException
-         */
-
-        public void publish() throws UsageException {
-
-            // get the collection view of values in usageMap
-            Collection<BandwidthUsage> usages = usageMap.values();
-
-            for (BandwidthUsage usage : usages) {
-                try {
-                    // publish the usage entry if it is not the super-tenant
-                    if(MultitenantConstants.SUPER_TENANT_ID != usage.getTenantId()){
-                        PublisherUtils.publish(usage);
-                    }
-                } catch (UsageException e) {
-                    log.error("Error in publishing bandwidth usage data", e);
-                }
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/services/CustomMeteringService.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/services/CustomMeteringService.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/services/CustomMeteringService.java
deleted file mode 100644
index 23e684d..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/services/CustomMeteringService.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2008, 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.usage.agent.services;
-
-import org.wso2.carbon.core.AbstractAdmin;
-import org.wso2.carbon.usage.agent.api.CustomMeteringAgent;
-import org.wso2.carbon.usage.agent.exception.UsageException;
-
-/**
- *      CustomMeteringService class defines methods to get recorded duration, to check whether
- *      usage entries exists, persist usage, retrieve usage and add usage.
- */
-public class CustomMeteringService extends AbstractAdmin {
-
-    /**
-     * method to get recorded durations
-     * @param measurement  the measurement name
-     * @return  duration array
-     * @throws Exception
-     */
-
-    public String[] getRecordedDurations(String measurement) throws Exception {
-        return new CustomMeteringAgent(getGovernanceRegistry()).getRecordedDurations(measurement);
-    }
-
-    /**
-     * method to check whether usage entry exists or not
-     * @param duration  duration
-     * @param measurement measurement name
-     * @return true if usage entry exist
-     * @throws Exception
-     */
-    public boolean isUsageEntryExists( String duration, String measurement)
-            throws Exception {
-        return new CustomMeteringAgent(getGovernanceRegistry()).isUsageEntryExists(duration,
-                measurement);
-    }
-
-    /**
-     * method to persist usage
-     * @param duration
-     * @param measurement measurement name
-     * @param value   value of measurement
-     * @throws Exception
-     */
-    public void persistUsage( String duration, String measurement, String value)
-            throws Exception {
-        new CustomMeteringAgent(getGovernanceRegistry()).persistUsage(duration, measurement, value);
-    }
-
-    /**
-     * method to retrieve usage
-     * @param duration
-     * @param measurement measurement name
-     * @return usage value
-     * @throws UsageException
-     */
-
-    public String retrieveUsage( String duration, String measurement)
-            throws UsageException {
-        return new CustomMeteringAgent(getGovernanceRegistry())
-                .retrieveUsage(duration, measurement);
-    }
-
-    /**
-     * method to add usage entries
-     * @param userName user name
-     * @param duration duration of the measurement
-     * @param measurement measurement name
-     * @param value usage value
-     * @return usage value
-     * @throws Exception
-     */
-    public long addUsage(String userName, String duration, String measurement, long value)
-            throws Exception {
-        return new CustomMeteringAgent(getGovernanceRegistry()).addUsage(duration, measurement,
-                value);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/util/MonitoredReader.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/util/MonitoredReader.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/util/MonitoredReader.java
deleted file mode 100644
index 821ed82..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/util/MonitoredReader.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2008, 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.usage.agent.util;
-
-import java.io.IOException;
-import java.io.Reader;
-
-
-/**
- * this class is used to wrap the Reader object
- */
-public class MonitoredReader extends Reader {
-    Reader reader;
-    long totalRead;
-
-    public MonitoredReader(Reader reader) {
-        this.reader = reader;
-        totalRead = 0;
-    }
-
-    public int read(char cbuf[], int off, int len) throws IOException {
-        int read = reader.read(cbuf, off, len);
-        totalRead += read;
-        return read;
-    }
-
-    public void close() throws IOException {
-        reader.close();
-    }
-
-    public long getTotalRead() {
-        return totalRead;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/util/MonitoredWriter.java
----------------------------------------------------------------------
diff --git a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/util/MonitoredWriter.java b/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/util/MonitoredWriter.java
deleted file mode 100644
index 856fd18..0000000
--- a/components/stratos/usage/org.wso2.carbon.usage.agent/2.1.0/src/main/java/org/wso2/carbon/usage/agent/util/MonitoredWriter.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2008, 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.usage.agent.util;
-
-import java.io.IOException;
-import java.io.Writer;
-
-
-/**
- * this class is used to wrap Writer object
- */
-public class MonitoredWriter extends Writer {
-    Writer writer;
-    long totalWritten;
-
-    public MonitoredWriter(Writer writer) {
-        this.writer = writer;
-        totalWritten = 0;
-    }
-
-    public void write(char cbuf[], int off, int len) throws IOException {
-        totalWritten += (len - off);
-        writer.write(cbuf, off, len);
-    }
-
-    public void flush() throws IOException {
-        writer.flush();
-    }
-
-    public void close() throws IOException {
-        writer.close();
-    }
-
-    public long getTotalWritten() {
-        return totalWritten;
-    }
-}