Last active
September 22, 2018 03:08
-
-
Save cbodley/896a466718a715ac2e59c1cd4760c55a to your computer and use it in GitHub Desktop.
RGWRados factory with dependency injection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RGWRados *RGWStoreManager::init_storage_provider(CephContext *cct, bool use_cache) | |
{ | |
// service factory functions return unique_ptr and take dependencies as raw pointers, | |
// or as unique_ptr&& to transfer ownership. errors are thrown as std::system_errors | |
try { | |
auto rados = create_rados(cct); | |
auto core = create_sysobj_core(cct, rados.get()); | |
auto sysobj = create_sysobj(cct, rados.get(), core.get()); | |
auto sync = create_sync_modules(cct); | |
auto zone = create_zone(cct, rados.get(), sync.get()); | |
auto zoneutils = create_zone_utils(cct, rados.get(), zone.get()); | |
auto quota = create_quota(cct, zone.default_bucket_quota(), zone.default_user_quota()); | |
std::unique_ptr<RGWSI_SysObj_Cache> cache; | |
if (use_cache) { | |
auto finisher = create_finisher(cct); | |
auto notify = create_notify(cct, rados.get(), std::move(finisher), zone.get_control_pool()); | |
cache = create_sysobj_cache(cct, core.get(), std::move(notify)); | |
} | |
// transfer ownership to RGWRados | |
auto store = new RGWRados(cct, std::move(rados), std::move(core), std::move(sysobj), | |
std::move(sync), std::move(zone), std::move(zoneutils), | |
std::move(quota), std::move(cache))); | |
if (!store->initialize()) { | |
delete store; | |
return nullptr; | |
} | |
return store; | |
} catch (const std::exception &e) { | |
return nullptr; | |
} | |
} | |
// example service factory | |
std::unique_ptr<RGWSI_Zone> create_zone(CephContext *cct, RGWSI_RADOS *rados, RGWSI_SyncModules *sync) | |
{ | |
auto zone = std::make_unique<RGWSI_Zone>(cct, rados, sync); | |
int r = zone->init(); | |
if (r < 0) { | |
lderr(cct) << "failed to init zone: " << r << dendl; | |
throw std::system_error(-r, std::system_category()); | |
} | |
return zone; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment