Search in sources :

Example 1 with CacheConfigException

use of com.alicp.jetcache.CacheConfigException in project jetcache by alibaba.

the class ExpressionUtil method parseEL.

public static Object[] parseEL(String script) {
    if (script == null || script.trim().equals("")) {
        return null;
    }
    Object[] rt = new Object[2];
    Matcher matcher = pattern.matcher(script);
    if (!matcher.matches()) {
        return null;
    }
    String s = matcher.group(1);
    if ("spel".equals(s)) {
        rt[0] = EL.SPRING_EL;
    } else if ("mvel".equals(s)) {
        rt[0] = EL.MVEL;
    } else if ("buildin".equals(s)) {
        rt[0] = EL.BUILD_IN;
    } else {
        throw new CacheConfigException("Can't parse \"" + script + "\"");
    }
    rt[1] = matcher.group(2);
    return rt;
}
Also used : CacheConfigException(com.alicp.jetcache.CacheConfigException) Matcher(java.util.regex.Matcher)

Example 2 with CacheConfigException

use of com.alicp.jetcache.CacheConfigException in project jetcache by alibaba.

the class CacheContext method buildLocal.

protected Cache buildLocal(CacheAnnoConfig cacheAnnoConfig, String area) {
    Cache cache;
    EmbeddedCacheBuilder cacheBuilder = (EmbeddedCacheBuilder) globalCacheConfig.getLocalCacheBuilders().get(area);
    if (cacheBuilder == null) {
        throw new CacheConfigException("no local cache builder: " + area);
    }
    cacheBuilder = (EmbeddedCacheBuilder) cacheBuilder.clone();
    if (cacheAnnoConfig.getLocalLimit() != CacheConsts.UNDEFINED_INT) {
        cacheBuilder.setLimit(cacheAnnoConfig.getLocalLimit());
    }
    if (cacheAnnoConfig.getExpire() > 0) {
        cacheBuilder.expireAfterWrite(cacheAnnoConfig.getExpire(), cacheAnnoConfig.getTimeUnit());
    }
    if (!CacheConsts.UNDEFINED_STRING.equals(cacheAnnoConfig.getKeyConvertor())) {
        cacheBuilder.setKeyConvertor(configProvider.parseKeyConvertor(cacheAnnoConfig.getKeyConvertor()));
    }
    cache = cacheBuilder.buildCache();
    return cache;
}
Also used : EmbeddedCacheBuilder(com.alicp.jetcache.embedded.EmbeddedCacheBuilder) CacheConfigException(com.alicp.jetcache.CacheConfigException) RefreshCache(com.alicp.jetcache.RefreshCache) Cache(com.alicp.jetcache.Cache) EnableCache(com.alicp.jetcache.anno.EnableCache)

Example 3 with CacheConfigException

use of com.alicp.jetcache.CacheConfigException in project jetcache by alibaba.

the class LutteceConnectionManager method asyncCommands.

public Object asyncCommands(AbstractRedisClient redisClient) {
    connection(redisClient);
    LutteceObjects lo = getLutteceObjectsFromMap(redisClient);
    if (lo.asyncCommands == null) {
        if (lo.connection instanceof StatefulRedisConnection) {
            lo.asyncCommands = ((StatefulRedisConnection) lo.connection).async();
        } else if (lo.connection instanceof StatefulRedisClusterConnection) {
            lo.asyncCommands = ((StatefulRedisClusterConnection) lo.connection).async();
        } else {
            throw new CacheConfigException("type " + lo.connection.getClass() + " is not supported");
        }
    }
    return lo.asyncCommands;
}
Also used : CacheConfigException(com.alicp.jetcache.CacheConfigException) StatefulRedisClusterConnection(com.lambdaworks.redis.cluster.api.StatefulRedisClusterConnection) StatefulRedisConnection(com.lambdaworks.redis.api.StatefulRedisConnection)

Example 4 with CacheConfigException

use of com.alicp.jetcache.CacheConfigException in project jetcache by alibaba.

the class CacheContext method buildRemote.

protected Cache buildRemote(CacheAnnoConfig cacheAnnoConfig, String area, String cacheName) {
    ExternalCacheBuilder cacheBuilder = (ExternalCacheBuilder) globalCacheConfig.getRemoteCacheBuilders().get(area);
    if (cacheBuilder == null) {
        throw new CacheConfigException("no remote cache builder: " + area);
    }
    cacheBuilder = (ExternalCacheBuilder) cacheBuilder.clone();
    if (cacheAnnoConfig.getExpire() > 0) {
        cacheBuilder.expireAfterWrite(cacheAnnoConfig.getExpire(), cacheAnnoConfig.getTimeUnit());
    }
    if (cacheBuilder.getConfig().getKeyPrefix() != null) {
        cacheBuilder.setKeyPrefix(cacheBuilder.getConfig().getKeyPrefix() + cacheName);
    } else {
        cacheBuilder.setKeyPrefix(cacheName);
    }
    if (!CacheConsts.UNDEFINED_STRING.equals(cacheAnnoConfig.getKeyConvertor())) {
        cacheBuilder.setKeyConvertor(configProvider.parseKeyConvertor(cacheAnnoConfig.getKeyConvertor()));
    }
    if (!CacheConsts.UNDEFINED_STRING.equals(cacheAnnoConfig.getSerialPolicy())) {
        cacheBuilder.setValueEncoder(configProvider.parseValueEncoder(cacheAnnoConfig.getSerialPolicy()));
        cacheBuilder.setValueDecoder(configProvider.parseValueDecoder(cacheAnnoConfig.getSerialPolicy()));
    }
    return cacheBuilder.buildCache();
}
Also used : ExternalCacheBuilder(com.alicp.jetcache.external.ExternalCacheBuilder) CacheConfigException(com.alicp.jetcache.CacheConfigException)

Example 5 with CacheConfigException

use of com.alicp.jetcache.CacheConfigException in project jetcache by alibaba.

the class LutteceConnectionManager method commands.

public Object commands(AbstractRedisClient redisClient) {
    connection(redisClient);
    LutteceObjects lo = getLutteceObjectsFromMap(redisClient);
    if (lo.commands == null) {
        if (lo.connection instanceof StatefulRedisConnection) {
            lo.commands = ((StatefulRedisConnection) lo.connection).sync();
        } else if (lo.connection instanceof StatefulRedisClusterConnection) {
            lo.commands = ((StatefulRedisClusterConnection) lo.connection).sync();
        } else {
            throw new CacheConfigException("type " + lo.connection.getClass() + " is not supported");
        }
    }
    return lo.commands;
}
Also used : CacheConfigException(com.alicp.jetcache.CacheConfigException) StatefulRedisClusterConnection(com.lambdaworks.redis.cluster.api.StatefulRedisClusterConnection) StatefulRedisConnection(com.lambdaworks.redis.api.StatefulRedisConnection)

Aggregations

CacheConfigException (com.alicp.jetcache.CacheConfigException)6 StatefulRedisConnection (com.lambdaworks.redis.api.StatefulRedisConnection)3 StatefulRedisClusterConnection (com.lambdaworks.redis.cluster.api.StatefulRedisClusterConnection)3 Cache (com.alicp.jetcache.Cache)1 RefreshCache (com.alicp.jetcache.RefreshCache)1 EnableCache (com.alicp.jetcache.anno.EnableCache)1 EmbeddedCacheBuilder (com.alicp.jetcache.embedded.EmbeddedCacheBuilder)1 ExternalCacheBuilder (com.alicp.jetcache.external.ExternalCacheBuilder)1 Matcher (java.util.regex.Matcher)1