Author: etnu
Date: Thu Jan 24 16:44:18 2008
New Revision: 615088
URL: http://svn.apache.org/viewvc?rev=615088&view=rev
Log:
Continued refactoring GadgetServer configuration by exposing a read-only view
of configuration data and allowing classes to get access to the GadgetServer's
configuration at run time so that they don't have to pass parallel copies of
shared objects around.
Added:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfigReader.java
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfig.java
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java?rev=615088&r1=615087&r2=615088&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServer.java
Thu Jan 24 16:44:18 2008
@@ -37,12 +37,7 @@
import java.util.logging.Logger;
public class GadgetServer {
- private final Executor executor;
- private GadgetFeatureRegistry registry;
- private GadgetDataCache<GadgetSpec> specCache;
- private GadgetDataCache<MessageBundle> messageBundleCache;
- private RemoteContentFetcher fetcher;
- private GadgetBlacklist gadgetBlacklist;
+ private final GadgetServerConfig config;
private static final Logger logger
= Logger.getLogger("org.apache.shindig.gadgets");
@@ -50,53 +45,80 @@
/**
* Creates a GadgetServer without a config.
*
- * @deprecated Replaced by [EMAIL PROTECTED] #GadgetServer(GadgetConfig)}.
+ * @deprecated Replaced by [EMAIL PROTECTED]
#GadgetServer(GadgetServerConfigReader)}.
* @param executor
*/
@Deprecated
public GadgetServer(Executor executor) {
- this.executor = executor;
+ config = new GadgetServerConfig();
+ config.setExecutor(executor);
}
/**
* Creates a GadgetServer using the provided configuration.
*
- * @param config
+ * @param configuration
* @throws IllegalArgumentException When missing required fields aren't set.
*/
- public GadgetServer(GadgetServerConfig config) {
- executor = config.getExecutor();
- Check.notNull(executor, "setExecutor is required.");
- registry = config.getFeatureRegistry();
- Check.notNull(registry, "setFeatureRegistry is required.");
- specCache = config.getSpecCache();
- Check.notNull(specCache, "setSpecCache is required.");
- messageBundleCache = config.getMessageBundleCache();
- Check.notNull(messageBundleCache, "setMessageBundleCache is required.");
- fetcher = config.getContentFetcher();
- Check.notNull(fetcher, "setContentFetcher is required.");
+ public GadgetServer(GadgetServerConfigReader configuration) {
+ Check.notNull(configuration.getExecutor(), "Executor is required.");
+ Check.notNull(configuration.getFeatureRegistry(),
+ "FeatureRegistry is required.");
+ Check.notNull(configuration.getSpecCache(), "SpecCache is required.");
+ Check.notNull(configuration.getMessageBundleCache(),
+ "MessageBundleCache is required.");
+ Check.notNull(configuration.getContentFetcher(),
+ "ContentFetcher is required.");
- gadgetBlacklist = config.getGadgetBlacklist();
+ config = new GadgetServerConfig();
+ config.copyFrom(configuration);
}
+ /**
+ * @deprecated Replaced by [EMAIL PROTECTED]
#GadgetServer(GadgetServerConfigReader)}.
+ */
+ @Deprecated
public void setSpecCache(GadgetDataCache<GadgetSpec> specCache) {
- this.specCache = specCache;
+ config.setSpecCache(specCache);
}
+ /**
+ * @deprecated Replaced by [EMAIL PROTECTED]
#GadgetServer(GadgetServerConfigReader)}.
+ */
+ @Deprecated
public void setMessageBundleCache(GadgetDataCache<MessageBundle> cache) {
- messageBundleCache = cache;
+ config.setMessageBundleCache(cache);
}
+ /**
+ * @deprecated Replaced by [EMAIL PROTECTED]
#GadgetServer(GadgetServerConfigReader)}.
+ */
+ @Deprecated
public void setContentFetcher(RemoteContentFetcher fetcher) {
- this.fetcher = fetcher;
+ config.setContentFetcher(fetcher);
}
+ /**
+ * @deprecated Replaced by [EMAIL PROTECTED]
#GadgetServer(GadgetServerConfigReader)}.
+ */
+ @Deprecated
public void setGadgetFeatureRegistry(GadgetFeatureRegistry registry) {
- this.registry = registry;
+ config.setFeatureRegistry(registry);
}
+ /**
+ * @deprecated Replaced by [EMAIL PROTECTED]
#GadgetServer(GadgetServerConfigReader)}.
+ */
+ @Deprecated
public void setGadgetBlacklist(GadgetBlacklist gadgetBlacklist) {
- this.gadgetBlacklist = gadgetBlacklist;
+ config.setGadgetBlacklist(gadgetBlacklist);
+ }
+
+ /**
+ * @return A read-only view of the server's configuration.
+ */
+ public GadgetServerConfigReader getConfig() {
+ return config;
}
/**
@@ -117,47 +139,58 @@
ProcessingOptions options)
throws GadgetProcessException {
// TODO: Remove dep checks when GadgetServer(Executor) is removed.
- if (specCache == null) {
+ if (config.getSpecCache() == null) {
throw new
GadgetProcessException(GadgetException.Code.MISSING_SPEC_CACHE);
}
- if (messageBundleCache == null ) {
+ if (config.getMessageBundleCache() == null ) {
throw new GadgetProcessException(
GadgetException.Code.MISSING_MESSAGE_BUNDLE_CACHE);
}
- if (fetcher == null) {
+ if (config.getContentFetcher() == null) {
throw new GadgetProcessException(
GadgetException.Code.MISSING_REMOTE_OBJECT_FETCHER);
}
- if (registry == null) {
+ if (config.getFeatureRegistry() == null) {
throw new GadgetProcessException(
GadgetException.Code.MISSING_FEATURE_REGISTRY);
}
// Queue/tree of all jobs to be run for successful processing
- GadgetContext gc
- = new GadgetContext(fetcher, messageBundleCache, locale, rctx,
options);
+ GadgetContext gc = new GadgetContext(config.getContentFetcher(),
+ config.getMessageBundleCache(),
+ locale,
+ rctx,
+ options);
WorkflowContext wc = new WorkflowContext(gc);
// Bootstrap tree of jobs to process
WorkflowDependency cacheLoadDep =
new WorkflowDependency(WorkflowDependency.Type.CORE, CACHE_LOAD);
- wc.jobsToRun.addJob(new CacheLoadTask(gadgetId, userPrefs, specCache),
- cacheLoadDep);
+
+ CacheLoadTask cacheLoadTask = new CacheLoadTask(gadgetId,
+ userPrefs,
+ config.getSpecCache());
+ wc.jobsToRun.addJob(cacheLoadTask, cacheLoadDep);
WorkflowDependency urlFetchDep =
new WorkflowDependency(WorkflowDependency.Type.CORE, URL_FETCH);
- wc.jobsToRun.addJob(
- new SpecLoadTask(fetcher, gadgetId, userPrefs, specCache,
gadgetBlacklist),
- urlFetchDep, cacheLoadDep);
+
+ SpecLoadTask specLoadTask = new SpecLoadTask(config.getContentFetcher(),
+ gadgetId,
+ userPrefs,
+ config.getSpecCache(),
+ config.getGadgetBlacklist());
+ wc.jobsToRun.addJob(specLoadTask, urlFetchDep, cacheLoadDep);
WorkflowDependency enqueueFeatDep =
new WorkflowDependency(WorkflowDependency.Type.CORE, ENQUEUE_FEATURES);
- wc.jobsToRun.addJob(new EnqueueFeaturesTask(registry), enqueueFeatDep,
+ wc.jobsToRun.addJob(new EnqueueFeaturesTask(config.getFeatureRegistry()),
+ enqueueFeatDep,
urlFetchDep);
// Instantiate CompletionService
CompletionService<GadgetException> processor =
- new ExecutorCompletionService<GadgetException>(executor);
+ new ExecutorCompletionService<GadgetException>(config.getExecutor());
// All exceptions caught during processing
List<GadgetException> gadgetExceptions = new LinkedList<GadgetException>();
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfig.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfig.java?rev=615088&r1=615087&r2=615088&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfig.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfig.java
Thu Jan 24 16:44:18 2008
@@ -23,7 +23,9 @@
* Stores configuration data for a GadgetServer.
*
* The main purpose of this class is to allow for better readability of
- * GadgetServer ctor parameters.
+ * GadgetServer ctor parameters and to simplify interacting with its
components.
+ *
+ *
*
* Usage:
*
@@ -37,71 +39,41 @@
* Any missing data will result in GadgetServer throwing an
IllegalArgsException
* unless noted as "optional" here.
*/
-public class GadgetServerConfig {
-
- private Executor executor;
-
- public Executor getExecutor() {
- return executor;
- }
+public class GadgetServerConfig extends GadgetServerConfigReader {
public GadgetServerConfig setExecutor(Executor executor) {
this.executor = executor;
return this;
}
- private GadgetFeatureRegistry featureRegistry;
-
- public GadgetFeatureRegistry getFeatureRegistry() {
- return featureRegistry;
- }
-
- public GadgetServerConfig setFeatureRegistry(GadgetFeatureRegistry
featureRegistry) {
+ public GadgetServerConfig setFeatureRegistry(
+ GadgetFeatureRegistry featureRegistry) {
this.featureRegistry = featureRegistry;
return this;
}
- private GadgetDataCache<GadgetSpec> specCache;
-
- public GadgetDataCache<GadgetSpec> getSpecCache() {
- return specCache;
- }
-
- public GadgetServerConfig setSpecCache(GadgetDataCache<GadgetSpec>
specCache) {
+ public GadgetServerConfig setSpecCache(
+ GadgetDataCache<GadgetSpec> specCache) {
this.specCache = specCache;
return this;
}
- private GadgetDataCache<MessageBundle> messageBundleCache;
-
- public GadgetDataCache<MessageBundle> getMessageBundleCache() {
- return messageBundleCache;
- }
-
- public GadgetServerConfig
setMessageBundleCache(GadgetDataCache<MessageBundle> mbCache) {
+ public GadgetServerConfig setMessageBundleCache(
+ GadgetDataCache<MessageBundle> mbCache) {
messageBundleCache = mbCache;
return this;
}
- private RemoteContentFetcher contentFetcher;
-
- public RemoteContentFetcher getContentFetcher() {
- return contentFetcher;
- }
-
- public GadgetServerConfig setContentFetcher(RemoteContentFetcher
contentFetcher) {
+ public GadgetServerConfig setContentFetcher(
+ RemoteContentFetcher contentFetcher) {
this.contentFetcher = contentFetcher;
return this;
}
// Optional
- private GadgetBlacklist gadgetBlacklist;
-
- public GadgetBlacklist getGadgetBlacklist() {
- return gadgetBlacklist;
- }
- public GadgetServerConfig setGadgetBlacklist(GadgetBlacklist
gadgetBlacklist) {
+ public GadgetServerConfig setGadgetBlacklist(
+ GadgetBlacklist gadgetBlacklist) {
this.gadgetBlacklist = gadgetBlacklist;
return this;
}
Added:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfigReader.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfigReader.java?rev=615088&view=auto
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfigReader.java
(added)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetServerConfigReader.java
Thu Jan 24 16:44:18 2008
@@ -0,0 +1,82 @@
+/**
+ * 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.shindig.gadgets;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Stores configuration data for a GadgetServer.
+ *
+ * The main purpose of this class is to allow for better readability of
+ * GadgetServer ctor parameters and to simplify interacting with its
components.
+ *
+ * Works in conjunction with [EMAIL PROTECTED] GadgetServerConfig} to create
immutable
+ * configuration objects. Note that members are still potentially mutable.
+ *
+ */
+public class GadgetServerConfigReader {
+
+ protected Executor executor;
+
+ public Executor getExecutor() {
+ return executor;
+ }
+
+ protected GadgetFeatureRegistry featureRegistry;
+
+ public GadgetFeatureRegistry getFeatureRegistry() {
+ return featureRegistry;
+ }
+
+ protected GadgetDataCache<GadgetSpec> specCache;
+
+ public GadgetDataCache<GadgetSpec> getSpecCache() {
+ return specCache;
+ }
+
+ protected GadgetDataCache<MessageBundle> messageBundleCache;
+
+ public GadgetDataCache<MessageBundle> getMessageBundleCache() {
+ return messageBundleCache;
+ }
+
+ protected RemoteContentFetcher contentFetcher;
+
+ public RemoteContentFetcher getContentFetcher() {
+ return contentFetcher;
+ }
+
+ protected GadgetBlacklist gadgetBlacklist;
+
+ public GadgetBlacklist getGadgetBlacklist() {
+ return gadgetBlacklist;
+ }
+
+ /**
+ * Copies all fields from [EMAIL PROTECTED] base} into this instance.
+ * @param base
+ */
+ public void copyFrom(GadgetServerConfigReader base) {
+ executor = base.getExecutor();
+ featureRegistry = base.getFeatureRegistry();
+ contentFetcher = base.getContentFetcher();
+ specCache = base.getSpecCache();
+ messageBundleCache = base.getMessageBundleCache();
+ gadgetBlacklist = base.getGadgetBlacklist();
+ }
+}