Using Kilimanjaro

Boot an OsidRuntimeManager, resolve a manager, and start calling OSID services.

Getting Started

import org.osid.OSID; import org.osid.OsidRuntimeManager; import org.osid.ConfigurationErrorException; import org.osid.NotFoundException; import org.osid.OperationFailedException; import org.osid.resource.ResourceManager; import net.okapia.osid.kilimanjaro.BootLoader; import net.okapia.osid.kilimanjaro.OsidVersions; void main() { OsidRuntimeManager runtime = null; ResourceManager mgr = null; try { runtime = new BootLoader().getRuntimeManager("test"); mgr = (ResourceManager) runtime.getManager(OSID.RESOURCE, "my.resource.impl.ResourceManager", OsidVersions.V3_0_0.getVersion()); // do stuff } catch (ConfigurationErrorException | NotFoundException | OperationFailedException e) { e.printStackTrace(); } finally { if (mgr != null) { mgr.close(); } if (runtime != null) { runtime.close(); } } }

Walking Through It

new BootLoader() can itself throw OperationFailedException if a bootloader configuration file exists but can't be parsed, so construction belongs inside the try, not before it.

org.osid.OsidRuntimeManager getRuntimeManager(String context)
throws ConfigurationErrorException, OperationFailedException

The context argument ("test" above) isn't a magic keyword — it's an application-chosen label that seeds the configuration service, so the app (and the OSIDs underneath it) can look up configuration values keyed to that label later. See Configuration for how that label turns into a search path over configuration files.

org.osid.OsidManager getManager(org.osid.OSID osid, String implClassName, org.osid.installation.Version version)
throws ConfigurationErrorException, NotFoundException, OperationFailedException
ParameterTypeDescription
osidorg.osid.OSIDwhich OSID domain to broker, e.g. OSID.RESOURCE
implClassNameStringfully-qualified class name of the Provider implementation to instantiate
versionorg.osid.installation.Versionthe minimum OSID version the returned manager must support

kilimanjaro loads implClassName off the thread's context classloader, checks that it actually implements the requested OSID interface, instantiates it, and verifies it reports support for version before handing it back — see Brokering for the full enforcement chain and every exception this step can raise.

OsidVersions is a small enum of well-known OSID release versions; OsidVersions.V3_0_0.getVersion() returns the corresponding org.osid.installation.Version instance to pass as the third argument above.

Both mgr and runtime are OSID-managed resources — closing them in finally, guarded with a null check in case construction failed partway through, releases whatever the Provider is holding (connections, file handles, caches).

Native vs. Caching Runtime Managers

BootLoader always instantiates NativeRuntimeManager (or whichever class name configuration resolves to) by reflection — it never produces a caching runtime on its own. If you want managers cached across repeated getManager() calls for the same (osid, implClassName) pair, wrap the runtime explicitly:

OsidRuntimeManager runtime = CachingRuntimeManager.runtime(new BootLoader().getRuntimeManager("test"));

CachingRuntimeManager intercepts close() on the managers it hands out, so an individual consumer can't tear down a shared cached instance — only closing the CachingRuntimeManager itself closes the cached managers and the underlying runtime beneath them. It still re-checks version compatibility on every cache hit, so a version mismatch is caught per call rather than only at first instantiation.