commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r651963 - in /commons/sandbox/monitoring/trunk/src: main/java/org/apache/commons/monitoring/ main/java/org/apache/commons/monitoring/reporting/ main/java/org/apache/commons/monitoring/reporting/web/ main/java/org/apache/commons/monitoring/s...
Date Sun, 27 Apr 2008 14:55:32 GMT
Author: nicolas
Date: Sun Apr 27 07:55:28 2008
New Revision: 651963

URL: http://svn.apache.org/viewvc?rev=651963&view=rev
Log:
initial code base for JSP tags
Role now requires a StatValue type

Added:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/AbstractSelectTag.java
  (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/CategoriesTag.java
  (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/RolesTag.java
  (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/StatValueTag.java
  (with props)
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/SubsystemsTag.java
  (with props)
Modified:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Role.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/OptionsSupport.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/Renderer.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/web/MonitoringServlet.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/MonitoringTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java?rev=651963&r1=651962&r2=651963&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Monitor.java
Sun Apr 27 07:55:28 2008
@@ -53,13 +53,13 @@
 public interface Monitor
 {
     /** default role key for code performances */
-    Role<Counter> PERFORMANCES = new Role<Counter>( "performances", Unit.NANOS
);
+    Role<Counter> PERFORMANCES = new Role<Counter>( "performances", Unit.NANOS,
Counter.class );
 
     /** default role for multi-thread concurrency */
-    Role<Gauge> CONCURRENCY = new Role<Gauge>( "concurrency", Unit.UNARY );
+    Role<Gauge> CONCURRENCY = new Role<Gauge>( "concurrency", Unit.UNARY, Gauge.class
);
 
     /** default Role for the invocation failure counter */
-    Role<Counter> FAILURES = new Role<Counter>( "failures", Unit.UNARY );
+    Role<Counter> FAILURES = new Role<Counter>( "failures", Unit.UNARY, Counter.class
);
 
     /**
      * @return the monitor key

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Role.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Role.java?rev=651963&r1=651962&r2=651963&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Role.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/Role.java
Sun Apr 27 07:55:28 2008
@@ -17,6 +17,8 @@
 
 package org.apache.commons.monitoring;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -25,15 +27,22 @@
     private String name;
 
     private Unit unit;
+    
+    private Class<T> type;
 
     private static final Map<String, Role> ROLES = new ConcurrentHashMap<String,
Role>();
 
-    public static Role<? extends StatValue> getRole( String name )
+    public static Role getRole( String name )
     {
         return ROLES.get( name );
     }
+    
+    public static Collection<Role> getRoles()
+    {
+        return Collections.unmodifiableCollection( ROLES.values() );
+    }    
 
-    public Role( String name, Unit unit )
+    public Role( String name, Unit unit, Class<T> type )
     {
         super();
         if (name == null)
@@ -44,8 +53,13 @@
         {
             throw new IllegalArgumentException( "A role unit is required" );
         }
+        if (type == null)
+        {
+            throw new IllegalArgumentException( "A role type is required" );
+        }
         this.name = name;
         this.unit = unit;
+        this.type = type;
         ROLES.put( name, this );
     }
 
@@ -120,6 +134,11 @@
     public String toString()
     {
         return name;
+    }
+
+    public Class<T> getType()
+    {
+        return type;
     }
 
 }

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java?rev=651963&r1=651962&r2=651963&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/AbstractRenderer.java
Sun Apr 27 07:55:28 2008
@@ -236,7 +236,7 @@
 
     private void renderInternal( Context ctx, StatValue value, String attribute, long l,
Options options, int ratio )
     {
-        Unit unit = options.unitFor( value );
+        Unit unit = options.unitFor( value.getRole() );
         if ( unit != null )
         {
             while ( ratio-- > 0 )
@@ -255,7 +255,7 @@
             renderNaN( ctx );
             return;
         }
-        Unit unit = options.unitFor( value );
+        Unit unit = options.unitFor( value.getRole() );
         if ( unit != null )
         {
             while ( ratio-- > 0 )

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java?rev=651963&r1=651962&r2=651963&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/HtmlRenderer.java
Sun Apr 27 07:55:28 2008
@@ -45,10 +45,9 @@
 
     /**
      * {@inheritDoc}
-     *
-     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#render(java.io.Context,
-     * java.util.Collection,
-     * org.apache.commons.monitoring.reporting.Renderer.Options)
+     * 
+     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#render(java.io.Context,
java.util.Collection,
+     *      org.apache.commons.monitoring.reporting.Renderer.Options)
      */
     @Override
     public void render( Context ctx, Collection<Monitor> monitors, Options options
)
@@ -100,7 +99,7 @@
         Map<String, Integer> columns = new HashMap<String, Integer>();
 
         ctx.println( "<thead><tr>" );
-        boolean detached = ( monitors.size() > 0 && monitors.iterator().next()instanceof
Detachable );
+        boolean detached = ( monitors.size() > 0 && monitors.iterator().next()
instanceof Detachable );
 
         if ( detached )
         {
@@ -111,38 +110,16 @@
         ctx.println( "<th rowspan='2'>subsystem</th>" );
         for ( Role role : roles )
         {
-            // Search the first monitor that has a StatValue for the role...
-            for ( Monitor monitor : monitors )
+            ctx.print( "<td colspan='" );
+            ctx.print( role.getType() == Counter.class ? "7" : "5" );
+            ctx.print( "'>" );
+            ctx.print( role.getName() );
+            Unit unit = options.unitFor( role );
+            if ( unit != null && unit.getName().length() > 0 )
             {
-                StatValue value = monitor.getValue( role );
-                if ( value != null )
-                {
-                    int span = 0;
-                    if ( value instanceof Counter )
-                    {
-                        span += options.render( role, "hits" ) ? 1 : 0;
-                        span += options.render( role, "sum" ) ? 1 : 0;
-                    }
-                    span += options.render( role, "min" ) ? 1 : 0;
-                    span += options.render( role, "max" ) ? 1 : 0;
-                    span += options.render( role, "mean" ) ? 1 : 0;
-                    span += options.render( role, "deviation" ) ? 1 : 0;
-                    span += options.render( role, "value" ) ? 1 : 0;
-
-                    ctx.print( "<td colspan='" );
-                    ctx.print( String.valueOf( span ) );
-                    ctx.print( "'>" );
-                    ctx.print( value.getRole().getName() );
-                    Unit unit = options.unitFor( value );
-                    if ( unit != null && unit.getName().length() > 0 )
-                    {
-                        renderUnit( ctx, unit );
-                    }
-                    ctx.print( "</td>" );
-                    columns.put( role.getName(), span );
-                    break;
-                }
+                renderUnit( ctx, unit );
             }
+            ctx.print( "</td>" );
         }
         ctx.print( "</tr>" );
 
@@ -155,32 +132,24 @@
 
         for ( Role role : roles )
         {
-            for ( Monitor monitor : monitors )
+            if ( role.getType() == Counter.class )
             {
-                StatValue value = monitor.getValue( role );
-                if ( value != null )
-                {
-                    if ( value instanceof Counter )
-                    {
-                        writeColumnHead( ctx, options, value, "hits" );
-                        writeColumnHead( ctx, options, value, "sum" );
-                    }
-                    writeColumnHead( ctx, options, value, "min" );
-                    writeColumnHead( ctx, options, value, "max" );
-                    writeColumnHead( ctx, options, value, "mean" );
-                    writeColumnHead( ctx, options, value, "deviation" );
-                    writeColumnHead( ctx, options, value, "value" );
-                    break;
-                }
+                writeColumnHead( ctx, options, role, "hits" );
+                writeColumnHead( ctx, options, role, "sum" );
             }
+            writeColumnHead( ctx, options, role, "min" );
+            writeColumnHead( ctx, options, role, "max" );
+            writeColumnHead( ctx, options, role, "mean" );
+            writeColumnHead( ctx, options, role, "deviation" );
+            writeColumnHead( ctx, options, role, "value" );
         }
         ctx.println( "</tr></thead>" );
         ctx.put( COLUMNS, columns );
     }
 
-    protected void writeColumnHead( Context ctx, Options options, StatValue value, String
attribute )
+    protected void writeColumnHead( Context ctx, Options options, Role role, String attribute
)
     {
-        if ( options.render( value.getRole(), attribute ) )
+        if ( options.render( role, attribute ) )
         {
             ctx.print( "<th>" );
             ctx.print( attribute );
@@ -190,15 +159,18 @@
 
     /**
      * {@inheritDoc}
-     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#renderDetached(org.apache.commons.monitoring.reporting.Context,
org.apache.commons.monitoring.listeners.SecondaryMonitor, org.apache.commons.monitoring.reporting.Renderer.Options)
+     * 
+     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#renderDetached(org.apache.commons.monitoring.reporting.Context,
+     *      org.apache.commons.monitoring.listeners.SecondaryMonitor,
+     *      org.apache.commons.monitoring.reporting.Renderer.Options)
      */
     @Override
     protected void renderDetached( Context ctx, Detachable detached, Options options )
     {
         ctx.print( "<td>" );
-        ctx.print( options.getDateFormat().format( new Date( detached.getAttachedAt()) )
);
+        ctx.print( options.getDateFormat().format( new Date( detached.getAttachedAt() ) )
);
         ctx.print( "</td><td>" );
-        ctx.print( options.getDateFormat().format( new Date( detached.getDetachedAt()) )
);
+        ctx.print( options.getDateFormat().format( new Date( detached.getDetachedAt() ) )
);
         ctx.print( "</td>" );
     }
 
@@ -237,11 +209,11 @@
 
     /**
      * {@inheritDoc}
-     *
+     * 
      * @see org.apache.commons.monitoring.reporting.AbstractRenderer#renderMissingValue(org.apache.commons.monitoring.reporting.Context,
-     * java.lang.String)
+     *      java.lang.String)
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     @Override
     protected void renderMissingValue( Context ctx, Role role )
     {
@@ -253,9 +225,8 @@
 
     /**
      * {@inheritDoc}
-     *
-     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#hasNext(java.io.Context,
-     * java.lang.Class)
+     * 
+     * @see org.apache.commons.monitoring.reporting.AbstractRenderer#hasNext(java.io.Context,
java.lang.Class)
      */
     @Override
     protected void hasNext( Context ctx, Class<?> type )

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/OptionsSupport.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/OptionsSupport.java?rev=651963&r1=651962&r2=651963&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/OptionsSupport.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/OptionsSupport.java
Sun Apr 27 07:55:28 2008
@@ -26,7 +26,6 @@
 
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Role;
-import org.apache.commons.monitoring.StatValue;
 import org.apache.commons.monitoring.Unit;
 
 /**
@@ -53,9 +52,9 @@
     }
 
 
-    public Unit unitFor( StatValue value )
+    public Unit unitFor( Role role )
     {
-        return value.getUnit();
+        return role.getUnit();
     }
 
     public NumberFormat getDecimalFormat()

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/Renderer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/Renderer.java?rev=651963&r1=651962&r2=651963&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/Renderer.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/Renderer.java
Sun Apr 27 07:55:28 2008
@@ -24,7 +24,6 @@
 
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Role;
-import org.apache.commons.monitoring.StatValue;
 import org.apache.commons.monitoring.Unit;
 
 /**
@@ -48,7 +47,7 @@
 
         boolean renderRole( Role role );
 
-        Unit unitFor( StatValue value );
+        Unit unitFor( Role role );
 
         NumberFormat getNumberFormat();
 

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/web/MonitoringServlet.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/web/MonitoringServlet.java?rev=651963&r1=651962&r2=651963&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/web/MonitoringServlet.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/reporting/web/MonitoringServlet.java
Sun Apr 27 07:55:28 2008
@@ -35,7 +35,6 @@
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.Repository;
 import org.apache.commons.monitoring.Role;
-import org.apache.commons.monitoring.StatValue;
 import org.apache.commons.monitoring.Unit;
 import org.apache.commons.monitoring.Monitor.Key;
 import org.apache.commons.monitoring.reporting.Context;
@@ -226,21 +225,21 @@
         }
 
         @Override
-        public Unit unitFor( StatValue value )
+        public Unit unitFor( Role role )
         {
-            String unitName = request.getParameter( value.getRole().getName() + ".unit" );
+            String unitName = request.getParameter( role.getName() + ".unit" );
             if ( unitName != null )
             {
-                if ( value.getUnit() != null )
+                if ( role.getUnit() != null )
                 {
-                    Unit unit = value.getUnit().getDerived( unitName );
+                    Unit unit = role.getUnit().getDerived( unitName );
                     if ( unit != null )
                     {
                         return unit;
                     }
                 }
             }
-            return value.getUnit();
+            return role.getUnit();
         }
     }
 

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/AbstractSelectTag.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/AbstractSelectTag.java?rev=651963&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/AbstractSelectTag.java
(added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/AbstractSelectTag.java
Sun Apr 27 07:55:28 2008
@@ -0,0 +1,94 @@
+package org.apache.commons.monitoring.servlet.jsp;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.commons.monitoring.Monitoring;
+import org.apache.commons.monitoring.Repository;
+import org.apache.commons.monitoring.servlet.ServletContextUtil;
+
+public abstract class AbstractSelectTag
+    extends TagSupport
+{
+    protected Repository repository;
+    
+    private String id;
+    
+    private String name;
+
+    public AbstractSelectTag()
+    {
+        super();
+    }
+
+    @Override
+    public int doEndTag()
+        throws JspException
+    {
+        if (repository == null)
+        {
+            repository = (Repository) pageContext.getAttribute( ServletContextUtil.REPOSITORY_KEY
);
+        }
+        
+        StringBuffer stb = new StringBuffer( "<select" );
+        if ( id != null )
+        {
+            stb.append( " id='" ).append( id ).append( "'" );
+        }
+        if ( name != null )
+        {
+            stb.append( " name='" ).append( name ).append( "'" );
+        }
+        stb.append( ">" );
+        List<String> categories = new LinkedList<String>( getElements() );
+        Collections.sort( categories );
+        for ( String category : categories )
+        {
+            stb.append( "<option value='" );
+            stb.append( category );
+            stb.append( "'>" );
+            stb.append( category );
+            stb.append( "</option>" );
+        }
+        
+        stb.append( "</select>" );
+        try
+        {
+            pageContext.getOut().print( stb.toString() );
+        }
+        catch ( Exception e )
+        {
+            throw new JspTagException( "CategoriesTag : " + e.getMessage() );
+        }
+    
+        return EVAL_PAGE;
+    }
+
+    /**
+     * The set of elements to display as a select list
+     * @return
+     */
+    protected abstract  Collection<? extends String> getElements();
+
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    public void setRepository( String repository )
+    {
+        this.repository = (Repository) pageContext.getAttribute( repository );
+    }
+
+}
\ No newline at end of file

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/AbstractSelectTag.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/CategoriesTag.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/CategoriesTag.java?rev=651963&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/CategoriesTag.java
(added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/CategoriesTag.java
Sun Apr 27 07:55:28 2008
@@ -0,0 +1,36 @@
+/*
+ * 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.commons.monitoring.servlet.jsp;
+
+import java.util.Set;
+
+
+
+/**
+ * A JSP tag to output a select box for repositoy categories
+ * 
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class CategoriesTag
+    extends AbstractSelectTag
+{
+    protected Set<String> getElements()
+    {
+        return repository.getCategories();
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/CategoriesTag.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/RolesTag.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/RolesTag.java?rev=651963&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/RolesTag.java
(added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/RolesTag.java
Sun Apr 27 07:55:28 2008
@@ -0,0 +1,71 @@
+package org.apache.commons.monitoring.servlet.jsp;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.tagext.BodyContent;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+
+import org.apache.commons.monitoring.Role;
+
+public class RolesTag
+    extends BodyTagSupport
+{
+    private Iterator<Role> roles;
+
+    private String role;
+
+    @Override
+    public int doStartTag()
+        throws JspException
+    {
+        roles = Role.getRoles().iterator();
+        pageContext.setAttribute( role, roles.next() );
+        return roles.hasNext() ? EVAL_BODY_BUFFERED : SKIP_BODY;
+    }
+
+    @Override
+    public int doAfterBody()
+        throws JspException
+    {
+        BodyContent body = getBodyContent();
+        try
+        {
+            body.writeOut( getPreviousOut() );
+        }
+        catch ( IOException e )
+        {
+            throw new JspTagException( "RolesTag: " + e.getMessage() );
+        }
+
+        // clear up so the next time the body content is empty
+        body.clearBody();
+        if ( roles.hasNext() )
+        {
+            pageContext.setAttribute( role, roles.next() );
+            return EVAL_BODY_AGAIN;
+        }
+        else
+        {
+            return SKIP_BODY;
+        }
+    }
+
+    /**
+     * Name of the pageContext attribute to contain the current role during interation
+     * 
+     * @param role
+     */
+    public void setRole( String role )
+    {
+        this.role = role;
+    }
+
+    @Override
+    public void release()
+    {
+        role = "role";
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/RolesTag.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/StatValueTag.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/StatValueTag.java?rev=651963&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/StatValueTag.java
(added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/StatValueTag.java
Sun Apr 27 07:55:28 2008
@@ -0,0 +1,61 @@
+package org.apache.commons.monitoring.servlet.jsp;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.commons.monitoring.Counter;
+import org.apache.commons.monitoring.Role;
+
+public class StatValueTag
+    extends TagSupport
+{
+    private String roleAttrName;
+
+    @Override
+    public int doStartTag()
+        throws JspException
+    {
+        Role role = (Role) pageContext.getAttribute( roleAttrName );
+
+        String name = role.getName();
+        StringBuffer stb = new StringBuffer();
+        checkbox( name, "value", stb );
+        checkbox( name, "min", stb );
+        checkbox( name, "max", stb );
+        checkbox( name, "mean", stb );
+        checkbox( name, "deviation", stb );
+        if ( role.getType() == Counter.class )
+        {
+            checkbox( name, "hits", stb );
+            checkbox( name, "total", stb );
+        }
+
+        return EVAL_PAGE;
+    }
+
+    private void checkbox( String name, String property, StringBuffer stb )
+    {
+        stb.append( "<li>" );
+        stb.append( "<input type='checkbox' name='" );
+        stb.append( property );
+        stb.append( "' id='" );
+        stb.append( name );
+        stb.append( "." );
+        stb.append( property );
+        stb.append( "'/>" );
+        stb.append( "<label for='" );
+        stb.append( "'>" );
+        stb.append( name );
+        stb.append( "." );
+        stb.append( property );
+        stb.append( "</label>" );
+        stb.append( "</li>" );
+    }
+
+    public void setRole( String role )
+    {
+        this.roleAttrName = role;
+    }
+
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/StatValueTag.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/SubsystemsTag.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/SubsystemsTag.java?rev=651963&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/SubsystemsTag.java
(added)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/SubsystemsTag.java
Sun Apr 27 07:55:28 2008
@@ -0,0 +1,36 @@
+/*
+ * 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.commons.monitoring.servlet.jsp;
+
+import java.util.Set;
+
+
+
+/**
+ * A JSP tag to output a select box for repositoy categories
+ * 
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class SubsystemsTag
+    extends AbstractSelectTag
+{
+    protected Set<String> getElements()
+    {
+        return repository.getSubSystems();
+    }
+}

Propchange: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/servlet/jsp/SubsystemsTag.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/MonitoringTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/MonitoringTest.java?rev=651963&r1=651962&r2=651963&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/MonitoringTest.java
(original)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/MonitoringTest.java
Sun Apr 27 07:55:28 2008
@@ -31,9 +31,9 @@
 public class MonitoringTest
     extends TestCase
 {
-    public final static Role<Counter> COUNTER = new Role<Counter>( "COUNTER",
Unit.UNARY );
+    public final static Role<Counter> COUNTER = new Role<Counter>( "COUNTER",
Unit.UNARY, Counter.class );
 
-    public final static Role<Gauge> GAUGE = new Role<Gauge>( "GAUGE", Unit.UNARY
);
+    public final static Role<Gauge> GAUGE = new Role<Gauge>( "GAUGE", Unit.UNARY,
Gauge.class );
 
 
     public void testStopWatchConcurrencyMonitoring()

Modified: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java?rev=651963&r1=651962&r2=651963&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java
(original)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/reporting/RendererTest.java
Sun Apr 27 07:55:28 2008
@@ -29,7 +29,7 @@
 import org.apache.commons.monitoring.Counter;
 import org.apache.commons.monitoring.Monitor;
 import org.apache.commons.monitoring.MonitoringTest;
-import org.apache.commons.monitoring.StatValue;
+import org.apache.commons.monitoring.Role;
 import org.apache.commons.monitoring.Unit;
 import org.apache.commons.monitoring.impl.monitors.CreateValuesOnDemandMonitor;
 import org.apache.commons.monitoring.impl.values.ThreadSafeCounter;
@@ -91,7 +91,7 @@
     {
         Options options = new OptionsSupport()
         {
-            public Unit unitFor( StatValue value )
+            public Unit unitFor( Role role )
             {
                 return Unit.MICROS;
             }



Mime
View raw message