You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2012/12/13 07:45:02 UTC

[6/7] git commit: TS-1621: Adopt the ConfigUpdateHandler pattern for IpAllow updates

TS-1621: Adopt the ConfigUpdateHandler pattern for IpAllow updates


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/f22407aa
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/f22407aa
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/f22407aa

Branch: refs/heads/master
Commit: f22407aad7541b7f653fb5e215bb6f673c630b74
Parents: 472c613
Author: Ethan Lai <yz...@yahoo.com>
Authored: Wed Dec 12 22:00:34 2012 -0800
Committer: James Peach <jp...@apache.org>
Committed: Wed Dec 12 22:03:28 2012 -0800

----------------------------------------------------------------------
 proxy/IPAllow.cc |   42 +++++++-----------------------------------
 proxy/IPAllow.h  |   12 ++++++------
 proxy/Main.cc    |    2 +-
 3 files changed, 14 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f22407aa/proxy/IPAllow.cc
----------------------------------------------------------------------
diff --git a/proxy/IPAllow.cc b/proxy/IPAllow.cc
index 093cf73..2cd1d77 100644
--- a/proxy/IPAllow.cc
+++ b/proxy/IPAllow.cc
@@ -51,55 +51,27 @@ uint32_t IpAllow::ALL_METHOD_MASK;
 
 int IpAllow::configid = 0;
 
-static Ptr<ProxyMutex> ip_reconfig_mutex;
-
-// struct IpAllowUpdate
-//
-//   Used to read the ip_allow.conf file after the manager signals
-//      a change
-//
-struct IpAllowUpdate: public Continuation
-{
-  int update(int /* etype */, void * /* data */) {
-    IpAllow::ReloadInstance();
-    delete this;
-    return EVENT_DONE;
-  }
-
-  IpAllowUpdate(ProxyMutex * m):Continuation(m) {
-    SET_HANDLER(&IpAllowUpdate::update);
-  }
-};
-
-int
-ipAllowFile_CB(const char *name, RecDataT data_type, RecData data, void *cookie)
-{
-  NOWARN_UNUSED(name);
-  NOWARN_UNUSED(data_type);
-  NOWARN_UNUSED(data);
-  NOWARN_UNUSED(cookie);
-  eventProcessor.schedule_imm(NEW(new IpAllowUpdate(ip_reconfig_mutex)), ET_CACHE);
-  return 0;
-}
+static ConfigUpdateHandler<IpAllow> * ipAllowUpdate;
 
 //
 //   Begin API functions
 //
 void
-IpAllow::InitInstance()
+IpAllow::startup()
 {
   // Should not have been initialized before
   ink_assert(IpAllow::configid == 0);
 
   ALL_METHOD_MASK = ~0;
 
-  ip_reconfig_mutex = new_ProxyMutex();
-  REC_RegisterConfigUpdateFunc("proxy.config.cache.ip_allow.filename", ipAllowFile_CB, NULL);
-  ReloadInstance();
+  ipAllowUpdate = NEW(new ConfigUpdateHandler<IpAllow>());
+  ipAllowUpdate->attach("proxy.config.cache.ip_allow.filename");
+
+  reconfigure();
 }
 
 void
-IpAllow::ReloadInstance()
+IpAllow::reconfigure()
 {
   self *new_table;
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f22407aa/proxy/IPAllow.h
----------------------------------------------------------------------
diff --git a/proxy/IPAllow.h b/proxy/IPAllow.h
index 456f6aa..941a7e7 100644
--- a/proxy/IPAllow.h
+++ b/proxy/IPAllow.h
@@ -74,11 +74,12 @@ public:
 
   IpAllow(const char *config_var, const char *name, const char *action_val);
    ~IpAllow();
-  int BuildTable();
   void Print();
   uint32_t match(IpEndpoint const* ip) const;
   uint32_t match(sockaddr const* ip) const;
 
+  static void startup();
+  static void reconfigure();
   /// @return The global instance.
   static IpAllow * acquire();
   static void release(IpAllow * params);
@@ -92,9 +93,11 @@ public:
   typedef ConfigProcessor::scoped_config<IpAllow, IpAllow> scoped_config;
 
 private:
-  static void InitInstance();
-  static void ReloadInstance();
   static uint32_t MethodIdxToMask(int);
+  static uint32_t ALL_METHOD_MASK;
+  static int configid;
+
+  int BuildTable();
 
   const char *config_file_var;
   char config_file_path[PATH_NAME_MAX];
@@ -102,9 +105,6 @@ private:
   const char *action;
   IpMap _map;
   Vec<AclRecord> _acls;
-  static uint32_t ALL_METHOD_MASK;
-
-  static int configid;
 };
 
 inline uint32_t IpAllow::MethodIdxToMask(int idx) { return 1 << (idx - HTTP_WKSIDX_CONNECT); }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f22407aa/proxy/Main.cc
----------------------------------------------------------------------
diff --git a/proxy/Main.cc b/proxy/Main.cc
index f825c2e..231e084 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -1627,7 +1627,7 @@ main(int argc, char **argv)
     initCacheControl();
 #endif
     initCongestionControl();
-    IpAllow::InitInstance();
+    IpAllow::startup();
     ParentConfig::startup();
 #ifdef SPLIT_DNS
     SplitDNSConfig::startup();