Package org.apache.excalibur.instrument.manager

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


        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;
        String detailFormat;
        if( interval < 1000 )
        {
            // Once per 10 seconds.
            hInterval = (int)( 10000 / interval );
            format = "{3}:{4}:{5}";
            detailFormat = "{1}/{2} {3}:{4}:{5}.{6}";
        }
        else if( interval < 60000 )
        {
            // Once per minute.
            hInterval = (int)( 60000 / interval );
            format = "{3}:{4}:{5}";
            detailFormat = "{1}/{2} {3}:{4}:{5}";
        }
        else if( interval < 600000 )
        {
            // Once per 10 minutes
            hInterval = (int)( 600000 / interval );
            format = "{1}/{2} {3}:{4}";
            detailFormat = "{1}/{2} {3}:{4}";
        }
        else if( interval < 3600000 )
        {
            // Once per hour.
            hInterval = (int)( 3600000 / interval );
            format = "{1}/{2} {3}:{4}";
            detailFormat = "{1}/{2} {3}:{4}";
        }
        else if( interval < 86400000 )
        {
            // Once per day.
            hInterval = (int)( 86400000 / interval );
            format = "{1}/{2}";
            detailFormat = "{1}/{2} {3}:{4}";
        }
        else if( interval < 604800000 )
        {
            // Once per week.
            hInterval = (int)( 604800000 / interval );
            format = "{0}/{1}/{2}";
            detailFormat = "{0}/{1}/{2}";
        }
        else
        {
            // Default to every 10 points.
            hInterval = 10;
            format = "{0}/{1}/{2}";
            detailFormat = "{0}/{1}/{2}";
        }
           
        // Actually create the chart and add it to the content pane
        LineChart chart = new LineChart( hInterval, interval, format, detailFormat, 20, antialias );
        chart.setValues( snapshot.getSamples(), snapshot.getTime() );
       
        byte[] imageData = null;
       
        // Create a new BufferedImage onto which the plant will be painted.
        BufferedImage bi = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
View Full Code Here


        synchronized( this )
        {
            long time = System.currentTimeMillis();
            update( time, false );

            return new InstrumentSampleSnapshot(
                m_name,
                m_interval,
                m_size,
                m_time,
                getHistorySnapshot(),
View Full Code Here

                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
        {
View Full Code Here

                                        long baseTime,
                                        boolean packed,
                                        boolean compact )
        throws IOException
    {
        InstrumentSampleSnapshot snapshot = sample.getSnapshot();
        int[] values = snapshot.getSamples();
       
        // Given the base time, decide on the first value index and this time which
        //  will be included.
        long firstTime = snapshot.getTime() - ( snapshot.getSize() - 1 ) * snapshot.getInterval();
        int firstIndex;
        if ( baseTime <= firstTime )
        {
            firstIndex = 0;
        }
        else if ( baseTime >= snapshot.getTime() )
        {
            firstTime = snapshot.getTime();
            firstIndex = values.length - 1;
        }
        else
        {
            int count = (int)Math.ceil(
                ( (double)snapshot.getTime() - baseTime ) / snapshot.getInterval() ) + 1;
            firstTime = snapshot.getTime() - ( count - 1 ) * snapshot.getInterval();
            firstIndex = values.length - count;
        }
       
        // Where possible, display values from the snapshot rather than the sample
        //  to avoid any synchronization issues.
        outputLine( out, indent, packed, "<sample "
            + "name=\"" + makeSafeAttribute( sample.getName() ) + "\" "
            + "description=\"" + makeSafeAttribute( sample.getDescription() ) + "\" "
            + "type=\"" + sample.getType() + "\" "
            + "interval=\"" + snapshot.getInterval() + "\" "
            + "size=\"" + snapshot.getSize() + "\" "
            + "value=\"" + values[values.length - 1] + "\" "
            + "time=\"" + snapshot.getTime() + "\" "
            + "first-time=\"" + firstTime + "\" "
            + "count=\"" + ( values.length - firstIndex ) + "\" "
            + "expiration-time=\"" + sample.getLeaseExpirationTime() + "\" "
            + "state-version=\"" + snapshot.getStateVersion() + "\" "
            + "configured=\"" + sample.isConfigured() + "\">" );
       
        String childIndent = indent + INDENT;
       
        if ( compact )
        {
            // Output the values as a comma separated list.
            StringBuffer sb = new StringBuffer();
            sb.append( "<values>" );
            for ( int i = firstIndex; i < values.length; i++ )
            {
                if ( i > firstIndex )
                {
                    sb.append( "," );
                }
                sb.append( values[i] );
            }
            sb.append( "</values>" );
           
            outputLine( out, childIndent, packed, sb.toString() );
        }
        else
        {
            // Output an element for each value.
            long interval = snapshot.getInterval();
            long time = firstTime;
            for ( int i = firstIndex; i < values.length; i++ )
            {
                outputLine( out, childIndent, packed,
                    "<value time=\"" + time + "\" value=\"" + values[i] + "\"/>" );
View Full Code Here

        synchronized( this )
        {
            long time = System.currentTimeMillis();
            update( time, false );

            return new InstrumentSampleSnapshot(
                m_name,
                m_interval,
                m_size,
                m_time,
                getHistorySnapshot(),
View Full Code Here

                                        long baseTime,
                                        boolean packed,
                                        boolean compact )
        throws IOException
    {
        InstrumentSampleSnapshot snapshot = sample.getSnapshot();
        int[] values = snapshot.getSamples();
       
        // Given the base time, decide on the first value index and this time which
        //  will be included.
        long firstTime = snapshot.getTime() - ( snapshot.getSize() - 1 ) * snapshot.getInterval();
        int firstIndex;
        if ( baseTime <= firstTime )
        {
            firstIndex = 0;
        }
        else if ( baseTime >= snapshot.getTime() )
        {
            firstTime = snapshot.getTime();
            firstIndex = values.length - 1;
        }
        else
        {
            int count = (int)Math.ceil(
                ( (double)snapshot.getTime() - baseTime ) / snapshot.getInterval() ) + 1;
            firstTime = snapshot.getTime() - ( count - 1 ) * snapshot.getInterval();
            firstIndex = values.length - count;
        }
       
        // Where possible, display values from the snapshot rather than the sample
        //  to avoid any synchronization issues.
        outputLine( out, indent, packed, "<sample "
            + "name=\"" + makeSafeAttribute( sample.getName() ) + "\" "
            + "description=\"" + makeSafeAttribute( sample.getDescription() ) + "\" "
            + "type=\"" + sample.getType() + "\" "
            + "interval=\"" + snapshot.getInterval() + "\" "
            + "size=\"" + snapshot.getSize() + "\" "
            + "value=\"" + values[values.length - 1] + "\" "
            + "time=\"" + snapshot.getTime() + "\" "
            + "first-time=\"" + firstTime + "\" "
            + "count=\"" + ( values.length - firstIndex ) + "\" "
            + "expiration-time=\"" + sample.getLeaseExpirationTime() + "\" "
            + "state-version=\"" + snapshot.getStateVersion() + "\" "
            + "configured=\"" + sample.isConfigured() + "\">" );
       
        String childIndent = indent + INDENT;
       
        if ( compact )
        {
            // Output the values as a comma separated list.
            StringBuffer sb = new StringBuffer();
            sb.append( "<values>" );
            for ( int i = firstIndex; i < values.length; i++ )
            {
                if ( i > firstIndex )
                {
                    sb.append( "," );
                }
                sb.append( values[i] );
            }
            sb.append( "</values>" );
           
            outputLine( out, childIndent, packed, sb.toString() );
        }
        else
        {
            // Output an element for each value.
            long interval = snapshot.getInterval();
            long time = firstTime;
            for ( int i = firstIndex; i < values.length; i++ )
            {
                outputLine( out, childIndent, packed,
                    "<value time=\"" + time + "\" value=\"" + values[i] + "\"/>" );
View Full Code Here

        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;
        String detailFormat;
        if( interval < 1000 )
        {
            // Once per 10 seconds.
            hInterval = (int)( 10000 / interval );
            format = "{3}:{4}:{5}";
            detailFormat = "{1}/{2} {3}:{4}:{5}.{6}";
        }
        else if( interval < 60000 )
        {
            // Once per minute.
            hInterval = (int)( 60000 / interval );
            format = "{3}:{4}:{5}";
            detailFormat = "{1}/{2} {3}:{4}:{5}";
        }
        else if( interval < 600000 )
        {
            // Once per 10 minutes
            hInterval = (int)( 600000 / interval );
            format = "{1}/{2} {3}:{4}";
            detailFormat = "{1}/{2} {3}:{4}";
        }
        else if( interval < 3600000 )
        {
            // Once per hour.
            hInterval = (int)( 3600000 / interval );
            format = "{1}/{2} {3}:{4}";
            detailFormat = "{1}/{2} {3}:{4}";
        }
        else if( interval < 86400000 )
        {
            // Once per day.
            hInterval = (int)( 86400000 / interval );
            format = "{1}/{2}";
            detailFormat = "{1}/{2} {3}:{4}";
        }
        else if( interval < 604800000 )
        {
            // Once per week.
            hInterval = (int)( 604800000 / interval );
            format = "{0}/{1}/{2}";
            detailFormat = "{0}/{1}/{2}";
        }
        else
        {
            // Default to every 10 points.
            hInterval = 10;
            format = "{0}/{1}/{2}";
            detailFormat = "{0}/{1}/{2}";
        }
           
        // Actually create the chart and add it to the content pane
        LineChart chart = new LineChart( hInterval, interval, format, detailFormat, 20, antialias );
        chart.setValues( snapshot.getSamples(), snapshot.getTime() );
       
        byte[] imageData = null;
       
        // Create a new BufferedImage onto which the plant will be painted.
        BufferedImage bi = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
View Full Code Here

                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 ( !m_connector.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
        {
View Full Code Here

TOP

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

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.