| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* | 
 | 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 |  */ | 
| pwyckoff | 99b000b | 2008-04-03 19:30:55 +0000 | [diff] [blame] | 19 |  | 
 | 20 | package com.facebook.fb303; | 
 | 21 |  | 
 | 22 | import java.util.AbstractMap; | 
 | 23 | import java.util.HashMap; | 
 | 24 | import java.util.concurrent.ConcurrentHashMap; | 
 | 25 |  | 
 | 26 | public 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 Lipcon | 6193478 | 2010-09-21 18:01:43 +0000 | [diff] [blame] | 47 |   public abstract fb_status getStatus(); | 
| pwyckoff | 99b000b | 2008-04-03 19:30:55 +0000 | [diff] [blame] | 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 |  | 
| Bryan Duxbury | 4e98a25 | 2011-07-13 21:17:26 +0000 | [diff] [blame] | 67 |   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 |  | 
| pwyckoff | 99b000b | 2008-04-03 19:30:55 +0000 | [diff] [blame] | 78 |   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 |  | 
| pwyckoff | 99b000b | 2008-04-03 19:30:55 +0000 | [diff] [blame] | 110 |   public void reinitialize() {} | 
 | 111 |  | 
 | 112 |   public void shutdown() {} | 
 | 113 |  | 
 | 114 | } |