You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by Andreas Veithen <an...@skynet.be> on 2008/09/24 21:38:46 UTC

Re: svn commit: r698699 - in /synapse/trunk/java/modules/core/src/main/java/org/apache/synapse: ./ audit/ audit/statatistics/ audit/statatistics/view/ core/axis2/

I guess the package name should have "statistics" instead of  
"statatistics" :-)

Andreas

On 24 sept. 08, at 21:26, indika@apache.org wrote:

> Author: indika
> Date: Wed Sep 24 12:26:26 2008
> New Revision: 698699
>
> URL: http://svn.apache.org/viewvc?rev=698699&view=rev
> Log:
> add in memory statisc view
> Add more logs and comments for statistics
>
> Added:
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/PerUserDomainViewStrategy.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/PerUserIPViewStrategy.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/PerUserViewStrategy.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/Statistics.java
>      - copied, changed from r698269, synapse/trunk/java/modules/core/ 
> src/main/java/org/apache/synapse/audit/statatistics/Statistics.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/StatisticsViewStrategy.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/SystemViewStrategy.java
> Removed:
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/Statistics.java
> Modified:
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> SynapseConstants.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/AuditConfigurable.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/AuditConfiguration.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/AuditHelper.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsCollector.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsLog.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsRecord.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsRecordFactory.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsReporter.java
>    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> core/axis2/Axis2MessageContext.java
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/SynapseConstants.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> SynapseConstants.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> SynapseConstants.java Wed Sep 24 12:26:26 2008
> @@ -166,11 +166,11 @@
>
>         public static final String STATISTICS_STACK  
> ="synapse.statistics.stack";
>
> -        public static final String SYNAPSE_STATISTICS_STATE =  
> "synapse.statistics.state";
> +        public static final String SYNAPSE_AUDIT_STATE =  
> "synapse.audit.state";
>
>         public static final String SYNAPSE_AUDIT_CONFIGURATION =  
> "synapse.audit.configuration";
>
> -        public static final String SYNAPSE_STATISTICS  
> ="synapse.statistics";
> +        public static final String SYNAPSE_AUDIT ="synapse.audit";
>
>     //- handling of timed out events from the callbacks -
>         /** The System property that states the duration at which  
> the timeout handler runs */
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/AuditConfigurable.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfigurable.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/AuditConfigurable.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/AuditConfigurable.java Wed Sep 24 12:26:26 2008
> @@ -19,13 +19,39 @@
> package org.apache.synapse.audit;
>
> /**
> - *
> + * Capability for configurable auditing
>  */
> public interface AuditConfigurable {
> -
> -    public String getAuditId();
> -    public void setAuditId(String id);
> +
> +    /**
> +     * Returns audit id , identifier for a particular audit
> +     * Example , component name , endpoint name
> +     *
> +     * @return audit id
> +     */
> +    public String getAuditId();
> +
> +    /**
> +     * Sets the identifier for a particular audit
> +     *
> +     * @param id audit id
> +     */
> +    public void setAuditId(String id);
> +
> +    /**
> +     * Whether statistics has been enabled
> +     *
> +     * @return True if enable , o.w , false
> +     */
>     public boolean isStatisticsEnable();
> +
> +    /**
> +     * To disable statistics
> +     */
>     public void disableStatistics();
> +
> +    /**
> +     * To enable statistics
> +     */
>     public void enableStatistics();
> }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/AuditConfiguration.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfiguration.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/AuditConfiguration.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/AuditConfiguration.java Wed Sep 24 12:26:26 2008
> @@ -19,20 +19,23 @@
> package org.apache.synapse.audit;
>
> /**
> - *
> + * Audit configuration
> + * Currently contains only statistics configuration related things
>  */
> public class AuditConfiguration implements AuditConfigurable {
>
> +    /* Whether statistics enable */
>     private boolean statisticsEnable = false;
> -    private String AuditId;
> +    /* Identifier for a particular audit configuration */
> +    private String auditId;
>
>     public AuditConfiguration(String auditId, boolean  
> statisticsEnable) {
>         this.statisticsEnable = statisticsEnable;
> -        AuditId = auditId;
> +        this.auditId = auditId;
>     }
>
>     public AuditConfiguration(String auditId) {
> -        AuditId = auditId;
> +        this.auditId = auditId;
>     }
>
>     public boolean isStatisticsEnable() {
> @@ -40,24 +43,22 @@
>     }
>
>     public void disableStatistics() {
> -
>         if (statisticsEnable) {
>             this.statisticsEnable = false;
>         }
>     }
>
>     public void enableStatistics() {
> -
>         if (!statisticsEnable) {
>             statisticsEnable = true;
>         }
>     }
>
>     public String getAuditId() {
> -        return AuditId;
> +        return auditId;
>     }
>
>     public void setAuditId(String auditId) {
> -        AuditId = auditId;
> +        this.auditId = auditId;
>     }
> }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/AuditHelper.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditHelper.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/AuditHelper.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/AuditHelper.java Wed Sep 24 12:26:26 2008
> @@ -18,32 +18,57 @@
>  */
> package org.apache.synapse.audit;
>
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> import org.apache.synapse.MessageContext;
> import org.apache.synapse.SynapseConstants;
> import org.apache.synapse.audit.statatistics.StatisticsReporter;
> import org.apache.synapse.config.xml.XMLConfigConstants;
>
> /**
> - *
> + * Contains helper methods required for auditing.
> + * This class need to evolved as any audit related things are adding
>  */
> public class AuditHelper {
>
> +    private static final Log log =  
> LogFactory.getLog(AuditHelper.class);
> +
> +    /**
> +     * Sets the Global audit configuration if it has been forced by  
> setting
> +     *
> +     * @param synCtx Current Message through synapse
> +     */
>     public static void setGlobalAudit(MessageContext synCtx) {
>
>         if (XMLConfigConstants.STATISTICS_ENABLE.equals(
> -                 
> synCtx 
> .getConfiguration 
> ().getProperty(SynapseConstants.SYNAPSE_STATISTICS_STATE))) {
> -            AuditConfigurable auditConfigurable = new  
> AuditConfiguration(SynapseConstants.SYNAPSE_STATISTICS, true);
> +                 
> synCtx 
> .getConfiguration 
> ().getProperty(SynapseConstants.SYNAPSE_AUDIT_STATE))) {
> +
> +            AuditConfigurable auditConfigurable = new  
> AuditConfiguration(SynapseConstants.SYNAPSE_AUDIT, true);
> +
> +            if (log.isDebugEnabled()) {
> +                log.debug("Global Audit is enabled. System-wide  
> auditing will be occurred.");
> +            }
> +
>             StatisticsReporter.collect(synCtx, auditConfigurable);
>              
> synCtx.setProperty(SynapseConstants.SYNAPSE_AUDIT_CONFIGURATION,
>                     auditConfigurable);
>         }
>     }
>
> +    /**
> +     * Report Global audit for this message
> +     *
> +     * @param synCtx Current Message through synapse
> +     */
>     public static void reportGlobalAudit(MessageContext synCtx) {
> -
> +
>         AuditConfigurable auditConfigurable = (AuditConfigurable)  
> synCtx.getProperty(
>                 SynapseConstants.SYNAPSE_AUDIT_CONFIGURATION);
> +
>         if (auditConfigurable != null) {
> +            if (log.isDebugEnabled()) {
> +                log.debug("System-wide audit record is reported.");
> +            }
>             StatisticsReporter.report(synCtx, auditConfigurable);
>         }
>     }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/StatisticsCollector.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsCollector.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsCollector.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsCollector.java Wed Sep 24 12:26:26 2008
> @@ -18,35 +18,61 @@
>  */
> package org.apache.synapse.audit.statatistics;
>
> +import org.apache.synapse.audit.statatistics.view.Statistics;
> +import  
> org.apache.synapse.audit.statatistics.view.StatisticsViewStrategy;
> +
> import java.util.ArrayList;
> import java.util.List;
> +import java.util.Map;
>
> /**
> - * To collect statistics
> + * Collects statistics and provides those collected data
>  */
>
> public class StatisticsCollector {
>
>     private final List<StatisticsRecord> statisticsCollection = new  
> ArrayList<StatisticsRecord>();
>
> -    public void collect(StatisticsRecord statisticsRegistry) {
> -        this.statisticsCollection.add(statisticsRegistry);
> -    }
> -
> -    public Statistics getEndpointStatistics(String id) {
> -        Statistics statistics = new Statistics();
> -        for (StatisticsRecord statisticsRegistry :  
> statisticsCollection) {
> -            if (statisticsRegistry != null) {
> -                StatisticsLog log =  
> statisticsRegistry.getEndpointStatisticsRecord(id);
> -                if (log != null) {
> -                    statistics.update(log.getProcessingTime(),  
> statisticsRegistry.isFaultResponse());
> -                }
> -            }
> -        }
> -        return statistics;
> +    /**
> +     * Registering a statistics record
> +     *
> +     * @param statisticsRecord statistics record instance
> +     */
> +    public void collect(StatisticsRecord statisticsRecord) {
> +        this.statisticsCollection.add(statisticsRecord);
>     }
>
> +    /**
> +     * Check whether given statistics record has  already been  
> registered
> +     *
> +     * @param statisticsRecord statisticsRecord statistics record  
> instance
> +     * @return True if there
> +     */
>     public boolean contains(StatisticsRecord statisticsRecord) {
>         return statisticsCollection.contains(statisticsRecord);
>     }
> +
> +    /**
> +     * Returns a particular statistics view according to a given  
> strategy for a given resource with particular type
> +     *
> +     * @param id       Resource id
> +     * @param type     Type of the resource
> +     * @param strategy Statistics viewing strategy
> +     * @return Statistics view
> +     */
> +    public Map<String, Statistics> getStatistics(String id, int  
> type, StatisticsViewStrategy strategy) {
> +        return strategy.determineView(id, statisticsCollection,  
> type);
> +    }
> +
> +    /**
> +     * Returns a particular statistics view according to a given  
> strategy for a given resource type
> +     *
> +     * @param type     type Type of the resource
> +     * @param strategy strategy Statistics viewing strategy
> +     * @return Statistics view
> +     */
> +    public Map<String, Map<String, Statistics>> getStatistics(int  
> type, StatisticsViewStrategy strategy) {
> +        return strategy.determineView(statisticsCollection, type);
> +    }
> +
> }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/StatisticsLog.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsLog.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsLog.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsLog.java Wed Sep 24 12:26:26 2008
> @@ -19,12 +19,18 @@
> package org.apache.synapse.audit.statatistics;
>
> /**
> - *
> + *
>  */
> public class StatisticsLog {
> -
> -    private String id ;
> -    private long startTime =-1;
> +
> +    public static final int ENDPOINT_STATISTICS = 0;
> +
> +    public static final int PROXY_SERVICE_STATISTICS = 1;
> +
> +    public static final int MEDIATOR_STATISTICS = 2;
> +
> +    private String id;
> +    private long startTime = -1;
>     private long endTime = -1;
>
>     public StatisticsLog(String id) {
> @@ -59,8 +65,8 @@
>     public void setEndTime(long endTime) {
>         this.endTime = endTime;
>     }
> -
> -    public long getProcessingTime(){
> +
> +    public long getProcessingTime() {
>         return this.endTime - this.startTime;
>     }
> }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/StatisticsRecord.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecord.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsRecord.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsRecord.java Wed Sep 24 12:26:26 2008
> @@ -20,14 +20,16 @@
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> -import org.apache.synapse.endpoints.Endpoint;
> +import org.apache.synapse.Mediator;
> import org.apache.synapse.audit.AuditConfigurable;
> +import org.apache.synapse.core.axis2.ProxyService;
> +import org.apache.synapse.endpoints.Endpoint;
>
> import java.util.HashMap;
> import java.util.Map;
>
> /**
> - *
> + * Holds a record for statistics for current message
>  */
> public class StatisticsRecord {
>
> @@ -38,8 +40,6 @@
>             new HashMap<String, StatisticsLog>();
>     private final Map<String, StatisticsLog>  
> mediatorsStatisticsRecordMap =
>             new HashMap<String, StatisticsLog>();
> -    private final Map<String, StatisticsLog>  
> sequencesStatisticsRecordMap =
> -            new HashMap<String, StatisticsLog>();
>     private final Map<String, StatisticsLog>  
> proxyServicesStatisticsRecordMap =
>             new HashMap<String, StatisticsLog>();
>
> @@ -73,28 +73,48 @@
>         isFaultResponse = faultResponse;
>     }
>
> +    /**
> +     * Collecting statistics for a particular component
> +     *
> +     * @param auditConfigurable audit configurable component
> +     */
>     public void collect(AuditConfigurable auditConfigurable) {
> -
> +
>         if (isValid(auditConfigurable)) {
>
> -            String auditID = auditConfigurable.getAuditId();
> +            String auditID = auditConfigurable.getAuditId();
> +            if (log.isDebugEnabled()) {
> +                log.debug("Start to collect statistics for : " +  
> auditID);
> +            }
>             if (auditConfigurable instanceof Endpoint) {
>                 endPointsStatisticsRecordMap.put(auditID, new  
> StatisticsLog(auditID));
> +            } else if (auditConfigurable instanceof ProxyService) {
> +                proxyServicesStatisticsRecordMap.put(auditID, new  
> StatisticsLog(auditID));
> +            } else if (auditConfigurable instanceof Mediator) {
> +                mediatorsStatisticsRecordMap.put(auditID, new  
> StatisticsLog(auditID));
>             }
> -
>         }
>     }
>
> +    /**
> +     * Reporting statistics for a particular component
> +     *
> +     * @param auditConfigurable audit configurable component
> +     */
>     public void commit(AuditConfigurable auditConfigurable) {
>
>         if (isValid(auditConfigurable)) {
>
>             String auditID = auditConfigurable.getAuditId();
> +            if (log.isDebugEnabled()) {
> +                log.debug("Reporting statistics for : " + auditID);
> +            }
>             if (auditConfigurable instanceof Endpoint) {
> -                StatisticsLog log =  
> endPointsStatisticsRecordMap.get(auditID);
> -                if (log != null) {
> -                    log.setEndTime(System.currentTimeMillis());
> -                }
> +                commit(auditID, endPointsStatisticsRecordMap);
> +            } else if (auditConfigurable instanceof ProxyService) {
> +                commit(auditID, proxyServicesStatisticsRecordMap);
> +            } else if (auditConfigurable instanceof Mediator) {
> +                commit(auditID, mediatorsStatisticsRecordMap);
>             }
>         }
>     }
> @@ -102,17 +122,17 @@
>     private boolean isValid(AuditConfigurable auditConfigurable) {
>
>         if (auditConfigurable == null) {
> -            if(log.isDebugEnabled()){
> -                    log.debug("TODO");
> -                }
> +            if (log.isDebugEnabled()) {
> +                log.debug("Invalid audit configuration , It is  
> null.");
> +            }
>             return false;
>         }
>
>         if (auditConfigurable.isStatisticsEnable()) {
>             String auditID = auditConfigurable.getAuditId();
>             if (auditID == null || "".equals(auditID)) {
> -                if(log.isDebugEnabled()){
> -                    log.debug("TODO");
> +                if (log.isDebugEnabled()) {
> +                    log.debug("Invalid audit configuration , Audit  
> name is null.");
>                 }
>                 return false;
>             }
> @@ -120,8 +140,43 @@
>         }
>         return false;
>     }
> -
> -    public StatisticsLog getEndpointStatisticsRecord(String name){
> +
> +    private void commit(String auditID, Map<String, StatisticsLog>  
> map) {
> +        StatisticsLog log = map.get(auditID);
> +        if (log != null) {
> +            log.setEndTime(System.currentTimeMillis());
> +        }
> +    }
> +
> +    public StatisticsLog getEndpointStatisticsRecord(String name) {
>         return endPointsStatisticsRecordMap.get(name);
>     }
> +
> +    public StatisticsLog getMediatorStatisticsRecord(String name) {
> +        return mediatorsStatisticsRecordMap.get(name);
> +    }
> +
> +    public StatisticsLog getProxyServiceStatisticsRecord(String  
> name) {
> +        return proxyServicesStatisticsRecordMap.get(name);
> +    }
> +
> +    public Map<String, StatisticsLog>  
> getAllEndpointStatisticsRecords() {
> +        return endPointsStatisticsRecordMap;
> +    }
> +
> +    public Map<String, StatisticsLog>  
> getAllMediatorStatisticsRecords() {
> +        return mediatorsStatisticsRecordMap;
> +    }
> +
> +    public Map<String, StatisticsLog>  
> getAllProxyServiceStatisticsRecords() {
> +        return proxyServicesStatisticsRecordMap;
> +    }
> +
> +    public String toString() {
> +        return new StringBuffer()
> +                .append("[Message id : ").append(id).append(" ]")
> +                .append("[Remote  IP :  
> ").append(clientIP).append(" ]")
> +                .append("[Remote host :  
> ").append(clientHost).append(" ]")
> +                .toString();
> +    }
> }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/StatisticsRecordFactory.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecordFactory.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsRecordFactory.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsRecordFactory.java Wed Sep 24 12:26:26  
> 2008
> @@ -18,23 +18,36 @@
>  */
> package org.apache.synapse.audit.statatistics;
>
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> import org.apache.synapse.MessageContext;
> import org.apache.synapse.core.axis2.Axis2MessageContext;
> import org.apache.synapse.transport.nhttp.NhttpConstants;
>
> /**
> - *
> + * Factory for creating a StatisticsRecord
>  */
> public class StatisticsRecordFactory {
> -
> +
> +    private static final Log log =  
> LogFactory.getLog(StatisticsRecordFactory.class);
> +
> +    /**
> +     * Factory method to create a a StatisticsRecord
> +     *
> +     * @param synCtx Current Message through synapse
> +     * @return StatisticsRecord instance
> +     */
>     public static StatisticsRecord  
> getStatisticsRecord(MessageContext synCtx) {
> -
> +
>         String messageId = synCtx.getMessageID();
>         org.apache.axis2.context.MessageContext axisMC =  
> ((Axis2MessageContext) synCtx).getAxis2MessageContext();
>         String remoteIP = (String) axisMC.getPropertyNonReplicable(
>                 org.apache.axis2.context.MessageContext.REMOTE_ADDR);
>         String domainName = (String)  
> axisMC.getPropertyNonReplicable(NhttpConstants.REMOTE_HOST);
> -        return new StatisticsRecord(messageId, remoteIP, domainName);
> -
> +        StatisticsRecord statisticsRecord = new  
> StatisticsRecord(messageId, remoteIP, domainName);
> +        if (log.isDebugEnabled()) {
> +            log.debug("Created a StatisticsRecord with " +  
> statisticsRecord.toString());
> +        }
> +        return statisticsRecord;
>     }
> }
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/StatisticsReporter.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsReporter.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsReporter.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/StatisticsReporter.java Wed Sep 24 12:26:26 2008
> @@ -18,6 +18,8 @@
>  */
> package org.apache.synapse.audit.statatistics;
>
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> import org.apache.synapse.MessageContext;
> import org.apache.synapse.SynapseConstants;
> import org.apache.synapse.audit.AuditConfigurable;
> @@ -28,14 +30,22 @@
>
> public class StatisticsReporter {
>
> -    private static StatisticsRecord  
> getStatisticsRecord(MessageContext synCtx) {
> -        return (StatisticsRecord)  
> synCtx.getProperty(SynapseConstants.STATISTICS_STACK);
> -    }
> +    private static final Log log =  
> LogFactory.getLog(StatisticsReporter.class);
>
> +    /**
> +     * Initialize the audit details collection by setting a  
> AuditConfiguration
> +     *
> +     * @param synCtx            Current Message through synapse
> +     * @param auditConfigurable Instance that can be configured  
> it's audit
> +     */
>     public static void collect(MessageContext synCtx,  
> AuditConfigurable auditConfigurable) {
>
>         StatisticsRecord statisticsRecord =  
> StatisticsReporter.getStatisticsRecord(synCtx);
>         if (statisticsRecord == null) {
> +
> +            if (log.isDebugEnabled()) {
> +                log.debug("Setting statistics stack on the message  
> context.");
> +            }
>             statisticsRecord =  
> StatisticsRecordFactory.getStatisticsRecord(synCtx);
>             synCtx.setProperty(SynapseConstants.STATISTICS_STACK,  
> statisticsRecord);
>         }
> @@ -43,6 +53,10 @@
>
>         StatisticsCollector collector =  
> synCtx.getEnvironment().getStatisticsCollector();
>         if (collector == null) {
> +
> +            if (log.isDebugEnabled()) {
> +                log.debug("Setting statistics collector in the  
> synapse environment.");
> +            }
>             collector = new StatisticsCollector();
>             synCtx.getEnvironment().setStatisticsCollector(collector);
>         }
> @@ -51,6 +65,12 @@
>         }
>     }
>
> +    /**
> +     * Reporting audit for a particular resource
> +     *
> +     * @param synCtx            Current Message through synapse
> +     * @param auditConfigurable Instance that can be configured  
> it's audit
> +     */
>     public static void report(MessageContext synCtx,  
> AuditConfigurable auditConfigurable) {
>
>         StatisticsRecord statisticsRecord =  
> StatisticsReporter.getStatisticsRecord(synCtx);
> @@ -59,10 +79,23 @@
>         }
>     }
>
> +    /**
> +     * Reporting a fault
> +     *
> +     * @param synCtx synCtx  Current Message through synapse
> +     */
>     public static void reportFault(MessageContext synCtx) {
> +
>         StatisticsRecord statisticsRecord =  
> StatisticsReporter.getStatisticsRecord(synCtx);
>         if (statisticsRecord != null) {
> +            if (log.isDebugEnabled()) {
> +                log.debug("Reporting a fault : " + statisticsRecord);
> +            }
>             statisticsRecord.setFaultResponse(true);
>         }
>     }
> +
> +    private static StatisticsRecord  
> getStatisticsRecord(MessageContext synCtx) {
> +        return (StatisticsRecord)  
> synCtx.getProperty(SynapseConstants.STATISTICS_STACK);
> +    }
> }
>
> Added: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/view/PerUserDomainViewStrategy.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserDomainViewStrategy.java?rev=698699&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/PerUserDomainViewStrategy.java (added)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/PerUserDomainViewStrategy.java Wed Sep 24  
> 12:26:26 2008
> @@ -0,0 +1,38 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
> +
> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
> +
> +import java.util.List;
> +import java.util.Map;
> +
> +/**
> + * PerUserViewStrategy - user domain name is used.
> + */
> +public class PerUserDomainViewStrategy extends PerUserViewStrategy {
> +
> +    public Map<String, Map<String, Statistics>>  
> determineView(List<StatisticsRecord> statisticsRecords, int type) {
> +        return determineView(statisticsRecords, type, DOMAIN);
> +    }
> +
> +    public Map<String, Statistics> determineView(String id,  
> List<StatisticsRecord> statisticsRecords, int type) {
> +        return determineView(id, statisticsRecords, type, DOMAIN);
> +    }
> +}
>
> Added: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/view/PerUserIPViewStrategy.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserIPViewStrategy.java?rev=698699&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/PerUserIPViewStrategy.java (added)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/PerUserIPViewStrategy.java Wed Sep 24  
> 12:26:26 2008
> @@ -0,0 +1,38 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
> +
> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
> +
> +import java.util.List;
> +import java.util.Map;
> +
> +/**
> + * PerUserViewStrategy , user IP is used
> + */
> +public class PerUserIPViewStrategy extends PerUserViewStrategy {
> +
> +    public Map<String, Map<String, Statistics>>  
> determineView(List<StatisticsRecord> statisticsRecords, int type) {
> +        return determineView(statisticsRecords, type, IP);
> +    }
> +
> +    public Map<String, Statistics> determineView(String id,  
> List<StatisticsRecord> statisticsRecords, int type) {
> +        return determineView(id, statisticsRecords, type, IP);
> +    }
> +}
>
> Added: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/view/PerUserViewStrategy.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserViewStrategy.java?rev=698699&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/PerUserViewStrategy.java (added)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/PerUserViewStrategy.java Wed Sep 24 12:26:26  
> 2008
> @@ -0,0 +1,231 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
> +
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +import org.apache.synapse.SynapseException;
> +import org.apache.synapse.audit.statatistics.StatisticsLog;
> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
> +
> +import java.util.HashMap;
> +import java.util.List;
> +import java.util.Map;
> +
> +/**
> + * Strategy that determine a per user of remote party statistics view
> + */
> +public abstract class PerUserViewStrategy implements  
> StatisticsViewStrategy {
> +
> +    protected final static int IP = 0;
> +    protected final static int DOMAIN = 1;
> +    private static Log log;
> +
> +    protected PerUserViewStrategy() {
> +        log = LogFactory.getLog(getClass());
> +    }
> +
> +    public Map<String, Map<String, Statistics>>  
> determineView(List<StatisticsRecord> statisticsRecords, int type,  
> int userIDType) {
> +
> +        Map<String, Map<String, Statistics>> statisticsMap = new  
> HashMap<String, Map<String, Statistics>>();
> +
> +        if (statisticsRecords == null) {
> +            if (log.isDebugEnabled()) {
> +                log.debug("Statistics records cannot be found.");
> +            }
> +            return statisticsMap;
> +        }
> +
> +        for (StatisticsRecord record : statisticsRecords) {
> +
> +            if (record == null) {
> +                if (log.isDebugEnabled()) {
> +                    log.debug("Statistics record cannot be found.");
> +                }
> +                continue;
> +            }
> +
> +            Map<String, StatisticsLog> statisticsLogMap = null;
> +            switch (type) {
> +                case StatisticsLog.ENDPOINT_STATISTICS: {
> +                    statisticsLogMap =  
> record.getAllEndpointStatisticsRecords();
> +                    break;
> +                }
> +                case StatisticsLog.PROXY_SERVICE_STATISTICS: {
> +                    statisticsLogMap =  
> record.getAllProxyServiceStatisticsRecords();
> +                    break;
> +                }
> +                case StatisticsLog.MEDIATOR_STATISTICS: {
> +                    statisticsLogMap =  
> record.getAllMediatorStatisticsRecords();
> +                    break;
> +                }
> +            }
> +
> +            if (statisticsLogMap == null) {
> +                if (log.isDebugEnabled()) {
> +                    log.debug("Statistics Logs cannot be found for  
> statistics record :" + record);
> +                }
> +                continue;
> +            }
> +
> +            String userID;
> +            if (IP == userIDType) {
> +                userID = record.getClientIP();
> +            } else {
> +                userID = record.getClientHost();
> +            }
> +
> +            if (userID == null || "".equals(userID)) {
> +                if (log.isDebugEnabled()) {
> +                    log.debug("user ID cannot be found.");
> +                }
> +                continue;
> +            }
> +
> +            Map<String, Statistics> perResourceMap;
> +            if (statisticsMap.containsKey(userID)) {
> +                perResourceMap = statisticsMap.get(userID);
> +            } else {
> +                perResourceMap = new HashMap<String, Statistics>();
> +                statisticsMap.put(userID, perResourceMap);
> +            }
> +
> +            if (perResourceMap == null) {
> +                if (log.isDebugEnabled()) {
> +                    log.debug("There are not statistics for user  
> ID : " + userID);
> +                }
> +                continue;
> +            }
> +
> +            for (String rName : statisticsLogMap.keySet()) {
> +
> +                if (rName == null) {
> +                    if (log.isDebugEnabled()) {
> +                        log.debug("Resource name cannot be found.");
> +                    }
> +                    continue;
> +                }
> +
> +                StatisticsLog statisticsLog =  
> statisticsLogMap.get(rName);
> +                if (statisticsLog == null) {
> +                    if (log.isDebugEnabled()) {
> +                        log.debug("Statistics Logs cannot be found  
> for resource with given name " + rName);
> +                    }
> +                    continue;
> +                }
> +
> +                Statistics statistics;
> +                if (!perResourceMap.containsKey(rName)) {
> +                    statistics = new Statistics(rName);
> +                    perResourceMap.put(rName, statistics);
> +                } else {
> +                    statistics = perResourceMap.get(rName);
> +                }
> +
> +                if (statistics != null) {
> +                     
> statistics.update(statisticsLog.getProcessingTime(),  
> record.isFaultResponse());
> +                }
> +            }
> +        }
> +
> +        return statisticsMap;
> +
> +    }
> +
> +    public Map<String, Statistics> determineView(String id,  
> List<StatisticsRecord> statisticsRecords, int type, int userIDType) {
> +
> +        if (id == null || "".equals(id)) {
> +            handleException("Resource Id cannot be null");
> +        }
> +
> +        Map<String, Statistics> statisticsMap = new HashMap<String,  
> Statistics>();
> +
> +        if (statisticsRecords == null) {
> +            if (log.isDebugEnabled()) {
> +                log.debug("Statistics records cannot be found.");
> +            }
> +            return statisticsMap;
> +        }
> +
> +        for (StatisticsRecord record : statisticsRecords) {
> +
> +            if (record == null) {
> +                if (log.isDebugEnabled()) {
> +                    log.debug("Statistics record cannot be found.");
> +                }
> +                continue;
> +            }
> +
> +            StatisticsLog statisticsLog = null;
> +            switch (type) {
> +                case StatisticsLog.ENDPOINT_STATISTICS: {
> +                    statisticsLog =  
> record.getEndpointStatisticsRecord(id);
> +                    break;
> +                }
> +                case StatisticsLog.PROXY_SERVICE_STATISTICS: {
> +                    statisticsLog =  
> record.getProxyServiceStatisticsRecord(id);
> +                    break;
> +                }
> +                case StatisticsLog.MEDIATOR_STATISTICS: {
> +                    statisticsLog =  
> record.getMediatorStatisticsRecord(id);
> +                    break;
> +                }
> +            }
> +
> +            if (statisticsLog == null) {
> +                if (log.isDebugEnabled()) {
> +                    log.debug("Statistics Logs cannot be found for  
> statistics record  " + record);
> +                }
> +                continue;
> +            }
> +
> +            String userID;
> +            if (IP == userIDType) {
> +                userID = record.getClientIP();
> +            } else {
> +                userID = record.getClientHost();
> +            }
> +
> +            if (userID == null || "".equals(userID)) {
> +                if (log.isDebugEnabled()) {
> +                    log.debug("user ID cannot be found.");
> +                }
> +                continue;
> +            }
> +
> +            Statistics statistics;
> +            if (statisticsMap.containsKey(userID)) {
> +                statistics = statisticsMap.get(userID);
> +            } else {
> +                statistics = new Statistics(userID);
> +                statisticsMap.put(userID, statistics);
> +            }
> +
> +            if (statistics != null) {
> +                 
> statistics.update(statisticsLog.getProcessingTime(),  
> record.isFaultResponse());
> +            }
> +        }
> +        return statisticsMap;
> +    }
> +
> +    private static void handleException(String msg) {
> +        log.error(msg);
> +        throw new SynapseException(msg);
> +    }
> +}
>
> Copied: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/view/Statistics.java (from r698269,  
> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/Statistics.java)
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/Statistics.java?p2=synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/Statistics.java&p1=synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/Statistics.java&r1=698269&r2=698699&rev=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/Statistics.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/Statistics.java Wed Sep 24 12:26:26 2008
> @@ -16,7 +16,7 @@
>  *  specific language governing permissions and limitations
>  *  under the License.
>  */
> -package org.apache.synapse.audit.statatistics;
> +package org.apache.synapse.audit.statatistics.view;
>
> /**
>  * The statistics data structure
> @@ -24,25 +24,46 @@
>
> public class Statistics {
>
> -    /**  Maximum processing time for a one way flow  */
> +    public static final String ALL = "all";
> +
> +    /**
> +     * Maximum processing time for a one way flow
> +     */
>     private long maxProcessingTime = 0;
> -    /** Minimum processing time for a one way flow   */
> +    /**
> +     * Minimum processing time for a one way flow
> +     */
>     private long minProcessingTime = -1;
> -    /** Average processing time for a one way flow */
> +    /**
> +     * Average processing time for a one way flow
> +     */
>     private double avgProcessingTime = 0;
> -    /** Total processing time for a one way flow  */
> +    /**
> +     * Total processing time for a one way flow
> +     */
>     private double totalProcessingTime;
> -    /** The number of access count for a one way flow  */
> +    /**
> +     * The number of access count for a one way flow
> +     */
>     private int count = 0;
> -    /** The number of fault count for a one way flow  */
> +    /**
> +     * The number of fault count for a one way flow
> +     */
>     private int faultCount = 0;
> +    /**
> +     * Identifier for this statistics , whose statistics
> +     */
> +    private String id;
> +
> +    public Statistics(String id) {
> +        this.id = id;
> +    }
>
>     /**
>      * Update the statistics
>      *
> -     *
>      * @param currentProcessingTime - The processing end time
> -     * @param isFault - A boolean value that indicate whether fault  
> has occurred or not
> +     * @param isFault               - A Boolean value that indicate  
> whether fault has occurred or not
>      */
>     public void update(long currentProcessingTime, boolean isFault) {
>
> @@ -103,17 +124,21 @@
>         return count;
>     }
>
> +    public String getId() {
> +        return id;
> +    }
> +
> +    public void setId(String id) {
> +        this.id = id;
> +    }
> +
>     public String toString() {
> -        return new StringBuffer().append(" Avg Processing Time : ").
> -                append(avgProcessingTime)
> -                .append(" Max Processing Time : ").
> -                append(maxProcessingTime)
> -                .append(" Min Processing Time : ").
> -                append(minProcessingTime)
> -                .append(" Total Request Count : ").
> -                append(count)
> -                .append(" Total Fault Response Count : ").
> -                append(faultCount).
> -                toString();
> +        return new StringBuffer().append("[Avg Processing Time :  
> ").append(avgProcessingTime).append(" ]")
> +                .append(" [Max Processing Time :  
> ").append(maxProcessingTime).append(" ]")
> +                .append(" [Min Processing Time :  
> ").append(minProcessingTime).append(" ]")
> +                .append(" [Total Request Count :  
> ").append(count).append(" ]")
> +                .append(" [Total Fault Response Count :  
> ").append(faultCount).append(" ]")
> +                .toString();
>     }
> +
> }
>
> Added: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/view/StatisticsViewStrategy.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/StatisticsViewStrategy.java?rev=698699&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/StatisticsViewStrategy.java (added)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/StatisticsViewStrategy.java Wed Sep 24  
> 12:26:26 2008
> @@ -0,0 +1,49 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
> +
> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
> +
> +import java.util.List;
> +import java.util.Map;
> +
> +/**
> + * Strategy for determine Statistics Views
> + */
> +public interface StatisticsViewStrategy {
> +
> +    /**
> +     * Return a statistics view for all resource with given type
> +     *
> +     * @param statisticsRecords Statistics Data
> +     * @param type              Type of resource
> +     * @return A particular statistics view
> +     */
> +    public Map<String, Map<String, Statistics>>  
> determineView(List<StatisticsRecord> statisticsRecords, int type);
> +
> +    /**
> +     * Return a statistics view for a resource with given type and  
> given name
> +     *
> +     * @param id                The resource name or identifier
> +     * @param statisticsRecords Statistics Data
> +     * @param type              Type of resource
> +     * @return A particular statistics view
> +     */
> +    public Map<String, Statistics> determineView(String id,  
> List<StatisticsRecord> statisticsRecords, int type);
> +}
>
> Added: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/audit/statatistics/view/SystemViewStrategy.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/SystemViewStrategy.java?rev=698699&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/SystemViewStrategy.java (added)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> audit/statatistics/view/SystemViewStrategy.java Wed Sep 24 12:26:26  
> 2008
> @@ -0,0 +1,168 @@
> +/*
> + *  Licensed to the Apache Software Foundation (ASF) under one
> + *  or more contributor license agreements.  See the NOTICE file
> + *  distributed with this work for additional information
> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
> +
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +import org.apache.synapse.SynapseException;
> +import org.apache.synapse.audit.statatistics.StatisticsLog;
> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
> +
> +import java.util.HashMap;
> +import java.util.List;
> +import java.util.Map;
> +
> +/**
> + * Strategy that determine a system wide statistics view
> + */
> +public class SystemViewStrategy implements StatisticsViewStrategy {
> +
> +    private static final Log log =  
> LogFactory.getLog(SystemViewStrategy.class);
> +
> +    public Map<String, Map<String, Statistics>>  
> determineView(List<StatisticsRecord> statisticsRecords, int type) {
> +
> +        Map<String, Map<String, Statistics>> statisticsMap = new  
> HashMap<String, Map<String, Statistics>>();
> +        if (statisticsRecords == null) {
> +            if (log.isDebugEnabled()) {
> +                log.debug("Statistics records cannot be found.");
> +            }
> +            return statisticsMap;
> +        }
> +
> +        Map<String, Statistics> perResourceMap = new  
> HashMap<String, Statistics>();
> +
> +        for (StatisticsRecord record : statisticsRecords) {
> +
> +            if (record != null) {
> +
> +                Map<String, StatisticsLog> statisticsLogMap = null;
> +
> +                switch (type) {
> +                    case StatisticsLog.ENDPOINT_STATISTICS: {
> +                        statisticsLogMap =  
> record.getAllEndpointStatisticsRecords();
> +                        break;
> +                    }
> +                    case StatisticsLog.PROXY_SERVICE_STATISTICS: {
> +                        statisticsLogMap =  
> record.getAllProxyServiceStatisticsRecords();
> +                        break;
> +                    }
> +                    case StatisticsLog.MEDIATOR_STATISTICS: {
> +                        statisticsLogMap =  
> record.getAllMediatorStatisticsRecords();
> +                        break;
> +                    }
> +                }
> +
> +                if (statisticsLogMap == null) {
> +                    if (log.isDebugEnabled()) {
> +                        log.debug("Cannot find the statistics logs  
> for : " + record);
> +                    }
> +                    continue;
> +                }
> +
> +                for (String rName : statisticsLogMap.keySet()) {
> +
> +                    if (rName == null) {
> +                        if (log.isDebugEnabled()) {
> +                            log.debug("Cannot find the resource  
> name ");
> +                        }
> +                        continue;
> +                    }
> +
> +                    StatisticsLog statisticsLog =  
> statisticsLogMap.get(rName);
> +                    if (statisticsLog == null) {
> +                        if (log.isDebugEnabled()) {
> +                            log.debug("Cannot find the statistics  
> log for resource with name : " + rName);
> +                        }
> +                        continue;
> +                    }
> +
> +                    Statistics statistics;
> +
> +                    if (!perResourceMap.containsKey(rName)) {
> +
> +                        statistics = new Statistics(rName);
> +                        perResourceMap.put(rName, statistics);
> +
> +                    } else {
> +                        statistics = perResourceMap.get(rName);
> +                    }
> +
> +                    if (statistics != null) {
> +                         
> statistics.update(statisticsLog.getProcessingTime(),  
> record.isFaultResponse());
> +                    }
> +                }
> +            }
> +
> +        }
> +
> +        statisticsMap.put(Statistics.ALL, perResourceMap);
> +        return statisticsMap;
> +
> +    }
> +
> +    public Map<String, Statistics> determineView(String id,  
> List<StatisticsRecord> statisticsRecords, int type) {
> +
> +        if (id == null || "".equals(id)) {
> +            handleException("Resource Id cannot be null");
> +        }
> +
> +        Map<String, Statistics> statisticsMap = new HashMap<String,  
> Statistics>();
> +        if (statisticsRecords == null) {
> +            if (log.isDebugEnabled()) {
> +                log.debug("Statistics records cannot be found.");
> +            }
> +            return statisticsMap;
> +        }
> +
> +        Statistics statistics = new Statistics(Statistics.ALL);
> +        for (StatisticsRecord record : statisticsRecords) {
> +
> +            if (record != null) {
> +                StatisticsLog log = null;
> +
> +                switch (type) {
> +                    case StatisticsLog.ENDPOINT_STATISTICS: {
> +                        log = record.getEndpointStatisticsRecord(id);
> +                        break;
> +                    }
> +                    case StatisticsLog.PROXY_SERVICE_STATISTICS: {
> +                        log =  
> record.getProxyServiceStatisticsRecord(id);
> +                        break;
> +                    }
> +                    case StatisticsLog.MEDIATOR_STATISTICS: {
> +                        log = record.getMediatorStatisticsRecord(id);
> +                        break;
> +                    }
> +                }
> +
> +                if (log != null) {
> +                    statistics.update(log.getProcessingTime(),  
> record.isFaultResponse());
> +                }
> +            }
> +        }
> +
> +        statisticsMap.put(Statistics.ALL, statistics);
> +        return statisticsMap;
> +    }
> +
> +    private static void handleException(String msg) {
> +        log.error(msg);
> +        throw new SynapseException(msg);
> +    }
> +}
>
> Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/ 
> synapse/core/axis2/Axis2MessageContext.java
> URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java?rev=698699&r1=698698&r2=698699&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> core/axis2/Axis2MessageContext.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ 
> core/axis2/Axis2MessageContext.java Wed Sep 24 12:26:26 2008
> @@ -483,9 +483,9 @@
>     private void initAudit(MessageContext synCtx) {
>
>         if (XMLConfigConstants.STATISTICS_ENABLE.equals(
> -                 
> synCtx 
> .getConfiguration 
> ().getProperty(SynapseConstants.SYNAPSE_STATISTICS_STATE))) {
> +                 
> synCtx 
> .getConfiguration 
> ().getProperty(SynapseConstants.SYNAPSE_AUDIT_STATE))) {
>              
> synCtx.setProperty(SynapseConstants.SYNAPSE_AUDIT_CONFIGURATION,
> -                    new  
> AuditConfiguration(SynapseConstants.SYNAPSE_STATISTICS, true));
> +                    new  
> AuditConfiguration(SynapseConstants.SYNAPSE_AUDIT, true));
>         }
>     }
> }
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
For additional commands, e-mail: dev-help@synapse.apache.org


Re: svn commit: r698699 - in /synapse/trunk/java/modules/core/src/main/java/org/apache/synapse: ./ audit/ audit/statatistics/ audit/statatistics/view/ core/axis2/

Posted by indika kumara <in...@gmail.com>.
Thanks Andreas , I correct the mistake.

Thanks
Indika

On Thu, Sep 25, 2008 at 1:08 AM, Andreas Veithen
<an...@skynet.be> wrote:
> I guess the package name should have "statistics" instead of "statatistics"
> :-)
>
> Andreas
>
> On 24 sept. 08, at 21:26, indika@apache.org wrote:
>
>> Author: indika
>> Date: Wed Sep 24 12:26:26 2008
>> New Revision: 698699
>>
>> URL: http://svn.apache.org/viewvc?rev=698699&view=rev
>> Log:
>> add in memory statisc view
>> Add more logs and comments for statistics
>>
>> Added:
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserDomainViewStrategy.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserIPViewStrategy.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserViewStrategy.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/Statistics.java
>>     - copied, changed from r698269,
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/Statistics.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/StatisticsViewStrategy.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/SystemViewStrategy.java
>> Removed:
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/Statistics.java
>> Modified:
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfigurable.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfiguration.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditHelper.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsCollector.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsLog.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecord.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecordFactory.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsReporter.java
>>
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
>> Wed Sep 24 12:26:26 2008
>> @@ -166,11 +166,11 @@
>>
>>        public static final String STATISTICS_STACK
>> ="synapse.statistics.stack";
>>
>> -        public static final String SYNAPSE_STATISTICS_STATE =
>> "synapse.statistics.state";
>> +        public static final String SYNAPSE_AUDIT_STATE =
>> "synapse.audit.state";
>>
>>        public static final String SYNAPSE_AUDIT_CONFIGURATION =
>> "synapse.audit.configuration";
>>
>> -        public static final String SYNAPSE_STATISTICS
>> ="synapse.statistics";
>> +        public static final String SYNAPSE_AUDIT ="synapse.audit";
>>
>>    //- handling of timed out events from the callbacks -
>>        /** The System property that states the duration at which the
>> timeout handler runs */
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfigurable.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfigurable.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfigurable.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfigurable.java
>> Wed Sep 24 12:26:26 2008
>> @@ -19,13 +19,39 @@
>> package org.apache.synapse.audit;
>>
>> /**
>> - *
>> + * Capability for configurable auditing
>>  */
>> public interface AuditConfigurable {
>> -
>> -    public String getAuditId();
>> -    public void setAuditId(String id);
>> +
>> +    /**
>> +     * Returns audit id , identifier for a particular audit
>> +     * Example , component name , endpoint name
>> +     *
>> +     * @return audit id
>> +     */
>> +    public String getAuditId();
>> +
>> +    /**
>> +     * Sets the identifier for a particular audit
>> +     *
>> +     * @param id audit id
>> +     */
>> +    public void setAuditId(String id);
>> +
>> +    /**
>> +     * Whether statistics has been enabled
>> +     *
>> +     * @return True if enable , o.w , false
>> +     */
>>    public boolean isStatisticsEnable();
>> +
>> +    /**
>> +     * To disable statistics
>> +     */
>>    public void disableStatistics();
>> +
>> +    /**
>> +     * To enable statistics
>> +     */
>>    public void enableStatistics();
>> }
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfiguration.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfiguration.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfiguration.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditConfiguration.java
>> Wed Sep 24 12:26:26 2008
>> @@ -19,20 +19,23 @@
>> package org.apache.synapse.audit;
>>
>> /**
>> - *
>> + * Audit configuration
>> + * Currently contains only statistics configuration related things
>>  */
>> public class AuditConfiguration implements AuditConfigurable {
>>
>> +    /* Whether statistics enable */
>>    private boolean statisticsEnable = false;
>> -    private String AuditId;
>> +    /* Identifier for a particular audit configuration */
>> +    private String auditId;
>>
>>    public AuditConfiguration(String auditId, boolean statisticsEnable) {
>>        this.statisticsEnable = statisticsEnable;
>> -        AuditId = auditId;
>> +        this.auditId = auditId;
>>    }
>>
>>    public AuditConfiguration(String auditId) {
>> -        AuditId = auditId;
>> +        this.auditId = auditId;
>>    }
>>
>>    public boolean isStatisticsEnable() {
>> @@ -40,24 +43,22 @@
>>    }
>>
>>    public void disableStatistics() {
>> -
>>        if (statisticsEnable) {
>>            this.statisticsEnable = false;
>>        }
>>    }
>>
>>    public void enableStatistics() {
>> -
>>        if (!statisticsEnable) {
>>            statisticsEnable = true;
>>        }
>>    }
>>
>>    public String getAuditId() {
>> -        return AuditId;
>> +        return auditId;
>>    }
>>
>>    public void setAuditId(String auditId) {
>> -        AuditId = auditId;
>> +        this.auditId = auditId;
>>    }
>> }
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditHelper.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditHelper.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditHelper.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/AuditHelper.java
>> Wed Sep 24 12:26:26 2008
>> @@ -18,32 +18,57 @@
>>  */
>> package org.apache.synapse.audit;
>>
>> +import org.apache.commons.logging.Log;
>> +import org.apache.commons.logging.LogFactory;
>> import org.apache.synapse.MessageContext;
>> import org.apache.synapse.SynapseConstants;
>> import org.apache.synapse.audit.statatistics.StatisticsReporter;
>> import org.apache.synapse.config.xml.XMLConfigConstants;
>>
>> /**
>> - *
>> + * Contains helper methods required for auditing.
>> + * This class need to evolved as any audit related things are adding
>>  */
>> public class AuditHelper {
>>
>> +    private static final Log log = LogFactory.getLog(AuditHelper.class);
>> +
>> +    /**
>> +     * Sets the Global audit configuration if it has been forced by
>> setting
>> +     *
>> +     * @param synCtx Current Message through synapse
>> +     */
>>    public static void setGlobalAudit(MessageContext synCtx) {
>>
>>        if (XMLConfigConstants.STATISTICS_ENABLE.equals(
>> -
>>  synCtx.getConfiguration().getProperty(SynapseConstants.SYNAPSE_STATISTICS_STATE)))
>> {
>> -            AuditConfigurable auditConfigurable = new
>> AuditConfiguration(SynapseConstants.SYNAPSE_STATISTICS, true);
>> +
>>  synCtx.getConfiguration().getProperty(SynapseConstants.SYNAPSE_AUDIT_STATE)))
>> {
>> +
>> +            AuditConfigurable auditConfigurable = new
>> AuditConfiguration(SynapseConstants.SYNAPSE_AUDIT, true);
>> +
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Global Audit is enabled. System-wide auditing
>> will be occurred.");
>> +            }
>> +
>>            StatisticsReporter.collect(synCtx, auditConfigurable);
>>
>>  synCtx.setProperty(SynapseConstants.SYNAPSE_AUDIT_CONFIGURATION,
>>                    auditConfigurable);
>>        }
>>    }
>>
>> +    /**
>> +     * Report Global audit for this message
>> +     *
>> +     * @param synCtx Current Message through synapse
>> +     */
>>    public static void reportGlobalAudit(MessageContext synCtx) {
>> -
>> +
>>        AuditConfigurable auditConfigurable = (AuditConfigurable)
>> synCtx.getProperty(
>>                SynapseConstants.SYNAPSE_AUDIT_CONFIGURATION);
>> +
>>        if (auditConfigurable != null) {
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("System-wide audit record is reported.");
>> +            }
>>            StatisticsReporter.report(synCtx, auditConfigurable);
>>        }
>>    }
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsCollector.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsCollector.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsCollector.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsCollector.java
>> Wed Sep 24 12:26:26 2008
>> @@ -18,35 +18,61 @@
>>  */
>> package org.apache.synapse.audit.statatistics;
>>
>> +import org.apache.synapse.audit.statatistics.view.Statistics;
>> +import org.apache.synapse.audit.statatistics.view.StatisticsViewStrategy;
>> +
>> import java.util.ArrayList;
>> import java.util.List;
>> +import java.util.Map;
>>
>> /**
>> - * To collect statistics
>> + * Collects statistics and provides those collected data
>>  */
>>
>> public class StatisticsCollector {
>>
>>    private final List<StatisticsRecord> statisticsCollection = new
>> ArrayList<StatisticsRecord>();
>>
>> -    public void collect(StatisticsRecord statisticsRegistry) {
>> -        this.statisticsCollection.add(statisticsRegistry);
>> -    }
>> -
>> -    public Statistics getEndpointStatistics(String id) {
>> -        Statistics statistics = new Statistics();
>> -        for (StatisticsRecord statisticsRegistry : statisticsCollection)
>> {
>> -            if (statisticsRegistry != null) {
>> -                StatisticsLog log =
>> statisticsRegistry.getEndpointStatisticsRecord(id);
>> -                if (log != null) {
>> -                    statistics.update(log.getProcessingTime(),
>> statisticsRegistry.isFaultResponse());
>> -                }
>> -            }
>> -        }
>> -        return statistics;
>> +    /**
>> +     * Registering a statistics record
>> +     *
>> +     * @param statisticsRecord statistics record instance
>> +     */
>> +    public void collect(StatisticsRecord statisticsRecord) {
>> +        this.statisticsCollection.add(statisticsRecord);
>>    }
>>
>> +    /**
>> +     * Check whether given statistics record has  already been registered
>> +     *
>> +     * @param statisticsRecord statisticsRecord statistics record
>> instance
>> +     * @return True if there
>> +     */
>>    public boolean contains(StatisticsRecord statisticsRecord) {
>>        return statisticsCollection.contains(statisticsRecord);
>>    }
>> +
>> +    /**
>> +     * Returns a particular statistics view according to a given strategy
>> for a given resource with particular type
>> +     *
>> +     * @param id       Resource id
>> +     * @param type     Type of the resource
>> +     * @param strategy Statistics viewing strategy
>> +     * @return Statistics view
>> +     */
>> +    public Map<String, Statistics> getStatistics(String id, int type,
>> StatisticsViewStrategy strategy) {
>> +        return strategy.determineView(id, statisticsCollection, type);
>> +    }
>> +
>> +    /**
>> +     * Returns a particular statistics view according to a given strategy
>> for a given resource type
>> +     *
>> +     * @param type     type Type of the resource
>> +     * @param strategy strategy Statistics viewing strategy
>> +     * @return Statistics view
>> +     */
>> +    public Map<String, Map<String, Statistics>> getStatistics(int type,
>> StatisticsViewStrategy strategy) {
>> +        return strategy.determineView(statisticsCollection, type);
>> +    }
>> +
>> }
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsLog.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsLog.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsLog.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsLog.java
>> Wed Sep 24 12:26:26 2008
>> @@ -19,12 +19,18 @@
>> package org.apache.synapse.audit.statatistics;
>>
>> /**
>> - *
>> + *
>>  */
>> public class StatisticsLog {
>> -
>> -    private String id ;
>> -    private long startTime =-1;
>> +
>> +    public static final int ENDPOINT_STATISTICS = 0;
>> +
>> +    public static final int PROXY_SERVICE_STATISTICS = 1;
>> +
>> +    public static final int MEDIATOR_STATISTICS = 2;
>> +
>> +    private String id;
>> +    private long startTime = -1;
>>    private long endTime = -1;
>>
>>    public StatisticsLog(String id) {
>> @@ -59,8 +65,8 @@
>>    public void setEndTime(long endTime) {
>>        this.endTime = endTime;
>>    }
>> -
>> -    public long getProcessingTime(){
>> +
>> +    public long getProcessingTime() {
>>        return this.endTime - this.startTime;
>>    }
>> }
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecord.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecord.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecord.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecord.java
>> Wed Sep 24 12:26:26 2008
>> @@ -20,14 +20,16 @@
>>
>> import org.apache.commons.logging.Log;
>> import org.apache.commons.logging.LogFactory;
>> -import org.apache.synapse.endpoints.Endpoint;
>> +import org.apache.synapse.Mediator;
>> import org.apache.synapse.audit.AuditConfigurable;
>> +import org.apache.synapse.core.axis2.ProxyService;
>> +import org.apache.synapse.endpoints.Endpoint;
>>
>> import java.util.HashMap;
>> import java.util.Map;
>>
>> /**
>> - *
>> + * Holds a record for statistics for current message
>>  */
>> public class StatisticsRecord {
>>
>> @@ -38,8 +40,6 @@
>>            new HashMap<String, StatisticsLog>();
>>    private final Map<String, StatisticsLog> mediatorsStatisticsRecordMap =
>>            new HashMap<String, StatisticsLog>();
>> -    private final Map<String, StatisticsLog> sequencesStatisticsRecordMap
>> =
>> -            new HashMap<String, StatisticsLog>();
>>    private final Map<String, StatisticsLog>
>> proxyServicesStatisticsRecordMap =
>>            new HashMap<String, StatisticsLog>();
>>
>> @@ -73,28 +73,48 @@
>>        isFaultResponse = faultResponse;
>>    }
>>
>> +    /**
>> +     * Collecting statistics for a particular component
>> +     *
>> +     * @param auditConfigurable audit configurable component
>> +     */
>>    public void collect(AuditConfigurable auditConfigurable) {
>> -
>> +
>>        if (isValid(auditConfigurable)) {
>>
>> -            String auditID = auditConfigurable.getAuditId();
>> +            String auditID = auditConfigurable.getAuditId();
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Start to collect statistics for : " +
>> auditID);
>> +            }
>>            if (auditConfigurable instanceof Endpoint) {
>>                endPointsStatisticsRecordMap.put(auditID, new
>> StatisticsLog(auditID));
>> +            } else if (auditConfigurable instanceof ProxyService) {
>> +                proxyServicesStatisticsRecordMap.put(auditID, new
>> StatisticsLog(auditID));
>> +            } else if (auditConfigurable instanceof Mediator) {
>> +                mediatorsStatisticsRecordMap.put(auditID, new
>> StatisticsLog(auditID));
>>            }
>> -
>>        }
>>    }
>>
>> +    /**
>> +     * Reporting statistics for a particular component
>> +     *
>> +     * @param auditConfigurable audit configurable component
>> +     */
>>    public void commit(AuditConfigurable auditConfigurable) {
>>
>>        if (isValid(auditConfigurable)) {
>>
>>            String auditID = auditConfigurable.getAuditId();
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Reporting statistics for : " + auditID);
>> +            }
>>            if (auditConfigurable instanceof Endpoint) {
>> -                StatisticsLog log =
>> endPointsStatisticsRecordMap.get(auditID);
>> -                if (log != null) {
>> -                    log.setEndTime(System.currentTimeMillis());
>> -                }
>> +                commit(auditID, endPointsStatisticsRecordMap);
>> +            } else if (auditConfigurable instanceof ProxyService) {
>> +                commit(auditID, proxyServicesStatisticsRecordMap);
>> +            } else if (auditConfigurable instanceof Mediator) {
>> +                commit(auditID, mediatorsStatisticsRecordMap);
>>            }
>>        }
>>    }
>> @@ -102,17 +122,17 @@
>>    private boolean isValid(AuditConfigurable auditConfigurable) {
>>
>>        if (auditConfigurable == null) {
>> -            if(log.isDebugEnabled()){
>> -                    log.debug("TODO");
>> -                }
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Invalid audit configuration , It is null.");
>> +            }
>>            return false;
>>        }
>>
>>        if (auditConfigurable.isStatisticsEnable()) {
>>            String auditID = auditConfigurable.getAuditId();
>>            if (auditID == null || "".equals(auditID)) {
>> -                if(log.isDebugEnabled()){
>> -                    log.debug("TODO");
>> +                if (log.isDebugEnabled()) {
>> +                    log.debug("Invalid audit configuration , Audit name
>> is null.");
>>                }
>>                return false;
>>            }
>> @@ -120,8 +140,43 @@
>>        }
>>        return false;
>>    }
>> -
>> -    public StatisticsLog getEndpointStatisticsRecord(String name){
>> +
>> +    private void commit(String auditID, Map<String, StatisticsLog> map) {
>> +        StatisticsLog log = map.get(auditID);
>> +        if (log != null) {
>> +            log.setEndTime(System.currentTimeMillis());
>> +        }
>> +    }
>> +
>> +    public StatisticsLog getEndpointStatisticsRecord(String name) {
>>        return endPointsStatisticsRecordMap.get(name);
>>    }
>> +
>> +    public StatisticsLog getMediatorStatisticsRecord(String name) {
>> +        return mediatorsStatisticsRecordMap.get(name);
>> +    }
>> +
>> +    public StatisticsLog getProxyServiceStatisticsRecord(String name) {
>> +        return proxyServicesStatisticsRecordMap.get(name);
>> +    }
>> +
>> +    public Map<String, StatisticsLog> getAllEndpointStatisticsRecords() {
>> +        return endPointsStatisticsRecordMap;
>> +    }
>> +
>> +    public Map<String, StatisticsLog> getAllMediatorStatisticsRecords() {
>> +        return mediatorsStatisticsRecordMap;
>> +    }
>> +
>> +    public Map<String, StatisticsLog>
>> getAllProxyServiceStatisticsRecords() {
>> +        return proxyServicesStatisticsRecordMap;
>> +    }
>> +
>> +    public String toString() {
>> +        return new StringBuffer()
>> +                .append("[Message id : ").append(id).append(" ]")
>> +                .append("[Remote  IP : ").append(clientIP).append(" ]")
>> +                .append("[Remote host : ").append(clientHost).append("
>> ]")
>> +                .toString();
>> +    }
>> }
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecordFactory.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecordFactory.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecordFactory.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsRecordFactory.java
>> Wed Sep 24 12:26:26 2008
>> @@ -18,23 +18,36 @@
>>  */
>> package org.apache.synapse.audit.statatistics;
>>
>> +import org.apache.commons.logging.Log;
>> +import org.apache.commons.logging.LogFactory;
>> import org.apache.synapse.MessageContext;
>> import org.apache.synapse.core.axis2.Axis2MessageContext;
>> import org.apache.synapse.transport.nhttp.NhttpConstants;
>>
>> /**
>> - *
>> + * Factory for creating a StatisticsRecord
>>  */
>> public class StatisticsRecordFactory {
>> -
>> +
>> +    private static final Log log =
>> LogFactory.getLog(StatisticsRecordFactory.class);
>> +
>> +    /**
>> +     * Factory method to create a a StatisticsRecord
>> +     *
>> +     * @param synCtx Current Message through synapse
>> +     * @return StatisticsRecord instance
>> +     */
>>    public static StatisticsRecord getStatisticsRecord(MessageContext
>> synCtx) {
>> -
>> +
>>        String messageId = synCtx.getMessageID();
>>        org.apache.axis2.context.MessageContext axisMC =
>> ((Axis2MessageContext) synCtx).getAxis2MessageContext();
>>        String remoteIP = (String) axisMC.getPropertyNonReplicable(
>>                org.apache.axis2.context.MessageContext.REMOTE_ADDR);
>>        String domainName = (String)
>> axisMC.getPropertyNonReplicable(NhttpConstants.REMOTE_HOST);
>> -        return new StatisticsRecord(messageId, remoteIP, domainName);
>> -
>> +        StatisticsRecord statisticsRecord = new
>> StatisticsRecord(messageId, remoteIP, domainName);
>> +        if (log.isDebugEnabled()) {
>> +            log.debug("Created a StatisticsRecord with " +
>> statisticsRecord.toString());
>> +        }
>> +        return statisticsRecord;
>>    }
>> }
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsReporter.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsReporter.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsReporter.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/StatisticsReporter.java
>> Wed Sep 24 12:26:26 2008
>> @@ -18,6 +18,8 @@
>>  */
>> package org.apache.synapse.audit.statatistics;
>>
>> +import org.apache.commons.logging.Log;
>> +import org.apache.commons.logging.LogFactory;
>> import org.apache.synapse.MessageContext;
>> import org.apache.synapse.SynapseConstants;
>> import org.apache.synapse.audit.AuditConfigurable;
>> @@ -28,14 +30,22 @@
>>
>> public class StatisticsReporter {
>>
>> -    private static StatisticsRecord getStatisticsRecord(MessageContext
>> synCtx) {
>> -        return (StatisticsRecord)
>> synCtx.getProperty(SynapseConstants.STATISTICS_STACK);
>> -    }
>> +    private static final Log log =
>> LogFactory.getLog(StatisticsReporter.class);
>>
>> +    /**
>> +     * Initialize the audit details collection by setting a
>> AuditConfiguration
>> +     *
>> +     * @param synCtx            Current Message through synapse
>> +     * @param auditConfigurable Instance that can be configured it's
>> audit
>> +     */
>>    public static void collect(MessageContext synCtx, AuditConfigurable
>> auditConfigurable) {
>>
>>        StatisticsRecord statisticsRecord =
>> StatisticsReporter.getStatisticsRecord(synCtx);
>>        if (statisticsRecord == null) {
>> +
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Setting statistics stack on the message
>> context.");
>> +            }
>>            statisticsRecord =
>> StatisticsRecordFactory.getStatisticsRecord(synCtx);
>>            synCtx.setProperty(SynapseConstants.STATISTICS_STACK,
>> statisticsRecord);
>>        }
>> @@ -43,6 +53,10 @@
>>
>>        StatisticsCollector collector =
>> synCtx.getEnvironment().getStatisticsCollector();
>>        if (collector == null) {
>> +
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Setting statistics collector in the synapse
>> environment.");
>> +            }
>>            collector = new StatisticsCollector();
>>            synCtx.getEnvironment().setStatisticsCollector(collector);
>>        }
>> @@ -51,6 +65,12 @@
>>        }
>>    }
>>
>> +    /**
>> +     * Reporting audit for a particular resource
>> +     *
>> +     * @param synCtx            Current Message through synapse
>> +     * @param auditConfigurable Instance that can be configured it's
>> audit
>> +     */
>>    public static void report(MessageContext synCtx, AuditConfigurable
>> auditConfigurable) {
>>
>>        StatisticsRecord statisticsRecord =
>> StatisticsReporter.getStatisticsRecord(synCtx);
>> @@ -59,10 +79,23 @@
>>        }
>>    }
>>
>> +    /**
>> +     * Reporting a fault
>> +     *
>> +     * @param synCtx synCtx  Current Message through synapse
>> +     */
>>    public static void reportFault(MessageContext synCtx) {
>> +
>>        StatisticsRecord statisticsRecord =
>> StatisticsReporter.getStatisticsRecord(synCtx);
>>        if (statisticsRecord != null) {
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Reporting a fault : " + statisticsRecord);
>> +            }
>>            statisticsRecord.setFaultResponse(true);
>>        }
>>    }
>> +
>> +    private static StatisticsRecord getStatisticsRecord(MessageContext
>> synCtx) {
>> +        return (StatisticsRecord)
>> synCtx.getProperty(SynapseConstants.STATISTICS_STACK);
>> +    }
>> }
>>
>> Added:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserDomainViewStrategy.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserDomainViewStrategy.java?rev=698699&view=auto
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserDomainViewStrategy.java
>> (added)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserDomainViewStrategy.java
>> Wed Sep 24 12:26:26 2008
>> @@ -0,0 +1,38 @@
>> +/*
>> + *  Licensed to the Apache Software Foundation (ASF) under one
>> + *  or more contributor license agreements.  See the NOTICE file
>> + *  distributed with this work for additional information
>> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
>> +
>> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
>> +
>> +import java.util.List;
>> +import java.util.Map;
>> +
>> +/**
>> + * PerUserViewStrategy - user domain name is used.
>> + */
>> +public class PerUserDomainViewStrategy extends PerUserViewStrategy {
>> +
>> +    public Map<String, Map<String, Statistics>>
>> determineView(List<StatisticsRecord> statisticsRecords, int type) {
>> +        return determineView(statisticsRecords, type, DOMAIN);
>> +    }
>> +
>> +    public Map<String, Statistics> determineView(String id,
>> List<StatisticsRecord> statisticsRecords, int type) {
>> +        return determineView(id, statisticsRecords, type, DOMAIN);
>> +    }
>> +}
>>
>> Added:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserIPViewStrategy.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserIPViewStrategy.java?rev=698699&view=auto
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserIPViewStrategy.java
>> (added)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserIPViewStrategy.java
>> Wed Sep 24 12:26:26 2008
>> @@ -0,0 +1,38 @@
>> +/*
>> + *  Licensed to the Apache Software Foundation (ASF) under one
>> + *  or more contributor license agreements.  See the NOTICE file
>> + *  distributed with this work for additional information
>> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
>> +
>> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
>> +
>> +import java.util.List;
>> +import java.util.Map;
>> +
>> +/**
>> + * PerUserViewStrategy , user IP is used
>> + */
>> +public class PerUserIPViewStrategy extends PerUserViewStrategy {
>> +
>> +    public Map<String, Map<String, Statistics>>
>> determineView(List<StatisticsRecord> statisticsRecords, int type) {
>> +        return determineView(statisticsRecords, type, IP);
>> +    }
>> +
>> +    public Map<String, Statistics> determineView(String id,
>> List<StatisticsRecord> statisticsRecords, int type) {
>> +        return determineView(id, statisticsRecords, type, IP);
>> +    }
>> +}
>>
>> Added:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserViewStrategy.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserViewStrategy.java?rev=698699&view=auto
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserViewStrategy.java
>> (added)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/PerUserViewStrategy.java
>> Wed Sep 24 12:26:26 2008
>> @@ -0,0 +1,231 @@
>> +/*
>> + *  Licensed to the Apache Software Foundation (ASF) under one
>> + *  or more contributor license agreements.  See the NOTICE file
>> + *  distributed with this work for additional information
>> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
>> +
>> +import org.apache.commons.logging.Log;
>> +import org.apache.commons.logging.LogFactory;
>> +import org.apache.synapse.SynapseException;
>> +import org.apache.synapse.audit.statatistics.StatisticsLog;
>> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
>> +
>> +import java.util.HashMap;
>> +import java.util.List;
>> +import java.util.Map;
>> +
>> +/**
>> + * Strategy that determine a per user of remote party statistics view
>> + */
>> +public abstract class PerUserViewStrategy implements
>> StatisticsViewStrategy {
>> +
>> +    protected final static int IP = 0;
>> +    protected final static int DOMAIN = 1;
>> +    private static Log log;
>> +
>> +    protected PerUserViewStrategy() {
>> +        log = LogFactory.getLog(getClass());
>> +    }
>> +
>> +    public Map<String, Map<String, Statistics>>
>> determineView(List<StatisticsRecord> statisticsRecords, int type, int
>> userIDType) {
>> +
>> +        Map<String, Map<String, Statistics>> statisticsMap = new
>> HashMap<String, Map<String, Statistics>>();
>> +
>> +        if (statisticsRecords == null) {
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Statistics records cannot be found.");
>> +            }
>> +            return statisticsMap;
>> +        }
>> +
>> +        for (StatisticsRecord record : statisticsRecords) {
>> +
>> +            if (record == null) {
>> +                if (log.isDebugEnabled()) {
>> +                    log.debug("Statistics record cannot be found.");
>> +                }
>> +                continue;
>> +            }
>> +
>> +            Map<String, StatisticsLog> statisticsLogMap = null;
>> +            switch (type) {
>> +                case StatisticsLog.ENDPOINT_STATISTICS: {
>> +                    statisticsLogMap =
>> record.getAllEndpointStatisticsRecords();
>> +                    break;
>> +                }
>> +                case StatisticsLog.PROXY_SERVICE_STATISTICS: {
>> +                    statisticsLogMap =
>> record.getAllProxyServiceStatisticsRecords();
>> +                    break;
>> +                }
>> +                case StatisticsLog.MEDIATOR_STATISTICS: {
>> +                    statisticsLogMap =
>> record.getAllMediatorStatisticsRecords();
>> +                    break;
>> +                }
>> +            }
>> +
>> +            if (statisticsLogMap == null) {
>> +                if (log.isDebugEnabled()) {
>> +                    log.debug("Statistics Logs cannot be found for
>> statistics record :" + record);
>> +                }
>> +                continue;
>> +            }
>> +
>> +            String userID;
>> +            if (IP == userIDType) {
>> +                userID = record.getClientIP();
>> +            } else {
>> +                userID = record.getClientHost();
>> +            }
>> +
>> +            if (userID == null || "".equals(userID)) {
>> +                if (log.isDebugEnabled()) {
>> +                    log.debug("user ID cannot be found.");
>> +                }
>> +                continue;
>> +            }
>> +
>> +            Map<String, Statistics> perResourceMap;
>> +            if (statisticsMap.containsKey(userID)) {
>> +                perResourceMap = statisticsMap.get(userID);
>> +            } else {
>> +                perResourceMap = new HashMap<String, Statistics>();
>> +                statisticsMap.put(userID, perResourceMap);
>> +            }
>> +
>> +            if (perResourceMap == null) {
>> +                if (log.isDebugEnabled()) {
>> +                    log.debug("There are not statistics for user ID : " +
>> userID);
>> +                }
>> +                continue;
>> +            }
>> +
>> +            for (String rName : statisticsLogMap.keySet()) {
>> +
>> +                if (rName == null) {
>> +                    if (log.isDebugEnabled()) {
>> +                        log.debug("Resource name cannot be found.");
>> +                    }
>> +                    continue;
>> +                }
>> +
>> +                StatisticsLog statisticsLog =
>> statisticsLogMap.get(rName);
>> +                if (statisticsLog == null) {
>> +                    if (log.isDebugEnabled()) {
>> +                        log.debug("Statistics Logs cannot be found for
>> resource with given name " + rName);
>> +                    }
>> +                    continue;
>> +                }
>> +
>> +                Statistics statistics;
>> +                if (!perResourceMap.containsKey(rName)) {
>> +                    statistics = new Statistics(rName);
>> +                    perResourceMap.put(rName, statistics);
>> +                } else {
>> +                    statistics = perResourceMap.get(rName);
>> +                }
>> +
>> +                if (statistics != null) {
>> +                    statistics.update(statisticsLog.getProcessingTime(),
>> record.isFaultResponse());
>> +                }
>> +            }
>> +        }
>> +
>> +        return statisticsMap;
>> +
>> +    }
>> +
>> +    public Map<String, Statistics> determineView(String id,
>> List<StatisticsRecord> statisticsRecords, int type, int userIDType) {
>> +
>> +        if (id == null || "".equals(id)) {
>> +            handleException("Resource Id cannot be null");
>> +        }
>> +
>> +        Map<String, Statistics> statisticsMap = new HashMap<String,
>> Statistics>();
>> +
>> +        if (statisticsRecords == null) {
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Statistics records cannot be found.");
>> +            }
>> +            return statisticsMap;
>> +        }
>> +
>> +        for (StatisticsRecord record : statisticsRecords) {
>> +
>> +            if (record == null) {
>> +                if (log.isDebugEnabled()) {
>> +                    log.debug("Statistics record cannot be found.");
>> +                }
>> +                continue;
>> +            }
>> +
>> +            StatisticsLog statisticsLog = null;
>> +            switch (type) {
>> +                case StatisticsLog.ENDPOINT_STATISTICS: {
>> +                    statisticsLog =
>> record.getEndpointStatisticsRecord(id);
>> +                    break;
>> +                }
>> +                case StatisticsLog.PROXY_SERVICE_STATISTICS: {
>> +                    statisticsLog =
>> record.getProxyServiceStatisticsRecord(id);
>> +                    break;
>> +                }
>> +                case StatisticsLog.MEDIATOR_STATISTICS: {
>> +                    statisticsLog =
>> record.getMediatorStatisticsRecord(id);
>> +                    break;
>> +                }
>> +            }
>> +
>> +            if (statisticsLog == null) {
>> +                if (log.isDebugEnabled()) {
>> +                    log.debug("Statistics Logs cannot be found for
>> statistics record  " + record);
>> +                }
>> +                continue;
>> +            }
>> +
>> +            String userID;
>> +            if (IP == userIDType) {
>> +                userID = record.getClientIP();
>> +            } else {
>> +                userID = record.getClientHost();
>> +            }
>> +
>> +            if (userID == null || "".equals(userID)) {
>> +                if (log.isDebugEnabled()) {
>> +                    log.debug("user ID cannot be found.");
>> +                }
>> +                continue;
>> +            }
>> +
>> +            Statistics statistics;
>> +            if (statisticsMap.containsKey(userID)) {
>> +                statistics = statisticsMap.get(userID);
>> +            } else {
>> +                statistics = new Statistics(userID);
>> +                statisticsMap.put(userID, statistics);
>> +            }
>> +
>> +            if (statistics != null) {
>> +                statistics.update(statisticsLog.getProcessingTime(),
>> record.isFaultResponse());
>> +            }
>> +        }
>> +        return statisticsMap;
>> +    }
>> +
>> +    private static void handleException(String msg) {
>> +        log.error(msg);
>> +        throw new SynapseException(msg);
>> +    }
>> +}
>>
>> Copied:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/Statistics.java
>> (from r698269,
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/Statistics.java)
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/Statistics.java?p2=synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/Statistics.java&p1=synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/Statistics.java&r1=698269&r2=698699&rev=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/Statistics.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/Statistics.java
>> Wed Sep 24 12:26:26 2008
>> @@ -16,7 +16,7 @@
>>  *  specific language governing permissions and limitations
>>  *  under the License.
>>  */
>> -package org.apache.synapse.audit.statatistics;
>> +package org.apache.synapse.audit.statatistics.view;
>>
>> /**
>>  * The statistics data structure
>> @@ -24,25 +24,46 @@
>>
>> public class Statistics {
>>
>> -    /**  Maximum processing time for a one way flow  */
>> +    public static final String ALL = "all";
>> +
>> +    /**
>> +     * Maximum processing time for a one way flow
>> +     */
>>    private long maxProcessingTime = 0;
>> -    /** Minimum processing time for a one way flow   */
>> +    /**
>> +     * Minimum processing time for a one way flow
>> +     */
>>    private long minProcessingTime = -1;
>> -    /** Average processing time for a one way flow */
>> +    /**
>> +     * Average processing time for a one way flow
>> +     */
>>    private double avgProcessingTime = 0;
>> -    /** Total processing time for a one way flow  */
>> +    /**
>> +     * Total processing time for a one way flow
>> +     */
>>    private double totalProcessingTime;
>> -    /** The number of access count for a one way flow  */
>> +    /**
>> +     * The number of access count for a one way flow
>> +     */
>>    private int count = 0;
>> -    /** The number of fault count for a one way flow  */
>> +    /**
>> +     * The number of fault count for a one way flow
>> +     */
>>    private int faultCount = 0;
>> +    /**
>> +     * Identifier for this statistics , whose statistics
>> +     */
>> +    private String id;
>> +
>> +    public Statistics(String id) {
>> +        this.id = id;
>> +    }
>>
>>    /**
>>     * Update the statistics
>>     *
>> -     *
>>     * @param currentProcessingTime - The processing end time
>> -     * @param isFault - A boolean value that indicate whether fault has
>> occurred or not
>> +     * @param isFault               - A Boolean value that indicate
>> whether fault has occurred or not
>>     */
>>    public void update(long currentProcessingTime, boolean isFault) {
>>
>> @@ -103,17 +124,21 @@
>>        return count;
>>    }
>>
>> +    public String getId() {
>> +        return id;
>> +    }
>> +
>> +    public void setId(String id) {
>> +        this.id = id;
>> +    }
>> +
>>    public String toString() {
>> -        return new StringBuffer().append(" Avg Processing Time : ").
>> -                append(avgProcessingTime)
>> -                .append(" Max Processing Time : ").
>> -                append(maxProcessingTime)
>> -                .append(" Min Processing Time : ").
>> -                append(minProcessingTime)
>> -                .append(" Total Request Count : ").
>> -                append(count)
>> -                .append(" Total Fault Response Count : ").
>> -                append(faultCount).
>> -                toString();
>> +        return new StringBuffer().append("[Avg Processing Time :
>> ").append(avgProcessingTime).append(" ]")
>> +                .append(" [Max Processing Time :
>> ").append(maxProcessingTime).append(" ]")
>> +                .append(" [Min Processing Time :
>> ").append(minProcessingTime).append(" ]")
>> +                .append(" [Total Request Count :
>> ").append(count).append(" ]")
>> +                .append(" [Total Fault Response Count :
>> ").append(faultCount).append(" ]")
>> +                .toString();
>>    }
>> +
>> }
>>
>> Added:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/StatisticsViewStrategy.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/StatisticsViewStrategy.java?rev=698699&view=auto
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/StatisticsViewStrategy.java
>> (added)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/StatisticsViewStrategy.java
>> Wed Sep 24 12:26:26 2008
>> @@ -0,0 +1,49 @@
>> +/*
>> + *  Licensed to the Apache Software Foundation (ASF) under one
>> + *  or more contributor license agreements.  See the NOTICE file
>> + *  distributed with this work for additional information
>> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
>> +
>> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
>> +
>> +import java.util.List;
>> +import java.util.Map;
>> +
>> +/**
>> + * Strategy for determine Statistics Views
>> + */
>> +public interface StatisticsViewStrategy {
>> +
>> +    /**
>> +     * Return a statistics view for all resource with given type
>> +     *
>> +     * @param statisticsRecords Statistics Data
>> +     * @param type              Type of resource
>> +     * @return A particular statistics view
>> +     */
>> +    public Map<String, Map<String, Statistics>>
>> determineView(List<StatisticsRecord> statisticsRecords, int type);
>> +
>> +    /**
>> +     * Return a statistics view for a resource with given type and given
>> name
>> +     *
>> +     * @param id                The resource name or identifier
>> +     * @param statisticsRecords Statistics Data
>> +     * @param type              Type of resource
>> +     * @return A particular statistics view
>> +     */
>> +    public Map<String, Statistics> determineView(String id,
>> List<StatisticsRecord> statisticsRecords, int type);
>> +}
>>
>> Added:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/SystemViewStrategy.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/SystemViewStrategy.java?rev=698699&view=auto
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/SystemViewStrategy.java
>> (added)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/audit/statatistics/view/SystemViewStrategy.java
>> Wed Sep 24 12:26:26 2008
>> @@ -0,0 +1,168 @@
>> +/*
>> + *  Licensed to the Apache Software Foundation (ASF) under one
>> + *  or more contributor license agreements.  See the NOTICE file
>> + *  distributed with this work for additional information
>> + *  regarding copyright ownership.  The ASF 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.apache.synapse.audit.statatistics.view;
>> +
>> +import org.apache.commons.logging.Log;
>> +import org.apache.commons.logging.LogFactory;
>> +import org.apache.synapse.SynapseException;
>> +import org.apache.synapse.audit.statatistics.StatisticsLog;
>> +import org.apache.synapse.audit.statatistics.StatisticsRecord;
>> +
>> +import java.util.HashMap;
>> +import java.util.List;
>> +import java.util.Map;
>> +
>> +/**
>> + * Strategy that determine a system wide statistics view
>> + */
>> +public class SystemViewStrategy implements StatisticsViewStrategy {
>> +
>> +    private static final Log log =
>> LogFactory.getLog(SystemViewStrategy.class);
>> +
>> +    public Map<String, Map<String, Statistics>>
>> determineView(List<StatisticsRecord> statisticsRecords, int type) {
>> +
>> +        Map<String, Map<String, Statistics>> statisticsMap = new
>> HashMap<String, Map<String, Statistics>>();
>> +        if (statisticsRecords == null) {
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Statistics records cannot be found.");
>> +            }
>> +            return statisticsMap;
>> +        }
>> +
>> +        Map<String, Statistics> perResourceMap = new HashMap<String,
>> Statistics>();
>> +
>> +        for (StatisticsRecord record : statisticsRecords) {
>> +
>> +            if (record != null) {
>> +
>> +                Map<String, StatisticsLog> statisticsLogMap = null;
>> +
>> +                switch (type) {
>> +                    case StatisticsLog.ENDPOINT_STATISTICS: {
>> +                        statisticsLogMap =
>> record.getAllEndpointStatisticsRecords();
>> +                        break;
>> +                    }
>> +                    case StatisticsLog.PROXY_SERVICE_STATISTICS: {
>> +                        statisticsLogMap =
>> record.getAllProxyServiceStatisticsRecords();
>> +                        break;
>> +                    }
>> +                    case StatisticsLog.MEDIATOR_STATISTICS: {
>> +                        statisticsLogMap =
>> record.getAllMediatorStatisticsRecords();
>> +                        break;
>> +                    }
>> +                }
>> +
>> +                if (statisticsLogMap == null) {
>> +                    if (log.isDebugEnabled()) {
>> +                        log.debug("Cannot find the statistics logs for :
>> " + record);
>> +                    }
>> +                    continue;
>> +                }
>> +
>> +                for (String rName : statisticsLogMap.keySet()) {
>> +
>> +                    if (rName == null) {
>> +                        if (log.isDebugEnabled()) {
>> +                            log.debug("Cannot find the resource name ");
>> +                        }
>> +                        continue;
>> +                    }
>> +
>> +                    StatisticsLog statisticsLog =
>> statisticsLogMap.get(rName);
>> +                    if (statisticsLog == null) {
>> +                        if (log.isDebugEnabled()) {
>> +                            log.debug("Cannot find the statistics log for
>> resource with name : " + rName);
>> +                        }
>> +                        continue;
>> +                    }
>> +
>> +                    Statistics statistics;
>> +
>> +                    if (!perResourceMap.containsKey(rName)) {
>> +
>> +                        statistics = new Statistics(rName);
>> +                        perResourceMap.put(rName, statistics);
>> +
>> +                    } else {
>> +                        statistics = perResourceMap.get(rName);
>> +                    }
>> +
>> +                    if (statistics != null) {
>> +
>>  statistics.update(statisticsLog.getProcessingTime(),
>> record.isFaultResponse());
>> +                    }
>> +                }
>> +            }
>> +
>> +        }
>> +
>> +        statisticsMap.put(Statistics.ALL, perResourceMap);
>> +        return statisticsMap;
>> +
>> +    }
>> +
>> +    public Map<String, Statistics> determineView(String id,
>> List<StatisticsRecord> statisticsRecords, int type) {
>> +
>> +        if (id == null || "".equals(id)) {
>> +            handleException("Resource Id cannot be null");
>> +        }
>> +
>> +        Map<String, Statistics> statisticsMap = new HashMap<String,
>> Statistics>();
>> +        if (statisticsRecords == null) {
>> +            if (log.isDebugEnabled()) {
>> +                log.debug("Statistics records cannot be found.");
>> +            }
>> +            return statisticsMap;
>> +        }
>> +
>> +        Statistics statistics = new Statistics(Statistics.ALL);
>> +        for (StatisticsRecord record : statisticsRecords) {
>> +
>> +            if (record != null) {
>> +                StatisticsLog log = null;
>> +
>> +                switch (type) {
>> +                    case StatisticsLog.ENDPOINT_STATISTICS: {
>> +                        log = record.getEndpointStatisticsRecord(id);
>> +                        break;
>> +                    }
>> +                    case StatisticsLog.PROXY_SERVICE_STATISTICS: {
>> +                        log = record.getProxyServiceStatisticsRecord(id);
>> +                        break;
>> +                    }
>> +                    case StatisticsLog.MEDIATOR_STATISTICS: {
>> +                        log = record.getMediatorStatisticsRecord(id);
>> +                        break;
>> +                    }
>> +                }
>> +
>> +                if (log != null) {
>> +                    statistics.update(log.getProcessingTime(),
>> record.isFaultResponse());
>> +                }
>> +            }
>> +        }
>> +
>> +        statisticsMap.put(Statistics.ALL, statistics);
>> +        return statisticsMap;
>> +    }
>> +
>> +    private static void handleException(String msg) {
>> +        log.error(msg);
>> +        throw new SynapseException(msg);
>> +    }
>> +}
>>
>> Modified:
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
>> URL:
>> http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java?rev=698699&r1=698698&r2=698699&view=diff
>>
>> ==============================================================================
>> ---
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
>> (original)
>> +++
>> synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
>> Wed Sep 24 12:26:26 2008
>> @@ -483,9 +483,9 @@
>>    private void initAudit(MessageContext synCtx) {
>>
>>        if (XMLConfigConstants.STATISTICS_ENABLE.equals(
>> -
>>  synCtx.getConfiguration().getProperty(SynapseConstants.SYNAPSE_STATISTICS_STATE)))
>> {
>> +
>>  synCtx.getConfiguration().getProperty(SynapseConstants.SYNAPSE_AUDIT_STATE)))
>> {
>>
>>  synCtx.setProperty(SynapseConstants.SYNAPSE_AUDIT_CONFIGURATION,
>> -                    new
>> AuditConfiguration(SynapseConstants.SYNAPSE_STATISTICS, true));
>> +                    new
>> AuditConfiguration(SynapseConstants.SYNAPSE_AUDIT, true));
>>        }
>>    }
>> }
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
For additional commands, e-mail: dev-help@synapse.apache.org