[bitbake-devel] [PATCH 1/4] fetch2/__init__.py: Add FetchConnectionCache class
Aníbal Limón
anibal.limon at linux.intel.com
Tue Jun 23 19:26:02 UTC 2015
FetchConnectionCache class acts as a container for socket connections
useful when implement connection cache into fetcher modules.
Signed-off-by: Aníbal Limón <anibal.limon at linux.intel.com>
---
lib/bb/fetch2/__init__.py | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index cc772df..7fd9ec7 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -1711,6 +1711,42 @@ class Fetch(object):
if ud.lockfile:
bb.utils.unlockfile(lf)
+class FetchConnectionCache(object):
+ """
+ A class which represents an container for socket connections.
+ """
+ def __init__(self):
+ self.cache = {}
+
+ def get_connection_name(self, host, port):
+ return host + ':' + str(port)
+
+ def add_connection(self, host, port, connection):
+ cn = self.get_connection_name(host, port)
+
+ if cn not in self.cache:
+ self.cache[cn] = connection
+
+ def get_connection(self, host, port):
+ connection = None
+
+ cn = self.get_connection_name(host, port)
+ if cn in self.cache:
+ connection = self.cache[cn]
+
+ return connection
+
+ def remove_connection(self, host, port):
+ cn = self.get_connection_name(host, port)
+ if cn in self.cache:
+ self.cache[cn].close()
+ del self.cache[cn]
+
+ def close_connections(self):
+ for cn in self.cache.keys():
+ self.cache[cn].close()
+ del self.cache[cn]
+
from . import cvs
from . import git
from . import gitsm
--
1.9.1
More information about the bitbake-devel
mailing list