Package org.jclouds
Class ContextBuilder
- java.lang.Object
-
- org.jclouds.ContextBuilder
-
public class ContextBuilder extends Object
CreatesContext
orInjector
configured to an api and endpoint. Alternatively, this can be used to make a portableView
of that api.
ex. to build aApi
on a particular endpoint using the typed interfaceapi = ContextBuilder.newBuilder(new NovaApiMetadata()) .endpoint("http://10.10.10.10:5000/v2.0") .credentials(user, pass) .buildApi(NovaApi.class);
ex. to build aView
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 noModule
s are specified, the defaultlogging
andhttp transports
will be installed.- See Also:
Context
,View
,ApiMetadata
,ProviderMetadata
-
-
Field Summary
Fields Modifier and Type Field Description protected ApiMetadata
apiMetadata
protected String
apiVersion
protected String
buildVersion
protected String
credential
protected com.google.common.base.Optional<com.google.common.base.Supplier<Credentials>>
credentialsSupplierOption
protected com.google.common.base.Optional<String>
endpoint
protected com.google.common.base.Optional<String>
identity
protected List<com.google.inject.Module>
modules
protected com.google.common.base.Optional<String>
name
protected com.google.common.base.Optional<Properties>
overrides
protected String
providerId
protected com.google.common.base.Optional<ProviderMetadata>
providerMetadata
-
Constructor Summary
Constructors Modifier Constructor Description ContextBuilder(ApiMetadata apiMetadata)
protected
ContextBuilder(ProviderMetadata providerMetadata)
protected
ContextBuilder(ProviderMetadata providerMetadata, ApiMetadata apiMetadata)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ContextBuilder
apiVersion(String apiVersion)
<C extends Context>
Cbuild()
Builds the base context for this api.<C extends Context>
Cbuild(com.google.common.reflect.TypeToken<C> contextType)
this will build thecontext
supported by the current ApiMetadata.<V extends View>
Vbuild(Class<V> viewType)
<A extends Closeable>
AbuildApi(com.google.common.reflect.TypeToken<A> apiType)
likebuildApi(Class)
but permits a type-token for convenience.<A extends Closeable>
AbuildApi(Class<A> api)
This will return the top-level interface for the api or provider.protected com.google.common.base.Supplier<Credentials>
buildCredentialsSupplier(Properties expanded)
com.google.inject.Injector
buildInjector()
static com.google.inject.Injector
buildInjector(String name, ProviderMetadata providerMetadata, com.google.common.base.Supplier<Credentials> creds, List<com.google.inject.Module> inputModules)
ContextBuilder
buildVersion(String buildVersion)
<V extends View>
VbuildView(com.google.common.reflect.TypeToken<V> viewType)
this will build anyview
supported by the ApiMetadata.<V extends View>
VbuildView(Class<V> viewType)
ContextBuilder
credentials(String identity, String credential)
constant value of the cloud identity and credential.ContextBuilder
credentialsSupplier(com.google.common.base.Supplier<Credentials> credentialsSupplier)
returns the current login credentials.ContextBuilder
endpoint(String endpoint)
ApiMetadata
getApiMetadata()
protected Properties
getSystemProperties()
ContextBuilder
modules(Iterable<? extends com.google.inject.Module> modules)
ContextBuilder
name(String name)
static ContextBuilder
newBuilder(String providerOrApi)
looks up a provider or api with the given idstatic ContextBuilder
newBuilder(ApiMetadata apiMetadata)
static ContextBuilder
newBuilder(ProviderMetadata providerMetadata)
ContextBuilder
overrides(Properties overrides)
static String
searchPropertiesForProviderScopedProperty(Properties mutable, String prov, String key)
String
toString()
-
-
-
Field Detail
-
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
-
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 Detail
-
ContextBuilder
protected ContextBuilder(ProviderMetadata providerMetadata)
-
ContextBuilder
protected ContextBuilder(@Nullable ProviderMetadata providerMetadata, ApiMetadata apiMetadata)
-
ContextBuilder
public ContextBuilder(ApiMetadata apiMetadata)
-
-
Method Detail
-
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)
-
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 onApiMetadata.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 typeCloser
, if nothing else was configured viaApiMetadata.getContext()
. Typically, the type returned isApiContext
- See Also:
ApiMetadata.getContext()
,build(TypeToken)
-
build
public <V extends View> V build(Class<V> viewType)
- See Also:
buildView(Class)
-
buildView
public <V extends View> V buildView(Class<V> viewType)
- See Also:
buildView(TypeToken)
-
buildView
public <V extends View> V buildView(com.google.common.reflect.TypeToken<V> viewType)
-
build
public <C extends Context> C build(com.google.common.reflect.TypeToken<C> contextType)
this will build thecontext
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)
likebuildApi(Class)
but permits a type-token for convenience.
-
getApiMetadata
public ApiMetadata getApiMetadata()
-
-