Search in sources :

Example 1 with CacheProvider

use of org.springframework.roo.addon.cache.providers.CacheProvider in project spring-roo by spring-projects.

the class CacheCommands method cacheSetup.

/**
 * Method that register "cache setup" command on Spring Roo Shell.
 *
 * Installs support for intermediate memory. Users can specify different providers
 * to use for managing it.
 *
 * @param provider
 *            the String with the name of a provider to use for intermediate memory managing.
 * @param shellContext
 *            ShellContext used to know if --force parameter has been used by developer
 */
@CliCommand(value = "cache setup", help = "Installs support for using intermediate memory in generated project by using Spring Cache abstraction. Users can specify different providers to use for managing it.")
public void cacheSetup(@CliOption(key = "provider", mandatory = false, help = "Parameter that indicates the provider to use for managing intermediate memory. " + "Possible values are: `GUAVA`.") String provider, ShellContext shellContext) {
    // Check for provider value
    CacheProvider selectedCacheProvider = null;
    if (StringUtils.isNotBlank(provider)) {
        for (CacheProvider cacheProvider : getCacheProviders()) {
            if (provider.equals(cacheProvider.getName())) {
                selectedCacheProvider = cacheProvider;
            }
        }
    }
    cacheOperations.setupCache(selectedCacheProvider, shellContext.getProfile());
}
Also used : CacheProvider(org.springframework.roo.addon.cache.providers.CacheProvider) CliCommand(org.springframework.roo.shell.CliCommand)

Example 2 with CacheProvider

use of org.springframework.roo.addon.cache.providers.CacheProvider in project spring-roo by spring-projects.

the class CacheCommands method getCacheProviders.

/**
 * Gets the right implementation of FieldCreatorProvider for a JavaType
 *
 * @param type the JavaType to get the implementation
 * @return FieldCreatorProvider implementation
 */
public List<CacheProvider> getCacheProviders() {
    // Get all Services implement FieldCreatorProvider interface
    if (cacheProviders.isEmpty()) {
        try {
            ServiceReference<?>[] references = this.context.getAllServiceReferences(CacheProvider.class.getName(), null);
            for (ServiceReference<?> ref : references) {
                CacheProvider cacheProvider = (CacheProvider) this.context.getService(ref);
                cacheProviders.add(cacheProvider);
            }
        } catch (InvalidSyntaxException e) {
            LOGGER.warning("Cannot load CacheProvider on CacheCommands.");
            return null;
        }
    }
    return cacheProviders;
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CacheProvider(org.springframework.roo.addon.cache.providers.CacheProvider) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

CacheProvider (org.springframework.roo.addon.cache.providers.CacheProvider)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1 CliCommand (org.springframework.roo.shell.CliCommand)1