Skip to content

Commit

Permalink
Added option to disable default persistence
Browse files Browse the repository at this point in the history
If the pelix.configadmin.persistence.default.disable property is set to
a non-empty value at framework level, the default persistence service
won't be automatically instantiated.
This is compatible with the previous behaviour.

See #113
  • Loading branch information
tcalmant committed Apr 22, 2020
1 parent 65f4978 commit 38431df
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pelix/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
SERVICE_CONFIGADMIN_PERSISTENCE = "pelix.configadmin.persistence"
""" Specification of a ConfigurationAdmin storage service """

FRAMEWORK_PROP_CONFIGADMIN_DISABLE_DEFAULT_PERSISTENCE = (
"pelix.configadmin.persistence.default.disable"
)
"""
If this framework property has a value, the default persistence service of
ConfigurationAdmin won't be started
"""

FACTORY_CONFIGADMIN_JSON = "pelix-configadmin-persistence-json-factory"
""" Name of the JSON ConfigurationAdmin storage component factory """

Expand Down
31 changes: 30 additions & 1 deletion pelix/services/configadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,6 @@ def list_configurations(self, ldap_filter=None):
@Requires("_directory", SERVICE_CONFIGADMIN_DIRECTORY)
@Property("_conf_folder", "configuration.folder")
@Property("_watched_folder", services.PROP_FILEINSTALL_FOLDER)
@Instantiate("pelix-services-configuration-json-default")
class JsonPersistence(object):
"""
JSON configuration persistence
Expand Down Expand Up @@ -1201,3 +1200,33 @@ def folder_change(self, folder, added, updated, deleted):
except (KeyError, ValueError, IOError) as ex:
# Log other errors
_logger.error("Error updating %s: %s", pid, ex)


@pelix.constants.BundleActivator
class Activator(object):
"""
Instantiates the default JSON configuration provider
"""

@staticmethod
def start(context):
"""
Bundle started
"""
if context.get_property(
services.FRAMEWORK_PROP_CONFIGADMIN_DISABLE_DEFAULT_PERSISTENCE
):
# No need to run the default provider
return

# Small trick to add a late Instantiate decoration
# to the component factory
Instantiate("pelix-services-configuration-json-default")(
JsonPersistence
)

@staticmethod
def stop(_):
"""
Bundle stopped
"""

0 comments on commit 38431df

Please sign in to comment.