Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class App
- {
- private static String zkAdminUser = "zookeeper";
- private static String zkAdminPassword = "********";
- private static String theServers = "**.**.***.***:10181,**.**.***.***:10181,**.**.***.***:10181";
- public static void main(String[] args)
- {
- CuratorFrameworkFactory.Builder builder =
- CuratorFrameworkFactory.builder().connectString(theServers).retryPolicy(new ExponentialBackoffRetry(30000, 20)).connectionTimeoutMs(30000)
- .sessionTimeoutMs(10000);
- builder = builder.aclProvider(new ACLProvider()
- {
- @Override
- public List<ACL> getDefaultAcl()
- {
- return ZooDefs.Ids.CREATOR_ALL_ACL;
- }
- @Override
- public List<ACL> getAclForPath(String path)
- {
- // TODO Auto-generated method stub
- return null;
- }
- }
- );
- if (zkAdminUser != null && zkAdminPassword != null)
- {
- String authenticationString = zkAdminUser + ":" + zkAdminPassword;
- builder.authorization("ztpasswd", authenticationString.getBytes());
- // .aclProvider(new ACLProvider()
- // {
- // @Override
- // public List<ACL> getDefaultAcl()
- // {
- // return ZooDefs.Ids.CREATOR_ALL_ACL;
- // }
- //
- // @Override
- // public List<ACL> getAclForPath(String path)
- // {
- // return ZooDefs.Ids.CREATOR_ALL_ACL;
- // }
- // });
- }
- CuratorFramework client = builder.build();
- client.start();
- try
- {
- client.create().withMode(CreateMode.PERSISTENT).forPath("/beans/demo");
- }
- catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- finally
- {
- client.close();
- }
- }
- }
Add Comment
Please, Sign In to add comment