Skip to content

Counter

Purpose

Access and control of the Counters service behaviour.

Methods

Binding name: p6.counter


Method: String list()

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


Method: String get(String counterName)

Returns the counter detail as a JSON text


Method: String synchronize(String counterName)

Returns the synchronized counter value

Examples

Example 1

Retrieve all the counters and their value

import groovy.json.JsonSlurper

def counters = new JsonSlurper().parseText(p6.counter.list())

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

Example 2

Retrieve a specific counter value

import groovy.json.JsonSlurper

def c = new JsonSlurper().parseText(p6.counter.get('<appKey>.<name>'))
println "Value: " + c['value']

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

Example 3

Retrieve a synchronized counter value

def syncValue = p6.counter.synchronize('<appKey>.<name>')
println "Value: " + syncValue

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