zoukankan      html  css  js  c++  java
  • activiti的缓存(redis)

    activiti的缓存(redis)

    activit可以使用spring的缓存也可使用默认缓存,这里介绍使用redis进行缓存。默认可以在api中找到使用方式。

    activiti的缓存需要实现接口org.activiti.engine.impl.persistence.deploy.DeploymentCache:
    下面的示例介绍简单的使用方式,无非就是实现CRUD的过程。可以直接复制代码。
    里面的jedis池参照上一篇博文就行了。
    public class DistributedCache implements DeploymentCache<ProcessDefinitionEntity> {

    private Logger logger = LoggerFactory.getLogger(DistributedCache.class);

    private JedisPoolManager jedisPoolManager;

    public void setJedisPoolManager(JedisPoolManager jedisPoolManager) {
    this.jedisPoolManager = jedisPoolManager;
    }


    public Jedis getJedits(){
    return jedisPoolManager.getJedisPool().getResource();
    }

    public JedisPool getResources(){
    return jedisPoolManager.getJedisPool();
    }

    @Override
    public ProcessDefinitionEntity get(String id) {
    logger.error("从redis获取数据["+Constants.REDIS_ACT_PRE+id+"]");
    byte[] entityBt = null;
    JedisPool resources = getResources();
    Jedis jedits = null;
    try {
    resources = getResources();
    jedits = getJedits();
    entityBt = jedits.hget(Constants.REDIS_ACT_PRE.getBytes(), id.getBytes());
    if(entityBt==null)return null;
    } catch (Exception e) {
    e.printStackTrace();
    logger.error("从redis获取数据失败["+Constants.REDIS_ACT_PRE+id+"]-->"+e.toString());
    }finally{
    if (resources != null) {
    resources.returnBrokenResource(jedits);
    }
    }
    return (ProcessDefinitionEntity)SerializationUtils.deserialize(entityBt);
    }

    @Override
    public void add(String id, ProcessDefinitionEntity processDefinitionEntity) {
    logger.error("向redis存储数据["+Constants.REDIS_ACT_PRE+id+"]");
    JedisPool resources = getResources();
    Jedis jedits = null;
    try {
    resources = getResources();
    jedits = getJedits();
    jedits.hset(Constants.REDIS_ACT_PRE.getBytes(), id.getBytes(),SerializationUtils.serialize(processDefinitionEntity));
    } catch (Exception e) {
    e.printStackTrace();
    logger.error("向redis存储数据失败["+Constants.REDIS_ACT_PRE+id+"]-->"+e.toString());
    }finally{
    if (resources != null) {
    resources.returnBrokenResource(jedits);
    }
    }
    }

    @Override
    public void remove(String id) {
    logger.error("从redis删除数据["+Constants.REDIS_ACT_PRE+id+"]");
    JedisPool resources = getResources();
    Jedis jedits = null;
    try {
    resources = getResources();
    jedits = getJedits();
    jedits.hdel(Constants.REDIS_ACT_PRE.getBytes(), id.getBytes());
    } catch (Exception e) {
    e.printStackTrace();
    logger.error("从redis删除数据失败["+Constants.REDIS_ACT_PRE+id+"]-->"+e.toString());
    }finally{
    if (resources != null) {
    resources.returnBrokenResource(jedits);
    }
    }
    }

    @Override
    public void clear() {
    logger.error("从redis删除全部流程数据["+Constants.REDIS_ACT_PRE +"]");
    JedisPool resources = getResources();
    Jedis jedits = null;
    try {
    resources = getResources();
    jedits = getJedits();
    jedits.hdel(Constants.REDIS_ACT_PRE.getBytes());
    } catch (Exception e) {
    e.printStackTrace();
    logger.error("从redis删除全部流程失败["+Constants.REDIS_ACT_PRE +"]-->"+e.toString());
    }finally{
    if (resources != null) {
    resources.returnBrokenResource(jedits);
    }
    }
    }

    }

  • 相关阅读:
    用cascade删除有约束的表或记录
    易混淆的Window窗体与父窗体之间位置关系
    界面主窗体,子窗体的InitializeComponent(构造函数)、Load事件执行顺序
    DEV CheckComboboxEdit、CheckedListBoxControl(转)
    程序实现DataGrid过滤设置
    创建触发器的基本语法
    查看dll中的函数(方法)
    delphi xe2 64位嵌入汇编问题 https://bbs.csdn.net/topics/390333981
    USB转换PS2接线原理
    Win8.1+VS2013+WDK8.1+VirtualBox or VMware 驱动开发环境配置
  • 原文地址:https://www.cnblogs.com/core404/p/7550519.html
Copyright © 2011-2022 走看看