From: "Aníbal Limón" <anibal.limon@linux.intel.com>
To: bitbake-devel@lists.openembedded.org
Subject: [PATCHv2 1/4] fetch2/__init__.py: Add FetchConnectionCache class
Date: Tue, 23 Jun 2015 16:58:46 -0500 [thread overview]
Message-ID: <1435096729-14507-2-git-send-email-anibal.limon@linux.intel.com> (raw)
In-Reply-To: <1435096729-14507-1-git-send-email-anibal.limon@linux.intel.com>
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@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
next prev parent reply other threads:[~2015-06-23 22:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-23 21:58 [PATCHv2 0/4] Add connection cache support in wget checkstatus Aníbal Limón
2015-06-23 21:58 ` Aníbal Limón [this message]
2015-06-23 21:58 ` [PATCH 2/4] fetch2: Add fetch parameter to checkstatus Aníbal Limón
2015-06-23 21:58 ` [PATCHv2 3/4] fetch2/__init__.py: Add connection_cache param in Fetch __init__ Aníbal Limón
2015-06-23 21:58 ` [PATCHv2 4/4] tests/fetch.py: Add FetchCheckStatusTest tests Aníbal Limón
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1435096729-14507-2-git-send-email-anibal.limon@linux.intel.com \
--to=anibal.limon@linux.intel.com \
--cc=bitbake-devel@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox