mirror of https://github.com/apache/jclouds.git
formatting
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2048 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
37a497d911
commit
819a16e635
|
@ -64,25 +64,30 @@ import com.google.inject.util.Jsr330;
|
||||||
*/
|
*/
|
||||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
|
|
||||||
private Map<String, BlobStoreContext<?>> contexts;
|
private Map<String, BlobStoreContext<?>> providerTypeToBlobStoreMap;
|
||||||
private TwitterClient client;
|
private TwitterClient twitterClient;
|
||||||
private String container;
|
private String container;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
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),
|
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
|
||||||
PROPERTY_TWEETSTORE_CONTAINER);
|
PROPERTY_TWEETSTORE_CONTAINER);
|
||||||
ImmutableList<String> list = ImmutableList.<String> of(checkNotNull(
|
ImmutableList<String> contextBuilderClassNames = ImmutableList.<String> of(checkNotNull(
|
||||||
props.getProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS),
|
props.getProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS),
|
||||||
PROPERTY_BLOBSTORE_CONTEXTBUILDERS).split(","));
|
PROPERTY_BLOBSTORE_CONTEXTBUILDERS).split(","));
|
||||||
contexts = Maps.newHashMap();
|
|
||||||
client = TwitterContextFactory
|
// instantiate and store references to all blobstores by provider name
|
||||||
.createContext(props, new GaeHttpCommandExecutorServiceModule()).getApi();
|
providerTypeToBlobStoreMap = Maps.newHashMap();
|
||||||
for (String className : list) {
|
for (String className : contextBuilderClassNames) {
|
||||||
Class<BlobStoreContextBuilder<?>> builderClass;
|
Class<BlobStoreContextBuilder<?>> builderClass;
|
||||||
Constructor<BlobStoreContextBuilder<?>> constructor;
|
Constructor<BlobStoreContextBuilder<?>> constructor;
|
||||||
String name;
|
String name;
|
||||||
|
@ -90,14 +95,20 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
try {
|
try {
|
||||||
builderClass = (Class<BlobStoreContextBuilder<?>>) Class.forName(className);
|
builderClass = (Class<BlobStoreContextBuilder<?>>) Class.forName(className);
|
||||||
name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", "");
|
name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", "");
|
||||||
queue.add(url("/store/do").header("context", name).method(Method.GET));
|
|
||||||
constructor = builderClass.getConstructor(Properties.class);
|
constructor = builderClass.getConstructor(Properties.class);
|
||||||
context = constructor.newInstance(props).withModules(
|
context = constructor.newInstance(props).withModules(
|
||||||
new GaeHttpCommandExecutorServiceModule()).buildContext();
|
new GaeHttpCommandExecutorServiceModule()).buildContext();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("error instantiating " + className, 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);
|
super.contextInitialized(servletContextEvent);
|
||||||
|
@ -123,21 +134,20 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
@Override
|
@Override
|
||||||
protected void configureServlets() {
|
protected void configureServlets() {
|
||||||
bind(new TypeLiteral<Map<String, BlobStoreContext<?>>>() {
|
bind(new TypeLiteral<Map<String, BlobStoreContext<?>>>() {
|
||||||
}).toInstance(GuiceServletConfig.this.contexts);
|
}).toInstance(GuiceServletConfig.this.providerTypeToBlobStoreMap);
|
||||||
bind(TwitterClient.class).toInstance(client);
|
bind(TwitterClient.class).toInstance(twitterClient);
|
||||||
bindConstant().annotatedWith(Jsr330.named(PROPERTY_TWEETSTORE_CONTAINER)).to(container);
|
bindConstant().annotatedWith(Jsr330.named(PROPERTY_TWEETSTORE_CONTAINER)).to(container);
|
||||||
serve("/store/*").with(StoreTweetsController.class);
|
serve("/store/*").with(StoreTweetsController.class);
|
||||||
serve("/tweets/*").with(AddTweetsController.class);
|
serve("/tweets/*").with(AddTweetsController.class);
|
||||||
requestInjection(this);
|
requestInjection(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
||||||
for (BlobStoreContext<?> context : contexts.values()) {
|
for (BlobStoreContext<?> context : providerTypeToBlobStoreMap.values()) {
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
super.contextDestroyed(servletContextEvent);
|
super.contextDestroyed(servletContextEvent);
|
||||||
|
|
Loading…
Reference in New Issue