com.bigdata.counters.query
Class QueryUtil

java.lang.Object
  extended by com.bigdata.counters.query.QueryUtil

public class QueryUtil
extends Object

Some static utility methods.

Version:
$Id: QueryUtil.java 3796 2010-10-14 12:33:37Z thompsonbry $
Author:
Bryan Thompson

Nested Class Summary
static class QueryUtil.ReadCounterSetXMLFileTask
          Task reads counters matching a regular expression into the caller's CounterSet.
 
Field Summary
protected static org.apache.log4j.Logger log
           
 
Constructor Summary
QueryUtil()
           
 
Method Summary
static Collection<File> collectFiles(Collection<File> in, FileFilter filter)
          Return the specified files, substituting recursively spanned files when a given file is a directory.
static String[] getCapturedGroups(Pattern pattern, ICounter counter)
          Return the data captured by Pattern from the path of the specified counter.
static Pattern getPattern(Collection<Pattern> regex)
          Generate a Pattern from the OR of zero or more regular expressions which must be matched.
static Pattern getPattern(Collection<String> filter, Collection<String> regex)
          Generate a Pattern from the OR of zero or more strings which must be matched and zero or more regular expressions which must be matched.
static Pattern getRequiredPerformanceCountersFilter()
          Return a Pattern which will match the minimum set of performance counters required by the load balancer to perform its function.
static void main(String[] args)
          Utility may be used to read the required performance counters for the load balancer from zero or more files specified on the command line.
static void readCountersFromFile(File file, CounterSet counterSet, Pattern filter, ICounterSet.IInstrumentFactory instrumentFactory)
          Read counters matching the optional filter from the file into the given CounterSet.
static void readCountersFromFile(File file, CounterSet counterSet, Pattern filter, int nslots, PeriodEnum unit)
          Read counters matching the optional filter from the file into the given CounterSet.
static void readEvents(DummyEventReportingService service, File file)
          Read in Events logged on a file in a tab-delimited format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log
Constructor Detail

QueryUtil

public QueryUtil()
Method Detail

getCapturedGroups

public static String[] getCapturedGroups(Pattern pattern,
                                         ICounter counter)
Return the data captured by Pattern from the path of the specified counter.

Note: This is used to extract the parts of the Pattern which are of interest - presuming that you mark some parts with capturing groups and other parts that you do not care about with non-capturing groups.

Note: There is a presumption that Pattern was used to select the counters and that counter is one of the selected counters, in which case Pattern is KNOWN to match ICounterNode.getPath().

Returns:
The captured groups -or- null if there are no capturing groups.

getPattern

public static Pattern getPattern(Collection<String> filter,
                                 Collection<String> regex)
Generate a Pattern from the OR of zero or more strings which must be matched and zero or more regular expressions which must be matched.

Parameters:
filter - A list of strings to be matched (may be null).
regex - A list of regular expressions to be matched (may be null).
Returns:
The Pattern -or- null if both collects are empty.

getPattern

public static Pattern getPattern(Collection<Pattern> regex)
Generate a Pattern from the OR of zero or more regular expressions which must be matched.

Parameters:
regex - A list of regular expressions to be matched (may be null).
Returns:
The Pattern -or- null if both collects are empty.

readCountersFromFile

public static void readCountersFromFile(File file,
                                        CounterSet counterSet,
                                        Pattern filter,
                                        int nslots,
                                        PeriodEnum unit)
                                 throws IOException,
                                        SAXException,
                                        ParserConfigurationException
Read counters matching the optional filter from the file into the given CounterSet.

Parameters:
file - The file.
counterSet - The CounterSet.
filter - An optional filter.
nslots - The #of periods worth of data to be retained. This is used when a counter not already present in counterSet is encountered and controls the #of slots to be retained by History allocated for that counter.
unit - The unit in which the #of slots was expressed.
Throws:
IOException
SAXException
ParserConfigurationException

readCountersFromFile

public static void readCountersFromFile(File file,
                                        CounterSet counterSet,
                                        Pattern filter,
                                        ICounterSet.IInstrumentFactory instrumentFactory)
                                 throws IOException,
                                        SAXException,
                                        ParserConfigurationException
Read counters matching the optional filter from the file into the given CounterSet.

Parameters:
file - The file.
counterSet - The CounterSet.
filter - An optional filter.
instrumentFactory -
Throws:
IOException
SAXException
ParserConfigurationException

readEvents

public static void readEvents(DummyEventReportingService service,
                              File file)
                       throws IOException
Read in Events logged on a file in a tab-delimited format.

Parameters:
service - The events will be added to this service.
file - The file from which the events will be read.
Throws:
IOException
TODO:
support reading the events.jnl, which should be opened in a read-only mode.

collectFiles

public static Collection<File> collectFiles(Collection<File> in,
                                            FileFilter filter)
Return the specified files, substituting recursively spanned files when a given file is a directory.

Parameters:
in - A collection of zero or more files.
filter - A filter which will select the files to be accepted.
Returns:
A collection of the accepted files.

getRequiredPerformanceCountersFilter

public static Pattern getRequiredPerformanceCountersFilter()
Return a Pattern which will match the minimum set of performance counters required by the load balancer to perform its function.


main

public static void main(String[] args)
                 throws IOException,
                        SAXException,
                        ParserConfigurationException
Utility may be used to read the required performance counters for the load balancer from zero or more files specified on the command line. The results are written using the XML interchange format on stdout.

Parameters:
args - The file(s).
Throws:
IOException
SAXException
ParserConfigurationException


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.