1/********************************************************************
2 * Copyright (c) 2013 - 2014, Pivotal Inc.
3 * All rights reserved.
4 *
5 * Author: Zhanwei Wang
6 ********************************************************************/
7/********************************************************************
8 * 2014 -
9 * open source under Apache License Version 2.0
10 ********************************************************************/
11/**
12 * Licensed to the Apache Software Foundation (ASF) under one
13 * or more contributor license agreements. See the NOTICE file
14 * distributed with this work for additional information
15 * regarding copyright ownership. The ASF licenses this file
16 * to you under the Apache License, Version 2.0 (the
17 * "License"); you may not use this file except in compliance
18 * with the License. You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28#ifndef _HDFS_LIBHDFS3_CLIENT_LEASE_RENEW_H_
29#define _HDFS_LIBHDFS3_CLIENT_LEASE_RENEW_H_
30
31#include <map>
32
33#include "Atomic.h"
34#include "Memory.h"
35#include "Thread.h"
36
37namespace Hdfs {
38namespace Internal {
39
40class FileSystemInter;
41
42class LeaseRenewer {
43public:
44 virtual ~LeaseRenewer() {
45 }
46
47 virtual void StartRenew(shared_ptr<FileSystemInter> filesystem) = 0;
48 virtual void StopRenew(shared_ptr<FileSystemInter> filesystem) = 0;
49
50public:
51 static LeaseRenewer & GetLeaseRenewer();
52 static void CreateSinglten();
53
54private:
55 static once_flag once;
56 static shared_ptr<LeaseRenewer> renewer;
57};
58
59class LeaseRenewerImpl: public LeaseRenewer {
60public:
61 LeaseRenewerImpl();
62 ~LeaseRenewerImpl();
63 int getInterval() const;
64 void setInterval(int interval);
65 void StartRenew(shared_ptr<FileSystemInter> filesystem);
66 void StopRenew(shared_ptr<FileSystemInter> filesystem);
67
68private:
69 void renewer();
70
71private:
72 atomic<bool> stop;
73 condition_variable cond;
74 int interval;
75 mutex mut;
76 std::map<std::string, shared_ptr<FileSystemInter> > maps;
77 thread worker;
78};
79
80}
81}
82#endif /* _HDFS_LIBHDFS3_CLIENT_LEASE_RENEW_H_ */
83