~mrooney/etherpad/ubuntu

« back to all changes in this revision

Viewing changes to trunk/trunk/infrastructure/framework-src/modules/varz.js

  • Committer: Aaron Iba
  • Date: 2009-12-18 07:40:23 UTC
  • Revision ID: hg-v1:a9f8774a2e00cc15b35857471fecea17f649e3c9
initial code push

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2009 Google Inc.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS-IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
jimport("java.util.concurrent.atomic.AtomicInteger");
 
18
 
 
19
import("sync");
 
20
 
 
21
function varz() {
 
22
  sync.callsyncIfTrue(appjet.cache,
 
23
    function() { return ! appjet.cache.varz; },
 
24
    function() { appjet.cache.varz = {}; });
 
25
  return appjet.cache.varz;
 
26
}
 
27
 
 
28
function _getInteger(name) {
 
29
  sync.callsyncIfTrue(varz(), 
 
30
    function() { return ! varz()[name] },
 
31
    function() { varz()[name] = new AtomicInteger(0) });
 
32
  return varz()[name];
 
33
}
 
34
 
 
35
function incrementInt(name) {
 
36
  _getInteger(name).getAndIncrement();
 
37
}
 
38
 
 
39
function addToInt(name, count) {
 
40
  _getInteger(name).getAndAdd(count);
 
41
}
 
42
 
 
43
function getSnapshot() {
 
44
  var ret = {};
 
45
  for (var k in varz()) {
 
46
    if (k[0] == '_') {
 
47
      continue;
 
48
    }
 
49
    ret[k] = varz()[k].toString();
 
50
  }
 
51
  return ret;
 
52
}