blob: f8f26a31896d1464ffc0085381791137d1a6fd80 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
pwyckoff99b000b2008-04-03 19:30:55 +000019
20package com.facebook.fb303;
21
22import java.util.AbstractMap;
23import java.util.HashMap;
24import java.util.concurrent.ConcurrentHashMap;
25
26public abstract class FacebookBase implements FacebookService.Iface {
27
28 private String name_;
29
30 private long alive_;
31
32 private final ConcurrentHashMap<String,Long> counters_ =
33 new ConcurrentHashMap<String, Long>();
34
35 private final ConcurrentHashMap<String,String> options_ =
36 new ConcurrentHashMap<String, String>();
37
38 protected FacebookBase(String name) {
39 name_ = name;
40 alive_ = System.currentTimeMillis() / 1000;
41 }
42
43 public String getName() {
44 return name_;
45 }
46
Todd Lipcon61934782010-09-21 18:01:43 +000047 public abstract fb_status getStatus();
pwyckoff99b000b2008-04-03 19:30:55 +000048
49 public String getStatusDetails() {
50 return "";
51 }
52
53 public void deleteCounter(String key) {
54 counters_.remove(key);
55 }
56
57 public void resetCounter(String key) {
58 counters_.put(key, 0L);
59 }
60
61 public long incrementCounter(String key) {
62 long val = getCounter(key) + 1;
63 counters_.put(key, val);
64 return val;
65 }
66
Bryan Duxbury4e98a252011-07-13 21:17:26 +000067 public long incrementCounter(String key, long increment) {
68 long val = getCounter(key) + increment;
69 counters_.put(key, val);
70 return val;
71 }
72
73 public long setCounter(String key, long value) {
74 counters_.put(key, value);
75 return value;
76 }
77
pwyckoff99b000b2008-04-03 19:30:55 +000078 public AbstractMap<String,Long> getCounters() {
79 return counters_;
80 }
81
82 public long getCounter(String key) {
83 Long val = counters_.get(key);
84 if (val == null) {
85 return 0;
86 }
87 return val.longValue();
88 }
89
90 public void setOption(String key, String value) {
91 options_.put(key, value);
92 }
93
94 public String getOption(String key) {
95 return options_.get(key);
96 }
97
98 public AbstractMap<String,String> getOptions() {
99 return options_;
100 }
101
102 public long aliveSince() {
103 return alive_;
104 }
105
106 public String getCpuProfile() {
107 return "";
108 }
109
pwyckoff99b000b2008-04-03 19:30:55 +0000110 public void reinitialize() {}
111
112 public void shutdown() {}
113
114}