curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [2/2] git commit: Added Dropwizard support
Date Sat, 15 Feb 2014 21:31:55 GMT
Added Dropwizard support


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/95b8e77e
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/95b8e77e
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/95b8e77e

Branch: refs/heads/CURATOR-88
Commit: 95b8e77e9962ab005a64b2f46c2d322b2c9933b6
Parents: 9d34d3d
Author: randgalt <randgalt@apache.org>
Authored: Sat Feb 15 16:32:55 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Sat Feb 15 16:32:55 2014 -0500

----------------------------------------------------------------------
 curator-x-rest/pom.xml                          | 17 +++++
 .../curator/x/rest/CuratorRestContext.java      |  2 +-
 .../x/rest/dropwizard/CuratorRestBundle.java    | 74 ++++++++++++++++++++
 .../x/rest/dropwizard/DropwizardRunner.java     | 56 +++++++++++++++
 4 files changed, 148 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/95b8e77e/curator-x-rest/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-rest/pom.xml b/curator-x-rest/pom.xml
index 2e26034..07b2b6e 100644
--- a/curator-x-rest/pom.xml
+++ b/curator-x-rest/pom.xml
@@ -28,10 +28,20 @@
     <artifactId>curator-x-rest</artifactId>
     <version>2.4.1-SNAPSHOT</version>
 
+    <properties>
+        <dropwizard-version>0.7.0-rc1</dropwizard-version>
+    </properties>
+
     <dependencies>
         <dependency>
             <groupId>org.apache.curator</groupId>
             <artifactId>curator-recipes</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>
@@ -43,5 +53,12 @@
             <groupId>javax.ws.rs</groupId>
             <artifactId>jsr311-api</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>io.dropwizard</groupId>
+            <artifactId>dropwizard-core</artifactId>
+            <version>${dropwizard-version}</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/curator/blob/95b8e77e/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
index baea57e..e2f57a2 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/CuratorRestContext.java
@@ -69,7 +69,7 @@ public class CuratorRestContext implements Closeable
         CLOSED
     }
 
-    public CuratorRestContext(CuratorFramework client, int sessionLengthMs) throws Exception
+    public CuratorRestContext(CuratorFramework client, int sessionLengthMs)
     {
         this.client = client;
         this.sessionLengthMs = sessionLengthMs;

http://git-wip-us.apache.org/repos/asf/curator/blob/95b8e77e/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorRestBundle.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorRestBundle.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorRestBundle.java
new file mode 100644
index 0000000..250b285
--- /dev/null
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/dropwizard/CuratorRestBundle.java
@@ -0,0 +1,74 @@
+/**
+ * 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.rest.dropwizard;
+
+import com.sun.jersey.spi.inject.SingletonTypeInjectableProvider;
+import io.dropwizard.Bundle;
+import io.dropwizard.setup.Bootstrap;
+import io.dropwizard.setup.Environment;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.x.rest.CuratorRestClasses;
+import org.apache.curator.x.rest.CuratorRestContext;
+import org.eclipse.jetty.util.component.AbstractLifeCycle;
+import org.eclipse.jetty.util.component.LifeCycle;
+import javax.ws.rs.core.Context;
+
+public class CuratorRestBundle implements Bundle
+{
+    private final CuratorRestContext context;
+
+    public CuratorRestBundle(CuratorFramework client, int sessionLengthMs)
+    {
+        this.context = new CuratorRestContext(client, sessionLengthMs);
+    }
+
+    @Override
+    public void initialize(Bootstrap<?> bootstrap)
+    {
+        // NOP
+    }
+
+    @Override
+    public void run(Environment environment)
+    {
+        SingletonTypeInjectableProvider<Context, CuratorRestContext> injectable = new
SingletonTypeInjectableProvider<Context, CuratorRestContext>(CuratorRestContext.class,
context){};
+        environment.jersey().register(injectable);
+        for ( Class<?> clazz : CuratorRestClasses.getClasses() )
+        {
+            environment.jersey().register(clazz);
+        }
+
+        LifeCycle.Listener listener = new AbstractLifeCycle.AbstractLifeCycleListener()
+        {
+            @Override
+            public void lifeCycleStarting(LifeCycle event)
+            {
+                context.start();
+            }
+
+            @Override
+            public void lifeCycleStopping(LifeCycle event)
+            {
+                context.close();
+            }
+        };
+        environment.lifecycle().addLifeCycleListener(listener);
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/95b8e77e/curator-x-rest/src/test/java/org/apache/curator/x/rest/dropwizard/DropwizardRunner.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/test/java/org/apache/curator/x/rest/dropwizard/DropwizardRunner.java
b/curator-x-rest/src/test/java/org/apache/curator/x/rest/dropwizard/DropwizardRunner.java
new file mode 100644
index 0000000..eb30590
--- /dev/null
+++ b/curator-x-rest/src/test/java/org/apache/curator/x/rest/dropwizard/DropwizardRunner.java
@@ -0,0 +1,56 @@
+/**
+ * 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.rest.dropwizard;
+
+import io.dropwizard.Application;
+import io.dropwizard.Configuration;
+import io.dropwizard.setup.Bootstrap;
+import io.dropwizard.setup.Environment;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.x.rest.CuratorRestContext;
+
+public class DropwizardRunner
+{
+    public static void main(String[] args) throws Exception
+    {
+        Application<Configuration> application = new Application<Configuration>()
+        {
+            @Override
+            public void initialize(Bootstrap<Configuration> bootstrap)
+            {
+                CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181",
new ExponentialBackoffRetry(100, 3));
+                client.start();
+                bootstrap.addBundle(new CuratorRestBundle(new CuratorRestContext(client,
60000)));
+            }
+
+            @Override
+            public void run(Configuration configuration, Environment environment) throws
Exception
+            {
+            }
+        };
+        if ( args.length == 0 )
+        {
+            args = new String[]{"server"};
+        }
+        application.run(args);
+    }
+}


Mime
View raw message