org.apache.curator.framework.api.ACLBackgroundPathAndBytesable Java Examples
The following examples show how to use
org.apache.curator.framework.api.ACLBackgroundPathAndBytesable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistentNode.java From xian with Apache License 2.0 | 5 votes |
private void createNode() { if ( !isActive() ) { return; } try { String existingPath = nodePath.get(); String createPath = (existingPath != null && !useProtection) ? existingPath : basePath; CreateModable<ACLBackgroundPathAndBytesable<String>> localCreateMethod = createMethod.get(); if ( localCreateMethod == null ) { CreateModable<ACLBackgroundPathAndBytesable<String>> tempCreateMethod = useProtection ? client.create().creatingParentContainersIfNeeded().withProtection() : client.create().creatingParentContainersIfNeeded(); if ( createMethod.compareAndSet(null, tempCreateMethod) ) { localCreateMethod = tempCreateMethod; } } localCreateMethod.withMode(getCreateMode(existingPath != null)).inBackground(backgroundCallback).forPath(createPath, data.get()); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); throw new RuntimeException("Creating node. BasePath: " + basePath, e); // should never happen unless there's a programming error - so throw RuntimeException } }
Example #2
Source File: CuratorStateManagerTest.java From incubator-heron with Apache License 2.0 | 5 votes |
/** * test createNode method * @throws Exception */ @Test public void testCreateNode() throws Exception { CuratorStateManager spyStateManager = spy(new CuratorStateManager()); CuratorFramework mockClient = mock(CuratorFramework.class); CreateBuilder mockCreateBuilder = mock(CreateBuilder.class); // Mockito doesn't support mock type-parametrized class, thus suppress the warning @SuppressWarnings("rawtypes") ACLBackgroundPathAndBytesable mockPath = spy(ACLBackgroundPathAndBytesable.class); final byte[] data = new byte[10]; doReturn(mockClient) .when(spyStateManager).getCuratorClient(); doReturn(true) .when(mockClient).blockUntilConnected(anyInt(), any(TimeUnit.class)); doReturn(mockCreateBuilder) .when(mockClient).create(); doReturn(mockPath) .when(mockCreateBuilder).withMode(any(CreateMode.class)); spyStateManager.initialize(config); // Verify the node is created successfully ListenableFuture<Boolean> result = spyStateManager.createNode(PATH, data, false); verify(mockCreateBuilder).withMode(any(CreateMode.class)); verify(mockPath).forPath(PATH, data); assertTrue(result.get()); }
Example #3
Source File: ZKUtil.java From codes-scratch-zookeeper-netty with Apache License 2.0 | 5 votes |
public static void createPath(CuratorFramework client, String path, String content, CreateMode mode) { try { ((ACLBackgroundPathAndBytesable) client.create().creatingParentsIfNeeded().withMode(mode)) .forPath(path, List2StringUtil.toBytes(content)); } catch (Exception e) { LOGGER.error("ZKUtil-->>createPath(CuratorFramework client, String path, String content, CreateMode mode) error,", e); } }
Example #4
Source File: ZKUtil.java From codes-scratch-zookeeper-netty with Apache License 2.0 | 5 votes |
public static void setPath(CuratorFramework client, String path, String content, CreateMode mode) { try { if (client.checkExists().forPath(path) == null) { ((ACLBackgroundPathAndBytesable) client.create().creatingParentsIfNeeded().withMode(mode)) .forPath(path, List2StringUtil.toBytes(content)); } else { client.setData().forPath(path, List2StringUtil.toBytes(content)); } } catch (Exception e) { LOGGER.error("ZKUtil-->>setPath(CuratorFramework client, String path, String content, CreateMode mode) error,", e); } }
Example #5
Source File: ZKUtil.java From codes-scratch-zookeeper-netty with Apache License 2.0 | 5 votes |
public static String createEphemeralSequential(CuratorFramework client, String path, byte[] payload) { try { return (String) ((ACLBackgroundPathAndBytesable) client.create().withProtection() .withMode(CreateMode.EPHEMERAL_SEQUENTIAL)) .forPath(path, payload); } catch (Exception e) { LOGGER.error("ZKUtil-->>createEphemeralSequential", e); } return null; }
Example #6
Source File: MockCurator.java From vespa with Apache License 2.0 | 4 votes |
public ACLBackgroundPathAndBytesable<T> withMode(CreateMode createMode) { throw new UnsupportedOperationException("Not implemented in MockCurator"); }
Example #7
Source File: MockCurator.java From vespa with Apache License 2.0 | 4 votes |
public ACLBackgroundPathAndBytesable<String> withMode(CreateMode createMode) { this.createMode = createMode; return this; }