public class Cloud extends Object
ServiceInfo
s obtained using the
underlying CloudConnector
and allows translating those to service connector such as a DataSource
.
It also passes along information obtained through CloudConnector
to let application take control on how
to use bound services.
NOTE: Users or cloud providers shouldn't need to instantiate an instance of this class (constructor has package-access only for
unit-testing purpose). Instead, they can obtain an appropriate instance through CloudFactory
Modifier and Type | Method and Description |
---|---|
ApplicationInstanceInfo |
getApplicationInstanceInfo() |
Properties |
getCloudProperties()
Get properties for app and services.
|
<SC> SC |
getServiceConnector(String serviceId,
Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig)
Get a service connector for the given service id, the connector type, configured with the given config
|
ServiceInfo |
getServiceInfo(String serviceId)
Get
ServiceInfo for the given service id |
List<ServiceInfo> |
getServiceInfos() |
<T> List<ServiceInfo> |
getServiceInfos(Class<T> serviceConnectorType)
Get
ServiceInfo s for the bound services that could be mapped to the given service connector type. |
<T extends ServiceInfo> |
getServiceInfosByType(Class<T> serviceInfoType)
Get all
ServiceInfo s for the given service info type. |
<SC> SC |
getSingletonServiceConnector(Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig)
Get the singleton service connector for the given connector type, configured with the given config
|
<T extends ServiceInfo> |
getSingletonServiceInfoByType(Class<T> serviceInfoType)
Get the singleton
ServiceInfo for the given service info type. |
void |
registerServiceConnectorCreator(ServiceConnectorCreator<?,? extends ServiceInfo> serviceConnectorCreator)
Register a new service connector creator
|
public ApplicationInstanceInfo getApplicationInstanceInfo()
CloudConnector.getApplicationInstanceInfo()
public ServiceInfo getServiceInfo(String serviceId)
ServiceInfo
for the given service idserviceId
- service idpublic List<ServiceInfo> getServiceInfos()
CloudConnector.getServiceInfos()
public <T> List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType)
ServiceInfo
s for the bound services that could be mapped to the given service connector type.
For example, if the connector type is DataSource
, then the method will return all ServiceInfo
objects
matching bound relational database services.
T
- The class of the connector to find services for.serviceConnectorType
- service connector type.
Passing null returns all ServiceInfo
s (matching that of getServiceInfos()
public <T extends ServiceInfo> List<T> getServiceInfosByType(Class<T> serviceInfoType)
ServiceInfo
s for the given service info type.
Unlike getServiceInfos(Class)
which checks if the service info
can be mapped to the given service connector type, this method only
checks the type of the service info.
T
- the class of service info to returnserviceInfoType
- service info typepublic <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType)
ServiceInfo
for the given service info type.T
- the class of service info to returnserviceInfoType
- service info typeCloudException
- if there are either 0 or more than 1 service info of the
given type.public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig)
SC
- The class of the service connector to return.serviceId
- the service idserviceConnectorType
- The expected class of service connector such as, DataSource.class.serviceConnectorConfig
- service connector configuration (such as pooling parameters).public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig)
SC
- The class of the service connector to return.serviceConnectorType
- The expected class of service connector such as, DataSource.class.serviceConnectorConfig
- service connector configuration (such as pooling parameters).public void registerServiceConnectorCreator(ServiceConnectorCreator<?,? extends ServiceInfo> serviceConnectorCreator)
serviceConnectorCreator
- the service connector to registerpublic Properties getCloudProperties()
Application properties always include cloud.application.app-id
and cloud.application.instance-id
with values bound to application id and instance id. The rest of the properties are cloud-provider specific, but take the
cloud.application.<property-name>
form.
cloud.application.app-id = helloworld cloud.application.instance-id = instance-0-0fab098f cloud.application.<property-name> = <property-value>
Service specific properties are exposed for each bound service, with each key starting in cloud.services
. Like
application properties, these too are cloud and service specific. Each key for a specific service starts with
cloud.services.<service-id>
cloud.services.customerDb.type = mysql-5.1 cloud.services.customerDb.plan = free cloud.services.customerDb.connection.hostname = ... cloud.services.customerDb.connection.port = ... etc...
If a there is only a single service of a given type (as defined by the {link ServiceInfo.ServiceLabel}
annoation's value of the corresponding ServiceInfo
class), that service is aliased
to the service type. Keys for such properties start in cloud.services.<service-type>
.
For example, if there is only a single MySQL service bound to the application, the service properties
will also be exposed starting with 'cloud.services.mysql
' key:
cloud.services.mysql.type = mysql-5.1 cloud.services.mysql.plan = free cloud.services.mysql.connection.hostname = ... cloud.services.mysql.connection.port = ... etc...