Package org.jclouds

Class ContextBuilder

java.lang.Object
org.jclouds.ContextBuilder

public class ContextBuilder extends Object
Creates Context or Injector configured to an api and endpoint. Alternatively, this can be used to make a portable View of that api.
ex. to build a Api on a particular endpoint using the typed interface
 api = ContextBuilder.newBuilder(new NovaApiMetadata())
                     .endpoint("http://10.10.10.10:5000/v2.0")
                     .credentials(user, pass)
                     .buildApi(NovaApi.class);
 

ex. to build a View of a particular backend context, looked up by key.
 context = ContextBuilder.newBuilder("aws-s3")
                         .credentials(apikey, secret)
                         .buildView(BlobStoreContext.class);
 

Assumptions

Threadsafe objects will be bound as singletons to the Injector or Context provided.

If no Modules are specified, the default logging and http transports will be installed.

See Also:
  • Field Details

    • name

      protected com.google.common.base.Optional<String> name
    • providerMetadata

      protected com.google.common.base.Optional<ProviderMetadata> providerMetadata
    • providerId

      protected final String providerId
    • endpoint

      protected com.google.common.base.Optional<String> endpoint
    • identity

      protected com.google.common.base.Optional<String> identity
    • credentialsSupplierOption

      protected com.google.common.base.Optional<com.google.common.base.Supplier<Credentials>> credentialsSupplierOption
    • credential

      @Nullable protected String credential
    • apiMetadata

      protected ApiMetadata apiMetadata
    • apiVersion

      protected String apiVersion
    • buildVersion

      protected String buildVersion
    • overrides

      protected com.google.common.base.Optional<Properties> overrides
    • modules

      protected List<com.google.inject.Module> modules
  • Constructor Details

  • Method Details

    • newBuilder

      public static ContextBuilder newBuilder(String providerOrApi) throws NoSuchElementException
      looks up a provider or api with the given id
      Parameters:
      providerOrApi - id of the provider or api
      Returns:
      means to build a context to that provider
      Throws:
      NoSuchElementException - if the id was not configured.
    • newBuilder

      public static ContextBuilder newBuilder(ApiMetadata apiMetadata)
    • newBuilder

      public static ContextBuilder newBuilder(ProviderMetadata providerMetadata)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • name

      public ContextBuilder name(String name)
    • credentialsSupplier

      public ContextBuilder credentialsSupplier(com.google.common.base.Supplier<Credentials> credentialsSupplier)
      returns the current login credentials. jclouds will not cache this value. Use this when you need to change credentials at runtime.
    • credentials

      public ContextBuilder credentials(String identity, @Nullable String credential)
      constant value of the cloud identity and credential.
      Parameters:
      credential - (optional depending on ApiMetadata.getCredentialName()
    • endpoint

      public ContextBuilder endpoint(String endpoint)
    • apiVersion

      public ContextBuilder apiVersion(String apiVersion)
    • buildVersion

      public ContextBuilder buildVersion(String buildVersion)
    • modules

      public ContextBuilder modules(Iterable<? extends com.google.inject.Module> modules)
    • overrides

      public ContextBuilder overrides(Properties overrides)
    • searchPropertiesForProviderScopedProperty

      public static String searchPropertiesForProviderScopedProperty(Properties mutable, String prov, String key) throws NoSuchElementException
      Throws:
      NoSuchElementException
    • buildInjector

      public com.google.inject.Injector buildInjector()
    • buildCredentialsSupplier

      protected com.google.common.base.Supplier<Credentials> buildCredentialsSupplier(Properties expanded)
    • getSystemProperties

      protected Properties getSystemProperties()
    • buildInjector

      public static com.google.inject.Injector buildInjector(String name, ProviderMetadata providerMetadata, com.google.common.base.Supplier<Credentials> creds, List<com.google.inject.Module> inputModules)
    • build

      public <C extends Context> C build()
      Builds the base context for this api. Note that this may be of type
      invalid reference
      Closer
      , if nothing else was configured via ApiMetadata.getContext(). Typically, the type returned is
      invalid reference
      ApiContext
      See Also:
    • build

      public <V extends View> V build(Class<V> viewType)
      See Also:
    • buildView

      public <V extends View> V buildView(Class<V> viewType)
      See Also:
    • buildView

      public <V extends View> V buildView(com.google.common.reflect.TypeToken<V> viewType)
      this will build any view supported by the ApiMetadata. ex. builder.build(BlobStoreContext.class) will work, if TypeToken<BlobStore> is a configured view of this api.
    • build

      public <C extends Context> C build(com.google.common.reflect.TypeToken<C> contextType)
      this will build the context supported by the current ApiMetadata.
    • buildApi

      public <A extends Closeable> A buildApi(Class<A> api)
      This will return the top-level interface for the api or provider. Ex.
       api = ContextBuilder.newBuilder("openstack-nova")
                           ... 
                           .buildApi(NovaApi.class);
      
    • buildApi

      public <A extends Closeable> A buildApi(com.google.common.reflect.TypeToken<A> apiType)
      like buildApi(Class) but permits a type-token for convenience.
    • getApiMetadata

      public ApiMetadata getApiMetadata()