From 819a16e6355e071d7a739f16edfbad154d35fc4f Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Fri, 6 Nov 2009 20:43:37 +0000 Subject: [PATCH] formatting git-svn-id: http://jclouds.googlecode.com/svn/trunk@2048 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../tweetstore/config/GuiceServletConfig.java | 40 ++++++++++++------- .../controller/StoreTweetsController.java | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java b/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java index 8d7e7659a2..0905d14abd 100755 --- a/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java +++ b/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java @@ -64,25 +64,30 @@ import com.google.inject.util.Jsr330; */ public class GuiceServletConfig extends GuiceServletContextListener { - private Map> contexts; - private TwitterClient client; + private Map> providerTypeToBlobStoreMap; + private TwitterClient twitterClient; private String container; @SuppressWarnings("unchecked") @Override public void contextInitialized(ServletContextEvent servletContextEvent) { - Properties props = loadJCloudsProperties(servletContextEvent); - Queue queue = QueueFactory.getQueue("twitter"); + Properties props = loadJCloudsProperties(servletContextEvent); + + // shared across all blobstores and used to retrieve tweets + twitterClient = TwitterContextFactory.createContext(props, + new GaeHttpCommandExecutorServiceModule()).getApi(); + + // common namespace for storing tweets. container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER); - ImmutableList list = ImmutableList. of(checkNotNull( + ImmutableList contextBuilderClassNames = ImmutableList. of(checkNotNull( props.getProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS), PROPERTY_BLOBSTORE_CONTEXTBUILDERS).split(",")); - contexts = Maps.newHashMap(); - client = TwitterContextFactory - .createContext(props, new GaeHttpCommandExecutorServiceModule()).getApi(); - for (String className : list) { + + // instantiate and store references to all blobstores by provider name + providerTypeToBlobStoreMap = Maps.newHashMap(); + for (String className : contextBuilderClassNames) { Class> builderClass; Constructor> constructor; String name; @@ -90,14 +95,20 @@ public class GuiceServletConfig extends GuiceServletContextListener { try { builderClass = (Class>) Class.forName(className); name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", ""); - queue.add(url("/store/do").header("context", name).method(Method.GET)); constructor = builderClass.getConstructor(Properties.class); context = constructor.newInstance(props).withModules( new GaeHttpCommandExecutorServiceModule()).buildContext(); } catch (Exception e) { throw new RuntimeException("error instantiating " + className, e); } - contexts.put(name, context); + providerTypeToBlobStoreMap.put(name, context); + } + + // get a queue for submitting store tweet requests + Queue queue = QueueFactory.getQueue("twitter"); + // submit a job to store tweets for each configured blobstore + for (String name : providerTypeToBlobStoreMap.keySet()) { + queue.add(url("/store/do").header("context", name).method(Method.GET)); } super.contextInitialized(servletContextEvent); @@ -123,21 +134,20 @@ public class GuiceServletConfig extends GuiceServletContextListener { @Override protected void configureServlets() { bind(new TypeLiteral>>() { - }).toInstance(GuiceServletConfig.this.contexts); - bind(TwitterClient.class).toInstance(client); + }).toInstance(GuiceServletConfig.this.providerTypeToBlobStoreMap); + bind(TwitterClient.class).toInstance(twitterClient); bindConstant().annotatedWith(Jsr330.named(PROPERTY_TWEETSTORE_CONTAINER)).to(container); serve("/store/*").with(StoreTweetsController.class); serve("/tweets/*").with(AddTweetsController.class); requestInjection(this); } } - ); } @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { - for (BlobStoreContext context : contexts.values()) { + for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) { context.close(); } super.contextDestroyed(servletContextEvent); diff --git a/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java b/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java index b6e97cefa6..b157b03678 100644 --- a/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java +++ b/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java @@ -83,7 +83,7 @@ public class StoreTweetsController extends HttpServlet { private final Map> contexts; private final TwitterClient client; private final String container; - + @Resource protected Logger logger = Logger.NULL;