public class ContextProvider extends Object
CloudContexts. The most basic method is
getCloudContext(String).
The method getResolvers() can be used to inspect what kind of CloudContexts are currently
available. Normally there is one named 'local' which represents the MMBase in the current
application. CloudContexts are pluggable. An extra jar may also provide one or more CloudContext
resolvers (e.g. the rmmci jar would do that).
There is also a method getDefaultCloudContext(). This returns
getCloudContext('local'), unless a System property
mmbase.defaultcloudcontext defines another URI (e.g. an rmmci implementation).
If your code does not have any user interaction, you'll typically be able to start like this:
Cloud cloud = ContextProvider.getDefaultCloudContext().getCloud("mmbase", "class", null);
// Now start doing things with the Cloud.
This acquires a cloud on the 'default context' authenticated with ClassAuthentication. During testing the default cloud context
can e.g. be a MockCloudContext or a org.mmbase.bridge.RemoteCloudContext.
Though discouraged, it is sometimes also possible to directly access the wanted CloudContext
implementation, and not use ContextProvider at all. It depends on that implementation how
precisely that would go. E.g. if you're absolutely certain that your code must only work on the
local MMBase, you may proceed like so:
Cloud cloud = LocalContext.getCloudContext().getCloud("mmbase", "class", null);
Another example, which is acceptable in test cases:
Cloud cloud = MockCloudContext.getInstance().getCloud("mmbase");
| Modifier and Type | Class and Description |
|---|---|
static class |
ContextProvider.LocalResolver
The resolver recognizing only the string 'local', which then returns
LocalContext.getCloudContext(). |
static class |
ContextProvider.Resolver
A Resolver resolves an URI-string (the argument of
getCloudContext(String) to a CloudContext object. |
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_CLOUD_CONTEXT_NAME
When no system property mmbase.defaultcloudcontext is set
the default cloud context is the context returned when
DEFAULT_CLOUD_CONTEXT_NAME is fed to getCloudContext(String)
DEFAULT_CLOUD_CONTEXT_NAME="local" |
| Modifier and Type | Method and Description |
|---|---|
static CloudContext |
getCloudContext(String uri)
Factory method to get an instance of a CloudContext.
|
static CloudContext |
getDefaultCloudContext()
Returns the 'default' cloud context.
|
static String |
getDefaultCloudContextName()
The uri defined as default (using the 'mmbase.defaultcloudcontext' system property) or
'local'.
|
static List<ContextProvider.Resolver> |
getResolvers()
Returns the list of
ContextProvider.Resolvers that is used in the implementation of getCloudContext(String). |
public static final String DEFAULT_CLOUD_CONTEXT_NAME
public static CloudContext getCloudContext(String uri)
uri - an identifier for the contextgetResolvers(), but probably include:
MockCloudContext.getDefaultCloudContext() getResolvers().BridgeException - if the cloudcontext was not foundpublic static String getDefaultCloudContextName()
getCloudContext(java.lang.String), and is used in getDefaultCloudContext().public static CloudContext getDefaultCloudContext()
getCloudContext('local'), or
getCloudContext('rmi://127.0.0.1:1111/remotecontext (as a fall back).public static List<ContextProvider.Resolver> getResolvers()
ContextProvider.Resolvers that is used in the implementation of getCloudContext(String). The contents of this list are defined by the resource
org.mmbase.config.contextproviders. A plain text resource just simply stating the
Resolver-classes. E.g. the RMMCI-jar provides this resource too, to add itself to this list.MMBase 1.9-SNAPSHOT - ${javadoctimestamp}