Skip to content

Counter

Purpose

Access and control of the Counters service behaviour.

Methods

Binding name: p6.counter


list

Returns a list of all counter names as a JSON text.

Syntax

String p6.counter.list()
Example
def counters = p6.json.fromString(p6.counter.list())

counters.each { c ->
    p6.log.debug "AppKey: " + c['appKey']
    p6.log.debug "Name: " + c['name']
    p6.log.debug "Value: " + c['value']
}

get

Returns the counter detail as a JSON text

Syntax

String p6.counter.get(String counterName)

Tip

You could omit the prefix <appKey>. if the counter is not packaged.

Examples

Unpackaged

def c = p6.json.fromString(p6.counter.get('counterId'))
p6.log.debug "Value: " + c['value']

Packaged

def c = p6.json.fromString(p6.counter.get('myApp.counterId'))
p6.log.debug "Value: " + c['value']


synchronize

Returns the synchronized counter value

Syntax

String p6.counter.synchronize(String counterName)

Tip

You could omit the prefix <appKey>. if the counter is not packaged.

Examples

Unpackaged

def syncValue = p6.counter.synchronize('counterName')
p6.log.debug 'Value: ' + syncValue

Packaged

def syncValue = p6.counter.synchronize('myApp.counterName')
p6.log.debug 'Value: ' + syncValue