@Override public ErrorListenerPathable<Stat> inBackground(BackgroundCallback callback, Object context, Executor executor) { backgrounding = new Backgrounding(client, callback, context, executor); return this; }
Backgrounding(CuratorFrameworkImpl client, BackgroundCallback callback, Object context, Executor executor) { this(wrapCallback(client, callback, executor), context); }
public byte[] forEnsemble() throws Exception { if ( backgrounding.inBackground() ) { client.processBackgroundOperation(new OperationAndData<>(this, null, backgrounding.getCallback(), null, backgrounding.getContext(), null), null); return new byte[0]; } else { return ensembleInForeground(); } }
@Override public void performBackgroundOperation(final OperationAndData<Void> data) throws Exception { try { final TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Background"); AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback() { @Override public void processResult(int rc, String path, Object ctx, byte[] bytes, Stat stat) { trace.commit(); if ( (responseStat != null) && (stat != null) ) { DataTree.copyStat(stat, responseStat); } CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.RECONFIG, rc, path, null, ctx, stat, bytes, null, null, null, null); client.processBackgroundOperation(data, event); } }; client.getZooKeeper().reconfig(joining, leaving, newMembers, fromConfig, callback, backgrounding.getContext()); } catch ( Throwable e ) { backgrounding.checkError(e, null); } }
@Override public Void forPath(String path) throws Exception { OperationAndData<String> operationAndData = new OperationAndData<String>(this, path, backgrounding.getCallback(), null, backgrounding.getContext(), null); client.processBackgroundOperation(operationAndData, null); return null; } }
@Override public void performBackgroundOperation(OperationAndData<PathAndBytes> op) throws Exception { try { client.getZooKeeper().setData(path, mainOperationAndData.getData().getData(), setDataIfExistsVersion, statCallback, backgrounding.getContext()); } catch ( KeeperException e ) { // ignore } } };
@Override public Void forPath(String path) throws Exception { final String adjustedPath = client.fixForNamespace(path); if(backgrounding.inBackground()) { pathInBackground(adjustedPath); } else { pathInForeground(adjustedPath); } return null; }
backgrounding.checkError(e, null);
@Override public byte[] forEnsemble() throws Exception { if ( backgrounding.inBackground() ) { client.processBackgroundOperation(new OperationAndData<Void>(this, null, backgrounding.getCallback(), null, backgrounding.getContext(), watching), null); return null; } else { return configInForeground(); } }
@Override public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception { try { final OperationTrace trace = client.getZookeeperClient().startAdvancedTracer("GetACLBuilderImpl-Background"); AsyncCallback.ACLCallback callback = new AsyncCallback.ACLCallback() { @Override public void processResult(int rc, String path, Object ctx, List<ACL> acl, Stat stat) { trace.setReturnCode(rc).setPath(path).setStat(stat).commit(); CuratorEventImpl event = new CuratorEventImpl(client, CuratorEventType.GET_ACL, rc, path, null, ctx, stat, null, null, null, acl, null); client.processBackgroundOperation(operationAndData, event); } }; client.getZooKeeper().getACL(operationAndData.getData(), responseStat, callback, backgrounding.getContext()); } catch ( Throwable e ) { backgrounding.checkError(e, null); } }
private void pathInBackground(final String path) { OperationAndData.ErrorCallback<String> errorCallback = null; //Only need an error callback if we're in guaranteed mode if(guaranteed) { errorCallback = new OperationAndData.ErrorCallback<String>() { @Override public void retriesExhausted(OperationAndData<String> operationAndData) { client.getFailedRemoveWatcherManager().addFailedOperation(new FailedRemoveWatchManager.FailedRemoveWatchDetails(path, watcher)); } }; } client.processBackgroundOperation(new OperationAndData<String>(this, path, backgrounding.getCallback(), errorCallback, backgrounding.getContext(), !local), null); }
private void backgroundDeleteChildrenThenNode(final OperationAndData<String> mainOperationAndData) { BackgroundOperation<String> operation = new BackgroundOperation<String>() { @Override public void performBackgroundOperation(OperationAndData<String> dummy) throws Exception { try { ZKPaths.deleteChildren(client.getZooKeeper(), mainOperationAndData.getData(), false); } catch ( KeeperException e ) { // ignore } client.queueOperation(mainOperationAndData); } }; OperationAndData<String> parentOperation = new OperationAndData<String>(operation, mainOperationAndData.getData(), null, null, backgrounding.getContext(), null); client.queueOperation(parentOperation); }
@Override public String forPath(final String givenPath, byte[] data) throws Exception { if ( compress ) { data = client.getCompressionProvider().compress(givenPath, data); } final String adjustedPath = adjustPath(client.fixForNamespace(givenPath, createMode.isSequential())); List<ACL> aclList = acling.getAclList(adjustedPath); client.getSchemaSet().getSchema(givenPath).validateCreate(createMode, givenPath, data, aclList); String returnPath = null; if ( backgrounding.inBackground() ) { pathInBackground(adjustedPath, data, givenPath); } else { String path = protectedPathInForeground(adjustedPath, data, aclList); returnPath = client.unfixForNamespace(path); } return returnPath; }
@Override public List<ACL> forPath(String path) throws Exception { path = client.fixForNamespace(path); List<ACL> result = null; if ( backgrounding.inBackground() ) { client.processBackgroundOperation(new OperationAndData<String>(this, path, backgrounding.getCallback(), null, backgrounding.getContext(), null), null); } else { result = pathInForeground(path); } return result; }
@Override public ErrorListenerMultiTransactionMain inBackground(Object context) { backgrounding = new Backgrounding(context); return this; }
@Override public void performBackgroundOperation(final OperationAndData<CuratorMultiTransactionRecord> operationAndData) throws Exception { try { final TimeTrace trace = client.getZookeeperClient().startTracer("CuratorMultiTransactionImpl-Background"); AsyncCallback.MultiCallback callback = new AsyncCallback.MultiCallback() { @Override public void processResult(int rc, String path, Object ctx, List<OpResult> opResults) { trace.commit(); List<CuratorTransactionResult> curatorResults = (opResults != null) ? CuratorTransactionImpl.wrapResults(client, opResults, operationAndData.getData()) : null; CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.TRANSACTION, rc, path, null, ctx, null, null, null, null, null, curatorResults); client.processBackgroundOperation(operationAndData, event); } }; client.getZooKeeper().multi(operationAndData.getData(), callback, backgrounding.getContext()); } catch ( Throwable e ) { backgrounding.checkError(e, null); } }
private void pathInBackground(final String path, final byte[] data, final String givenPath) OperationAndData<PathAndBytes> operationAndData = new OperationAndData<PathAndBytes>(this, new PathAndBytes(path, data), backgrounding.getCallback(), new OperationAndData.ErrorCallback<PathAndBytes>() backgrounding.getContext(), null)
static <T> void backgroundCreateParentsThenNode(final CuratorFrameworkImpl client, final OperationAndData<T> mainOperationAndData, final String path, Backgrounding backgrounding, final InternalACLProvider aclProvider, final boolean createParentsAsContainers) { BackgroundOperation<T> operation = new BackgroundOperation<T>() { @Override public void performBackgroundOperation(OperationAndData<T> dummy) throws Exception { try { ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers); } catch ( KeeperException e ) { if ( !RetryLoop.isRetryException(e) ) { throw e; } // otherwise safe to ignore as it will get retried } client.queueOperation(mainOperationAndData); } }; OperationAndData<T> parentOperation = new OperationAndData<>(operation, mainOperationAndData.getData(), null, null, backgrounding.getContext(), null); client.queueOperation(parentOperation); }
Backgrounding(CuratorFrameworkImpl client, BackgroundCallback callback, Executor executor) { this(wrapCallback(client, callback, executor)); }
@Override public String forPath(final String givenPath, byte[] data) throws Exception { if ( compress ) { data = client.getCompressionProvider().compress(givenPath, data); } final String adjustedPath = adjustPath(client.fixForNamespace(givenPath, createMode.isSequential())); String returnPath = null; if ( backgrounding.inBackground() ) { pathInBackground(adjustedPath, data, givenPath); } else { String path = protectedPathInForeground(adjustedPath, data); returnPath = client.unfixForNamespace(path); } return returnPath; }