org.mmbase.bridge
Class ContextProvider

java.lang.Object
  extended by org.mmbase.bridge.ContextProvider

public class ContextProvider
extends Object

This is the main factory to acquire certain 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");
 

Since:
MMBase-1.5
Version:
$Id: ContextProvider.java 42056 2010-04-27 13:41:43Z michiel $
Author:
Kees Jongenburger

Nested Class Summary
static class ContextProvider.Resolver
          A Resolver resolves an URI-string (the argument of getCloudContext(String) to a CloudContext object.
 
Field Summary
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"
 
Method Summary
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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CLOUD_CONTEXT_NAME

public static final 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"

See Also:
Constant Field Values
Method Detail

getCloudContext

public static CloudContext getCloudContext(String uri)
Factory method to get an instance of a CloudContext. Depending on the uri parameter given the CloudContext might be a local context, a remote context (rmi), or a CloudContext representing some other bridge implementation.

Parameters:
uri - an identifier for the context
possible values are defined by getResolvers(), but probably include:
  • local : will return a local context
  • mock:localhost : Will return a MockCloudContext.
  • rmi://hostname:port/contextname : will return a remote context (only if the rmmci or rmmci-client jar is available)
  • a null parameter: will return the default context. See getDefaultCloudContext()
The actual list can be found in the admin pages (a view on getResolvers().
Returns:
a cloud context
Throws:
BridgeException - if the cloudcontext was not found

getDefaultCloudContextName

public static String getDefaultCloudContextName()
The uri defined as default (using the 'mmbase.defaultcloudcontext' system property) or 'local'. The return value can be used in getCloudContext(java.lang.String), and is used in getDefaultCloudContext().

Returns:
the name of the cloud context to be used as default
Since:
MMBase-1.7

getDefaultCloudContext

public static CloudContext getDefaultCloudContext()
Returns the 'default' cloud context. This could be getCloudContext('local'), or getCloudContext('rmi://127.0.0.1:1111/remotecontext (as a fall back).

Returns:
the default cloud context This is the local cloud if mmbase is running or could be started (with mmbase.config system property), Otherwise a default rmmci cloud, or specified with the mmbase.defaultcloudtext system property
Since:
MMBase-1.7

getResolvers

public static List<ContextProvider.Resolver> getResolvers()
Returns the list of 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.

Since:
MMBase-1.9.2


MMBase 2.0-SNAPSHOT - null