com.github.ltsopensource.zookeeper.serializer.ZkSerializer类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中com.github.ltsopensource.zookeeper.serializer.ZkSerializer类的一些代码示例,展示了ZkSerializer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkSerializer类的具体详情如下:
包路径:com.github.ltsopensource.zookeeper.serializer.ZkSerializer
类名称:ZkSerializer

ZkSerializer介绍

暂无

代码示例

代码示例来源:origin: ltsopensource/light-task-scheduler

@SuppressWarnings("unchecked")
@Override
public <T> T getData(String path) {
  try {
    return (T) zkSerializer.deserialize(client.getData().forPath(path));
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

private byte[] serialize(Object data) {
  return serializer.serialize(data);
}

代码示例来源:origin: ltsopensource/light-task-scheduler

private byte[] serialize(Object data) {
  return serializer.serialize(data);
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@SuppressWarnings("unchecked")
@Override
public <T> T getData(String path) {
  try {
    return (T) zkSerializer.deserialize(client.getData().forPath(path));
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public void setData(String path, Object data) {
  byte[] zkDataBytes;
  if (data instanceof Serializable) {
    zkDataBytes = zkSerializer.serialize(data);
  } else {
    zkDataBytes = (byte[]) data;
  }
  try {
    client.setData().forPath(path, zkDataBytes);
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public <T> T getData(String path) {
  // 暂时不watch data change 所以第二个参数为false
  try {
    byte[] data = zk.getData(path, false, null);
    return (T) serializer.deserialize(data);
  } catch (KeeperException e) {
    throw new ZkException(e);
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public void setData(String path, Object data) {
  byte[] zkDataBytes;
  if (data instanceof Serializable) {
    zkDataBytes = zkSerializer.serialize(data);
  } else {
    zkDataBytes = (byte[]) data;
  }
  try {
    client.setData().forPath(path, zkDataBytes);
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public <T> T getData(String path) {
  // 暂时不watch data change 所以第二个参数为false
  try {
    byte[] data = zk.getData(path, false, null);
    return (T) serializer.deserialize(data);
  } catch (KeeperException e) {
    throw new ZkException(e);
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
protected String createPersistent(String path, Object data, boolean sequential) {
  try {
    if (sequential) {
      byte[] zkDataBytes;
      if (data instanceof Serializable) {
        zkDataBytes = zkSerializer.serialize(data);
      } else {
        zkDataBytes = (byte[]) data;
      }
      return client.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(path, zkDataBytes);
    } else {
      return client.create().withMode(CreateMode.PERSISTENT).forPath(path);
    }
  } catch (KeeperException.NodeExistsException e) {
    return path;
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: com.github.ltsopensource/lts-core

@SuppressWarnings("unchecked")
@Override
public <T> T getData(String path) {
  try {
    return (T) zkSerializer.deserialize(client.getData().forPath(path));
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
protected String createEphemeral(String path, Object data, boolean sequential) {
  try {
    if (sequential) {
      byte[] zkDataBytes;
      if (data instanceof Serializable) {
        zkDataBytes = zkSerializer.serialize(data);
      } else {
        zkDataBytes = (byte[]) data;
      }
      return client.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(path, zkDataBytes);
    } else {
      return client.create().withMode(CreateMode.EPHEMERAL).forPath(path);
    }
  } catch (KeeperException.NodeExistsException e) {
    return path;
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: com.github.ltsopensource/lts-core

@Override
public <T> T getData(String path) {
  // 暂时不watch data change 所以第二个参数为false
  try {
    byte[] data = zk.getData(path, false, null);
    return (T) serializer.deserialize(data);
  } catch (KeeperException e) {
    throw new ZkException(e);
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
protected String createPersistent(String path, Object data, boolean sequential) {
  try {
    if (sequential) {
      byte[] zkDataBytes;
      if (data instanceof Serializable) {
        zkDataBytes = zkSerializer.serialize(data);
      } else {
        zkDataBytes = (byte[]) data;
      }
      return client.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(path, zkDataBytes);
    } else {
      return client.create().withMode(CreateMode.PERSISTENT).forPath(path);
    }
  } catch (KeeperException.NodeExistsException e) {
    return path;
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
protected String createEphemeral(String path, Object data, boolean sequential) {
  try {
    if (sequential) {
      byte[] zkDataBytes;
      if (data instanceof Serializable) {
        zkDataBytes = zkSerializer.serialize(data);
      } else {
        zkDataBytes = (byte[]) data;
      }
      return client.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(path, zkDataBytes);
    } else {
      return client.create().withMode(CreateMode.EPHEMERAL).forPath(path);
    }
  } catch (KeeperException.NodeExistsException e) {
    return path;
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public void setData(String path, Object data) {
  byte[] bytes = serializer.serialize(data);
  try {
    zk.setData(path, bytes, -1);
  } catch (KeeperException e) {
    throw new ZkException(e);
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public void setData(String path, Object data) {
  byte[] bytes = serializer.serialize(data);
  try {
    zk.setData(path, bytes, -1);
  } catch (KeeperException e) {
    throw new ZkException(e);
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  }
}

代码示例来源:origin: com.github.ltsopensource/lts-core

private byte[] serialize(Object data) {
  return serializer.serialize(data);
}

代码示例来源:origin: com.github.ltsopensource/lts-core

@Override
public void setData(String path, Object data) {
  byte[] zkDataBytes;
  if (data instanceof Serializable) {
    zkDataBytes = zkSerializer.serialize(data);
  } else {
    zkDataBytes = (byte[]) data;
  }
  try {
    client.setData().forPath(path, zkDataBytes);
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: com.github.ltsopensource/lts-core

@Override
protected String createPersistent(String path, Object data, boolean sequential) {
  try {
    if (sequential) {
      byte[] zkDataBytes;
      if (data instanceof Serializable) {
        zkDataBytes = zkSerializer.serialize(data);
      } else {
        zkDataBytes = (byte[]) data;
      }
      return client.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(path, zkDataBytes);
    } else {
      return client.create().withMode(CreateMode.PERSISTENT).forPath(path);
    }
  } catch (KeeperException.NodeExistsException e) {
    return path;
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: com.github.ltsopensource/lts-core

@Override
protected String createEphemeral(String path, Object data, boolean sequential) {
  try {
    if (sequential) {
      byte[] zkDataBytes;
      if (data instanceof Serializable) {
        zkDataBytes = zkSerializer.serialize(data);
      } else {
        zkDataBytes = (byte[]) data;
      }
      return client.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(path, zkDataBytes);
    } else {
      return client.create().withMode(CreateMode.EPHEMERAL).forPath(path);
    }
  } catch (KeeperException.NodeExistsException e) {
    return path;
  } catch (Exception e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

相关文章

ZkSerializer类方法