blob: 5778cc8bd42eb312a85a5e3fd4b87fdf037968ae [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
47 public abstract int getStatus();
48
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
67 public AbstractMap<String,Long> getCounters() {
68 return counters_;
69 }
70
71 public long getCounter(String key) {
72 Long val = counters_.get(key);
73 if (val == null) {
74 return 0;
75 }
76 return val.longValue();
77 }
78
79 public void setOption(String key, String value) {
80 options_.put(key, value);
81 }
82
83 public String getOption(String key) {
84 return options_.get(key);
85 }
86
87 public AbstractMap<String,String> getOptions() {
88 return options_;
89 }
90
91 public long aliveSince() {
92 return alive_;
93 }
94
95 public String getCpuProfile() {
96 return "";
97 }
98
pwyckoff99b000b2008-04-03 19:30:55 +000099 public void reinitialize() {}
100
101 public void shutdown() {}
102
103}