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 2017/07/21 11:30:26 UTC
[16/16] curator git commit: Squashed commit of the following:
Squashed commit of the following:
commit 1e7902427f627f0efc5e2486437929a26bd237bd
Author: randgalt <ra...@apache.org>
Date: Thu Jul 20 14:42:41 2017 -0500
Remove Curator RPC code from git
commit 939994838320b7f0394bdf4f8919df101f5b7359
Author: randgalt <ra...@apache.org>
Date: Thu Jul 20 13:54:44 2017 -0500
Removed Curator RPC
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/95b70d2b
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/95b70d2b
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/95b70d2b
Branch: refs/heads/master
Commit: 95b70d2b4b04ca86194cbf54e9b5dc1869b36b3b
Parents: 7e611bd
Author: randgalt <ra...@apache.org>
Authored: Fri Jul 21 06:29:57 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Fri Jul 21 06:29:57 2017 -0500
----------------------------------------------------------------------
curator-x-rpc/pom.xml | 189 -
.../curator/x/rpc/CuratorProjectionServer.java | 152 -
.../AuthorizationConfiguration.java | 45 -
...dedExponentialBackoffRetryConfiguration.java | 69 -
.../x/rpc/configuration/Configuration.java | 86 -
.../rpc/configuration/ConfigurationBuilder.java | 87 -
.../configuration/ConnectionConfiguration.java | 129 -
.../ExponentialBackoffRetryConfiguration.java | 58 -
.../configuration/RetryNTimesConfiguration.java | 58 -
.../configuration/RetryPolicyConfiguration.java | 28 -
.../curator/x/rpc/connections/Closer.java | 24 -
.../x/rpc/connections/ConnectionManager.java | 141 -
.../curator/x/rpc/connections/CuratorEntry.java | 170 -
.../x/rpc/details/RpcBackgroundCallback.java | 44 -
.../curator/x/rpc/details/RpcWatcher.java | 43 -
.../x/rpc/idl/discovery/DiscoveryInstance.java | 95 -
.../idl/discovery/DiscoveryInstanceType.java | 26 -
.../rpc/idl/discovery/DiscoveryProjection.java | 38 -
.../discovery/DiscoveryProviderProjection.java | 38 -
.../x/rpc/idl/discovery/DiscoveryService.java | 259 -
.../idl/discovery/DiscoveryServiceLowLevel.java | 159 -
.../rpc/idl/discovery/ProviderStrategyType.java | 27 -
.../x/rpc/idl/exceptions/ExceptionType.java | 26 -
.../x/rpc/idl/exceptions/NodeExceptionType.java | 27 -
.../x/rpc/idl/exceptions/RpcException.java | 98 -
.../idl/exceptions/ZooKeeperExceptionType.java | 40 -
.../idl/services/CuratorProjectionService.java | 765 -
.../x/rpc/idl/services/EventService.java | 55 -
.../curator/x/rpc/idl/structs/CreateSpec.java | 66 -
.../x/rpc/idl/structs/CuratorProjection.java | 38 -
.../curator/x/rpc/idl/structs/DeleteSpec.java | 50 -
.../curator/x/rpc/idl/structs/ExistsSpec.java | 46 -
.../x/rpc/idl/structs/GetChildrenSpec.java | 46 -
.../curator/x/rpc/idl/structs/GetDataSpec.java | 50 -
.../curator/x/rpc/idl/structs/LeaderEvent.java | 46 -
.../x/rpc/idl/structs/LeaderProjection.java | 38 -
.../curator/x/rpc/idl/structs/LeaderResult.java | 42 -
.../x/rpc/idl/structs/LeaseProjection.java | 38 -
.../x/rpc/idl/structs/LockProjection.java | 38 -
.../x/rpc/idl/structs/NodeCacheProjection.java | 38 -
.../x/rpc/idl/structs/OptionalChildrenList.java | 39 -
.../curator/x/rpc/idl/structs/OptionalData.java | 38 -
.../rpc/idl/structs/OptionalLockProjection.java | 38 -
.../curator/x/rpc/idl/structs/OptionalPath.java | 38 -
.../x/rpc/idl/structs/OptionalRpcStat.java | 38 -
.../structs/PathChildrenCacheProjection.java | 38 -
.../idl/structs/PathChildrenCacheStartMode.java | 26 -
.../PersistentEphemeralNodeProjection.java | 38 -
.../curator/x/rpc/idl/structs/RpcAcl.java | 42 -
.../curator/x/rpc/idl/structs/RpcChildData.java | 57 -
.../x/rpc/idl/structs/RpcCreateMode.java | 31 -
.../x/rpc/idl/structs/RpcCuratorEvent.java | 224 -
.../x/rpc/idl/structs/RpcCuratorEventType.java | 46 -
.../curator/x/rpc/idl/structs/RpcEventType.java | 31 -
.../apache/curator/x/rpc/idl/structs/RpcId.java | 42 -
.../x/rpc/idl/structs/RpcKeeperState.java | 34 -
.../x/rpc/idl/structs/RpcParticipant.java | 42 -
.../idl/structs/RpcPathChildrenCacheEvent.java | 54 -
.../structs/RpcPathChildrenCacheEventType.java | 33 -
.../structs/RpcPersistentEphemeralNodeMode.java | 30 -
.../curator/x/rpc/idl/structs/RpcStat.java | 95 -
.../x/rpc/idl/structs/RpcWatchedEvent.java | 54 -
.../curator/x/rpc/idl/structs/SetDataSpec.java | 58 -
.../curator/x/rpc/idl/structs/Version.java | 38 -
.../src/main/resources/curator/help.txt | 72 -
curator-x-rpc/src/main/scripts/apply-thrift.sh | 36 -
curator-x-rpc/src/main/scripts/generate.sh | 56 -
curator-x-rpc/src/main/thrift/curator.thrift | 297 -
.../site/confluence/configuration.confluence | 143 -
.../src/site/confluence/deploy.confluence | 31 -
.../src/site/confluence/events.confluence | 90 -
.../src/site/confluence/index.confluence | 49 -
.../src/site/confluence/reference.confluence | 120 -
.../src/site/confluence/usage.confluence | 115 -
.../src/site/resources/images/topology.png | Bin 135534 -> 0 bytes
curator-x-rpc/src/site/site.xml | 33 -
.../java/org/apache/curator/generated/Acl.java | 491 -
.../org/apache/curator/generated/ChildData.java | 604 -
.../apache/curator/generated/CreateMode.java | 51 -
.../apache/curator/generated/CreateSpec.java | 1001 -
.../apache/curator/generated/CuratorEvent.java | 1636 --
.../curator/generated/CuratorEventType.java | 99 -
.../curator/generated/CuratorException.java | 736 -
.../curator/generated/CuratorProjection.java | 388 -
.../curator/generated/CuratorService.java | 24123 -----------------
.../apache/curator/generated/DeleteSpec.java | 691 -
.../curator/generated/DiscoveryInstance.java | 1201 -
.../generated/DiscoveryInstanceType.java | 48 -
.../curator/generated/DiscoveryProjection.java | 388 -
.../generated/DiscoveryProviderProjection.java | 388 -
.../curator/generated/DiscoveryService.java | 7236 -----
.../generated/DiscoveryServiceLowLevel.java | 6966 -----
.../apache/curator/generated/EventService.java | 1082 -
.../org/apache/curator/generated/EventType.java | 54 -
.../apache/curator/generated/ExceptionType.java | 48 -
.../apache/curator/generated/ExistsSpec.java | 586 -
.../curator/generated/GetChildrenSpec.java | 586 -
.../apache/curator/generated/GetDataSpec.java | 680 -
.../java/org/apache/curator/generated/Id.java | 488 -
.../apache/curator/generated/KeeperState.java | 63 -
.../apache/curator/generated/LeaderEvent.java | 586 -
.../curator/generated/LeaderProjection.java | 388 -
.../apache/curator/generated/LeaderResult.java | 491 -
.../curator/generated/LeaseProjection.java | 388 -
.../curator/generated/LockProjection.java | 388 -
.../curator/generated/NodeCacheProjection.java | 388 -
.../curator/generated/NodeExceptionType.java | 51 -
.../curator/generated/OptionalChildrenList.java | 437 -
.../apache/curator/generated/OptionalData.java | 399 -
.../generated/OptionalLockProjection.java | 393 -
.../apache/curator/generated/OptionalPath.java | 388 -
.../apache/curator/generated/OptionalStat.java | 393 -
.../apache/curator/generated/Participant.java | 486 -
.../generated/PathChildrenCacheEvent.java | 609 -
.../generated/PathChildrenCacheEventType.java | 60 -
.../generated/PathChildrenCacheProjection.java | 388 -
.../generated/PathChildrenCacheStartMode.java | 48 -
.../generated/PersistentEphemeralNodeMode.java | 51 -
.../PersistentEphemeralNodeProjection.java | 388 -
.../curator/generated/ProviderStrategyType.java | 51 -
.../apache/curator/generated/SetDataSpec.java | 896 -
.../java/org/apache/curator/generated/Stat.java | 1326 -
.../org/apache/curator/generated/Version.java | 386 -
.../apache/curator/generated/WatchedEvent.java | 620 -
.../generated/ZooKeeperExceptionType.java | 90 -
.../java/org/apache/curator/x/rpc/RpcTests.java | 294 -
.../org/apache/curator/x/rpc/TestClient.java | 168 -
.../org/apache/curator/x/rpc/TestServer.java | 34 -
.../resources/configuration/connections.json | 27 -
.../test/resources/configuration/logging.json | 19 -
.../test/resources/configuration/simple.json | 7 -
.../src/test/resources/configuration/test.json | 14 -
pom.xml | 7 -
src/site/confluence/index.confluence | 1 -
src/site/site.xml | 1 -
135 files changed, 66053 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-rpc/pom.xml b/curator-x-rpc/pom.xml
deleted file mode 100644
index e831e1f..0000000
--- a/curator-x-rpc/pom.xml
+++ /dev/null
@@ -1,189 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <artifactId>apache-curator</artifactId>
- <groupId>org.apache.curator</groupId>
- <version>3.3.1-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>curator-x-rpc</artifactId>
- <version>3.3.1-SNAPSHOT</version>
-
- <name>Curator RPC Proxy</name>
- <description>A proxy that bridges non-java environments with the Curator framework and recipes</description>
- <inceptionYear>2014</inceptionYear>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-recipes</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>log4j-over-slf4j</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </exclusion>
- <exclusion>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-x-discovery</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>log4j-over-slf4j</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </exclusion>
- <exclusion>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>com.facebook.swift</groupId>
- <artifactId>swift-service</artifactId>
- <exclusions>
- <exclusion>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>io.dropwizard</groupId>
- <artifactId>dropwizard-configuration</artifactId>
- </dependency>
-
- <dependency>
- <groupId>io.dropwizard</groupId>
- <artifactId>dropwizard-logging</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-test</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>log4j-over-slf4j</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </exclusion>
- <exclusion>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </exclusion>
- </exclusions>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <resources>
- <resource>
- <directory>${project.basedir}/src/main/resources</directory>
- <includes>
- <include>curator/help.txt</include>
- </includes>
- </resource>
- <resource>
- <directory>${project.basedir}/src/main/thrift</directory>
- <includes>
- <include>curator.thrift</include>
- </includes>
- </resource>
- </resources>
-
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <configuration>
- <createDependencyReducedPom>false</createDependencyReducedPom>
- <filters>
- <filter>
- <artifact>*:*</artifact>
- <excludes>
- <exclude>META-INF/*.SF</exclude>
- <exclude>META-INF/*.DSA</exclude>
- <exclude>META-INF/*.RSA</exclude>
- </excludes>
- </filter>
- </filters>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <transformers>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <mainClass>org.apache.curator.x.rpc.CuratorProjectionServer</mainClass>
- </transformer>
- </transformers>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>clirr-maven-plugin</artifactId>
- <configuration>
- <skip>true</skip> <!-- Clirr plugin can't handle shaded JARs - TODO -->
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
deleted file mode 100644
index a01f462..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
+++ /dev/null
@@ -1,152 +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;
-
-import com.codahale.metrics.MetricRegistry;
-import com.facebook.swift.codec.ThriftCodecManager;
-import com.facebook.swift.service.ThriftEventHandler;
-import com.facebook.swift.service.ThriftServer;
-import com.facebook.swift.service.ThriftServiceProcessor;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.io.Files;
-import com.google.common.io.Resources;
-import org.apache.curator.x.rpc.configuration.Configuration;
-import org.apache.curator.x.rpc.configuration.ConfigurationBuilder;
-import org.apache.curator.x.rpc.connections.ConnectionManager;
-import org.apache.curator.x.rpc.idl.discovery.DiscoveryService;
-import org.apache.curator.x.rpc.idl.discovery.DiscoveryServiceLowLevel;
-import org.apache.curator.x.rpc.idl.services.EventService;
-import org.apache.curator.x.rpc.idl.services.CuratorProjectionService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.concurrent.atomic.AtomicReference;
-
-public class CuratorProjectionServer
-{
- private final Logger log = LoggerFactory.getLogger(getClass());
- private final ConnectionManager connectionManager;
- private final ThriftServer server;
- private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
- private final Configuration configuration;
-
- private enum State
- {
- LATENT,
- STARTED,
- STOPPED
- }
-
- public static void main(String[] args) throws Exception
- {
- if ( (args.length != 1) || args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("-h") || args[0].equalsIgnoreCase("--help") )
- {
- printHelp();
- return;
- }
-
- String configurationSource;
- File f = new File(args[0]);
- if ( f.exists() )
- {
- configurationSource = Files.toString(f, Charset.defaultCharset());
- }
- else
- {
- System.out.println("First argument is not a file. Treating the command line as a json/yaml object");
- configurationSource = args[0];
- }
-
- final CuratorProjectionServer server = startServer(configurationSource);
-
- Runnable shutdown = new Runnable()
- {
- @Override
- public void run()
- {
- server.stop();
- }
- };
- Thread hook = new Thread(shutdown);
- Runtime.getRuntime().addShutdownHook(hook);
- }
-
- public static CuratorProjectionServer startServer(String configurationSource) throws Exception
- {
- Configuration configuration = new ConfigurationBuilder(configurationSource).build();
-
- final CuratorProjectionServer server = new CuratorProjectionServer(configuration);
- server.start();
- return server;
- }
-
- public CuratorProjectionServer(Configuration configuration)
- {
- this.configuration = configuration;
- connectionManager = new ConnectionManager(configuration.getConnections(), configuration.getProjectionExpiration().toMillis());
- EventService eventService = new EventService(connectionManager, configuration.getPingTime().toMillis());
- DiscoveryService discoveryService = new DiscoveryService(connectionManager);
- CuratorProjectionService projectionService = new CuratorProjectionService(connectionManager);
- DiscoveryServiceLowLevel discoveryServiceLowLevel = new DiscoveryServiceLowLevel(connectionManager);
- ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), Lists.<ThriftEventHandler>newArrayList(), projectionService, eventService, discoveryService, discoveryServiceLowLevel);
- server = new ThriftServer(processor, configuration.getThrift());
- }
-
- public void start()
- {
- Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Already started");
-
- configuration.getLogging().configure(new MetricRegistry(), "curator-rpc");
- connectionManager.start();
- server.start();
-
- log.info("Server listening on port: " + configuration.getThrift().getPort());
- }
-
- public void stop()
- {
- if ( state.compareAndSet(State.STARTED, State.STOPPED) )
- {
- log.info("Stopping...");
-
- server.close();
- connectionManager.close();
- configuration.getLogging().stop();
-
- log.info("Stopped");
- }
- }
-
- private static void printHelp() throws IOException
- {
- URL helpUrl = Resources.getResource("curator/help.txt");
- System.out.println(Resources.toString(helpUrl, Charset.defaultCharset()));
-
- System.out.println();
- System.out.println("======= Curator Thrift IDL =======");
- System.out.println();
-
- URL idlUrl = Resources.getResource("curator.thrift");
- System.out.println(Resources.toString(idlUrl, Charset.defaultCharset()));
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/AuthorizationConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/AuthorizationConfiguration.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/AuthorizationConfiguration.java
deleted file mode 100644
index d045a80..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/AuthorizationConfiguration.java
+++ /dev/null
@@ -1,45 +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.configuration;
-
-public class AuthorizationConfiguration
-{
- private String scheme;
- private String auth;
-
- public String getScheme()
- {
- return scheme;
- }
-
- public void setScheme(String scheme)
- {
- this.scheme = scheme;
- }
-
- public String getAuth()
- {
- return auth;
- }
-
- public void setAuth(String auth)
- {
- this.auth = auth;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/BoundedExponentialBackoffRetryConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/BoundedExponentialBackoffRetryConfiguration.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/BoundedExponentialBackoffRetryConfiguration.java
deleted file mode 100644
index 44231b1..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/BoundedExponentialBackoffRetryConfiguration.java
+++ /dev/null
@@ -1,69 +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.configuration;
-
-import com.fasterxml.jackson.annotation.JsonTypeName;
-import io.airlift.units.Duration;
-import org.apache.curator.RetryPolicy;
-import org.apache.curator.retry.BoundedExponentialBackoffRetry;
-import java.util.concurrent.TimeUnit;
-
-@JsonTypeName("bounded-exponential-backoff")
-public class BoundedExponentialBackoffRetryConfiguration extends RetryPolicyConfiguration
-{
- private Duration baseSleepTime = new Duration(100, TimeUnit.MILLISECONDS);
- private Duration maxSleepTime = new Duration(30, TimeUnit.SECONDS);
- private int maxRetries = 3;
-
- @Override
- public RetryPolicy build()
- {
- return new BoundedExponentialBackoffRetry((int)baseSleepTime.toMillis(), (int)maxSleepTime.toMillis(), maxRetries);
- }
-
- public Duration getBaseSleepTime()
- {
- return baseSleepTime;
- }
-
- public void setBaseSleepTime(Duration baseSleepTime)
- {
- this.baseSleepTime = baseSleepTime;
- }
-
- public int getMaxRetries()
- {
- return maxRetries;
- }
-
- public void setMaxRetries(int maxRetries)
- {
- this.maxRetries = maxRetries;
- }
-
- public Duration getMaxSleepTime()
- {
- return maxSleepTime;
- }
-
- public void setMaxSleepTime(Duration maxSleepTime)
- {
- this.maxSleepTime = maxSleepTime;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/Configuration.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/Configuration.java
deleted file mode 100644
index 973b6f0..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/Configuration.java
+++ /dev/null
@@ -1,86 +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.configuration;
-
-import com.facebook.swift.service.ThriftServerConfig;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import io.airlift.units.Duration;
-import io.dropwizard.logging.LoggingFactory;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
-public class Configuration
-{
- private ThriftServerConfig thrift = new ThriftServerConfig();
- private LoggingFactory logging = new LoggingFactory();
- private Duration projectionExpiration = new Duration(3, TimeUnit.MINUTES);
- private Duration pingTime = new Duration(5, TimeUnit.SECONDS);
- private List<ConnectionConfiguration> connections = Lists.newArrayList();
-
- public LoggingFactory getLogging()
- {
- return logging;
- }
-
- public void setLogging(LoggingFactory logging)
- {
- this.logging = logging;
- }
-
- public ThriftServerConfig getThrift()
- {
- return thrift;
- }
-
- public void setThrift(ThriftServerConfig thrift)
- {
- this.thrift = thrift;
- }
-
- public Duration getProjectionExpiration()
- {
- return projectionExpiration;
- }
-
- public void setProjectionExpiration(Duration projectionExpiration)
- {
- this.projectionExpiration = projectionExpiration;
- }
-
- public Duration getPingTime()
- {
- return pingTime;
- }
-
- public void setPingTime(Duration pingTime)
- {
- this.pingTime = pingTime;
- }
-
- public List<ConnectionConfiguration> getConnections()
- {
- return ImmutableList.copyOf(connections);
- }
-
- public void setConnections(List<ConnectionConfiguration> connections)
- {
- this.connections = connections;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
deleted file mode 100644
index e5cff3e..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
+++ /dev/null
@@ -1,87 +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.configuration;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
-import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver;
-import io.dropwizard.configuration.ConfigurationFactory;
-import io.dropwizard.configuration.ConfigurationFactoryFactory;
-import io.dropwizard.configuration.ConfigurationSourceProvider;
-import io.dropwizard.configuration.DefaultConfigurationFactoryFactory;
-import io.dropwizard.jackson.AnnotationSensitivePropertyNamingStrategy;
-import io.dropwizard.jackson.LogbackModule;
-import io.dropwizard.logging.ConsoleAppenderFactory;
-import io.dropwizard.logging.FileAppenderFactory;
-import io.dropwizard.logging.LoggingFactory;
-import io.dropwizard.logging.SyslogAppenderFactory;
-import org.jboss.netty.logging.InternalLoggerFactory;
-import org.jboss.netty.logging.Slf4JLoggerFactory;
-import javax.validation.Validation;
-import javax.validation.ValidatorFactory;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-public class ConfigurationBuilder
-{
- private final String configurationSource;
-
- static
- {
- LoggingFactory.bootstrap();
- InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
- }
-
- public ConfigurationBuilder(String configurationSource)
- {
- this.configurationSource = configurationSource;
- }
-
- public Configuration build() throws Exception
- {
- ObjectMapper mapper = new ObjectMapper();
- mapper.registerModule(new LogbackModule());
- mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
- SubtypeResolver subtypeResolver = new StdSubtypeResolver();
- subtypeResolver.registerSubtypes
- (
- ConsoleAppenderFactory.class,
- FileAppenderFactory.class,
- SyslogAppenderFactory.class,
- ExponentialBackoffRetryConfiguration.class,
- RetryNTimesConfiguration.class
- );
- mapper.setSubtypeResolver(subtypeResolver);
-
- ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
- ConfigurationFactoryFactory<Configuration> factoryFactory = new DefaultConfigurationFactoryFactory<Configuration>();
- ConfigurationFactory<Configuration> configurationFactory = factoryFactory.create(Configuration.class, validatorFactory.getValidator(), mapper, "curator");
- ConfigurationSourceProvider provider = new ConfigurationSourceProvider()
- {
- @Override
- public InputStream open(String path) throws IOException
- {
- return new ByteArrayInputStream(configurationSource.getBytes(Charset.defaultCharset()));
- }
- };
- return configurationFactory.build(provider, "");
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConnectionConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConnectionConfiguration.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConnectionConfiguration.java
deleted file mode 100644
index c69fdaa..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConnectionConfiguration.java
+++ /dev/null
@@ -1,129 +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.configuration;
-
-import com.google.common.base.Preconditions;
-import io.airlift.units.Duration;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import javax.validation.constraints.NotNull;
-import java.util.concurrent.TimeUnit;
-
-public class ConnectionConfiguration
-{
- @NotNull private String name;
- private String connectionString = null;
- private Duration sessionLength = new Duration(1, TimeUnit.MINUTES);
- private Duration connectionTimeout = new Duration(15, TimeUnit.SECONDS);
- private AuthorizationConfiguration authorization = null;
- private String namespace = null;
- private RetryPolicyConfiguration retry = new ExponentialBackoffRetryConfiguration();
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public String getConnectionString()
- {
- return connectionString;
- }
-
- public void setConnectionString(String connectionString)
- {
- this.connectionString = connectionString;
- }
-
- public Duration getSessionLength()
- {
- return sessionLength;
- }
-
- public void setSessionLength(Duration sessionLength)
- {
- this.sessionLength = sessionLength;
- }
-
- public Duration getConnectionTimeout()
- {
- return connectionTimeout;
- }
-
- public void setConnectionTimeout(Duration connectionTimeout)
- {
- this.connectionTimeout = connectionTimeout;
- }
-
- public AuthorizationConfiguration getAuthorization()
- {
- return authorization;
- }
-
- public void setAuthorization(AuthorizationConfiguration authorization)
- {
- this.authorization = authorization;
- }
-
- public String getNamespace()
- {
- return namespace;
- }
-
- public void setNamespace(String namespace)
- {
- this.namespace = namespace;
- }
-
- public RetryPolicyConfiguration getRetry()
- {
- return retry;
- }
-
- public void setRetry(RetryPolicyConfiguration retry)
- {
- this.retry = retry;
- }
-
- public CuratorFramework build()
- {
- Preconditions.checkState((connectionString != null) && (connectionString.length() > 0), "You must specify a connection string for connection: " + name);
- Preconditions.checkNotNull(retry, "retry cannot be null");
-
- CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
- builder = builder
- .connectString(connectionString)
- .sessionTimeoutMs((int)sessionLength.toMillis())
- .connectionTimeoutMs((int)connectionTimeout.toMillis())
- .retryPolicy(retry.build());
- if ( authorization != null )
- {
- builder = builder.authorization(authorization.getScheme(), authorization.getAuth().getBytes());
- }
- if ( namespace != null )
- {
- builder = builder.namespace(namespace);
- }
- return builder.build();
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ExponentialBackoffRetryConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ExponentialBackoffRetryConfiguration.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ExponentialBackoffRetryConfiguration.java
deleted file mode 100644
index 2c68440..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ExponentialBackoffRetryConfiguration.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.configuration;
-
-import com.fasterxml.jackson.annotation.JsonTypeName;
-import io.airlift.units.Duration;
-import org.apache.curator.RetryPolicy;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-import java.util.concurrent.TimeUnit;
-
-@JsonTypeName("exponential-backoff")
-public class ExponentialBackoffRetryConfiguration extends RetryPolicyConfiguration
-{
- private Duration baseSleepTime = new Duration(100, TimeUnit.MILLISECONDS);
- private int maxRetries = 3;
-
- @Override
- public RetryPolicy build()
- {
- return new ExponentialBackoffRetry((int)baseSleepTime.toMillis(), maxRetries);
- }
-
- public Duration getBaseSleepTime()
- {
- return baseSleepTime;
- }
-
- public void setBaseSleepTime(Duration baseSleepTime)
- {
- this.baseSleepTime = baseSleepTime;
- }
-
- public int getMaxRetries()
- {
- return maxRetries;
- }
-
- public void setMaxRetries(int maxRetries)
- {
- this.maxRetries = maxRetries;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryNTimesConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryNTimesConfiguration.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryNTimesConfiguration.java
deleted file mode 100644
index 448bde3..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryNTimesConfiguration.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.configuration;
-
-import com.fasterxml.jackson.annotation.JsonTypeName;
-import io.airlift.units.Duration;
-import org.apache.curator.RetryPolicy;
-import org.apache.curator.retry.RetryNTimes;
-import java.util.concurrent.TimeUnit;
-
-@JsonTypeName("ntimes")
-public class RetryNTimesConfiguration extends RetryPolicyConfiguration
-{
- private Duration sleepBetweenRetries = new Duration(100, TimeUnit.MILLISECONDS);
- private int n = 3;
-
- @Override
- public RetryPolicy build()
- {
- return new RetryNTimes(n, (int)sleepBetweenRetries.toMillis());
- }
-
- public Duration getSleepBetweenRetries()
- {
- return sleepBetweenRetries;
- }
-
- public void setSleepBetweenRetries(Duration sleepBetweenRetries)
- {
- this.sleepBetweenRetries = sleepBetweenRetries;
- }
-
- public int getN()
- {
- return n;
- }
-
- public void setN(int n)
- {
- this.n = n;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryPolicyConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryPolicyConfiguration.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryPolicyConfiguration.java
deleted file mode 100644
index d5d1d95..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryPolicyConfiguration.java
+++ /dev/null
@@ -1,28 +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.configuration;
-
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import org.apache.curator.RetryPolicy;
-
-@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
-public abstract class RetryPolicyConfiguration
-{
- public abstract RetryPolicy build();
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/Closer.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/Closer.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/Closer.java
deleted file mode 100644
index a113879..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/Closer.java
+++ /dev/null
@@ -1,24 +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.connections;
-
-public interface Closer
-{
- public void close();
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/ConnectionManager.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/ConnectionManager.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/ConnectionManager.java
deleted file mode 100644
index d644231..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/ConnectionManager.java
+++ /dev/null
@@ -1,141 +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.connections;
-
-import com.google.common.base.Preconditions;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
-import com.google.common.collect.ImmutableMap;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.utils.ThreadUtils;
-import org.apache.curator.x.rpc.configuration.ConnectionConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.Closeable;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-
-public class ConnectionManager implements Closeable
-{
- private final Logger log = LoggerFactory.getLogger(getClass());
- private final Cache<String, CuratorEntry> cache;
- private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
- private final Map<String, ConnectionConfiguration> connections;
- private final ScheduledExecutorService service = ThreadUtils.newSingleThreadScheduledExecutor("ConnectionManager");
-
- private static final int FORCED_CLEANUP_SECONDS = 30;
-
- private enum State
- {
- LATENT,
- STARTED,
- CLOSED
- }
-
- public ConnectionManager(List<ConnectionConfiguration> connections, long expirationMs)
- {
- this.connections = buildConnectionsMap(connections);
-
- RemovalListener<String, CuratorEntry> listener = new RemovalListener<String, CuratorEntry>()
- {
- @SuppressWarnings("NullableProblems")
- @Override
- public void onRemoval(RemovalNotification<String, CuratorEntry> notification)
- {
- if ( notification != null )
- {
- log.debug(String.format("Entry being removed. id (%s), reason (%s)", notification.getKey(), notification.getCause()));
-
- CuratorEntry entry = notification.getValue();
- if ( entry != null )
- {
- entry.close();
- }
- }
- }
- };
- cache = CacheBuilder.newBuilder().expireAfterAccess(expirationMs, TimeUnit.MILLISECONDS).removalListener(listener).build();
- }
-
- public void start()
- {
- Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Already started");
-
- Runnable cleanup = new Runnable()
- {
- @Override
- public void run()
- {
- cache.cleanUp();
- }
- };
- service.scheduleWithFixedDelay(cleanup, FORCED_CLEANUP_SECONDS, 30, TimeUnit.SECONDS);
- }
-
- @Override
- public void close()
- {
- if ( state.compareAndSet(State.STARTED, State.CLOSED) )
- {
- service.shutdownNow();
- cache.invalidateAll();
- cache.cleanUp();
- }
- }
-
- public CuratorFramework newConnection(String name)
- {
- ConnectionConfiguration configuration = connections.get(name);
- return (configuration != null) ? configuration.build() : null;
- }
-
- public void add(String id, CuratorFramework client)
- {
- Preconditions.checkState(state.get() == State.STARTED, "Not started");
- cache.put(id, new CuratorEntry(client));
- }
-
- public CuratorEntry get(String id)
- {
- return (state.get() == State.STARTED) ? cache.getIfPresent(id) : null;
- }
-
- public CuratorEntry remove(String id)
- {
- Preconditions.checkState(state.get() == State.STARTED, "Not started");
- return cache.asMap().remove(id);
- }
-
- private Map<String, ConnectionConfiguration> buildConnectionsMap(List<ConnectionConfiguration> connections)
- {
- Preconditions.checkArgument(connections.size() > 0, "You must have at least one connection configured");
-
- ImmutableMap.Builder<String, ConnectionConfiguration> builder = ImmutableMap.builder();
- for ( ConnectionConfiguration configuration : connections )
- {
- builder.put(configuration.getName(), configuration);
- }
- return builder.build();
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/CuratorEntry.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/CuratorEntry.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/CuratorEntry.java
deleted file mode 100644
index b077a76..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/connections/CuratorEntry.java
+++ /dev/null
@@ -1,170 +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.connections;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Queues;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.api.CuratorEvent;
-import org.apache.curator.x.rpc.idl.exceptions.ExceptionType;
-import org.apache.curator.x.rpc.idl.exceptions.RpcException;
-import org.apache.curator.x.rpc.idl.structs.CuratorProjection;
-import org.apache.curator.x.rpc.idl.structs.RpcCuratorEvent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.Closeable;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-
-public class CuratorEntry implements Closeable
-{
- private final Logger log = LoggerFactory.getLogger(getClass());
- private final CuratorFramework client;
- private final BlockingQueue<RpcCuratorEvent> events = Queues.newLinkedBlockingQueue();
- private final AtomicReference<State> state = new AtomicReference<State>(State.OPEN);
- private final Map<String, Entry> things = Maps.newConcurrentMap();
-
- public static <T> T mustGetThing(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;
- }
-
- private static class Entry
- {
- final Object thing;
- final Closer closer;
-
- private Entry(Object thing, Closer closer)
- {
- this.thing = thing;
- this.closer = closer;
- }
- }
-
- private enum State
- {
- OPEN,
- CLOSED
- }
-
- public CuratorEntry(CuratorFramework client)
- {
- this.client = client;
- }
-
- @Override
- public void close()
- {
- if ( state.compareAndSet(State.OPEN, State.CLOSED) )
- {
- for ( Map.Entry<String, Entry> mapEntry : things.entrySet() )
- {
- Entry entry = mapEntry.getValue();
- if ( entry.closer != null )
- {
- log.debug(String.format("Closing left over thing. Type: %s - Id: %s", entry.thing.getClass(), mapEntry.getKey()));
- entry.closer.close();
- }
- }
- things.clear();
-
- client.close();
- events.clear();
- }
- }
-
- public RpcCuratorEvent pollForEvent(long maxWaitMs) throws InterruptedException
- {
- if ( state.get() == State.OPEN )
- {
- return events.poll(maxWaitMs, TimeUnit.MILLISECONDS);
- }
- return null;
- }
-
- public void addEvent(RpcCuratorEvent event)
- {
- if ( state.get() == State.OPEN )
- {
- events.offer(event);
- }
- }
-
- public static CuratorEntry mustGetEntry(ConnectionManager connectionManager, CuratorProjection projection) throws RpcException
- {
- CuratorEntry entry = connectionManager.get(projection.id);
- if ( entry == null )
- {
- throw new RpcException(ExceptionType.GENERAL, null, null, "No CuratorProjection found with the id: " + projection.id);
- }
- return entry;
- }
-
- public CuratorFramework getClient()
- {
- return (state.get() == State.OPEN) ? client : null;
- }
-
- public String addThing(Object thing, Closer closer)
- {
- return addThing(newId(), thing, closer);
- }
-
- public static String newId()
- {
- return UUID.randomUUID().toString();
- }
-
- public <T> T getThing(String id, Class<T> clazz)
- {
- Entry entry = (id != null) ? things.get(id) : null;
- return cast(clazz, entry);
- }
-
- public boolean closeThing(String id)
- {
- Entry entry = (id != null) ? things.remove(id) : null;
- if ( entry != null )
- {
- entry.closer.close();
- }
- return false;
- }
-
- private <T> String addThing(String id, T thing, Closer closer)
- {
- things.put(id, new Entry(thing, closer));
- return id;
- }
-
- private <T> T cast(Class<T> clazz, Entry entry)
- {
- if ( entry != null )
- {
- return clazz.cast(entry.thing);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/details/RpcBackgroundCallback.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/details/RpcBackgroundCallback.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/details/RpcBackgroundCallback.java
deleted file mode 100644
index 519790c..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/details/RpcBackgroundCallback.java
+++ /dev/null
@@ -1,44 +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.details;
-
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.api.BackgroundCallback;
-import org.apache.curator.framework.api.CuratorEvent;
-import org.apache.curator.x.rpc.idl.structs.RpcCuratorEvent;
-import org.apache.curator.x.rpc.idl.structs.CuratorProjection;
-import org.apache.curator.x.rpc.idl.services.CuratorProjectionService;
-
-public class RpcBackgroundCallback implements BackgroundCallback
-{
- private final CuratorProjection projection;
- private final CuratorProjectionService projectionService;
-
- public RpcBackgroundCallback(CuratorProjectionService projectionService, CuratorProjection projection)
- {
- this.projection = projection;
- this.projectionService = projectionService;
- }
-
- @Override
- public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
- {
- projectionService.addEvent(projection, new RpcCuratorEvent(event));
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/details/RpcWatcher.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/details/RpcWatcher.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/details/RpcWatcher.java
deleted file mode 100644
index 6fa5961..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/details/RpcWatcher.java
+++ /dev/null
@@ -1,43 +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.details;
-
-import org.apache.curator.x.rpc.idl.structs.RpcCuratorEvent;
-import org.apache.curator.x.rpc.idl.structs.CuratorProjection;
-import org.apache.curator.x.rpc.idl.services.CuratorProjectionService;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-
-public class RpcWatcher implements Watcher
-{
- private final CuratorProjection projection;
- private final CuratorProjectionService projectionService;
-
- public RpcWatcher(CuratorProjectionService projectionService, CuratorProjection projection)
- {
- this.projection = projection;
- this.projectionService = projectionService;
- }
-
- @Override
- public void process(WatchedEvent event)
- {
- projectionService.addEvent(projection, new RpcCuratorEvent(event));
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryInstance.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryInstance.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryInstance.java
deleted file mode 100644
index 2547467..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryInstance.java
+++ /dev/null
@@ -1,95 +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.discovery;
-
-import com.facebook.swift.codec.ThriftField;
-import com.facebook.swift.codec.ThriftStruct;
-import com.google.common.base.Objects;
-import org.apache.curator.x.discovery.ServiceInstance;
-import org.apache.curator.x.discovery.ServiceType;
-import org.apache.curator.x.discovery.UriSpec;
-
-@ThriftStruct
-public class DiscoveryInstance
-{
- @ThriftField(1)
- public String name;
-
- @ThriftField(2)
- public String id;
-
- @ThriftField(3)
- public String address;
-
- @ThriftField(4)
- public int port;
-
- @ThriftField(5)
- public int sslPort;
-
- @ThriftField(6)
- public byte[] payload;
-
- @ThriftField(7)
- public long registrationTimeUTC;
-
- @ThriftField(8)
- public DiscoveryInstanceType serviceType;
-
- @ThriftField(9)
- public String uriSpec;
-
- public DiscoveryInstance()
- {
- }
-
- public DiscoveryInstance(ServiceInstance<byte[]> instance)
- {
- if ( instance != null )
- {
- this.name = instance.getName();
- this.id = instance.getId();
- this.address = instance.getAddress();
- this.port = Objects.firstNonNull(instance.getPort(), 0);
- this.sslPort = Objects.firstNonNull(instance.getSslPort(), 0);
- this.payload = instance.getPayload();
- this.registrationTimeUTC = instance.getRegistrationTimeUTC();
- this.serviceType = DiscoveryInstanceType.valueOf(instance.getServiceType().name());
- this.uriSpec = instance.buildUriSpec();
- }
- }
-
- public DiscoveryInstance(String name, String id, String address, int port, int sslPort, byte[] payload, long registrationTimeUTC, DiscoveryInstanceType serviceType, String uriSpec)
- {
- this.name = name;
- this.id = id;
- this.address = address;
- this.port = port;
- this.sslPort = sslPort;
- this.payload = payload;
- this.registrationTimeUTC = registrationTimeUTC;
- this.serviceType = serviceType;
- this.uriSpec = uriSpec;
- }
-
- public ServiceInstance<byte[]> toReal()
- {
- return new ServiceInstance<byte[]>(name, id, address, port, sslPort, payload, registrationTimeUTC, ServiceType.valueOf(serviceType.name()), new UriSpec(uriSpec));
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryInstanceType.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryInstanceType.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryInstanceType.java
deleted file mode 100644
index 352a12e..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryInstanceType.java
+++ /dev/null
@@ -1,26 +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.discovery;
-
-public enum DiscoveryInstanceType
-{
- DYNAMIC,
- STATIC,
- PERMANENT
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryProjection.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryProjection.java
deleted file mode 100644
index 6b1e0f4..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryProjection.java
+++ /dev/null
@@ -1,38 +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.discovery;
-
-import com.facebook.swift.codec.ThriftField;
-import com.facebook.swift.codec.ThriftStruct;
-
-@ThriftStruct
-public class DiscoveryProjection
-{
- @ThriftField(1)
- public String id;
-
- public DiscoveryProjection()
- {
- }
-
- public DiscoveryProjection(String id)
- {
- this.id = id;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryProviderProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryProviderProjection.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryProviderProjection.java
deleted file mode 100644
index c8655fa..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryProviderProjection.java
+++ /dev/null
@@ -1,38 +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.discovery;
-
-import com.facebook.swift.codec.ThriftField;
-import com.facebook.swift.codec.ThriftStruct;
-
-@ThriftStruct
-public class DiscoveryProviderProjection
-{
- @ThriftField(1)
- public String id;
-
- public DiscoveryProviderProjection()
- {
- }
-
- public DiscoveryProviderProjection(String id)
- {
- this.id = id;
- }
-}
http://git-wip-us.apache.org/repos/asf/curator/blob/95b70d2b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryService.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryService.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryService.java
deleted file mode 100644
index 22f732d..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/discovery/DiscoveryService.java
+++ /dev/null
@@ -1,259 +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.discovery;
-
-import com.facebook.swift.service.ThriftMethod;
-import com.facebook.swift.service.ThriftService;
-import com.google.common.base.Function;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-import org.apache.curator.utils.ThreadUtils;
-import org.apache.curator.x.discovery.DownInstancePolicy;
-import org.apache.curator.x.discovery.ProviderStrategy;
-import org.apache.curator.x.discovery.ServiceDiscovery;
-import org.apache.curator.x.discovery.ServiceDiscoveryBuilder;
-import org.apache.curator.x.discovery.ServiceInstance;
-import org.apache.curator.x.discovery.ServiceProvider;
-import org.apache.curator.x.discovery.ServiceType;
-import org.apache.curator.x.discovery.strategies.RandomStrategy;
-import org.apache.curator.x.discovery.strategies.RoundRobinStrategy;
-import org.apache.curator.x.discovery.strategies.StickyStrategy;
-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.idl.exceptions.RpcException;
-import org.apache.curator.x.rpc.idl.structs.CuratorProjection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
-
-@ThriftService
-public class DiscoveryService
-{
- private final Logger log = LoggerFactory.getLogger(getClass());
- private final ConnectionManager connectionManager;
-
- public DiscoveryService(ConnectionManager connectionManager)
- {
- this.connectionManager = connectionManager;
- }
-
- @ThriftMethod
- public DiscoveryInstance makeDiscoveryInstance(String name, byte[] payload, int port) throws RpcException
- {
- try
- {
- ServiceInstance<byte[]> serviceInstance = ServiceInstance.<byte[]>builder()
- .serviceType(ServiceType.DYNAMIC)
- .name(name)
- .payload(payload)
- .port(port)
- .build();
- return new DiscoveryInstance(serviceInstance);
- }
- catch ( Exception e )
- {
- ThreadUtils.checkInterrupted(e);
- throw new RpcException(e);
- }
- }
-
- @ThriftMethod
- public DiscoveryProjection startDiscovery(CuratorProjection projection, final String basePath, DiscoveryInstance yourInstance) throws RpcException
- {
- try
- {
- CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
- final ServiceDiscovery<byte[]> serviceDiscovery = ServiceDiscoveryBuilder
- .builder(byte[].class)
- .basePath(basePath)
- .client(entry.getClient())
- .thisInstance((yourInstance != null) ? yourInstance.toReal() : null)
- .build();
- serviceDiscovery.start();
-
- Closer closer = new Closer()
- {
- @Override
- public void close()
- {
- try
- {
- serviceDiscovery.close();
- }
- catch ( IOException e )
- {
- log.error("Could not close ServiceDiscovery with basePath: " + basePath, e);
- }
- }
- };
- String id = entry.addThing(serviceDiscovery, closer);
-
- return new DiscoveryProjection(id);
- }
- catch ( Exception e )
- {
- ThreadUtils.checkInterrupted(e);
- throw new RpcException(e);
- }
- }
-
- @ThriftMethod
- public DiscoveryProviderProjection startProvider(CuratorProjection projection, DiscoveryProjection discoveryProjection, final String serviceName, ProviderStrategyType providerStrategy, int downTimeoutMs, int downErrorThreshold) throws RpcException
- {
- ProviderStrategy<byte[]> strategy;
- switch ( providerStrategy )
- {
- default:
- case RANDOM:
- {
- strategy = new RandomStrategy<byte[]>();
- break;
- }
-
- case STICKY_RANDOM:
- {
- strategy = new StickyStrategy<byte[]>(new RandomStrategy<byte[]>());
- break;
- }
-
- case STICKY_ROUND_ROBIN:
- {
- strategy = new StickyStrategy<byte[]>(new RoundRobinStrategy<byte[]>());
- break;
- }
-
- case ROUND_ROBIN:
- {
- strategy = new RoundRobinStrategy<byte[]>();
- break;
- }
- }
-
- CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
- @SuppressWarnings("unchecked")
- ServiceDiscovery<byte[]> serviceDiscovery = CuratorEntry.mustGetThing(entry, discoveryProjection.id, ServiceDiscovery.class);
- final ServiceProvider<byte[]> serviceProvider = serviceDiscovery
- .serviceProviderBuilder()
- .downInstancePolicy(new DownInstancePolicy(downTimeoutMs, TimeUnit.MILLISECONDS, downErrorThreshold))
- .providerStrategy(strategy)
- .serviceName(serviceName)
- .build();
- try
- {
- serviceProvider.start();
- Closer closer = new Closer()
- {
- @Override
- public void close()
- {
- try
- {
- serviceProvider.close();
- }
- catch ( IOException e )
- {
- ThreadUtils.checkInterrupted(e);
- log.error("Could not close ServiceProvider with serviceName: " + serviceName, e);
- }
- }
- };
- String id = entry.addThing(serviceProvider, closer);
- return new DiscoveryProviderProjection(id);
- }
- catch ( Exception e )
- {
- ThreadUtils.checkInterrupted(e);
- throw new RpcException(e);
- }
- }
-
- @ThriftMethod
- public DiscoveryInstance getInstance(CuratorProjection projection, DiscoveryProviderProjection providerProjection) throws RpcException
- {
- CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
- @SuppressWarnings("unchecked")
- ServiceProvider<byte[]> serviceProvider = CuratorEntry.mustGetThing(entry, providerProjection.id, ServiceProvider.class);
- try
- {
- return new DiscoveryInstance(serviceProvider.getInstance());
- }
- catch ( Exception e )
- {
- ThreadUtils.checkInterrupted(e);
- throw new RpcException(e);
- }
- }
-
- @ThriftMethod
- public Collection<DiscoveryInstance> getAllInstances(CuratorProjection projection, DiscoveryProviderProjection providerProjection) throws RpcException
- {
- CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
- @SuppressWarnings("unchecked")
- ServiceProvider<byte[]> serviceProvider = CuratorEntry.mustGetThing(entry, providerProjection.id, ServiceProvider.class);
- try
- {
- Collection<ServiceInstance<byte[]>> allInstances = serviceProvider.getAllInstances();
- Collection<DiscoveryInstance> transformed = Collections2.transform
- (
- allInstances,
- new Function<ServiceInstance<byte[]>, DiscoveryInstance>()
- {
- @Override
- public DiscoveryInstance apply(ServiceInstance<byte[]> instance)
- {
- return new DiscoveryInstance(instance);
- }
- }
- );
- return Lists.newArrayList(transformed);
- }
- catch ( Exception e )
- {
- ThreadUtils.checkInterrupted(e);
- throw new RpcException(e);
- }
- }
-
- @ThriftMethod
- public void noteError(CuratorProjection projection, DiscoveryProviderProjection providerProjection, String instanceId) throws RpcException
- {
- CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
- @SuppressWarnings("unchecked")
- ServiceProvider<byte[]> serviceProvider = CuratorEntry.mustGetThing(entry, providerProjection.id, ServiceProvider.class);
- try
- {
- for ( ServiceInstance<byte[]> instance : serviceProvider.getAllInstances() )
- {
- if ( instance.getId().equals(instanceId) )
- {
- serviceProvider.noteError(instance);
- break;
- }
- }
- }
- catch ( Exception e )
- {
- ThreadUtils.checkInterrupted(e);
- throw new RpcException(e);
- }
- }
-}