当前位置: 首页>>代码示例>>Java>>正文


Java CloudFactory类代码示例

本文整理汇总了Java中org.springframework.cloud.CloudFactory的典型用法代码示例。如果您正苦于以下问题:Java CloudFactory类的具体用法?Java CloudFactory怎么用?Java CloudFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CloudFactory类属于org.springframework.cloud包,在下文中一共展示了CloudFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ServiceInfoPropertySourceAdapter

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ServiceInfoPropertySourceAdapter() {

	Cloud cloud;
	try {
		cloud = new CloudFactory().getCloud();
	}
	catch (CloudException e) {
		// not running on a known cloud environment, so nothing to do
		cloud = null;
	}

	this.cloud = cloud;

	this.serviceInfoType = (Class) ResolvableType.forClass(getClass()).getSuperType()
			.getGeneric(0).getRawClass();
}
 
开发者ID:pivotal-cf,项目名称:spring-cloud-vault-connector,代码行数:18,代码来源:ServiceInfoPropertySourceAdapter.java

示例2: getMatchOutcome

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {

	CloudFactory cloudFactory = new CloudFactory();
	try {
		Cloud cloud = cloudFactory.getCloud();
		List<ServiceInfo> serviceInfos = cloud.getServiceInfos();

		for (ServiceInfo serviceInfo : serviceInfos) {
			if (serviceInfo instanceof VaultServiceInfo) {
				return ConditionOutcome.match(String.format(
						"Found Vault service %s", serviceInfo.getId()));
			}
		}

		return ConditionOutcome.noMatch("No Vault service found");
	}
	catch (CloudException e) {
		return ConditionOutcome.noMatch("Not running in a Cloud");
	}
}
 
开发者ID:pivotal-cf,项目名称:spring-cloud-vault-connector,代码行数:23,代码来源:VaultConnectorBootstrapConfiguration.java

示例3: gemfireCache

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
@Bean
public ClientCache gemfireCache() {
    Cloud cloud = new CloudFactory().getCloud();
    ServiceInfo serviceInfo = (ServiceInfo) cloud.getServiceInfos().get(0);
    ClientCacheFactory factory = new ClientCacheFactory();
    for (URI locator : serviceInfo.getLocators()) {
        factory.addPoolLocator(locator.getHost(), locator.getPort());
    }

    factory.set(SECURITY_CLIENT, "io.pivotal.pccpizza.config.UserAuthInitialize.create");
    factory.set(SECURITY_USERNAME, serviceInfo.getUsername());
    factory.set(SECURITY_PASSWORD, serviceInfo.getPassword());
    factory.setPdxSerializer(new ReflectionBasedAutoSerializer("io.pivotal.model.PizzaOrder"));
    factory.setPoolSubscriptionEnabled(true); // to enable CQ
    return factory.create();
}
 
开发者ID:gemfire,项目名称:cf-gemfire-connector-examples,代码行数:17,代码来源:GemfireConfiguration.java

示例4: main

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
public static void main(String[] args) {
  CloudFactory cloudFactory = new CloudFactory();
  Cloud cloud = cloudFactory.getCloud();
  GemfireServiceInfo myService = (GemfireServiceInfo) cloud.getServiceInfo("service0");
  Properties props = new Properties();
  props.setProperty("security-client-auth-init", "io.pivotal.ClientAuthInitialize.create");
  ClientCacheFactory ccf = new ClientCacheFactory(props);
  URI[] locators = myService.getLocators();
  for (URI locator : locators) {
    ccf.addPoolLocator(locator.getHost(), locator.getPort());
  }
  ClientCache client = ccf.create();
  Region r = client.createClientRegionFactory(ClientRegionShortcut.PROXY).create("test");
  r.put("1", "one");
  if (!r.get("1").equals("one")) {
    throw new RuntimeException("Expected value to be \"one\", but was:"+r.get("1"));
  }
  try {
    Thread.sleep(Long.MAX_VALUE);
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
}
 
开发者ID:gemfire,项目名称:cf-gemfire-connector-examples,代码行数:24,代码来源:JavaAppSpringCloud.java

示例5: getGemfireClientCache

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
@Bean(name = "my-client-cache")
public ClientCache getGemfireClientCache() {
  CloudFactory cloudFactory = new CloudFactory();

  // Obtain the Cloud object for the environment in which the application is running.
  // Note that you must have a CloudConnector suitable for your deployment environment on your classpath.
  // For example, if you are deploying the application to Cloud Foundry, you must add the Cloud Foundry
  // Connector to your classpath. If no suitable CloudConnector is found, the getCloud() method will throw
  // a CloudException. Use the Cloud instance to access application and service information and to create
  // service connectors.
  Cloud cloud = cloudFactory.getCloud();

  // Let Spring Cloud create a service connector for you.
  ClientCache cache = cloud.getServiceConnector("service0", ClientCache.class,
      createGemfireConnectorConfig());

  return cache;
}
 
开发者ID:gemfire,项目名称:cf-gemfire-connector-examples,代码行数:19,代码来源:ClientConfiguration.java

示例6: SsoServiceInfoCreatorInitializer

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
public SsoServiceInfoCreatorInitializer(CloudFactory cloudFactory, Environment environment) {
    this.cloudFactory = cloudFactory;
    this.environment = environment;
    List<ServiceInfo> serviceInfos = cloudFactory.getCloud().getServiceInfos();
    for(ServiceInfo s : serviceInfos) {
        if (s instanceof SsoServiceInfo) {
            Map<String, Object> map = new HashMap<String, Object>();
            SsoServiceInfo ssoServiceInfo = (SsoServiceInfo) s;
            map.put(SPRING_OAUTH2_CLIENT_ID, ssoServiceInfo.getClientId());
            map.put(SPRING_OAUTH2_CLIENT_SECRET, ssoServiceInfo.getClientSecret());
            map.put(SPRING_OAUTH2_ACCESS_TOKEN_URI, ssoServiceInfo.getAuthDomain() + "/oauth/token");
            map.put(SPRING_OAUTH2_AUTHORIZE_URI, ssoServiceInfo.getAuthDomain() + "/oauth/authorize");
            map.put(SPRING_OAUTH2_KEY_URI, ssoServiceInfo.getAuthDomain() + "/token_key");
            map.put(SSO_SERVICE_URL, ssoServiceInfo.getAuthDomain());
            map.put(SPRING_OAUTH2_USER_INFO_URI, ssoServiceInfo.getAuthDomain() + "/userinfo");
            map.put(SPRING_OAUTH2_TOKEN_INFO_URI, ssoServiceInfo.getAuthDomain() + "/check_token");
            MapPropertySource mapPropertySource = new MapPropertySource(PROPERTY_SOURCE_NAME, map);

            ((ConfigurableEnvironment) environment).getPropertySources().addFirst(mapPropertySource);
        }
    }
}
 
开发者ID:pivotal-cf,项目名称:identity-sample-apps,代码行数:23,代码来源:SsoServiceInfoCreatorInitializer.java

示例7: rabbitConnectionFactory

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
@Bean(name="rabbitMQConnectionFactory")
public ConnectionFactory rabbitConnectionFactory() {
	CloudFactory cloudFactory = new CloudFactory();
	Cloud cloud = cloudFactory.getCloud();

	AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) cloud.getServiceInfo("activationAmqpBroker");

	String serviceID = amqpServiceInfo.getId();
	ConnectionFactory connectionFactory = cloud.getServiceConnector(serviceID, ConnectionFactory.class, null);
	try{
		LOGGER.info("Setting CachingConnectionFactory specific properties");
		((CachingConnectionFactory)connectionFactory).setChannelCacheSize(channelCacheSize);
		((CachingConnectionFactory)connectionFactory).setRequestedHeartBeat(requestedHeartbeat);
		((CachingConnectionFactory)connectionFactory).setConnectionTimeout(connectionTimeout);
	}   catch (ClassCastException cce){
		throw new TechnicalException("Cannot customize CachingConnectionFactory for rabbitConnectionFactory");
	}
	return connectionFactory;
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:20,代码来源:DatasourceCloudContext.java

示例8: afterPropertiesSet

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
	ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) getBeanFactory();

	if (cloud == null) {
		if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
			beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
		}
		CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
		cloud = cloudFactory.getCloud();
	}
	if (!StringUtils.hasText(serviceId)) {
		List<? extends ServiceInfo> infos = cloud.getServiceInfos(serviceConnectorType);
		if (infos.size() != 1) {
			throw new CloudException("Expected 1 service matching " + serviceConnectorType.getName() + " type, but found "
				+ infos.size());
		}
		serviceId = infos.get(0).getId();
	}

	super.afterPropertiesSet();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:23,代码来源:AbstractCloudServiceConnectorFactory.java

示例9: VaultConnectorBootstrapConfiguration

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
public VaultConnectorBootstrapConfiguration(
		VaultConnectorGenericBackendProperties connectorVaultProperties,
		VaultGenericBackendProperties genericBackendProperties,
		Environment environment) {

	this.connectorVaultProperties = connectorVaultProperties;
	this.genericBackendProperties = genericBackendProperties;
	this.environment = environment;

	Cloud cloud;
	VaultServiceInfo vaultServiceInfo = null;

	try {
		CloudFactory cloudFactory = new CloudFactory();
		cloud = cloudFactory.getCloud();

		List<ServiceInfo> serviceInfos = cloud.getServiceInfos(VaultOperations.class);
		if (serviceInfos.size() == 1) {
			vaultServiceInfo = (VaultServiceInfo) serviceInfos.get(0);
		}
	}
	catch (CloudException e) {
		// not running in a Cloud environment
	}

	this.vaultServiceInfo = vaultServiceInfo;
}
 
开发者ID:pivotal-cf,项目名称:spring-cloud-vault-connector,代码行数:28,代码来源:VaultConnectorBootstrapConfiguration.java

示例10: getTestApplicationContext

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
protected ApplicationContext getTestApplicationContext(Class<?> configClass,
		ServiceInfo... serviceInfos) {
	final CloudConnector stubCloudConnector = CloudTestUtil
			.getTestCloudConnector(serviceInfos);

	return new AnnotationConfigApplicationContext(configClass) {
		@Override
		protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
			CloudFactory cloudFactory = new CloudFactory();
			cloudFactory.registerCloudConnector(stubCloudConnector);
			getBeanFactory().registerSingleton(MOCK_CLOUD_BEAN_NAME, cloudFactory);
			super.prepareBeanFactory(beanFactory);
		}
	};
}
 
开发者ID:pivotal-cf,项目名称:spring-cloud-vault-connector,代码行数:16,代码来源:StubCloudConnectorTest.java

示例11: getFileServiceStorageLocation

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
private String getFileServiceStorageLocation(String serviceName) {
    try {
        if (serviceName != null && !serviceName.isEmpty()) {
            CloudFactory cloudFactory = new CloudFactory();
            Cloud cloud = cloudFactory.getCloud();
            FileSystemServiceInfo serviceInfo = (FileSystemServiceInfo) cloud.getServiceInfo(serviceName);
            return serviceInfo.getStoragePath();
        }
    } catch (CloudException e) {
        LOGGER.debug("Persistent Shared File System Service detection failed", e);
    }
    return null;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:14,代码来源:FileServiceFactoryBean.java

示例12: onApplicationEvent

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    if (cloud != null) {
        return;
    }

    try {
        cloud = new CloudFactory().getCloud();
    } catch (CloudException e) {
        // not running on a known cloud environment, so nothing to do
        log.log(Level.INFO, "Error getting cloud object", e);
        return;
    }

    for (ServiceInfo serviceInfo : cloud.getServiceInfos()) {
        if (serviceInfo instanceof ConfigServerServiceInfo) {
            final ConfigServerServiceInfo configServerServiceInfo =
                (ConfigServerServiceInfo) serviceInfo;
            Map<String, Object> properties = new ConcurrentHashMap<>();
            properties.put(SPRING_CLOUD_CONFIG_URI, configServerServiceInfo.getUri());
            MapPropertySource mapPropertySource =
                new MapPropertySource(PROPERTY_SOURCE_NAME, properties);

            event.getEnvironment().getPropertySources().addFirst(mapPropertySource);
        }
    }
}
 
开发者ID:serenity-devstack,项目名称:spring-cloud-services-connector,代码行数:28,代码来源:ConfigServerServiceConnector.java

示例13: cloudRedisConnectionFactory

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
@Profile(GitHubClaProfiles.CLOUDFOUNDRY)
@Bean
public RedisConnectionFactory cloudRedisConnectionFactory() {
	CloudFactory cloudFactory = new CloudFactory();
	Cloud cloud = cloudFactory.getCloud();
	RedisConnectionFactory connectionFactory = cloud.getSingletonServiceConnector(RedisConnectionFactory.class, null);

	if(connectionFactory instanceof LettuceConnectionFactory){
		((LettuceConnectionFactory) connectionFactory).setShutdownTimeout(0);
	}

	return connectionFactory;
}
 
开发者ID:pivotalsoftware,项目名称:pivotal-cla,代码行数:14,代码来源:SessionConfig.java

示例14: getCloud

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
private Cloud getCloud() {
    try {
        CloudFactory cloudFactory = new CloudFactory();
        return cloudFactory.getCloud();
    } catch (CloudException e) {
        return null;
    }
}
 
开发者ID:gluonhq,项目名称:gluon-samples,代码行数:9,代码来源:ContextInitializer.java

示例15: getTestApplicationContext

import org.springframework.cloud.CloudFactory; //导入依赖的package包/类
protected ApplicationContext getTestApplicationContext(Class<?> configClass, ServiceInfo... serviceInfos) {
	final CloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(serviceInfos);

	return new AnnotationConfigApplicationContext(configClass) {
		@Override
		protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
			CloudFactory cloudFactory = new CloudFactory();
			cloudFactory.registerCloudConnector(stubCloudConnector);
			getBeanFactory().registerSingleton(MOCK_CLOUD_BEAN_NAME, cloudFactory);
			super.prepareBeanFactory(beanFactory);
		}
	};
}
 
开发者ID:pivotal-cf,项目名称:spring-cloud-gemfire-connector,代码行数:14,代码来源:StubCloudConnectorTest.java


注:本文中的org.springframework.cloud.CloudFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。