Package org.apache.excalibur.instrument.manager

Examples of org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor


     */
    public void doGet( String path, Map parameters, OutputStream os )
        throws IOException
    {
        String name = getParameter( parameters, "name" );
        InstrumentSampleDescriptor desc;
        try
        {
            desc = m_manager.locateInstrumentSampleDescriptor( name );
        }
        catch ( NoSuchInstrumentSampleException e )
        {
            // Sample no longer exists, go back to the parent instrument.
            int pos = name.lastIndexOf( '.' );
            if ( pos >= 0 )
            {
                // Starting with Java 1.4, encode takes an encoding, but this needs to
                //  work with 1.3.   Use our own version.
                String iName = URLCoder.encode( name.substring( 0,  pos ),
                    InstrumentManagerHTTPConnector.ENCODING );
               
                throw new HTTPRedirect( "instrument.html?name=" + iName );
            }
            else
            {
                throw new HTTPRedirect( "instrumentable.html" );
            }
        }
       
        int width = getIntegerParameter( parameters, "width", m_width );
        width = Math.max( 1, Math.min( 2048, width ) );
        int height = getIntegerParameter( parameters, "height", m_height );
        height = Math.max( 1, Math.min( 1024, height ) );
       
        boolean antialias = getBooleanParameter( parameters, "antialias", m_antialias );
       
        InstrumentSampleSnapshot snapshot = desc.getSnapshot();
       
        // Decide on a line interval based on the interval of the sample.
        long interval = snapshot.getInterval();
        int hInterval;
        String format;
View Full Code Here


     */
    public void doGet( String path, Map parameters, PrintWriter out )
        throws IOException
    {
        String name = getParameter( parameters, "name" );
        InstrumentSampleDescriptor desc;
        try
        {
            desc = getInstrumentManager().locateInstrumentSampleDescriptor( name );
        }
        catch ( NoSuchInstrumentSampleException e )
        {
            // Sample no longer exists, go back to the parent instrument.
            int pos = name.lastIndexOf( '.' );
            if ( pos >= 0 )
            {
                throw new HTTPRedirect(
                    "instrument.html?name=" + urlEncode( name.substring( 0,  pos ) ) );
            }
            else
            {
                throw new HTTPRedirect( "instrument-manager.html" );
            }
        }
        String chart = getParameter( parameters, "chart", null );
       
        InstrumentSampleSnapshot snapshot = desc.getSnapshot();
       
        String type;
        switch ( desc.getType() )
        {
        case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_COUNTER:
            type = "Counter";
            break;
           
        case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MAXIMUM:
            type = "Max Value";
            break;
           
        case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MINIMUM:
            type = "Min Value";
            break;
           
        case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MEAN:
            type = "Mean Value";
            break;
           
        default:
            type = "Unknown";
            break;
        }
       
        out.println( "<html>" );
        out.println( "<head><title>" + desc.getDescription() + "</title></head>" );
        out.println( "<body>" );
       
        breadCrumbs( out, desc, false );
       
        out.println( "<h2>Instrument Sample</h2>" );
        startTable( out );
        tableRow( out, 0, "Name", desc.getName() );
        tableRow( out, 0, "Description", desc.getDescription() );
        tableRow( out, 0, "Type", type );
        tableRow( out, 0, "Interval", desc.getInterval() + "ms." );
        tableRow( out, 0, "Size", Integer.toString( desc.getSize() ) );
        if ( desc.getLeaseExpirationTime() > 0 )
        {
            String renewUrl = "sample-lease.html?name=" + urlEncode( desc.getName() )
                + ( chart == null ? "" : "&chart=true" ) + "&lease=";
           
            String value = new Date( desc.getLeaseExpirationTime() ).toString();
           
            if ( !getConnector().isReadOnly() )
            {
                value = value + " (Renew <a href='" + renewUrl + "600000'>10min</a>, "
                    + "<a href='" + renewUrl + "3600000'>1hr</a>, "
                    + "<a href='" + renewUrl + "86400000'>1day</a>)";
            }
           
            // Make the text red if it is about to expire.
            if ( desc.getLeaseExpirationTime() - System.currentTimeMillis() < 300000 )
            {
                value = "<font color='ff0000'>" + value + "</font>";
            }

            tableRow( out, 0, "Expiration", value );
        }
        else
        {
            tableRow( out, 0, "Expiration", "Permanent" );
        }
        endTable( out );
       
        if ( chart == null )
        {
            out.println( "<h2>Data Samples (<a href='sample.html?name="
                + urlEncode( desc.getName() ) + "&chart=true'>Chart</a>)</h2>" );
           
            startTable( out );
            startTableHeaderRow( out );
            tableHeaderCell( out, "Period" );
            tableHeaderCell( out, "Value" );
            endTableHeaderRow( out );
            long time = snapshot.getTime();
            int[] samples = snapshot.getSamples();
            for ( int i = 0; i < samples.length; i++ )
            {
                startTableRow( out, i );
                tableCell( out, new Date( time ).toString() );
                tableCellRight( out, Integer.toString( samples[samples.length - i - 1] ) );
                endTableRow( out );
               
                time -= snapshot.getInterval();
            }
            endTable( out );
        }
        else
        {
            out.println( "<h2>Data Samples (<a href='sample.html?name="
                + urlEncode( desc.getName() ) + "'>Plain</a>)</h2>" );
           
            // Originally, the JavaScript timer in the page made use of the setInterval
            //  function to build a simple timer.  This worked fine under normal
            //  operation.  But if a browser was suspended for 1 hour with a timer
            //  running at 1 second intervals, the timer would try to catch up when
            //  the machine was resumed.  This would result in the timer firing 3600
            //  times over the course of a few seconds.  The sudden burst of requests
            //  was swamping the server.
            // The current scripts below now always reset the timer each time it is
            //  fired.  If the timer ever falls behind it will recover smoothly
            //  without trying to catch up.  While not quite as accurate it is
            //  sufficient for our purposes.
           
            out.println( "<SCRIPT LANGUAGE=\"JavaScript\">" );
            out.println( "var timerId = 0;" );
            out.println( "var timerInterval = 5000;" );
            out.println( "function refreshChart() {" );
            //out.println( "  alert(\"in refreshChart()\");" );
            out.println( "  document.chart.src=\"sample-chart.jpg?name=" + urlEncode( desc.getName() ) + "&time=\" + new Date().getTime();" );
            out.println( "}" );
            out.println( "function timerFired() {" );
            //out.println( "  alert(\"in timerFired()\");" );
            out.println( "  if (timerId) {" );
            out.println( "    clearTimeout(timerId);" );
            out.println( "  }" );
            out.println( "  timerId = setTimeout(\"timerFired()\", timerInterval)" );
            out.println( "  refreshChart();" );
            out.println( "}" );
            out.println( "function setRefresh(refresh) {" );
            //out.println( "  alert(\"in setRefresh(\" + refresh + \")\");" );
            out.println( "  timerInterval = refresh;" );
            out.println( "  timerFired();" );
            out.println( "}" );
            out.println( "function chartError() {" );
            //out.println( "  alert(\"in chartError()\");" );
            out.println( "  clearTimeout(timerId);" );
            out.println( "  document.location=\"instrument.html?name=" + urlEncode( desc.getInstrumentDescriptor().getName() ) + "\";" );
            out.println( "}" );
            out.println( "</SCRIPT>" );
           
            out.println( "<form>" );
            startTable( out );
            // Add a time to the chart as is done in the Javascript.  Some browsers ignore the
            //  do not cache headers in the image and display a cached version of the image
            //  anyway.
            tableCell( out, "<img name='chart' src='sample-chart.jpg?name=" + urlEncode( desc.getName() )
                + "&time=" + System.currentTimeMillis() + "' onError='javascript:chartError()'>" );
            endTable( out );
            out.println( "Refresh rate:" );
            out.println( "<input type='button' value='No Refresh' onClick='javascript:clearTimeout(timerId)'>" );
            out.println( "<input type='button' value='1 Second' onClick='javascript:setRefresh(1000)'>" );
View Full Code Here

        tableHeaderCell( out, "Expiration Time" );
        endTableHeaderRow( out );
       
        for ( int i = 0; i < descs.length; i++ )
        {
            InstrumentSampleDescriptor desc = descs[i];
           
            startTableRow( out, i );
            tableCell( out, "<a href='sample.html?name=" + urlEncode( desc.getName() ) + "'>"
                + desc.getDescription() + "</a> (<a href='sample.html?name="
                + urlEncode( desc.getName() ) + "&chart=true'>Chart</a>)" );
            tableCellRight( out, Integer.toString( desc.getValue() ) );
            tableCell( out, new Date( desc.getTime() ).toString() );
            tableCellRight( out, Long.toString( desc.getInterval() ) );
            tableCellRight( out, Integer.toString( desc.getSize() ) );
            String value;
            if ( desc.getLeaseExpirationTime() == 0 )
            {
                value = "<i>Permanent</i>";
            }
            else
            {
                String renewUrl =
                    "sample-lease.html?name=" + urlEncode( desc.getName() ) + "&instrument=true&lease=";
               
                value = new Date( desc.getLeaseExpirationTime() ).toString();
                if ( !readOnly )
                {
                    value = value
                        + " (Renew <a href='" + renewUrl + "600000'>10min</a>, "
                        + "<a href='" + renewUrl + "3600000'>1hr</a>, "
                        + "<a href='" + renewUrl + "86400000'>1day</a>)";
                }
               
                // Make the text red if it is about to expire.
                if ( desc.getLeaseExpirationTime() - System.currentTimeMillis() < 300000 )
                {
                    value = "<font color='ff0000'>" + value + "</font>";
                }
            }
            tableCell( out, value );
View Full Code Here

        {
            outputLine( out, "", packed, "<samples>" );
           
            for ( int i = 0; i < names.length; i++ )
            {
                InstrumentSampleDescriptor desc;
                try
                {
                    desc =
                        getInstrumentManager().locateInstrumentSampleDescriptor( names[i] );
                   
View Full Code Here

        throws IOException
    {
        String name = getParameter( parameters, "name" );
        boolean packed = getBooleanParameter( parameters, "packed", false );
       
        InstrumentSampleDescriptor desc;
        try
        {
            desc = getInstrumentManager().locateInstrumentSampleDescriptor( name );
        }
        catch ( NoSuchInstrumentSampleException e )
View Full Code Here

        {
            String childIndent = indent + INDENT;
           
            for ( int i = 0; i < samples.length; i++ )
            {
                InstrumentSampleDescriptor sample = samples[i];
                if ( recurse )
                {
                    outputSample( out, sample, childIndent, packed );
                }
                else
View Full Code Here

                    {
                        lease = 1;
                    }
                   
                    // Register the new lease
                    InstrumentSampleDescriptor sample;
                    try
                    {
                        sample =
                            desc.createInstrumentSample( description, interval, size, lease, type );
                    }
View Full Code Here

        {
            lease = 1;
        }
       
        // Register the new lease
        InstrumentSampleDescriptor sample;
        try
        {
            sample = desc.createInstrumentSample( description, interval, size, lease, type );
        }
        catch ( IllegalArgumentException e )
View Full Code Here

            for ( int i = 0; i < names.length; i++ )
            {
                String name = names[i];
                long lease = leases[i];
               
                InstrumentSampleDescriptor desc;
                try
                {
                    desc = getInstrumentManager().locateInstrumentSampleDescriptor( name );
                }
                catch ( NoSuchInstrumentSampleException e )
                {
                    // Not found, ignore.
                    desc = null;
                }
               
                if ( desc != null )
                {
                    // The instrument manager will do its own tests of the lease, but the
                    //  restrictions on this connector may be stronger so they must be tested
                    //  here as well.
                    lease = Math.max(
                        1, Math.min( lease, getConnector().getMaxLeasedSampleLease() ) );
                   
                    if ( getInstrumentManager().getLeaseSampleCount() >=
                        getConnector().getMaxLeasedSamples() )
                    {
                        lease = 1;
                    }
                   
                    // Renew the lease
                    desc.extendLease( lease );
                   
                    outputSample( out, desc, "  ", packed );
                }
            }
           
View Full Code Here

        String name = getParameter( parameters, "name" );
        long lease = getLongParameter( parameters, "lease" );
        String instrument = getParameter( parameters, "instrument", null );
        String chart = getParameter( parameters, "chart", null );
       
        InstrumentSampleDescriptor desc;
        try
        {
            desc = getInstrumentManager().locateInstrumentSampleDescriptor( name );
        }
        catch ( NoSuchInstrumentSampleException e )
        {
            // Sample no longer exists, go back to the parent instrument.
            int pos = name.lastIndexOf( '.' );
            if ( pos >= 0 )
            {
                throw new HTTPRedirect(
                    "instrument.html?name=" + urlEncode( name.substring( 0,  pos ) ) );
            }
            else
            {
                throw new HTTPRedirect( "instrument-manager.html" );
            }
        }
       
        // The instrument manager will do its own tests of the lease, but the
        //  restrictions on this connector may be stronger so they must be tested
        //  here as well.
        lease = Math.max( 1, Math.min( lease, getConnector().getMaxLeasedSampleLease() ) );
       
        if ( getInstrumentManager().getLeaseSampleCount() >= getConnector().getMaxLeasedSamples() )
        {
            lease = 1;
        }
       
        // Renew the lease
        desc.extendLease( lease );
       
        if ( instrument != null )
        {
            // Go to the instrument page.
            int pos = name.lastIndexOf( '.' );
            if ( pos >= 0 )
            {
                throw new HTTPRedirect(
                    "instrument.html?name=" + urlEncode( name.substring( 0,  pos ) ) );
            }
            else
            {
                throw new HTTPRedirect( "instrumentable.html" );
            }
        }
        else
        {
            // Redirect to the sample page.
            throw new HTTPRedirect( "sample.html?name=" + urlEncode( desc.getName() )
                + ( chart == null ? "" : "&chart=true" ) );
        }
       
    }
View Full Code Here

TOP

Related Classes of org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.