Search in sources :

Example 1 with GXService

use of com.genexus.util.GXService in project JavaClasses by genexuslabs.

the class ConfigurationManager method getValueFromGXServices.

private static String getValueFromGXServices(GXServices services, String propName) {
    String[] tokens = propName.split(":");
    if (tokens.length < 2 || tokens.length > 3)
        return null;
    String key = tokens[0];
    String property = tokens[1];
    if (tokens.length == 3) {
        key = String.format("%s:%s", tokens[0], tokens[1]);
        property = tokens[2];
    }
    GXService service = services.get(key);
    if (service == null)
        return null;
    return service.getProperties().get(property);
}
Also used : GXService(com.genexus.util.GXService)

Example 2 with GXService

use of com.genexus.util.GXService in project JavaClasses by genexuslabs.

the class ExternalStorage method create.

public boolean create(String name, GXProperties properties, GXStorageProvider[] storageProvider, GXBaseCollection<SdtMessages_Message>[] messages) {
    storageProvider[0] = null;
    if (isNullOrEmpty(name)) {
        GXutil.ErrorToMessages("Unsupported", "Provider name cannot be empty", messages[0]);
        return false;
    }
    try {
        if (providerService == null || !providerService.getName().equals(name)) {
            providerService = new GXService();
            providerService.setType(GXServices.STORAGE_SERVICE);
            providerService.setName(name);
            providerService.setAllowMultiple(false);
            providerService.setAllowOverrideWithEnvVarSettings(false);
            providerService.setProperties(new GXProperties());
        }
        preprocess(name, properties);
        GXProperty prop = properties.first();
        while (!properties.eof()) {
            providerService.getProperties().set(prop.name, prop.value);
            prop = properties.next();
        }
        String classFullName = providerService.getClassName();
        logger.debug("Loading storage provider: " + classFullName);
        final Class<?> providerClass = Class.forName(classFullName);
        this.provider = (ExternalProvider) providerClass.getConstructor(GXService.class).newInstance(providerService);
    } catch (final Exception ex) {
        logger.error("Couldn't connect to external storage provider. ", ex.getMessage(), ex);
        storageMessages(ex, messages[0]);
        return false;
    }
    storageProvider[0] = this;
    return true;
}
Also used : GXProperties(com.genexus.util.GXProperties) GXService(com.genexus.util.GXService) GXProperty(com.genexus.util.GXProperty)

Example 3 with GXService

use of com.genexus.util.GXService in project JavaClasses by genexuslabs.

the class RedisClient method initCache.

private void initCache() throws URISyntaxException {
    GXService providerService = Application.getGXServices().get(GXServices.CACHE_SERVICE);
    String addresses = providerService.getProperties().get("CACHE_PROVIDER_ADDRESS");
    String cacheKeyPattern = providerService.getProperties().get("CACHE_PROVIDER_KEYPATTERN");
    String password = providerService.getProperties().get("CACHE_PROVIDER_PASSWORD");
    initCache(addresses, password, cacheKeyPattern);
}
Also used : GXService(com.genexus.util.GXService)

Example 4 with GXService

use of com.genexus.util.GXService in project JavaClasses by genexuslabs.

the class Memcached method InitCache.

MemcachedClient InitCache() throws IOException {
    GXService providerService = Application.getGXServices().get(GXServices.CACHE_SERVICE);
    String addresses = providerService.getProperties().get("CACHE_PROVIDER_ADDRESS");
    String username = providerService.getProperties().get("CACHE_PROVIDER_USER");
    String password = providerService.getProperties().get("CACHE_PROVIDER_PASSWORD");
    if (addresses == null || addresses.isEmpty())
        addresses = "127.0.0.1:11211";
    if (username == null || username.isEmpty()) {
        return new MemcachedClient(new BinaryConnectionFactory(), AddrUtil.getAddresses(addresses));
    } else {
        AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" }, new PlainCallbackHandler(username, password));
        return new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(Protocol.BINARY).setAuthDescriptor(ad).build(), AddrUtil.getAddresses(addresses));
    }
}
Also used : PlainCallbackHandler(net.spy.memcached.auth.PlainCallbackHandler) ConnectionFactoryBuilder(net.spy.memcached.ConnectionFactoryBuilder) MemcachedClient(net.spy.memcached.MemcachedClient) AuthDescriptor(net.spy.memcached.auth.AuthDescriptor) GXService(com.genexus.util.GXService) BinaryConnectionFactory(net.spy.memcached.BinaryConnectionFactory)

Example 5 with GXService

use of com.genexus.util.GXService in project JavaClasses by genexuslabs.

the class Application method getExternalProviderImpl.

private static ExternalProvider getExternalProviderImpl(String service) {
    ExternalProvider externalProviderImpl = null;
    GXService providerService = getGXServices().get(service);
    if (providerService != null) {
        Class providerClass;
        try {
            providerClass = Class.forName(providerService.getClassName());
        } catch (ClassNotFoundException e) {
            logger.fatal("Unrecognized External Provider class (ClassNotFound) : " + providerService.getName() + " / " + providerService.getClassName(), e);
            throw new InternalError("Unrecognized External Provider class (ClassNotFound) : " + providerService.getName() + " / " + providerService.getClassName());
        }
        try {
            externalProviderImpl = (ExternalProvider) providerClass.getConstructor(String.class).newInstance(service);
        } catch (Exception e) {
            logger.fatal("Unable to Initialize External Provider Class: " + providerService.getClassName(), e);
            throw new InternalError("Unable to Initialize External Provider Class: " + providerService.getClassName(), e);
        }
    }
    return externalProviderImpl;
}
Also used : ExternalProvider(com.genexus.db.driver.ExternalProvider) GXService(com.genexus.util.GXService) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Aggregations

GXService (com.genexus.util.GXService)8 SQLException (java.sql.SQLException)2 InProcessCache (com.genexus.db.InProcessCache)1 ExternalProvider (com.genexus.db.driver.ExternalProvider)1 GXProperties (com.genexus.util.GXProperties)1 GXProperty (com.genexus.util.GXProperty)1 IOException (java.io.IOException)1 BinaryConnectionFactory (net.spy.memcached.BinaryConnectionFactory)1 ConnectionFactoryBuilder (net.spy.memcached.ConnectionFactoryBuilder)1 MemcachedClient (net.spy.memcached.MemcachedClient)1 AuthDescriptor (net.spy.memcached.auth.AuthDescriptor)1 PlainCallbackHandler (net.spy.memcached.auth.PlainCallbackHandler)1