Github user HeartSaVioR commented on a diff in the pull request:

    https://github.com/apache/storm/pull/365#discussion_r23263342
  
    --- Diff: 
external/storm-redis/src/main/java/org/apache/storm/redis/trident/state/RedisClusterMapState.java
 ---
    @@ -0,0 +1,295 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.storm.redis.trident.state;
    +
    +import backtype.storm.task.IMetricsContext;
    +import backtype.storm.tuple.Values;
    +import com.google.common.base.Strings;
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.Lists;
    +import com.google.common.collect.Maps;
    +import org.apache.storm.redis.util.config.JedisClusterConfig;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import redis.clients.jedis.JedisCluster;
    +import storm.trident.state.JSONNonTransactionalSerializer;
    +import storm.trident.state.JSONOpaqueSerializer;
    +import storm.trident.state.JSONTransactionalSerializer;
    +import storm.trident.state.OpaqueValue;
    +import storm.trident.state.Serializer;
    +import storm.trident.state.State;
    +import storm.trident.state.StateFactory;
    +import storm.trident.state.StateType;
    +import storm.trident.state.TransactionalValue;
    +import storm.trident.state.map.CachedMap;
    +import storm.trident.state.map.IBackingMap;
    +import storm.trident.state.map.MapState;
    +import storm.trident.state.map.NonTransactionalMap;
    +import storm.trident.state.map.OpaqueMap;
    +import storm.trident.state.map.SnapshottableMap;
    +import storm.trident.state.map.TransactionalMap;
    +
    +import java.io.Serializable;
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.EnumMap;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +
    +public class RedisClusterMapState<T> implements IBackingMap<T> {
    +    private static final Logger logger = 
LoggerFactory.getLogger(RedisClusterMapState.class);
    +
    +    private static final EnumMap<StateType, Serializer> 
DEFAULT_SERIALIZERS = Maps.newEnumMap(ImmutableMap.of(
    +            StateType.NON_TRANSACTIONAL, new 
JSONNonTransactionalSerializer(),
    +            StateType.TRANSACTIONAL, new JSONTransactionalSerializer(),
    +            StateType.OPAQUE, new JSONOpaqueSerializer()
    +    ));
    +
    +    public static class DefaultKeyFactory implements KeyFactory {
    +        public String build(List<Object> key) {
    +            if (key.size() != 1)
    +                throw new RuntimeException("Default KeyFactory does not 
support compound keys");
    +            return (String) key.get(0);
    +        }
    +    };
    +
    +    public static class Options<T> implements Serializable {
    +        public int localCacheSize = 1000;
    +        public String globalKey = "$REDIS-MAP-STATE-GLOBAL";
    +        KeyFactory keyFactory = null;
    +        public Serializer<T> serializer = null;
    +        public String hkey = null;
    +    }
    +
    +    public static interface KeyFactory extends Serializable {
    +        String build(List<Object> key);
    +    }
    +
    +    /**
    +     * OpaqueTransactional for redis-cluster.
    +     * */
    +    public static StateFactory opaque(JedisClusterConfig 
jedisClusterConfig) {
    +        return opaque(jedisClusterConfig, new Options());
    +    }
    +
    +    public static StateFactory opaque(JedisClusterConfig 
jedisClusterConfig, String hkey) {
    +        Options opts = new Options();
    +        opts.hkey = hkey;
    +        return opaque(jedisClusterConfig, opts);
    +    }
    +
    +    public static StateFactory opaque(JedisClusterConfig 
jedisClusterConfig, KeyFactory factory) {
    +        Options opts = new Options();
    +        opts.keyFactory = factory;
    +        return opaque(jedisClusterConfig, opts);
    +    }
    +
    +    public static StateFactory opaque(JedisClusterConfig 
jedisClusterConfig, Options<OpaqueValue> opts) {
    +        return new Factory(jedisClusterConfig, StateType.OPAQUE, opts);
    +    }
    +
    +    /**
    +     * Transactional for redis-cluster.
    +     * */
    +    public static StateFactory transactional(JedisClusterConfig 
jedisClusterConfig) {
    +        return transactional(jedisClusterConfig, new Options());
    +    }
    +
    +    public static StateFactory transactional(JedisClusterConfig 
jedisClusterConfig, String hkey) {
    +        Options opts = new Options();
    +        opts.hkey = hkey;
    +        return transactional(jedisClusterConfig, opts);
    +    }
    +
    +    public static StateFactory transactional(JedisClusterConfig 
jedisClusterConfig, KeyFactory factory) {
    +        Options opts = new Options();
    +        opts.keyFactory = factory;
    +        return transactional(jedisClusterConfig, opts);
    +    }
    +
    +    public static StateFactory transactional(JedisClusterConfig 
jedisClusterConfig, Options<TransactionalValue> opts) {
    +        return new Factory(jedisClusterConfig, StateType.TRANSACTIONAL, 
opts);
    +    }
    +
    +    /**
    +     * NonTransactional for redis-cluster.
    +     * */
    +    public static StateFactory nonTransactional(JedisClusterConfig 
jedisClusterConfig) {
    +        return nonTransactional(jedisClusterConfig, new Options());
    +    }
    +
    +    public static StateFactory nonTransactional(JedisClusterConfig 
jedisClusterConfig, String hkey) {
    +        Options opts = new Options();
    +        opts.hkey = hkey;
    +        return nonTransactional(jedisClusterConfig, opts);
    +    }
    +
    +    public static StateFactory nonTransactional(JedisClusterConfig 
jedisClusterConfig, KeyFactory factory) {
    +        Options opts = new Options();
    +        opts.keyFactory = factory;
    +        return nonTransactional(jedisClusterConfig, opts);
    +    }
    +
    +    public static StateFactory nonTransactional(JedisClusterConfig 
jedisClusterConfig, Options<Object> opts) {
    +        return new Factory(jedisClusterConfig, 
StateType.NON_TRANSACTIONAL, opts);
    +    }
    +
    +
    +
    +    protected static class Factory implements StateFactory {
    +        // TODO : serialize redis.clients.jedis.JedisPoolConfig
    --- End diff --
    
    @revans2 
    Actually it is encouraged to allow custom JedisPoolConfig or 
GenericObjectPoolConfig object for modifying Pool configuration, and then 
serialization is necessary.
    But GenericObjectPoolConfig is from Apache Commons Pool 2, so it isn't easy 
way.
    
    We can add some kind of setup methods from JedisPoolConfig and 
JedisClusterConfig which are exactly same to GenericObjectPoolConfig, to allow 
custom Pool setup, and generate GenericObjectPoolConfig or JedisPoolConfig 
object from these.
    
    How do you think about?
    cc. @dashengju 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to