You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2014/05/30 18:02:19 UTC
[4/5] refactoring
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/RpcCreateMode.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/RpcCreateMode.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/RpcCreateMode.java
deleted file mode 100644
index 3ef6b45..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/RpcCreateMode.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.x.rpc.idl.projection;
-
-import com.facebook.swift.codec.ThriftEnum;
-
-@ThriftEnum("CreateMode")
-public enum RpcCreateMode
-{
- PERSISTENT,
- PERSISTENT_SEQUENTIAL,
- EPHEMERAL,
- EPHEMERAL_SEQUENTIAL
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/SetDataSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/SetDataSpec.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/SetDataSpec.java
deleted file mode 100644
index 195e620..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/SetDataSpec.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.x.rpc.idl.projection;
-
-import com.facebook.swift.codec.ThriftField;
-import com.facebook.swift.codec.ThriftStruct;
-
-@ThriftStruct
-public class SetDataSpec
-{
- @ThriftField(1)
- public String path;
-
- @ThriftField(2)
- public boolean watched;
-
- @ThriftField(3)
- public String asyncContext;
-
- @ThriftField(4)
- public boolean compressed;
-
- @ThriftField(5)
- public Version version;
-
- @ThriftField(6)
- public byte[] data;
-
- public SetDataSpec()
- {
- }
-
- public SetDataSpec(String path, boolean watched, String asyncContext, boolean compressed, Version version, byte[] data)
- {
- this.path = path;
- this.watched = watched;
- this.asyncContext = asyncContext;
- this.compressed = compressed;
- this.version = version;
- this.data = data;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/Version.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/Version.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/Version.java
deleted file mode 100644
index 172704b..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/Version.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.curator.x.rpc.idl.projection;
-
-import com.facebook.swift.codec.ThriftField;
-import com.facebook.swift.codec.ThriftStruct;
-
-@ThriftStruct
-public class Version
-{
- @ThriftField(1)
- public int version;
-
- public Version()
- {
- }
-
- public Version(int version)
- {
- this.version = version;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/services/CuratorProjectionService.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/services/CuratorProjectionService.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/services/CuratorProjectionService.java
new file mode 100644
index 0000000..7e9e9c1
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/services/CuratorProjectionService.java
@@ -0,0 +1,592 @@
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.services;
+
+import com.facebook.swift.service.ThriftMethod;
+import com.facebook.swift.service.ThriftService;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.api.*;
+import org.apache.curator.framework.recipes.cache.ChildData;
+import org.apache.curator.framework.recipes.cache.NodeCache;
+import org.apache.curator.framework.recipes.cache.NodeCacheListener;
+import org.apache.curator.framework.recipes.cache.PathChildrenCache;
+import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
+import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
+import org.apache.curator.framework.recipes.leader.LeaderLatch;
+import org.apache.curator.framework.recipes.leader.LeaderLatchListener;
+import org.apache.curator.framework.recipes.leader.Participant;
+import org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex;
+import org.apache.curator.framework.recipes.locks.InterProcessSemaphoreV2;
+import org.apache.curator.framework.recipes.locks.Lease;
+import org.apache.curator.framework.recipes.nodes.PersistentEphemeralNode;
+import org.apache.curator.framework.state.ConnectionState;
+import org.apache.curator.framework.state.ConnectionStateListener;
+import org.apache.curator.utils.ThreadUtils;
+import org.apache.curator.x.rpc.connections.Closer;
+import org.apache.curator.x.rpc.connections.ConnectionManager;
+import org.apache.curator.x.rpc.connections.CuratorEntry;
+import org.apache.curator.x.rpc.details.RpcBackgroundCallback;
+import org.apache.curator.x.rpc.details.RpcWatcher;
+import org.apache.curator.x.rpc.idl.structs.*;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.data.Stat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+@ThriftService("CuratorService")
+public class CuratorProjectionService
+{
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private final ConnectionManager connectionManager;
+
+ public CuratorProjectionService(ConnectionManager connectionManager)
+ {
+ this.connectionManager = connectionManager;
+ }
+
+ @ThriftMethod
+ public CuratorProjection newCuratorProjection(String connectionName)
+ {
+ CuratorFramework client = connectionManager.newConnection(connectionName);
+
+ String id = CuratorEntry.newId();
+ client.start();
+ connectionManager.add(id, client);
+ final CuratorProjection projection = new CuratorProjection(id);
+
+ ConnectionStateListener listener = new ConnectionStateListener()
+ {
+ @Override
+ public void stateChanged(CuratorFramework client, ConnectionState newState)
+ {
+ addEvent(projection, new RpcCuratorEvent(newState));
+ }
+ };
+ client.getConnectionStateListenable().addListener(listener);
+
+ return projection;
+ }
+
+ @ThriftMethod(oneway = true)
+ public void closeCuratorProjection(CuratorProjection projection)
+ {
+ CuratorEntry entry = connectionManager.remove(projection.id);
+ if ( entry != null )
+ {
+ entry.close();
+ }
+ }
+
+ @ThriftMethod(oneway = true)
+ public void pingCuratorProjection(CuratorProjection projection)
+ {
+ connectionManager.get(projection.id);
+ }
+
+ @ThriftMethod
+ public OptionalPath createNode(CuratorProjection projection, CreateSpec spec) throws Exception
+ {
+ CuratorFramework client = getEntry(projection).getClient();
+
+ Object builder = client.create();
+ if ( spec.creatingParentsIfNeeded )
+ {
+ builder = castBuilder(builder, CreateBuilder.class).creatingParentsIfNeeded();
+ }
+ if ( spec.compressed )
+ {
+ builder = castBuilder(builder, Compressible.class).compressed();
+ }
+ if ( spec.withProtection )
+ {
+ builder = castBuilder(builder, CreateBuilder.class).withProtection();
+ }
+ if ( spec.mode != null )
+ {
+ builder = castBuilder(builder, CreateModable.class).withMode(CreateMode.valueOf(spec.mode.name()));
+ }
+
+ if ( spec.asyncContext != null )
+ {
+ BackgroundCallback backgroundCallback = new RpcBackgroundCallback(this, projection);
+ builder = castBuilder(builder, Backgroundable.class).inBackground(backgroundCallback, spec.asyncContext);
+ }
+
+ Object path = castBuilder(builder, PathAndBytesable.class).forPath(spec.path, spec.data);
+ return new OptionalPath((path != null) ? String.valueOf(path) : null);
+ }
+
+ @ThriftMethod
+ public void deleteNode(CuratorProjection projection, DeleteSpec spec) throws Exception
+ {
+ CuratorFramework client = getEntry(projection).getClient();
+
+ Object builder = client.delete();
+ if ( spec.guaranteed )
+ {
+ builder = castBuilder(builder, DeleteBuilder.class).guaranteed();
+ }
+ if ( spec.version != null )
+ {
+ builder = castBuilder(builder, Versionable.class).withVersion(spec.version.version);
+ }
+
+ if ( spec.asyncContext != null )
+ {
+ BackgroundCallback backgroundCallback = new RpcBackgroundCallback(this, projection);
+ builder = castBuilder(builder, Backgroundable.class).inBackground(backgroundCallback, spec.asyncContext);
+ }
+
+ castBuilder(builder, Pathable.class).forPath(spec.path);
+ }
+
+ @ThriftMethod
+ public byte[] getData(CuratorProjection projection, GetDataSpec spec) throws Exception
+ {
+ CuratorFramework client = getEntry(projection).getClient();
+
+ Object builder = client.getData();
+ if ( spec.watched )
+ {
+ builder = castBuilder(builder, Watchable.class).usingWatcher(new RpcWatcher(this, projection));
+ }
+
+ if ( spec.decompressed )
+ {
+ builder = castBuilder(builder, Decompressible.class).decompressed();
+ }
+
+ if ( spec.asyncContext != null )
+ {
+ BackgroundCallback backgroundCallback = new RpcBackgroundCallback(this, projection);
+ builder = castBuilder(builder, Backgroundable.class).inBackground(backgroundCallback);
+ }
+
+ Stat stat = new Stat();
+ builder = castBuilder(builder, Statable.class).storingStatIn(stat);
+
+ return (byte[])castBuilder(builder, Pathable.class).forPath(spec.path);
+ }
+
+ @ThriftMethod
+ public RpcStat setData(CuratorProjection projection, SetDataSpec spec) throws Exception
+ {
+ CuratorFramework client = getEntry(projection).getClient();
+
+ Object builder = client.setData();
+ if ( spec.watched )
+ {
+ builder = castBuilder(builder, Watchable.class).usingWatcher(new RpcWatcher(this, projection));
+ }
+ if ( spec.version != null )
+ {
+ builder = castBuilder(builder, Versionable.class).withVersion(spec.version.version);
+ }
+
+ if ( spec.compressed )
+ {
+ builder = castBuilder(builder, Compressible.class).compressed();
+ }
+
+ if ( spec.asyncContext != null )
+ {
+ BackgroundCallback backgroundCallback = new RpcBackgroundCallback(this, projection);
+ builder = castBuilder(builder, Backgroundable.class).inBackground(backgroundCallback);
+ }
+
+ Stat stat = (Stat)castBuilder(builder, PathAndBytesable.class).forPath(spec.path, spec.data);
+ return RpcCuratorEvent.toRpcStat(stat);
+ }
+
+ @ThriftMethod
+ public OptionalRpcStat exists(CuratorProjection projection, ExistsSpec spec) throws Exception
+ {
+ CuratorFramework client = getEntry(projection).getClient();
+
+ Object builder = client.checkExists();
+ if ( spec.watched )
+ {
+ builder = castBuilder(builder, Watchable.class).usingWatcher(new RpcWatcher(this, projection));
+ }
+
+ if ( spec.asyncContext != null )
+ {
+ BackgroundCallback backgroundCallback = new RpcBackgroundCallback(this, projection);
+ castBuilder(builder, Backgroundable.class).inBackground(backgroundCallback);
+ }
+
+ Stat stat = (Stat)castBuilder(builder, Pathable.class).forPath(spec.path);
+ return new OptionalRpcStat((stat != null) ? RpcCuratorEvent.toRpcStat(stat) : null);
+ }
+
+ @ThriftMethod
+ public OptionalChildrenList getChildren(CuratorProjection projection, GetChildrenSpec spec) throws Exception
+ {
+ CuratorFramework client = getEntry(projection).getClient();
+
+ Object builder = client.getChildren();
+ if ( spec.watched )
+ {
+ builder = castBuilder(builder, Watchable.class).usingWatcher(new RpcWatcher(this, projection));
+ }
+
+ if ( spec.asyncContext != null )
+ {
+ BackgroundCallback backgroundCallback = new RpcBackgroundCallback(this, projection);
+ builder = castBuilder(builder, Backgroundable.class).inBackground(backgroundCallback);
+ }
+
+ @SuppressWarnings("unchecked")
+ List<String> children = (List<String>)castBuilder(builder, Pathable.class).forPath(spec.path);
+ return new OptionalChildrenList(children);
+ }
+
+ @ThriftMethod
+ public boolean closeGenericProjection(CuratorProjection curatorProjection, String id) throws Exception
+ {
+ CuratorEntry entry = getEntry(curatorProjection);
+ return entry.closeThing(id);
+ }
+
+ @ThriftMethod
+ public LockProjection acquireLock(CuratorProjection projection, final String path, int maxWaitMs) throws Exception
+ {
+ CuratorEntry entry = getEntry(projection);
+ final InterProcessSemaphoreMutex lock = new InterProcessSemaphoreMutex(entry.getClient(), path);
+ if ( !lock.acquire(maxWaitMs, TimeUnit.MILLISECONDS) )
+ {
+ return new LockProjection();
+ }
+
+ Closer closer = new Closer()
+ {
+ @Override
+ public void close()
+ {
+ if ( lock.isAcquiredInThisProcess() )
+ {
+ try
+ {
+ lock.release();
+ }
+ catch ( Exception e )
+ {
+ log.error("Could not release left-over lock for path: " + path, e);
+ }
+ }
+ }
+ };
+ String id = entry.addThing(lock, closer);
+ return new LockProjection(id);
+ }
+
+ @ThriftMethod
+ public LeaderResult startLeaderSelector(final CuratorProjection projection, final String path, final String participantId, int waitForLeadershipMs) throws Exception
+ {
+ CuratorEntry entry = getEntry(projection);
+
+ final LeaderLatch leaderLatch = new LeaderLatch(entry.getClient(), path, participantId);
+ leaderLatch.start();
+
+ Closer closer = new Closer()
+ {
+ @Override
+ public void close()
+ {
+ try
+ {
+ leaderLatch.close();
+ }
+ catch ( IOException e )
+ {
+ log.error("Could not close left-over leader latch for path: " + path, e);
+ }
+ }
+ };
+ String id = entry.addThing(leaderLatch, closer);
+
+ LeaderLatchListener listener = new LeaderLatchListener()
+ {
+ @Override
+ public void isLeader()
+ {
+ addEvent(projection, new RpcCuratorEvent(new LeaderEvent(path, participantId, true)));
+ }
+
+ @Override
+ public void notLeader()
+ {
+ addEvent(projection, new RpcCuratorEvent(new LeaderEvent(path, participantId, false)));
+ }
+ };
+ leaderLatch.addListener(listener);
+
+ if ( waitForLeadershipMs > 0 )
+ {
+ leaderLatch.await(waitForLeadershipMs, TimeUnit.MILLISECONDS);
+ }
+
+ return new LeaderResult(new LeaderProjection(id), leaderLatch.hasLeadership());
+ }
+
+ @ThriftMethod
+ public List<RpcParticipant> getLeaderParticipants(CuratorProjection projection, LeaderProjection leaderProjection) throws Exception
+ {
+ CuratorEntry entry = getEntry(projection);
+
+ LeaderLatch leaderLatch = getThing(entry, leaderProjection.id, LeaderLatch.class);
+ Collection<Participant> participants = leaderLatch.getParticipants();
+ return Lists.transform(Lists.newArrayList(participants), new Function<Participant, RpcParticipant>()
+ {
+ @Override
+ public RpcParticipant apply(Participant participant)
+ {
+ return new RpcParticipant(participant.getId(), participant.isLeader());
+ }
+ });
+ }
+
+ @ThriftMethod
+ public boolean isLeader(CuratorProjection projection, LeaderProjection leaderProjection) throws Exception
+ {
+ CuratorEntry entry = getEntry(projection);
+
+ LeaderLatch leaderLatch = getThing(entry, leaderProjection.id, LeaderLatch.class);
+ return leaderLatch.hasLeadership();
+ }
+
+ @ThriftMethod
+ public PathChildrenCacheProjection startPathChildrenCache(final CuratorProjection projection, final String path, boolean cacheData, boolean dataIsCompressed, PathChildrenCacheStartMode startMode) throws Exception
+ {
+ final CuratorEntry entry = getEntry(projection);
+
+ final PathChildrenCache cache = new PathChildrenCache(entry.getClient(), path, cacheData, dataIsCompressed, ThreadUtils.newThreadFactory("PathChildrenCacheResource"));
+ cache.start(PathChildrenCache.StartMode.valueOf(startMode.name()));
+
+ Closer closer = new Closer()
+ {
+ @Override
+ public void close()
+ {
+ try
+ {
+ cache.close();
+ }
+ catch ( IOException e )
+ {
+ log.error("Could not close left-over PathChildrenCache for path: " + path, e);
+ }
+ }
+ };
+ String id = entry.addThing(cache, closer);
+
+ PathChildrenCacheListener listener = new PathChildrenCacheListener()
+ {
+ @Override
+ public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception
+ {
+ entry.addEvent(new RpcCuratorEvent(new RpcPathChildrenCacheEvent(path, event)));
+ }
+ };
+ cache.getListenable().addListener(listener);
+
+ return new PathChildrenCacheProjection(id);
+ }
+
+ @ThriftMethod
+ public List<RpcChildData> getPathChildrenCacheData(CuratorProjection projection, PathChildrenCacheProjection cacheProjection) throws Exception
+ {
+ CuratorEntry entry = getEntry(projection);
+
+ PathChildrenCache pathChildrenCache = getThing(entry, cacheProjection.id, PathChildrenCache.class);
+ return Lists.transform
+ (
+ pathChildrenCache.getCurrentData(),
+ new Function<ChildData, RpcChildData>()
+ {
+ @Override
+ public RpcChildData apply(ChildData childData)
+ {
+ return new RpcChildData(childData);
+ }
+ }
+ );
+ }
+
+ @ThriftMethod
+ public RpcChildData getPathChildrenCacheDataForPath(CuratorProjection projection, PathChildrenCacheProjection cacheProjection, String path) throws Exception
+ {
+ CuratorEntry entry = getEntry(projection);
+
+ PathChildrenCache pathChildrenCache = getThing(entry, cacheProjection.id, PathChildrenCache.class);
+ return new RpcChildData(pathChildrenCache.getCurrentData(path));
+ }
+
+ @ThriftMethod
+ public NodeCacheProjection startNodeCache(CuratorProjection projection, final String path, boolean dataIsCompressed, boolean buildInitial) throws Exception
+ {
+ final CuratorEntry entry = getEntry(projection);
+
+ final NodeCache cache = new NodeCache(entry.getClient(), path, dataIsCompressed);
+ cache.start(buildInitial);
+
+ Closer closer = new Closer()
+ {
+ @Override
+ public void close()
+ {
+ try
+ {
+ cache.close();
+ }
+ catch ( IOException e )
+ {
+ log.error("Could not close left-over NodeCache for path: " + path, e);
+ }
+ }
+ };
+ String id = entry.addThing(cache, closer);
+
+ NodeCacheListener listener = new NodeCacheListener()
+ {
+ @Override
+ public void nodeChanged() throws Exception
+ {
+ entry.addEvent(new RpcCuratorEvent(RpcCuratorEventType.NODE_CACHE, path));
+ }
+ };
+ cache.getListenable().addListener(listener);
+
+ return new NodeCacheProjection(id);
+ }
+
+ @ThriftMethod
+ public RpcChildData getNodeCacheData(CuratorProjection projection, NodeCacheProjection cacheProjection) throws Exception
+ {
+ CuratorEntry entry = getEntry(projection);
+
+ NodeCache nodeCache = getThing(entry, cacheProjection.id, NodeCache.class);
+ return new RpcChildData(nodeCache.getCurrentData());
+ }
+
+ @ThriftMethod
+ public PersistentEphemeralNodeProjection startPersistentEphemeralNode(CuratorProjection projection, final String path, byte[] data, RpcPersistentEphemeralNodeMode mode) throws Exception
+ {
+ CuratorEntry entry = getEntry(projection);
+
+ final PersistentEphemeralNode node = new PersistentEphemeralNode(entry.getClient(), PersistentEphemeralNode.Mode.valueOf(mode.name()), path, data);
+ node.start();
+
+ Closer closer = new Closer()
+ {
+ @Override
+ public void close()
+ {
+ try
+ {
+ node.close();
+ }
+ catch ( Exception e )
+ {
+ log.error("Could not release left-over persistent ephemeral node for path: " + path, e);
+ }
+ }
+ };
+ String id = entry.addThing(node, closer);
+ return new PersistentEphemeralNodeProjection(id);
+ }
+
+ @ThriftMethod
+ public List<LeaseProjection> startSemaphore(CuratorProjection projection, final String path, int acquireQty, int maxWaitMs, int maxLeases) throws Exception
+ {
+ CuratorEntry entry = getEntry(projection);
+
+ final InterProcessSemaphoreV2 semaphore = new InterProcessSemaphoreV2(entry.getClient(), path, maxLeases);
+ final Collection<Lease> leases = semaphore.acquire(acquireQty, maxWaitMs, TimeUnit.MILLISECONDS);
+ if ( leases == null )
+ {
+ return Lists.newArrayList();
+ }
+
+ List<LeaseProjection> leaseProjections = Lists.newArrayList();
+ for ( final Lease lease : leases )
+ {
+ Closer closer = new Closer()
+ {
+ @Override
+ public void close()
+ {
+ try
+ {
+ semaphore.returnLease(lease);
+ }
+ catch ( Exception e )
+ {
+ log.error("Could not release semaphore leases for path: " + path, e);
+ }
+ }
+ };
+ leaseProjections.add(new LeaseProjection(entry.addThing(lease, closer)));
+ }
+ return leaseProjections;
+ }
+
+ public void addEvent(CuratorProjection projection, RpcCuratorEvent event)
+ {
+ CuratorEntry entry = connectionManager.get(projection.id);
+ if ( entry != null )
+ {
+ entry.addEvent(event);
+ }
+ }
+
+ private CuratorEntry getEntry(CuratorProjection projection) throws Exception
+ {
+ CuratorEntry entry = connectionManager.get(projection.id);
+ if ( entry == null )
+ {
+ throw new Exception("No client found with id: " + projection.id);
+ }
+ return entry;
+ }
+
+ private static <T> T castBuilder(Object createBuilder, Class<T> clazz) throws Exception
+ {
+ if ( clazz.isAssignableFrom(createBuilder.getClass()) )
+ {
+ return clazz.cast(createBuilder);
+ }
+ throw new Exception("That operation is not available");
+ }
+
+ private <T> T getThing(CuratorEntry entry, String id, Class<T> clazz)
+ {
+ T thing = entry.getThing(id, clazz);
+ Preconditions.checkNotNull(thing, "No item of type " + clazz.getSimpleName() + " found with id " + id);
+ return thing;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/services/EventService.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/services/EventService.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/services/EventService.java
new file mode 100644
index 0000000..c10c5df
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/services/EventService.java
@@ -0,0 +1,34 @@
+package org.apache.curator.x.rpc.idl.services;
+
+import com.facebook.swift.service.ThriftMethod;
+import com.facebook.swift.service.ThriftService;
+import org.apache.curator.x.rpc.connections.CuratorEntry;
+import org.apache.curator.x.rpc.connections.ConnectionManager;
+import org.apache.curator.x.rpc.idl.structs.CuratorProjection;
+import org.apache.curator.x.rpc.idl.structs.RpcCuratorEvent;
+
+@ThriftService("EventService")
+public class EventService
+{
+ private final ConnectionManager connectionManager;
+ private final long pingTimeMs;
+
+ public EventService(ConnectionManager connectionManager, long pingTimeMs)
+ {
+ this.connectionManager = connectionManager;
+ this.pingTimeMs = pingTimeMs;
+ }
+
+ @ThriftMethod
+ public RpcCuratorEvent getNextEvent(CuratorProjection projection) throws InterruptedException
+ {
+ CuratorEntry entry = connectionManager.get(projection.id);
+ if ( entry == null )
+ {
+ // TODO
+ return null;
+ }
+ RpcCuratorEvent event = entry.pollForEvent(pingTimeMs);
+ return (event != null) ? event : new RpcCuratorEvent();
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/CreateSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/CreateSpec.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/CreateSpec.java
new file mode 100644
index 0000000..d0232a9
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/CreateSpec.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class CreateSpec
+{
+ @ThriftField(1)
+ public String path;
+
+ @ThriftField(2)
+ public byte[] data;
+
+ @ThriftField(3)
+ public RpcCreateMode mode;
+
+ @ThriftField(4)
+ public String asyncContext;
+
+ @ThriftField(5)
+ public boolean compressed;
+
+ @ThriftField(6)
+ public boolean creatingParentsIfNeeded;
+
+ @ThriftField(7)
+ public boolean withProtection;
+
+ public CreateSpec()
+ {
+ }
+
+ public CreateSpec(String path, byte[] data, RpcCreateMode mode, String asyncContext, boolean compressed, boolean creatingParentsIfNeeded, boolean withProtection)
+ {
+ this.path = path;
+ this.data = data;
+ this.mode = mode;
+ this.asyncContext = asyncContext;
+ this.compressed = compressed;
+ this.creatingParentsIfNeeded = creatingParentsIfNeeded;
+ this.withProtection = withProtection;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/CuratorProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/CuratorProjection.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/CuratorProjection.java
new file mode 100644
index 0000000..a97ca4b
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/CuratorProjection.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftConstructor;
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class CuratorProjection
+{
+ @ThriftField(1)
+ public String id;
+
+ public CuratorProjection()
+ {
+ }
+
+ public CuratorProjection(String id)
+ {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/DeleteSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/DeleteSpec.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/DeleteSpec.java
new file mode 100644
index 0000000..2d418ee
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/DeleteSpec.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class DeleteSpec
+{
+ @ThriftField(1)
+ public String path;
+
+ @ThriftField(2)
+ public boolean guaranteed;
+
+ @ThriftField(3)
+ public String asyncContext;
+
+ @ThriftField(4)
+ public boolean compressed;
+
+ @ThriftField(5)
+ public Version version;
+
+ public DeleteSpec()
+ {
+ }
+
+ public DeleteSpec(String path, boolean guaranteed, String asyncContext, boolean compressed, Version version)
+ {
+ this.path = path;
+ this.guaranteed = guaranteed;
+ this.asyncContext = asyncContext;
+ this.compressed = compressed;
+ this.version = version;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/ExistsSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/ExistsSpec.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/ExistsSpec.java
new file mode 100644
index 0000000..f271f7e
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/ExistsSpec.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class ExistsSpec
+{
+ @ThriftField(1)
+ public String path;
+
+ @ThriftField(2)
+ public boolean watched;
+
+ @ThriftField(3)
+ public String asyncContext;
+
+ public ExistsSpec()
+ {
+ }
+
+ public ExistsSpec(String path, boolean watched, String asyncContext)
+ {
+ this.path = path;
+ this.watched = watched;
+ this.asyncContext = asyncContext;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/GetChildrenSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/GetChildrenSpec.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/GetChildrenSpec.java
new file mode 100644
index 0000000..37dea04
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/GetChildrenSpec.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class GetChildrenSpec
+{
+ @ThriftField(1)
+ public String path;
+
+ @ThriftField(2)
+ public boolean watched;
+
+ @ThriftField(3)
+ public String asyncContext;
+
+ public GetChildrenSpec()
+ {
+ }
+
+ public GetChildrenSpec(String path, boolean watched, String asyncContext)
+ {
+ this.path = path;
+ this.watched = watched;
+ this.asyncContext = asyncContext;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/GetDataSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/GetDataSpec.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/GetDataSpec.java
new file mode 100644
index 0000000..9b741d0
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/GetDataSpec.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class GetDataSpec
+{
+ @ThriftField(1)
+ public String path;
+
+ @ThriftField(2)
+ public boolean watched;
+
+ @ThriftField(3)
+ public String asyncContext;
+
+ @ThriftField(4)
+ public boolean decompressed;
+
+ public GetDataSpec()
+ {
+ }
+
+ public GetDataSpec(String path, boolean watched, String asyncContext, boolean decompressed)
+ {
+ this.path = path;
+ this.watched = watched;
+ this.asyncContext = asyncContext;
+ this.decompressed = decompressed;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderEvent.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderEvent.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderEvent.java
new file mode 100644
index 0000000..68f3916
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderEvent.java
@@ -0,0 +1,28 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class LeaderEvent
+{
+ @ThriftField(1)
+ public String path;
+
+ @ThriftField(2)
+ public String participantId;
+
+ @ThriftField(3)
+ public boolean isLeader;
+
+ public LeaderEvent()
+ {
+ }
+
+ public LeaderEvent(String path, String participantId, boolean isLeader)
+ {
+ this.path = path;
+ this.participantId = participantId;
+ this.isLeader = isLeader;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderProjection.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderProjection.java
new file mode 100644
index 0000000..0d12a4c
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderProjection.java
@@ -0,0 +1,20 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class LeaderProjection
+{
+ @ThriftField(1)
+ public String id;
+
+ public LeaderProjection()
+ {
+ }
+
+ public LeaderProjection(String id)
+ {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderResult.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderResult.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderResult.java
new file mode 100644
index 0000000..8161ef4
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaderResult.java
@@ -0,0 +1,24 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class LeaderResult
+{
+ @ThriftField(1)
+ public LeaderProjection projection;
+
+ @ThriftField(2)
+ public boolean hasLeadership;
+
+ public LeaderResult()
+ {
+ }
+
+ public LeaderResult(LeaderProjection projection, boolean hasLeadership)
+ {
+ this.projection = projection;
+ this.hasLeadership = hasLeadership;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaseProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaseProjection.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaseProjection.java
new file mode 100644
index 0000000..784bcf6
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LeaseProjection.java
@@ -0,0 +1,20 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class LeaseProjection
+{
+ @ThriftField(1)
+ public String id;
+
+ public LeaseProjection()
+ {
+ }
+
+ public LeaseProjection(String id)
+ {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LockProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LockProjection.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LockProjection.java
new file mode 100644
index 0000000..9421527
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/LockProjection.java
@@ -0,0 +1,20 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class LockProjection
+{
+ @ThriftField(1)
+ public String id;
+
+ public LockProjection()
+ {
+ }
+
+ public LockProjection(String id)
+ {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/NodeCacheProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/NodeCacheProjection.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/NodeCacheProjection.java
new file mode 100644
index 0000000..3a28704
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/NodeCacheProjection.java
@@ -0,0 +1,20 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class NodeCacheProjection
+{
+ @ThriftField(1)
+ public String id;
+
+ public NodeCacheProjection()
+ {
+ }
+
+ public NodeCacheProjection(String id)
+ {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalChildrenList.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalChildrenList.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalChildrenList.java
new file mode 100644
index 0000000..6a038bb
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalChildrenList.java
@@ -0,0 +1,21 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+import java.util.List;
+
+@ThriftStruct
+public class OptionalChildrenList
+{
+ @ThriftField(1)
+ public List<String> children;
+
+ public OptionalChildrenList()
+ {
+ }
+
+ public OptionalChildrenList(List<String> children)
+ {
+ this.children = children;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalPath.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalPath.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalPath.java
new file mode 100644
index 0000000..1e48a7d
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalPath.java
@@ -0,0 +1,20 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class OptionalPath
+{
+ @ThriftField(1)
+ public String path;
+
+ public OptionalPath()
+ {
+ }
+
+ public OptionalPath(String path)
+ {
+ this.path = path;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalRpcStat.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalRpcStat.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalRpcStat.java
new file mode 100644
index 0000000..df0c234
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/OptionalRpcStat.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct("OptionalStat")
+public class OptionalRpcStat
+{
+ @ThriftField(1)
+ public RpcStat stat;
+
+ public OptionalRpcStat()
+ {
+ }
+
+ public OptionalRpcStat(RpcStat stat)
+ {
+ this.stat = stat;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PathChildrenCacheProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PathChildrenCacheProjection.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PathChildrenCacheProjection.java
new file mode 100644
index 0000000..a909c83
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PathChildrenCacheProjection.java
@@ -0,0 +1,20 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class PathChildrenCacheProjection
+{
+ @ThriftField(1)
+ public String id;
+
+ public PathChildrenCacheProjection()
+ {
+ }
+
+ public PathChildrenCacheProjection(String id)
+ {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PathChildrenCacheStartMode.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PathChildrenCacheStartMode.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PathChildrenCacheStartMode.java
new file mode 100644
index 0000000..8a5d225
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PathChildrenCacheStartMode.java
@@ -0,0 +1,8 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+public enum PathChildrenCacheStartMode
+{
+ NORMAL,
+ BUILD_INITIAL_CACHE,
+ POST_INITIALIZED_EVENT
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PersistentEphemeralNodeProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PersistentEphemeralNodeProjection.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PersistentEphemeralNodeProjection.java
new file mode 100644
index 0000000..f775d8e
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/PersistentEphemeralNodeProjection.java
@@ -0,0 +1,20 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class PersistentEphemeralNodeProjection
+{
+ @ThriftField(1)
+ public String id;
+
+ public PersistentEphemeralNodeProjection()
+ {
+ }
+
+ public PersistentEphemeralNodeProjection(String id)
+ {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcAcl.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcAcl.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcAcl.java
new file mode 100644
index 0000000..c4cb9ac
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcAcl.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct("Acl")
+public class RpcAcl
+{
+ @ThriftField(1)
+ public int perms;
+
+ @ThriftField(2)
+ public RpcId id;
+
+ public RpcAcl()
+ {
+ }
+
+ public RpcAcl(int perms, RpcId id)
+ {
+ this.perms = perms;
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcChildData.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcChildData.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcChildData.java
new file mode 100644
index 0000000..f7862f7
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcChildData.java
@@ -0,0 +1,39 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+import org.apache.curator.framework.recipes.cache.ChildData;
+
+@ThriftStruct("ChildData")
+public class RpcChildData
+{
+ @ThriftField(1)
+ public String path;
+
+ @ThriftField(2)
+ public RpcStat stat;
+
+ @ThriftField(3)
+ public byte[] data;
+
+ public RpcChildData()
+ {
+ }
+
+ public RpcChildData(ChildData data)
+ {
+ if ( data != null )
+ {
+ this.path = data.getPath();
+ this.stat = RpcCuratorEvent.toRpcStat(data.getStat());
+ this.data = data.getData();
+ }
+ }
+
+ public RpcChildData(String path, RpcStat stat, byte[] data)
+ {
+ this.path = path;
+ this.stat = stat;
+ this.data = data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCreateMode.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCreateMode.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCreateMode.java
new file mode 100644
index 0000000..d50bb74
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCreateMode.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftEnum;
+
+@ThriftEnum("CreateMode")
+public enum RpcCreateMode
+{
+ PERSISTENT,
+ PERSISTENT_SEQUENTIAL,
+ EPHEMERAL,
+ EPHEMERAL_SEQUENTIAL
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCuratorEvent.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCuratorEvent.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCuratorEvent.java
new file mode 100644
index 0000000..52d18df
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCuratorEvent.java
@@ -0,0 +1,224 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.state.ConnectionState;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Stat;
+import javax.annotation.Nullable;
+import java.util.List;
+
+@SuppressWarnings("deprecation")
+@ThriftStruct("CuratorEvent")
+public class RpcCuratorEvent
+{
+ @ThriftField(2)
+ public RpcCuratorEventType type;
+
+ @ThriftField(3)
+ public int resultCode;
+
+ @ThriftField(4)
+ public String path;
+
+ @ThriftField(5)
+ public String context;
+
+ @ThriftField(6)
+ public RpcStat stat;
+
+ @ThriftField(7)
+ public byte[] data;
+
+ @ThriftField(8)
+ public String name;
+
+ @ThriftField(9)
+ public List<String> children;
+
+ @ThriftField(10)
+ public List<RpcAcl> aclList;
+
+ @ThriftField(11)
+ public RpcWatchedEvent watchedEvent;
+
+ @ThriftField(12)
+ public LeaderEvent leaderEvent;
+
+ @ThriftField(13)
+ public RpcPathChildrenCacheEvent childrenCacheEvent;
+
+ public RpcCuratorEvent()
+ {
+ this.type = RpcCuratorEventType.PING;
+ this.resultCode = 0;
+ this.path = null;
+ this.context = null;
+ this.stat = null;
+ this.data = null;
+ this.name = null;
+ this.children = null;
+ this.aclList = null;
+ this.watchedEvent = null;
+ this.leaderEvent = null;
+ this.childrenCacheEvent = null;
+ }
+
+ public RpcCuratorEvent(RpcCuratorEventType type, String path)
+ {
+ this.type = type;
+ this.resultCode = 0;
+ this.path = path;
+ this.context = null;
+ this.stat = null;
+ this.data = null;
+ this.name = null;
+ this.children = null;
+ this.aclList = null;
+ this.watchedEvent = null;
+ this.leaderEvent = null;
+ this.childrenCacheEvent = null;
+ }
+
+ public RpcCuratorEvent(RpcPathChildrenCacheEvent childrenCacheEvent)
+ {
+ this.type = RpcCuratorEventType.PATH_CHILDREN_CACHE;
+ this.resultCode = 0;
+ this.path = null;
+ this.context = null;
+ this.stat = null;
+ this.data = null;
+ this.name = null;
+ this.children = null;
+ this.aclList = null;
+ this.watchedEvent = null;
+ this.leaderEvent = null;
+ this.childrenCacheEvent = childrenCacheEvent;
+ }
+
+ public RpcCuratorEvent(CuratorEvent event)
+ {
+ this.type = RpcCuratorEventType.valueOf(event.getType().name());
+ this.resultCode = event.getResultCode();
+ this.path = event.getPath();
+ this.context = (event.getContext() != null) ? String.valueOf(event.getContext()) : null;
+ this.stat = toRpcStat(event.getStat());
+ this.data = event.getData();
+ this.name = event.getName();
+ this.children = event.getChildren();
+ this.aclList = toRpcAclList(event.getACLList());
+ this.watchedEvent = toRpcWatchedEvent(event.getWatchedEvent());
+ this.leaderEvent = null;
+ this.childrenCacheEvent = null;
+ }
+
+ public RpcCuratorEvent(ConnectionState newState)
+ {
+ this.type = RpcCuratorEventType.valueOf(newState.name());
+ this.resultCode = 0;
+ this.path = null;
+ this.context = null;
+ this.stat = null;
+ this.data = null;
+ this.name = null;
+ this.children = null;
+ this.aclList = null;
+ this.watchedEvent = null;
+ this.leaderEvent = null;
+ this.childrenCacheEvent = null;
+ }
+
+ public RpcCuratorEvent(WatchedEvent event)
+ {
+ this.type = RpcCuratorEventType.WATCHED;
+ this.resultCode = 0;
+ this.path = event.getPath();
+ this.context = null;
+ this.stat = null;
+ this.data = null;
+ this.name = null;
+ this.children = null;
+ this.aclList = null;
+ this.watchedEvent = new RpcWatchedEvent(RpcKeeperState.valueOf(event.getState().name()), RpcEventType.valueOf(event.getType().name()), event.getPath());
+ this.leaderEvent = null;
+ this.childrenCacheEvent = null;
+ }
+
+ public RpcCuratorEvent(LeaderEvent event)
+ {
+ this.type = RpcCuratorEventType.LEADER;
+ this.resultCode = 0;
+ this.path = event.path;
+ this.context = null;
+ this.stat = null;
+ this.data = null;
+ this.name = null;
+ this.children = null;
+ this.aclList = null;
+ this.watchedEvent = null;
+ this.leaderEvent = event;
+ this.childrenCacheEvent = null;
+ }
+
+ public static RpcStat toRpcStat(Stat stat)
+ {
+ if ( stat != null )
+ {
+ return new RpcStat(stat);
+ }
+ return null;
+ }
+
+ private List<RpcAcl> toRpcAclList(List<ACL> aclList)
+ {
+ if ( aclList != null )
+ {
+ return Lists.transform
+ (
+ aclList,
+ new Function<ACL, RpcAcl>()
+ {
+ @Nullable
+ @Override
+ public RpcAcl apply(ACL acl)
+ {
+ RpcId id = new RpcId(acl.getId().getScheme(), acl.getId().getId());
+ return new RpcAcl(acl.getPerms(), id);
+ }
+ }
+ );
+ }
+ return null;
+ }
+
+ private RpcWatchedEvent toRpcWatchedEvent(WatchedEvent watchedEvent)
+ {
+ if ( watchedEvent != null )
+ {
+ return new RpcWatchedEvent(watchedEvent);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCuratorEventType.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCuratorEventType.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCuratorEventType.java
new file mode 100644
index 0000000..88b4a1f
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcCuratorEventType.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftEnum;
+
+@ThriftEnum("CuratorEventType")
+public enum RpcCuratorEventType
+{
+ PING,
+ CREATE,
+ DELETE,
+ EXISTS,
+ GET_DATA,
+ SET_DATA,
+ CHILDREN,
+ SYNC,
+ GET_ACL,
+ SET_ACL,
+ WATCHED,
+ CLOSING,
+ CONNECTION_CONNECTED,
+ CONNECTION_SUSPENDED,
+ CONNECTION_RECONNECTED,
+ CONNECTION_LOST,
+ CONNECTION_READ_ONLY,
+ LEADER,
+ PATH_CHILDREN_CACHE,
+ NODE_CACHE
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcEventType.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcEventType.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcEventType.java
new file mode 100644
index 0000000..d20adb0
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcEventType.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftEnum;
+
+@ThriftEnum("EventType")
+public enum RpcEventType
+{
+ None,
+ NodeCreated,
+ NodeDeleted,
+ NodeDataChanged,
+ NodeChildrenChanged
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcId.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcId.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcId.java
new file mode 100644
index 0000000..233736b
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcId.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct("Id")
+public class RpcId
+{
+ @ThriftField(1)
+ public String scheme;
+
+ @ThriftField(2)
+ public String id;
+
+ public RpcId()
+ {
+ }
+
+ public RpcId(String scheme, String id)
+ {
+ this.scheme = scheme;
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcKeeperState.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcKeeperState.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcKeeperState.java
new file mode 100644
index 0000000..8839a1d
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcKeeperState.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftEnum;
+
+@ThriftEnum("KeeperState")
+public enum RpcKeeperState
+{
+ Unknown,
+ Disconnected,
+ NoSyncConnected,
+ SyncConnected,
+ AuthFailed,
+ ConnectedReadOnly,
+ SaslAuthenticated,
+ Expired
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcParticipant.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcParticipant.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcParticipant.java
new file mode 100644
index 0000000..7b1dfde
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcParticipant.java
@@ -0,0 +1,24 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct("Participant")
+public class RpcParticipant
+{
+ @ThriftField(1)
+ public String id;
+
+ @ThriftField(2)
+ public boolean isLeader;
+
+ public RpcParticipant()
+ {
+ }
+
+ public RpcParticipant(String id, boolean isLeader)
+ {
+ this.id = id;
+ this.isLeader = isLeader;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPathChildrenCacheEvent.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPathChildrenCacheEvent.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPathChildrenCacheEvent.java
new file mode 100644
index 0000000..6766e8e
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPathChildrenCacheEvent.java
@@ -0,0 +1,36 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
+
+@ThriftStruct("PathChildrenCacheEvent")
+public class RpcPathChildrenCacheEvent
+{
+ @ThriftField(1)
+ public String cachedPath;
+
+ @ThriftField(2)
+ public RpcPathChildrenCacheEventType type;
+
+ @ThriftField(3)
+ public RpcChildData data;
+
+ public RpcPathChildrenCacheEvent()
+ {
+ }
+
+ public RpcPathChildrenCacheEvent(String cachedPath, PathChildrenCacheEvent event)
+ {
+ this.cachedPath = cachedPath;
+ type = RpcPathChildrenCacheEventType.valueOf(event.getType().name());
+ data = (event.getData() != null) ? new RpcChildData(event.getData()) : null;
+ }
+
+ public RpcPathChildrenCacheEvent(String cachedPath, RpcPathChildrenCacheEventType type, RpcChildData data)
+ {
+ this.cachedPath = cachedPath;
+ this.type = type;
+ this.data = data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPathChildrenCacheEventType.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPathChildrenCacheEventType.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPathChildrenCacheEventType.java
new file mode 100644
index 0000000..e14284d
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPathChildrenCacheEventType.java
@@ -0,0 +1,15 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftEnum;
+
+@ThriftEnum("PathChildrenCacheEventType")
+public enum RpcPathChildrenCacheEventType
+{
+ CHILD_ADDED,
+ CHILD_UPDATED,
+ CHILD_REMOVED,
+ CONNECTION_SUSPENDED,
+ CONNECTION_RECONNECTED,
+ CONNECTION_LOST,
+ INITIALIZED
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPersistentEphemeralNodeMode.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPersistentEphemeralNodeMode.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPersistentEphemeralNodeMode.java
new file mode 100644
index 0000000..7fedaf9
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcPersistentEphemeralNodeMode.java
@@ -0,0 +1,12 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftEnum;
+
+@ThriftEnum("PersistentEphemeralNodeMode")
+public enum RpcPersistentEphemeralNodeMode
+{
+ EPHEMERAL,
+ EPHEMERAL_SEQUENTIAL,
+ PROTECTED_EPHEMERAL,
+ PROTECTED_EPHEMERAL_SEQUENTIAL
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcStat.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcStat.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcStat.java
new file mode 100644
index 0000000..5e62f15
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcStat.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+import org.apache.zookeeper.data.Stat;
+
+@ThriftStruct("Stat")
+public class RpcStat
+{
+ @ThriftField(1)
+ public long czxid;
+
+ @ThriftField(2)
+ public long mzxid;
+
+ @ThriftField(3)
+ public long ctime;
+
+ @ThriftField(4)
+ public long mtime;
+
+ @ThriftField(5)
+ public int version;
+
+ @ThriftField(6)
+ public int cversion;
+
+ @ThriftField(7)
+ public int aversion;
+
+ @ThriftField(8)
+ public long ephemeralOwner;
+
+ @ThriftField(9)
+ public int dataLength;
+
+ @ThriftField(10)
+ public int numChildren;
+
+ @ThriftField(11)
+ public long pzxid;
+
+ public RpcStat()
+ {
+ }
+
+ public RpcStat(Stat stat)
+ {
+ czxid = stat.getCzxid();
+ mzxid = stat.getMzxid();
+ ctime = stat.getCtime();
+ mtime = stat.getMtime();
+ version = stat.getVersion();
+ cversion = stat.getCversion();
+ aversion = stat.getAversion();
+ ephemeralOwner = stat.getEphemeralOwner();
+ dataLength = stat.getDataLength();
+ numChildren = stat.getNumChildren();
+ pzxid = stat.getPzxid();
+ }
+
+ public RpcStat(long czxid, long mzxid, long ctime, long mtime, int version, int cversion, int aversion, long ephemeralOwner, int dataLength, int numChildren, long pzxid)
+ {
+ this.czxid = czxid;
+ this.mzxid = mzxid;
+ this.ctime = ctime;
+ this.mtime = mtime;
+ this.version = version;
+ this.cversion = cversion;
+ this.aversion = aversion;
+ this.ephemeralOwner = ephemeralOwner;
+ this.dataLength = dataLength;
+ this.numChildren = numChildren;
+ this.pzxid = pzxid;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcWatchedEvent.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcWatchedEvent.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcWatchedEvent.java
new file mode 100644
index 0000000..cc7e818
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/RpcWatchedEvent.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+import org.apache.zookeeper.WatchedEvent;
+
+@ThriftStruct("WatchedEvent")
+public class RpcWatchedEvent
+{
+ @ThriftField(1)
+ public RpcKeeperState keeperState;
+
+ @ThriftField(2)
+ public RpcEventType eventType;
+
+ @ThriftField(3)
+ public String path;
+
+ public RpcWatchedEvent()
+ {
+ }
+
+ public RpcWatchedEvent(WatchedEvent watchedEvent)
+ {
+ keeperState = RpcKeeperState.valueOf(watchedEvent.getState().name());
+ eventType = RpcEventType.valueOf(watchedEvent.getType().name());
+ path = watchedEvent.getPath();
+ }
+
+ public RpcWatchedEvent(RpcKeeperState keeperState, RpcEventType eventType, String path)
+ {
+ this.keeperState = keeperState;
+ this.eventType = eventType;
+ this.path = path;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/SetDataSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/SetDataSpec.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/SetDataSpec.java
new file mode 100644
index 0000000..0814699
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/SetDataSpec.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class SetDataSpec
+{
+ @ThriftField(1)
+ public String path;
+
+ @ThriftField(2)
+ public boolean watched;
+
+ @ThriftField(3)
+ public String asyncContext;
+
+ @ThriftField(4)
+ public boolean compressed;
+
+ @ThriftField(5)
+ public Version version;
+
+ @ThriftField(6)
+ public byte[] data;
+
+ public SetDataSpec()
+ {
+ }
+
+ public SetDataSpec(String path, boolean watched, String asyncContext, boolean compressed, Version version, byte[] data)
+ {
+ this.path = path;
+ this.watched = watched;
+ this.asyncContext = asyncContext;
+ this.compressed = compressed;
+ this.version = version;
+ this.data = data;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/Version.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/Version.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/Version.java
new file mode 100644
index 0000000..cb3fcec
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/structs/Version.java
@@ -0,0 +1,20 @@
+package org.apache.curator.x.rpc.idl.structs;
+
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class Version
+{
+ @ThriftField(1)
+ public int version;
+
+ public Version()
+ {
+ }
+
+ public Version(int version)
+ {
+ this.version = version;
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/8bfaffd2/curator-x-rpc/src/main/scripts/generate.sh
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/scripts/generate.sh b/curator-x-rpc/src/main/scripts/generate.sh
index 15f6546..de5e21c 100755
--- a/curator-x-rpc/src/main/scripts/generate.sh
+++ b/curator-x-rpc/src/main/scripts/generate.sh
@@ -31,7 +31,7 @@ RPC_PATH="$BASE_DIR/curator-x-rpc/target/classes"
CLASSES=""
-for p in projection event; do
+for p in services structs; do
for f in `ls -m1 $RPC_PATH/org/apache/curator/x/rpc/idl/$p/*.class | xargs -n 1 basename | sed s/\.[^\.]*$//`; do
if [[ $f != *[\$]* ]]; then
CLASSES="$CLASSES org.apache.curator.x.rpc.idl.$p.$f";