Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to create new ThumbnailStore connection #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 78 additions & 24 deletions src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,7 @@ class _BlitzGateway (object):
def __init__(self, username=None, passwd=None, client_obj=None, group=None,
clone=False, try_super=False, host=None, port=None,
extra_config=None, secure=False, anonymous=True,
useragent=None, userip=None):
useragent=None, userip=None, cache_services=True):
"""
Create the connection wrapper.
Does not attempt to connect at this stage
Expand Down Expand Up @@ -1555,6 +1555,9 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None,
:param useragent: Log which python clients use this connection.
E.g. 'OMERO.webadmin'
:param userip: Log client ip.
:param cache_services: False to create a new service connection for
each request. Note: Make sure to close the
service in that case.
:type useragent: String
"""

Expand Down Expand Up @@ -1606,6 +1609,7 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None,

# The properties we are setting through the interface
self.setIdentity(username, passwd, not clone)
self._cache_services = cache_services

def __enter__(self):
"""
Expand Down Expand Up @@ -1672,6 +1676,12 @@ def _assert_unregistered(self, prefix="Service left open!"):
prefix, service_string, stack_msg))
return count

def cacheServices(self, cache_services):
"""Use cached services (default). Set to False in order to
create a new service connection for each request. Note: In that
case make sure that the connection is closed again."""
self._cache_services = cache_services

def createServiceOptsDict(self):
serviceOpts = ServiceOptsDict(self.c.getImplicitContext().getContext())
serviceOpts.setOmeroGroup(self.getDefaultOmeroGroup())
Expand Down Expand Up @@ -2553,15 +2563,19 @@ def getAdminService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['admin']
if self._cache_services:
return self._proxies['admin']
return ProxyObjectWrapper(self, 'getAdminService')

def getQueryService(self):
"""
Gets reference to the query service from ProxyObjectWrapper.

:return: omero.gateway.ProxyObjectWrapper
"""
return self._proxies['query']
if self._cache_services:
return self._proxies['query']
return ProxyObjectWrapper(self, 'getQueryService')

def getContainerService(self):
"""
Expand All @@ -2570,7 +2584,9 @@ def getContainerService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['container']
if self._cache_services:
return self._proxies['container']
return ProxyObjectWrapper(self, 'getContainerService')

def getPixelsService(self):
"""
Expand All @@ -2579,7 +2595,9 @@ def getPixelsService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['pixel']
if self._cache_services:
return self._proxies['pixel']
return ProxyObjectWrapper(self, 'getPixelsService')

def getMetadataService(self):
"""
Expand All @@ -2588,7 +2606,9 @@ def getMetadataService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['metadata']
if self._cache_services:
return self._proxies['metadata']
return ProxyObjectWrapper(self, 'getMetadataService')

def getRoiService(self):
"""
Expand All @@ -2597,7 +2617,9 @@ def getRoiService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['roi']
if self._cache_services:
return self._proxies['roi']
return ProxyObjectWrapper(self, 'getRoiService')

def getScriptService(self):
"""
Expand All @@ -2606,7 +2628,9 @@ def getScriptService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['script']
if self._cache_services:
return self._proxies['script']
return ProxyObjectWrapper(self, 'getScriptService')

def createRawFileStore(self):
"""
Expand All @@ -2616,7 +2640,9 @@ def createRawFileStore(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['rawfile']
if self._cache_services:
return self._proxies['rawfile']
return ProxyObjectWrapper(self, 'createRawFileStore')

def getRepositoryInfoService(self):
"""
Expand All @@ -2625,7 +2651,9 @@ def getRepositoryInfoService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['repository']
if self._cache_services:
return self._proxies['repository']
return ProxyObjectWrapper(self, 'getRepositoryInfoService')

def getShareService(self):
"""
Expand All @@ -2634,7 +2662,9 @@ def getShareService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['share']
if self._cache_services:
return self._proxies['share']
return ProxyObjectWrapper(self, 'getShareService')

def getSharedResources(self):
"""
Expand All @@ -2643,7 +2673,9 @@ def getSharedResources(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['sharedres']
if self._cache_services:
return self._proxies['sharedres']
return ProxyObjectWrapper(self, 'getSharedResources')

def getTimelineService(self):
"""
Expand All @@ -2652,7 +2684,9 @@ def getTimelineService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['timeline']
if self._cache_services:
return self._proxies['timeline']
return ProxyObjectWrapper(self, 'getTimelineService')

def getTypesService(self):
"""
Expand All @@ -2661,7 +2695,9 @@ def getTypesService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['types']
if self._cache_services:
return self._proxies['types']
return ProxyObjectWrapper(self, 'getTypesService')

def getConfigService(self):
"""
Expand All @@ -2670,7 +2706,9 @@ def getConfigService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['config']
if self._cache_services:
return self._proxies['config']
return ProxyObjectWrapper(self, 'getConfigService')

def createRenderingEngine(self):
"""
Expand All @@ -2682,7 +2720,10 @@ def createRenderingEngine(self):
:return: omero.gateway.ProxyObjectWrapper
"""

rv = self._proxies['rendering']
if self._cache_services:
rv = self._proxies['rendering']
else:
rv = ProxyObjectWrapper(self, 'createRenderingEngine')
if rv._tainted:
rv = self._proxies['rendering'] = rv.clone()
rv.taint()
Expand All @@ -2696,7 +2737,9 @@ def getRenderingSettingsService(self):
:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['rendsettings']
if self._cache_services:
return self._proxies['rendsettings']
return ProxyObjectWrapper(self, 'getRenderingSettingsService')

def createRawPixelsStore(self):
"""
Expand All @@ -2705,8 +2748,9 @@ def createRawPixelsStore(self):

:return: omero.gateway.ProxyObjectWrapper
"""

return self._proxies['rawpixels']
if self._cache_services:
return self._proxies['rawpixels']
return ProxyObjectWrapper(self, 'createRawPixelsStore')

def createThumbnailStore(self):
"""
Expand All @@ -2716,8 +2760,9 @@ def createThumbnailStore(self):
:rtype: omero.gateway.ProxyObjectWrapper
:return: The proxy wrapper of the thumbnail store
"""

return self._proxies['thumbs']
if self._cache_services:
return self._proxies['thumbs']
return ProxyObjectWrapper(self, 'createThumbnailStore')

def createSearchService(self):
"""
Expand All @@ -2726,23 +2771,29 @@ def createSearchService(self):

:return: omero.gateway.ProxyObjectWrapper
"""
return self._proxies['search']
if self._cache_services:
return self._proxies['search']
return ProxyObjectWrapper(self, 'createSearchService')

def getUpdateService(self):
"""
Gets reference to the update service from ProxyObjectWrapper.

:return: omero.gateway.ProxyObjectWrapper
"""
return self._proxies['update']
if self._cache_services:
return self._proxies['update']
return ProxyObjectWrapper(self, 'getUpdateService')

def getSessionService(self):
"""
Gets reference to the session service from ProxyObjectWrapper.

:return: omero.gateway.ProxyObjectWrapper
"""
return self._proxies['session']
if self._cache_services:
return self._proxies['session']
return ProxyObjectWrapper(self, 'getSessionService')

def createExporter(self):
"""
Expand Down Expand Up @@ -8271,13 +8322,16 @@ def _prepareTB(self, _r=False, rdefId=None):
:type _r: Boolean
:param rdefId: Rendering def ID to use for rendering thumbnail
:type rdefId: Long
:param use_cached_ts: If true (default) use the cached ThumbnailStore,
else create a new one.
:return: Thumbnail Store or None
:rtype: :class:`ProxyObjectWrapper`
"""

pid = self.getPrimaryPixels().id
if rdefId is None:
rdefId = self._getRDef()

tb = self._conn.createThumbnailStore()

ctx = self._conn.SERVICE_OPTS.copy()
Expand Down