Return-Path: X-Original-To: apmail-aurora-commits-archive@minotaur.apache.org Delivered-To: apmail-aurora-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 705FE186A6 for ; Fri, 28 Aug 2015 18:33:20 +0000 (UTC) Received: (qmail 1723 invoked by uid 500); 28 Aug 2015 18:33:20 -0000 Delivered-To: apmail-aurora-commits-archive@aurora.apache.org Received: (qmail 1641 invoked by uid 500); 28 Aug 2015 18:33:20 -0000 Mailing-List: contact commits-help@aurora.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aurora.apache.org Delivered-To: mailing list commits@aurora.apache.org Received: (qmail 928 invoked by uid 99); 28 Aug 2015 18:33:19 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Aug 2015 18:33:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A6C15E7EB6; Fri, 28 Aug 2015 18:33:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: wfarner@apache.org To: commits@aurora.apache.org Date: Fri, 28 Aug 2015 18:33:39 -0000 Message-Id: <62ab5533fd4846a29ac79d6d22edcc07@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [21/21] aurora git commit: Remove unused classes from commons fork. Remove unused classes from commons fork. Reviewed at https://reviews.apache.org/r/37872/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/356eeac9 Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/356eeac9 Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/356eeac9 Branch: refs/heads/master Commit: 356eeac974bdf2d57399ab082e1419cf0dd7c24d Parents: 06ddaad Author: Bill Farner Authored: Fri Aug 28 11:32:58 2015 -0700 Committer: Bill Farner Committed: Fri Aug 28 11:32:58 2015 -0700 ---------------------------------------------------------------------- build.gradle | 4 - .../application/http/DefaultQuitHandler.java | 43 - .../common/application/http/GraphViewer.java | 50 - .../application/http/HttpAssetConfig.java | 51 - .../application/http/HttpFilterConfig.java | 39 - .../application/http/HttpServletConfig.java | 65 - .../common/application/http/Registration.java | 155 -- .../application/modules/LifecycleModule.java | 26 - .../common/application/modules/LogModule.java | 117 -- .../application/modules/StatsExportModule.java | 85 - .../application/modules/ThriftModule.java | 41 - .../aurora/common/base/CachingSupplier.java | 68 - .../base/CallableExceptionalSupplier.java | 32 - .../org/apache/aurora/common/base/Either.java | 358 ---- .../common/base/ExceptionTransporter.java | 84 - .../common/base/ExceptionalFunctions.java | 153 -- .../apache/aurora/common/base/SupplierE.java | 25 - .../apache/aurora/common/collections/Bits.java | 116 -- .../webassets/bootstrap/BootstrapModule.java | 90 - .../common/webassets/jquery/JQueryModule.java | 36 - .../aurora/common/inject/DefaultProvider.java | 166 -- .../common/inject/ProviderMethodModule.java | 32 - .../aurora/common/io/Base64ZlibCodec.java | 169 -- .../org/apache/aurora/common/io/JsonCodec.java | 124 -- .../org/apache/aurora/common/io/Streamer.java | 54 - .../aurora/common/logging/BufferedLog.java | 278 --- .../apache/aurora/common/logging/LogUtil.java | 90 - .../logging/julbridge/JULBridgeHandler.java | 196 -- .../julbridge/JULBridgeLevelConverter.java | 99 - .../logging/julbridge/JULBridgeLogManager.java | 87 - .../aurora/common/net/ProxyAuthorizer.java | 41 - .../apache/aurora/common/net/ProxyConfig.java | 30 - .../org/apache/aurora/common/net/UrlHelper.java | 156 -- .../apache/aurora/common/net/UrlResolver.java | 446 ---- .../aurora/common/net/UrlResolverUtil.java | 148 -- .../aurora/common/net/UrlTokenizerUtil.java | 1905 ------------------ .../common/net/http/GuiceServletConfig.java | 41 - .../common/net/http/HttpServerDispatch.java | 123 -- .../net/http/JettyHttpServerDispatch.java | 283 --- .../aurora/common/net/http/RequestLogger.java | 130 -- .../net/http/filters/AbstractHttpFilter.java | 63 - .../net/http/filters/HttpStatsFilter.java | 158 -- .../common/net/http/handlers/ThriftServlet.java | 70 - .../loadbalancing/LeastConnectedStrategy.java | 170 -- .../common/net/loadbalancing/LoadBalancer.java | 76 - .../net/loadbalancing/LoadBalancerImpl.java | 122 -- .../loadbalancing/LoadBalancingStrategy.java | 79 - .../net/loadbalancing/MarkDeadStrategy.java | 220 -- .../MarkDeadStrategyWithHostCheck.java | 98 - .../net/loadbalancing/RandomStrategy.java | 57 - .../net/loadbalancing/RequestTracker.java | 37 - .../net/loadbalancing/RoundRobinStrategy.java | 49 - .../StaticLoadBalancingStrategy.java | 61 - .../net/loadbalancing/SubsetStrategy.java | 89 - .../loadbalancing/TrafficMonitorAdapter.java | 68 - .../net/monitoring/ConnectionMonitor.java | 36 - .../common/net/monitoring/TrafficMonitor.java | 259 --- .../common/net/pool/ConnectionFactory.java | 56 - .../aurora/common/net/pool/ConnectionPool.java | 334 --- .../common/net/pool/DynamicHostSetUtil.java | 46 - .../aurora/common/net/pool/DynamicPool.java | 170 -- .../apache/aurora/common/net/pool/MetaPool.java | 339 ---- .../aurora/common/net/pool/ObjectPool.java | 82 - .../net/pool/ResourceExhaustedException.java | 27 - .../common/objectsize/ObjectSizeCalculator.java | 427 ---- .../common/stats/ApproximateHistogram.java | 563 ------ .../apache/aurora/common/stats/CounterMap.java | 138 -- .../common/stats/CounterMapWithTopKey.java | 89 - .../org/apache/aurora/common/stats/Elapsed.java | 81 - .../org/apache/aurora/common/stats/Entropy.java | 51 - .../apache/aurora/common/stats/Histogram.java | 43 - .../apache/aurora/common/stats/Histograms.java | 39 - .../aurora/common/stats/MovingAverage.java | 68 - .../aurora/common/stats/MovingWindowDelta.java | 96 - .../common/stats/NumericStatExporter.java | 125 -- .../aurora/common/stats/PipelineStats.java | 134 -- .../apache/aurora/common/stats/Precision.java | 50 - .../aurora/common/stats/PrintableHistogram.java | 90 - .../aurora/common/stats/ReservoirSampler.java | 97 - .../aurora/common/stats/Significance.java | 59 - .../apache/aurora/common/stats/Statistics.java | 93 - .../common/stats/StatisticsInterface.java | 70 - .../apache/aurora/common/stats/Windowed.java | 136 -- .../common/stats/WindowedApproxHistogram.java | 153 -- .../aurora/common/stats/WindowedHistogram.java | 110 - .../aurora/common/stats/WindowedStatistics.java | 173 -- .../common/stats/testing/RealHistogram.java | 42 - .../aurora/common/testing/TearDownRegistry.java | 51 - .../common/testing/mockito/MockitoTest.java | 31 - .../org/apache/aurora/common/thrift/Config.java | 302 --- .../thrift/TResourceExhaustedException.java | 39 - .../aurora/common/thrift/TTimeoutException.java | 38 - .../common/thrift/TTransportConnection.java | 70 - .../org/apache/aurora/common/thrift/Thrift.java | 390 ---- .../common/thrift/ThriftConnectionFactory.java | 366 ---- .../aurora/common/thrift/ThriftException.java | 26 - .../aurora/common/thrift/ThriftFactory.java | 653 ------ .../aurora/common/thrift/callers/Caller.java | 99 - .../common/thrift/callers/CallerDecorator.java | 78 - .../common/thrift/callers/DeadlineCaller.java | 93 - .../common/thrift/callers/DebugCaller.java | 73 - .../common/thrift/callers/RetryingCaller.java | 224 -- .../thrift/callers/StatTrackingCaller.java | 103 - .../common/thrift/callers/ThriftCaller.java | 157 -- .../TMonitoredNonblockingServerSocket.java | 80 - .../thrift/monitoring/TMonitoredProcessor.java | 62 - .../monitoring/TMonitoredServerSocket.java | 111 - .../common/thrift/testing/MockTSocket.java | 45 - .../common/thrift/testing/TestThriftTypes.java | 7 +- .../apache/aurora/common/util/DateUtils.java | 57 - .../apache/aurora/common/util/FileUtils.java | 51 - .../apache/aurora/common/util/LowResClock.java | 108 - .../apache/aurora/common/util/ParsingUtil.java | 53 - .../apache/aurora/common/util/QueueDrainer.java | 53 - .../aurora/common/util/RangeNormalizer.java | 88 - .../common/util/RateLimitedCommandExecutor.java | 88 - .../aurora/common/util/RetryingRunnable.java | 131 -- .../aurora/common/util/caching/Cache.java | 46 - .../common/util/caching/CachingMethodProxy.java | 262 --- .../aurora/common/util/caching/LRUCache.java | 170 -- .../util/concurrent/BackingOffFutureTask.java | 56 - .../util/concurrent/RetryingFutureTask.java | 81 - .../logging/ResourceLoggingConfigurator.java | 49 - .../util/logging/UnresettableLogManager.java | 48 - .../common/zookeeper/CompoundServerSet.java | 224 -- .../common/zookeeper/DistributedLock.java | 39 - .../common/zookeeper/DistributedLockImpl.java | 286 --- .../aurora/common/zookeeper/Partitioner.java | 172 -- .../aurora/common/zookeeper/ServerSets.java | 32 +- .../common/zookeeper/StaticServerSet.java | 145 -- .../aurora/common/zookeeper/ZooKeeperMap.java | 411 ---- .../aurora/common/zookeeper/ZooKeeperNode.java | 349 ---- .../http/graphview/dygraph-combined.js | 14 - .../application/http/graphview/dygraph-extra.js | 367 ---- .../application/http/graphview/grapher.js | 365 ---- .../application/http/graphview/graphview.html | 84 - .../common/application/http/graphview/parser.js | 337 ---- .../2.1.1/css/bootstrap-responsive.min.css | 14 - .../bootstrap/2.1.1/css/bootstrap.min.css | 14 - .../2.1.1/img/glyphicons-halflings-white.png | Bin 8777 -> 0 bytes .../2.1.1/img/glyphicons-halflings.png | Bin 12799 -> 0 bytes .../bootstrap/2.1.1/js/bootstrap.min.js | 19 - .../2.3.2/css/bootstrap-responsive.min.css | 14 - .../bootstrap/2.3.2/css/bootstrap.min.css | 14 - .../2.3.2/img/glyphicons-halflings-white.png | Bin 8777 -> 0 bytes .../2.3.2/img/glyphicons-halflings.png | Bin 12799 -> 0 bytes .../bootstrap/2.3.2/js/bootstrap.min.js | 19 - .../webassets/jquery/js/jquery-1.8.2.min.js | 15 - .../modules/LifecycleModuleTest.java | 33 +- .../aurora/common/base/CachingSupplierTest.java | 64 - .../apache/aurora/common/base/EitherTest.java | 263 --- .../common/base/ExceptionTransporterTest.java | 57 - .../common/base/ExceptionalFunctionsTest.java | 166 -- .../aurora/common/collections/BitsTest.java | 299 --- .../common/inject/DefaultProviderTest.java | 65 - .../aurora/common/io/Base64ZlibCodecTest.java | 91 - .../apache/aurora/common/io/JsonCodecTest.java | 104 - .../aurora/common/logging/BufferedLogTest.java | 141 -- .../aurora/common/logging/LogUtilTest.java | 61 - .../logging/julbridge/JULBridgeHandlerTest.java | 94 - .../julbridge/JULBridgeLevelConverterTest.java | 94 - .../julbridge/JULBridgeLogManagerTest.java | 75 - .../apache/aurora/common/net/UrlHelperTest.java | 120 -- .../aurora/common/net/UrlResolverTest.java | 171 -- .../aurora/common/net/UrlResolverUtilTest.java | 162 -- .../aurora/common/net/UrlTokenizerUtilTest.java | 94 - .../common/net/http/RequestLoggerTest.java | 102 - .../filters/HttpStatsFilterIntegrationTest.java | 165 -- .../net/http/filters/HttpStatsFilterTest.java | 227 --- .../LeastConnectedStrategyTest.java | 286 --- .../net/loadbalancing/LoadBalancerImplTest.java | 141 -- .../net/loadbalancing/MarkDeadStrategyTest.java | 332 --- .../MarkDeadStrategyWithHostCheckTest.java | 146 -- .../net/loadbalancing/RandomStrategyTest.java | 97 - .../loadbalancing/RoundRobinStrategyTest.java | 104 - .../net/loadbalancing/SubsetStrategyTest.java | 98 - .../net/monitoring/TrafficMonitorTest.java | 122 -- .../common/net/pool/ConnectionPoolTest.java | 255 --- .../common/net/pool/DynamicHostSetUtilTest.java | 57 - .../aurora/common/net/pool/DynamicPoolTest.java | 168 -- .../objectsize/ObjectSizeCalculatorTest.java | 211 -- .../common/stats/ApproximateHistogramTest.java | 321 --- .../apache/aurora/common/stats/ElapsedTest.java | 83 - .../apache/aurora/common/stats/EntropyTest.java | 58 - .../common/stats/MergedHistogramTest.java | 94 - .../aurora/common/stats/MovingAverageTest.java | 83 - .../common/stats/MovingWindowDeltaTest.java | 91 - .../common/stats/NumericStatExporterTest.java | 144 -- .../aurora/common/stats/PipelineStatsTest.java | 147 -- .../common/stats/PrintableHistogramTest.java | 27 - .../common/stats/ReservoirSamplerTest.java | 75 - .../aurora/common/stats/StatisticsTest.java | 116 -- .../common/stats/WindowedHistogramTest.java | 234 --- .../aurora/common/stats/WindowedStatsTest.java | 202 -- .../aurora/common/stats/WindowedTest.java | 110 - .../common/testing/TearDownRegistryTest.java | 46 - .../thrift/ThriftConnectionFactoryTest.java | 140 -- .../aurora/common/thrift/ThriftFactoryTest.java | 242 --- .../apache/aurora/common/thrift/ThriftTest.java | 931 --------- .../thrift/callers/AbstractCallerTest.java | 56 - .../thrift/callers/DeadlineCallerTest.java | 119 -- .../thrift/callers/RetryingCallerTest.java | 150 -- .../aurora/common/util/LowResClockTest.java | 169 -- .../aurora/common/util/QueueDrainerTest.java | 59 - .../util/RateLimitedCommandExecutorTest.java | 115 -- .../util/caching/CachingMethodProxyTest.java | 257 --- .../common/util/caching/LRUCacheTest.java | 81 - .../common/zookeeper/CompoundServerSetTest.java | 233 --- .../common/zookeeper/DistributedLockTest.java | 174 -- .../common/zookeeper/PartitionerTest.java | 159 -- .../common/zookeeper/ServerSetImplTest.java | 115 +- .../common/zookeeper/StaticServerSetTest.java | 85 - .../common/zookeeper/ZooKeeperMapTest.java | 418 ---- .../common/zookeeper/ZooKeeperNodeTest.java | 297 --- 214 files changed, 18 insertions(+), 29580 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index 9444886..05cd36f 100644 --- a/build.gradle +++ b/build.gradle @@ -94,8 +94,6 @@ For more details, please see https://issues.apache.org/jira/browse/AURORA-1169 ext.stringTemplateRev = '3.2.1' ext.zookeeperRev = '3.3.4' ext.jerseyRev = '1.18.1' - // This can be removed onced the mockito dep is gone - ext.objenesisRev = '1.3' ext.jsrRev = '2.0.1' ext.commonsLangRev = '2.6' @@ -116,7 +114,6 @@ For more details, please see https://issues.apache.org/jira/browse/AURORA-1169 force "org.hamcrest:hamcrest-core:1.3" force "org.apache.thrift:libthrift:${thriftRev}" force "org.slf4j:slf4j-jdk14:${slf4jRev}" - force "org.objenesis:objenesis:${objenesisRev}" } } } @@ -174,7 +171,6 @@ project(':commons') { compile "org.antlr:stringtemplate:${stringTemplateRev}" compile "org.apache.zookeeper:zookeeper:${zookeeperRev}" compile "org.easymock:easymock:3.2" - compile "org.mockito:mockito-core:1.9.0" compile "org.slf4j:slf4j-jdk14:${slf4jRev}" // TODO(zmanji): Remove dependency on this old jetty package http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/http/DefaultQuitHandler.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/http/DefaultQuitHandler.java b/commons/src/main/java/org/apache/aurora/common/application/http/DefaultQuitHandler.java deleted file mode 100644 index 6a48b84..0000000 --- a/commons/src/main/java/org/apache/aurora/common/application/http/DefaultQuitHandler.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Licensed 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.aurora.common.application.http; - -import java.util.logging.Logger; - -import com.google.inject.Inject; - -import org.apache.aurora.common.application.Lifecycle; - -/** - * The default quit handler to use, which invokes {@link Lifecycle#shutdown()}. - * - * @author William Farner - */ -public class DefaultQuitHandler implements Runnable { - - private static final Logger LOG = Logger.getLogger(DefaultQuitHandler.class.getName()); - - private final Lifecycle lifecycle; - - @Inject - public DefaultQuitHandler(Lifecycle lifecycle) { - this.lifecycle = lifecycle; - } - - @Override - public void run() { - LOG.info("Instructing lifecycle to destroy."); - lifecycle.shutdown(); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/http/GraphViewer.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/http/GraphViewer.java b/commons/src/main/java/org/apache/aurora/common/application/http/GraphViewer.java deleted file mode 100644 index f786f9e..0000000 --- a/commons/src/main/java/org/apache/aurora/common/application/http/GraphViewer.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Licensed 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.aurora.common.application.http; - -import com.google.inject.Binder; - -/** - * A utility class to register the file resources for the graph viewer. - */ -public final class GraphViewer { - - private GraphViewer() { - // Utility class. - } - - private static void registerJs(Binder binder, String assetName) { - Registration.registerHttpAsset( - binder, - "/graphview/" + assetName, - GraphViewer.class, - "graphview/" + assetName, - "application/javascript", - true); - } - - /** - * Registers required resources with the binder. - * - * @param binder Binder to register with. - */ - public static void registerResources(Binder binder) { - registerJs(binder, "dygraph-combined.js"); - registerJs(binder, "dygraph-extra.js"); - registerJs(binder, "grapher.js"); - registerJs(binder, "parser.js"); - Registration.registerHttpAsset(binder, - "/graphview", GraphViewer.class, "graphview/graphview.html", "text/html", false); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/http/HttpAssetConfig.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/http/HttpAssetConfig.java b/commons/src/main/java/org/apache/aurora/common/application/http/HttpAssetConfig.java deleted file mode 100644 index e2160e7..0000000 --- a/commons/src/main/java/org/apache/aurora/common/application/http/HttpAssetConfig.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed 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.aurora.common.application.http; - -import java.net.URL; - -import com.google.common.io.Resources; - -import org.apache.aurora.common.net.http.handlers.AssetHandler; -import org.apache.aurora.common.net.http.handlers.AssetHandler.StaticAsset; - -import static org.apache.aurora.common.base.MorePreconditions.checkNotBlank; - -/** - * Configuration for a static HTTP-served asset. - * - * TODO(William Farner): Move this to a more appropriate package after initial AppLauncher check-in. - * - * @author William Farner - */ -public class HttpAssetConfig { - public final String path; - public final AssetHandler handler; - public final boolean silent; - - /** - * Creates a new asset configuration. - * - * @param path HTTP path the asset should be accessible from. - * @param asset Asset resource URL. - * @param contentType HTTP content-type to report for the asset. - * @param silent Whether the asset should be visible on the default index page. - */ - public HttpAssetConfig(String path, URL asset, String contentType, boolean silent) { - this.path = checkNotBlank(path); - this.handler = new AssetHandler( - new StaticAsset(Resources.newInputStreamSupplier(asset), contentType, true)); - this.silent = silent; - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/http/HttpFilterConfig.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/http/HttpFilterConfig.java b/commons/src/main/java/org/apache/aurora/common/application/http/HttpFilterConfig.java deleted file mode 100644 index d096317..0000000 --- a/commons/src/main/java/org/apache/aurora/common/application/http/HttpFilterConfig.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed 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.aurora.common.application.http; - -import javax.servlet.Filter; - -import org.apache.aurora.common.base.MorePreconditions; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Configuration tuple for an HTTP filter. - */ -public class HttpFilterConfig { - public final Class filterClass; - public final String pathSpec; - - /** - * Creates a new filter configuration. - * - * @param filterClass Filter class. - * @param pathSpec Path spec that the filter should match. - */ - public HttpFilterConfig(Class filterClass, String pathSpec) { - this.pathSpec = MorePreconditions.checkNotBlank(pathSpec); - this.filterClass = checkNotNull(filterClass); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/http/HttpServletConfig.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/http/HttpServletConfig.java b/commons/src/main/java/org/apache/aurora/common/application/http/HttpServletConfig.java deleted file mode 100644 index 4444e4c..0000000 --- a/commons/src/main/java/org/apache/aurora/common/application/http/HttpServletConfig.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed 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.aurora.common.application.http; - -import javax.servlet.http.HttpServlet; - -import com.google.common.collect.ImmutableMap; - -import static com.google.common.base.Preconditions.checkNotNull; - -import static org.apache.aurora.common.base.MorePreconditions.checkNotBlank; - -/** - * An {@link javax.servlet.http.HttpServlet} configuration used to mount HTTP handlers via - * {@link Registration#registerServlet(com.google.inject.Binder, HttpServletConfig)}. - * - * TODO(William Farner): Move this to a more appropriate package after initial AppLauncher check-in. - * - */ -public class HttpServletConfig { - public final String path; - public final Class handlerClass; - public final ImmutableMap params; - public final boolean silent; - - /** - * Creates a new servlet config. - * - * @param path the absolute path to mount the handler on - * @param servletClass the type of servlet that will render pages at {@code path} - * @param silent whether or not to display a link for this handler on the landing page - */ - public HttpServletConfig(String path, Class servletClass, - boolean silent) { - this(path, servletClass, ImmutableMap.of(), silent); - } - - /** - * Registers a new servlet config with servlet initialization parameters. - * - * @param path the absolute path to mount the handler on - * @param servletClass the type of servlet that will render pages at {@code path} - * @param params a map of servlet init parameters to initialize the servlet with - * @param silent whether or not to display a link for this handler on the landing page - */ - public HttpServletConfig(String path, Class servletClass, - ImmutableMap params, boolean silent) { - - this.path = checkNotBlank(path); - this.handlerClass = checkNotNull(servletClass); - this.params = checkNotNull(params); - this.silent = silent; - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/http/Registration.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/http/Registration.java b/commons/src/main/java/org/apache/aurora/common/application/http/Registration.java deleted file mode 100644 index b66c8c8..0000000 --- a/commons/src/main/java/org/apache/aurora/common/application/http/Registration.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Licensed 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.aurora.common.application.http; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import java.net.URL; - -import javax.servlet.Filter; -import javax.servlet.http.HttpServlet; - -import com.google.common.io.Resources; -import com.google.inject.Binder; -import com.google.inject.BindingAnnotation; -import com.google.inject.multibindings.Multibinder; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Utility class for registering HTTP servlets and assets. - */ -public final class Registration { - - private Registration() { - // Utility class. - } - - /** - * Equivalent to - * {@code registerServlet(binder, new HttpServletConfig(path, servletClass, silent))}. - */ - public static void registerServlet(Binder binder, String path, - Class servletClass, boolean silent) { - registerServlet(binder, new HttpServletConfig(path, servletClass, silent)); - } - - /** - * Registers a binding for an {@link javax.servlet.http.HttpServlet} to be exported at a specified - * path. - * - * @param binder a guice binder to register the handler with - * @param config a servlet mounting specification - */ - public static void registerServlet(Binder binder, HttpServletConfig config) { - Multibinder.newSetBinder(binder, HttpServletConfig.class).addBinding().toInstance(config); - } - - /** - * A binding annotation applied to the set of additional index page links bound via - * {@link #Registration#registerEndpoint()} - */ - @BindingAnnotation - @Target({FIELD, PARAMETER, METHOD}) - @Retention(RUNTIME) - public @interface IndexLink { } - - /** - * Gets the multibinder used to bind links on the root servlet. - * The resulting {@link java.util.Set} is bound with the {@link IndexLink} annotation. - * - * @param binder a guice binder to associate the multibinder with. - * @return The multibinder to bind index links against. - */ - public static Multibinder getEndpointBinder(Binder binder) { - return Multibinder.newSetBinder(binder, String.class, IndexLink.class); - } - - /** - * Registers a link to display on the root servlet. - * - * @param binder a guice binder to register the link with. - * @param endpoint Endpoint URI to include. - */ - public static void registerEndpoint(Binder binder, String endpoint) { - getEndpointBinder(binder).addBinding().toInstance(endpoint); - } - - /** - * Registers a binding for a URL asset to be served by the HTTP server, with an optional - * entity tag for cache control. - * - * @param binder a guice binder to register the handler with - * @param servedPath Path to serve the resource from in the HTTP server. - * @param asset Resource to be served. - * @param assetType MIME-type for the asset. - * @param silent Whether the server should hide this asset on the index page. - */ - public static void registerHttpAsset(Binder binder, String servedPath, URL asset, - String assetType, boolean silent) { - Multibinder.newSetBinder(binder, HttpAssetConfig.class).addBinding().toInstance( - new HttpAssetConfig(servedPath, asset, assetType, silent)); - } - - /** - * Registers a binding for a classpath resource to be served by the HTTP server, using a resource - * path relative to a class. - * - * @param binder a guice binder to register the handler with - * @param servedPath Path to serve the asset from in the HTTP server. - * @param contextClass Context class for defining the relative path to the asset. - * @param assetRelativePath Path to the served asset, relative to {@code contextClass}. - * @param assetType MIME-type for the asset. - * @param silent Whether the server should hide this asset on the index page. - */ - public static void registerHttpAsset( - Binder binder, - String servedPath, - Class contextClass, - String assetRelativePath, - String assetType, - boolean silent) { - - registerHttpAsset(binder, servedPath, Resources.getResource(contextClass, assetRelativePath), - assetType, silent); - } - - /** - * Gets the multibinder used to bind HTTP filters. - * - * @param binder a guice binder to associate the multibinder with. - * @return The multibinder to bind HTTP filter configurations against. - */ - public static Multibinder getFilterBinder(Binder binder) { - return Multibinder.newSetBinder(binder, HttpFilterConfig.class); - } - - /** - * Registers an HTTP servlet filter. - * - * @param binder a guice binder to register the filter with. - * @param filterClass Filter class to register. - * @param pathSpec Path spec that the filter should be activated on. - */ - public static void registerServletFilter( - Binder binder, - Class filterClass, - String pathSpec) { - - getFilterBinder(binder).addBinding().toInstance(new HttpFilterConfig(filterClass, pathSpec)); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/modules/LifecycleModule.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/modules/LifecycleModule.java b/commons/src/main/java/org/apache/aurora/common/application/modules/LifecycleModule.java index b3e59e7..6414208 100644 --- a/commons/src/main/java/org/apache/aurora/common/application/modules/LifecycleModule.java +++ b/commons/src/main/java/org/apache/aurora/common/application/modules/LifecycleModule.java @@ -120,32 +120,6 @@ public class LifecycleModule extends AbstractModule { } /** - * Binds a service runner that will start and stop a local service. - * - * @param binder Binder to bind against. - * @param launcher Launcher class for a service. - */ - public static void bindServiceRunner(Binder binder, Class launcher) { - runnerBinder(binder).addBinding().to(launcher); - binder.bind(launcher).in(Singleton.class); - } - - /** - * Binds a local service instance, without attaching an explicit lifecycle. - * - * @param binder Binder to bind against. - * @param service Local service instance to bind. - */ - public static void bindLocalService(Binder binder, final LocalServiceRegistry.LocalService service) { - runnerBinder(binder).addBinding().toInstance( - new ServiceRunner() { - @Override public LocalServiceRegistry.LocalService launch() { - return service; - } - }); - } - - /** * Adds a startup action to the startup registry binding. * * @param binder Binder to bind against. http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/modules/LogModule.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/modules/LogModule.java b/commons/src/main/java/org/apache/aurora/common/application/modules/LogModule.java deleted file mode 100644 index 107e3aa..0000000 --- a/commons/src/main/java/org/apache/aurora/common/application/modules/LogModule.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * Licensed 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.aurora.common.application.modules; - -import java.io.File; -import java.util.logging.Logger; - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Named; -import com.google.inject.name.Names; - -import org.apache.aurora.common.args.Arg; -import org.apache.aurora.common.args.CmdLine; -import org.apache.aurora.common.args.constraints.CanRead; -import org.apache.aurora.common.args.constraints.Exists; -import org.apache.aurora.common.args.constraints.IsDirectory; -import org.apache.aurora.common.base.Command; -import org.apache.aurora.common.logging.LogUtil; -import org.apache.aurora.common.logging.RootLogConfig; -import org.apache.aurora.common.logging.RootLogConfig.Configuration; -import org.apache.aurora.common.net.http.handlers.LogPrinter; -import org.apache.aurora.common.stats.StatImpl; -import org.apache.aurora.common.stats.Stats; - -/** - * Binding module for logging-related bindings, such as the log directory. - * - * This module uses a single optional command line argument 'log_dir'. If unset, the logging - * directory will be auto-discovered via: - * {@link LogUtil#getLogManagerLogDir()}. - * - * Bindings provided by this module: - *
    - *
  • {@code @Named(LogPrinter.LOG_DIR_KEY) File} - Log directory. - *
  • {@code Optional<RootLogConfig.Configuraton>} - If glog is enabled the configuration - * used. - *
- * - * Default bindings that may be overridden: - *
    - *
  • Log directory: directory where application logs are written. May be overridden by binding - * to: {@code bind(File.class).annotatedWith(Names.named(LogPrinter.LOG_DIR_KEY))}. - *
- * - * @author William Farner - */ -public class LogModule extends AbstractModule { - - private static final Logger LOG = Logger.getLogger(LogModule.class.getName()); - - @Exists - @CanRead - @IsDirectory - @CmdLine(name = "log_dir", - help = "The directory where application logs are written.") - private static final Arg LOG_DIR = Arg.create(null); - - @CmdLine(name = "use_glog", - help = "True to use the new glog-based configuration for the root logger.") - private static final Arg USE_GLOG = Arg.create(true); - - @Override - protected void configure() { - // Bind the default log directory. - bind(File.class).annotatedWith(Names.named(LogPrinter.LOG_DIR_KEY)).toInstance(getLogDir()); - - LifecycleModule.bindStartupAction(binder(), ExportLogDir.class); - - Configuration configuration = null; - if (USE_GLOG.get()) { - configuration = RootLogConfig.configurationFromFlags(); - configuration.apply(); - } - bind(new TypeLiteral>() { }) - .toInstance(Optional.fromNullable(configuration)); - } - - private File getLogDir() { - File logDir = LOG_DIR.get(); - if (logDir == null) { - logDir = LogUtil.getLogManagerLogDir(); - LOG.info("From logging properties, parsed log directory " + logDir.getAbsolutePath()); - } - return logDir; - } - - public static final class ExportLogDir implements Command { - private final File logDir; - - @Inject ExportLogDir(@Named(LogPrinter.LOG_DIR_KEY) final File logDir) { - this.logDir = Preconditions.checkNotNull(logDir); - } - - @Override public void execute() { - Stats.exportStatic(new StatImpl("logging_dir") { - @Override public String read() { - return logDir.getAbsolutePath(); - } - }); - } - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/modules/StatsExportModule.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/modules/StatsExportModule.java b/commons/src/main/java/org/apache/aurora/common/application/modules/StatsExportModule.java deleted file mode 100644 index ba93d4c..0000000 --- a/commons/src/main/java/org/apache/aurora/common/application/modules/StatsExportModule.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Licensed 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.aurora.common.application.modules; - -import java.util.Map; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; - -import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; - -import org.apache.aurora.common.application.ShutdownRegistry; -import org.apache.aurora.common.args.Arg; -import org.apache.aurora.common.args.CmdLine; -import org.apache.aurora.common.base.Closure; -import org.apache.aurora.common.base.Command; -import org.apache.aurora.common.quantity.Amount; -import org.apache.aurora.common.quantity.Time; -import org.apache.aurora.common.stats.NumericStatExporter; - -/** - * Module to enable periodic exporting of registered stats to an external service. - * - * This modules supports a single command line argument, {@code stat_export_interval}, which - * controls the export interval (defaulting to 1 minute). - * - * Bindings required by this module: - *
    - *
  • {@code @ShutdownStage ShutdownRegistry} - Shutdown action registry. - *
- * - * @author William Farner - */ -public class StatsExportModule extends AbstractModule { - - @CmdLine(name = "stat_export_interval", - help = "Amount of time to wait between stat exports.") - private static final Arg> EXPORT_INTERVAL = - Arg.create(Amount.of(1L, Time.MINUTES)); - - @Override - protected void configure() { - requireBinding(Key.get(new TypeLiteral>>() { })); - LifecycleModule.bindStartupAction(binder(), StartCuckooExporter.class); - } - - public static final class StartCuckooExporter implements Command { - - private final Closure> statSink; - private final ShutdownRegistry shutdownRegistry; - - @Inject StartCuckooExporter( - Closure> statSink, - ShutdownRegistry shutdownRegistry) { - - this.statSink = Preconditions.checkNotNull(statSink); - this.shutdownRegistry = Preconditions.checkNotNull(shutdownRegistry); - } - - @Override public void execute() { - ThreadFactory threadFactory = - new ThreadFactoryBuilder().setNameFormat("CuckooExporter-%d").setDaemon(true).build(); - - final NumericStatExporter exporter = new NumericStatExporter(statSink, - Executors.newScheduledThreadPool(1, threadFactory), EXPORT_INTERVAL.get()); - - exporter.start(shutdownRegistry); - } - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/application/modules/ThriftModule.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/application/modules/ThriftModule.java b/commons/src/main/java/org/apache/aurora/common/application/modules/ThriftModule.java deleted file mode 100644 index 55236df..0000000 --- a/commons/src/main/java/org/apache/aurora/common/application/modules/ThriftModule.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed 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.aurora.common.application.modules; - -import com.google.inject.AbstractModule; -import com.google.inject.multibindings.Multibinder; -import com.google.inject.name.Names; - -import org.apache.aurora.common.application.http.Registration; -import org.apache.aurora.common.net.http.handlers.ThriftServlet; -import org.apache.aurora.common.net.monitoring.TrafficMonitor; - -/** - * Binding module for thrift traffic monitor servlets, to ensure an empty set is available for - * the thrift traffic monitor servlet. - * - * @author William Farner - */ -public class ThriftModule extends AbstractModule { - @Override - protected void configure() { - // Make sure that there is at least an empty set bound to client andserver monitors. - Multibinder.newSetBinder(binder(), TrafficMonitor.class, - Names.named(ThriftServlet.THRIFT_CLIENT_MONITORS)); - Multibinder.newSetBinder(binder(), TrafficMonitor.class, - Names.named(ThriftServlet.THRIFT_SERVER_MONITORS)); - - Registration.registerServlet(binder(), "/thrift", ThriftServlet.class, false); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/base/CachingSupplier.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/base/CachingSupplier.java b/commons/src/main/java/org/apache/aurora/common/base/CachingSupplier.java deleted file mode 100644 index 3a1511d..0000000 --- a/commons/src/main/java/org/apache/aurora/common/base/CachingSupplier.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed 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.aurora.common.base; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; - -import org.apache.aurora.common.quantity.Amount; -import org.apache.aurora.common.quantity.Time; -import org.apache.aurora.common.util.Clock; - -/** - * A supplier that caches responses from an underling supplier, expiring the cached value after - * a fixed expiration time. - * - * @param Supplied value type. - * - * @author William Farner - */ -public class CachingSupplier implements Supplier { - - private final Supplier wrapped; - private final long expirationNanos; - private final Clock clock; - - private long lastFetchNanos = -1; - private T cachedValue; - - /** - * Creates a new caching supplier. - * - * @param wrapped The supplier to delegate fetches to. - * @param expiration The maximum amount of time that a response from {@code supplier} will be - * cached for. The expiration must be positive. - */ - public CachingSupplier(Supplier wrapped, Amount expiration) { - this(wrapped, expiration, Clock.SYSTEM_CLOCK); - } - - @VisibleForTesting - CachingSupplier(Supplier wrapped, Amount expiration, Clock clock) { - this.wrapped = Preconditions.checkNotNull(wrapped); - this.expirationNanos = Preconditions.checkNotNull(expiration).as(Time.NANOSECONDS); - Preconditions.checkArgument(expiration.getValue() > 0, "Expiration must be positive."); - this.clock = Preconditions.checkNotNull(clock); - } - - @Override - public synchronized T get() { - if ((lastFetchNanos == -1) || (clock.nowNanos() - lastFetchNanos > expirationNanos)) { - cachedValue = wrapped.get(); - lastFetchNanos = clock.nowNanos(); - } - - return cachedValue; - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/base/CallableExceptionalSupplier.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/base/CallableExceptionalSupplier.java b/commons/src/main/java/org/apache/aurora/common/base/CallableExceptionalSupplier.java deleted file mode 100644 index b4f2d53..0000000 --- a/commons/src/main/java/org/apache/aurora/common/base/CallableExceptionalSupplier.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed 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.aurora.common.base; - -import java.util.concurrent.Callable; - -/** - * A supplier that may also be called. - * - * @param The supplier type. - * @param Supplier exception type. - * - * @author John Sirois - */ -public abstract class CallableExceptionalSupplier - implements ExceptionalSupplier, Callable { - - @Override public T call() throws Exception { - return get(); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/base/Either.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/base/Either.java b/commons/src/main/java/org/apache/aurora/common/base/Either.java deleted file mode 100644 index a746e72..0000000 --- a/commons/src/main/java/org/apache/aurora/common/base/Either.java +++ /dev/null @@ -1,358 +0,0 @@ -/** - * Licensed 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.aurora.common.base; - -import javax.annotation.Nullable; - -import com.google.common.base.Objects; -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -/** - * A value of one of two possible types. - * - *

Often Either processing is used as an alternative exception flow control. In these uses the - * left type represents failure by convention and the right type the success path result. - * - * @param The left type. - * @param The right type. - */ -public final class Either { - private final Optional left; - private final Optional right; - - private Either(Optional left, Optional right) { - this.left = left; - this.right = right; - } - - /** - * Turns a left into a right and vice-versa. - * - * @return A new swapped either instance. - */ - public Either swap() { - return new Either(right, left); - } - - /** - * Returns an optional the will be {@link Optional#isPresent() present} is this is a left - * instance. - * - * @return An optional value for the left. - */ - public Optional left() { - return left; - } - - /** - * Returns an optional the will be {@link Optional#isPresent() present} is this is a right - * instance. - * - * @return An optional value for the right. - */ - public Optional right() { - return right; - } - - /** - * Returns {@code true} if this is a left instance. - * - * @return {@code true} if this is a left. - */ - public boolean isLeft() { - return left().isPresent(); - } - - /** - * Returns {@code true} if this is a right instance. - * - * @return {@code true} if this is a right. - */ - public boolean isRight() { - return right().isPresent(); - } - - /** - * Returns the underlying value if this is a left; otherwise, throws. - * - * @return The underlying value. - * @throws IllegalStateException if this is a right instance. - */ - public L getLeft() { - return left().get(); - } - - /** - * Returns the underlying value if this is a right; otherwise, throws. - * - * @return The underlying value. - * @throws IllegalStateException if this is a right instance. - */ - public R getRight() { - return right().get(); - } - - /** - * If this is a left, maps its value into a new left; otherwise just returns this right. - * - * @param transformer The transformation to apply to the left value. - * @param The type a left value will be mapped to. - * @return The mapped left or else the right. - */ - public Either mapLeft(Function transformer) { - if (isLeft()) { - return left(transformer.apply(getLeft())); - } else { - @SuppressWarnings("unchecked") // I am a right so my left is never accessible - Either self = (Either) this; - return self; - } - } - - /** - * If this is a right, maps its value into a new right; otherwise just returns this left. - * - * @param transformer The transformation to apply to the left value. - * @param The type a right value will be mapped to. - * @return The mapped right or else the left. - */ - public Either mapRight(Function transformer) { - if (isRight()) { - return right(transformer.apply(getRight())); - } else { - @SuppressWarnings("unchecked") // I am a left so my right is never accessible - Either self = (Either) this; - return self; - } - } - - /** - * Can transform either a left or a right into a result. - * - * @param The left type. - * @param The right type. - * @param The transformation result type. - */ - public abstract static class Transformer implements Function, T> { - - /** - * Maps left values to a result. - * - * @param left the left value to map. - * @return The mapped value. - */ - public abstract T mapLeft(L left); - - /** - * Maps right values to a result. - * - * @param right the right value to map. - * @return The mapped value. - */ - public abstract T mapRight(R right); - - @Override - public final T apply(Either either) { - return either.map(this); - } - } - - /** - * Creates a transformer from left and right transformation functions. - * - * @param leftTransformer A transformer to process left values. - * @param rightTransformer A transformer to process right values. - * @param The left type. - * @param The right type. - * @param The transformation result type. - * @return A new transformer composed of left and right transformer functions. - */ - public static Transformer transformer( - final Function leftTransformer, - final Function rightTransformer) { - - return new Transformer() { - @Override public T mapLeft(L item) { - return leftTransformer.apply(item); - } - @Override public T mapRight(R item) { - return rightTransformer.apply(item); - } - }; - } - - /** - * Transforms this either instance to a value regardless of whether it is a left or a right. - * - * @param transformer The transformer to map this either instance. - * @param The type the transformer produces. - * @return A value mapped by the transformer from this left or right instance. - */ - public T map(final Transformer transformer) { - if (isLeft()) { - return transformer.mapLeft(getLeft()); - } else { - return transformer.mapRight(getRight()); - } - } - - @Override - public boolean equals(@Nullable Object o) { - if (!(o instanceof Either)) { - return false; - } - Either other = (Either) o; - return Objects.equal(left, other.left) - && Objects.equal(right, other.right); - } - - @Override - public int hashCode() { - return Objects.hashCode(left, right); - } - - @Override - public String toString() { - if (isLeft()) { - return String.format("Left(%s)", getLeft()); - } else { - return String.format("Right(%s)", getRight()); - } - } - - /** - * Creates a left either instance. - * - * @param value The left value to wrap - may not be null. - * @param The left type. - * @param The right type. - * @return A left either instance wrapping {@code value}. - */ - public static Either left(L value) { - return new Either(Optional.of(value), Optional.absent()); - } - - /** - * Creates a right either instance. - * - * @param value The right value to wrap - may not be null. - * @param The left type. - * @param The right type. - * @return A right either instance wrapping {@code value}. - */ - public static Either right(R value) { - return new Either(Optional.absent(), Optional.of(value)); - } - - /** - * Extracts all the lefts from a sequence of eithers lazily. - * - * @param results A sequence of either's to process. - * @param The left type. - * @param The right type. - * @return A lazy iterable that will produce the lefts present in results in order. - */ - public static Iterable lefts(Iterable> results) { - return Optional.presentInstances(Iterables.transform(results, - new Function, Optional>() { - @Override public Optional apply(Either item) { - return item.left(); - } - })); - } - - /** - * Extracts all the rights from a sequence of eithers lazily. - * - * @param results A sequence of either's to process. - * @param The left type. - * @param The right type. - * @return A lazy iterable that will produce the rights present in results in order. - */ - public static Iterable rights(Iterable> results) { - return Optional.presentInstances(Iterables.transform(results, - new Function, Optional>() { - @Override public Optional apply(Either item) { - return item.right(); - } - })); - } - - /** - * A convenience method equivalent to calling {@code guard(work, exceptionType)}. - */ - public static Either guard( - Class exceptionType, - ExceptionalSupplier work) { - - @SuppressWarnings("unchecked") - Either either = guard(work, exceptionType); - return either; - } - - /** - * A convenience method equivalent to calling - * {@code guard(Lists.asList(execpetionType, rest), work)}. - */ - public static Either guard( - ExceptionalSupplier work, - Class exceptionType, - Class... rest) { - - return guard(Lists.asList(exceptionType, rest), work); - } - - /** - * Thrown when guarded work throws an unguarded exception. The {@link #getCause() cause} will - * contain the original unguarded exception. - */ - public static class UnguardedException extends RuntimeException { - public UnguardedException(Throwable cause) { - super(cause); - } - } - - /** - * Converts work that can throw exceptions into an either with a left exception base type. This - * can be useful to fold an exception throwing library call into an either processing style - * pipeline. - * - * @param exceptionTypes The expected exception types. - * @param work The work to perform to get a result produce an error. - * @param The base error type. - * @param The success type. - * @return An either wrapping the result of performing {@code work}. - * @throws UnguardedException if work throws an unguarded exception type. - */ - public static Either guard( - Iterable> exceptionTypes, - ExceptionalSupplier work) { - - try { - return right(work.get()); - // We're explicitly dealing with generic exception types here by design. - // SUPPRESS CHECKSTYLE RegexpSinglelineJava - } catch (Exception e) { - for (Class exceptionType : exceptionTypes) { - if (exceptionType.isInstance(e)) { - X exception = exceptionType.cast(e); - return left(exception); - } - } - throw new UnguardedException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/base/ExceptionTransporter.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/base/ExceptionTransporter.java b/commons/src/main/java/org/apache/aurora/common/base/ExceptionTransporter.java deleted file mode 100644 index e5cb60d..0000000 --- a/commons/src/main/java/org/apache/aurora/common/base/ExceptionTransporter.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Licensed 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.aurora.common.base; - -import com.google.common.base.Function; - -/** - * A utility for transporting checked exceptions across boundaries that do not allow for checked - * exception propagation. - * - * @param The type of checked exception the ExceptionTransported can transport - * - * @author John Sirois - */ -public class ExceptionTransporter { - - /** - * An exception wrapper used to transport checked exceptions. Never leaves an - * {@link ExceptionTransporter#guard(com.google.common.base.Function)} call. - */ - private static final class TransportingException extends RuntimeException { - private TransportingException(Exception cause) { - super("It is a usage error to see this message!", cause); - } - } - - /** - * Guards a unit of work that internally can generate checked exceptions. Callers wrap up the - * work in a function that rethrows any checked exceptions using the supplied - * ExceptionTransporter. Guard will ensure the original exception is unwrapped an re-thrown. - * - * @param work The unit of work that guards its checked exceptions. - * @param The type returned by the unit of work when it successfully completes. - * @param The type of checked exception that the unit of work wishes to guard. - * @return the result of the unit of work if no excpetions are thrown - * @throws X when the unit of work uses the ExceptionTransporter to throw a checked exception - */ - public static T guard(Function, T> work) - throws X { - - try { - return work.apply(new ExceptionTransporter()); - } catch (TransportingException e) { - @SuppressWarnings("unchecked") - X cause = (X) e.getCause(); - throw cause; - } - } - - /** - * Throws the given {@code checked} exception across a boundary that does not allow checked - * exceptions. Although a RuntimeException is returned by this method signature, the method never - * actually completes normally. The return type does allow the following usage idiom however: - *

-   * public String apply(ExceptionTransporter transporter) {
-   *   try {
-   *     return doChecked();
-   *   } catch (CheckedException e) {
-   *     // Although transport internally throws and does not return, we satisfy the compiler that
-   *     // our method returns a value or throws by pretending to throw the RuntimeException that
-   *     // never actually gets returned by transporter.transport(...)
-   *     throw transporter.transport(e);
-   *   }
-   * }
-   * 
- * - * @param checked The checked exception to transport. - * @return A RuntimeException that can be thrown to satisfy the compiler at the call site - */ - public RuntimeException transport(E checked) { - throw new TransportingException(checked); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/base/ExceptionalFunctions.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/base/ExceptionalFunctions.java b/commons/src/main/java/org/apache/aurora/common/base/ExceptionalFunctions.java deleted file mode 100644 index f06c66c..0000000 --- a/commons/src/main/java/org/apache/aurora/common/base/ExceptionalFunctions.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Licensed 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.aurora.common.base; - -import com.google.common.collect.ImmutableList; - -/** - * Utility functions for working with exceptional functions. - * - * @author John Sirois - */ -public final class ExceptionalFunctions { - - private ExceptionalFunctions() { - // utility - } - - /** - * Returns an {@link ExceptionalSupplier}/{@link java.util.concurrent.Callable} object that will - * return the result of {@code function} applied to {@code argument}. Evaluation is lazy and - * un-memoized. - */ - public static CallableExceptionalSupplier curry( - final ExceptionalFunction function, final S argument) { - - return new CallableExceptionalSupplier() { - @Override - public T get() throws E { - return function.apply(argument); - } - }; - } - - /** - * Returns an ExceptionalFunction that is a composition of multiple ExceptionalFunctions. - */ - public static ExceptionalFunction compose( - final Iterable> functions) { - return new ExceptionalFunction() { - @Override - public T apply(T input) throws E { - T result = input; - for (ExceptionalFunction f : functions) { - result = f.apply(result); - } - return result; - } - }; - } - - /** - * Returns a List of ExceptionalFunctions from variable number of ExceptionalFunctions. - */ - public static ExceptionalFunction compose( - ExceptionalFunction function, ExceptionalFunction... functions) { - return compose(ImmutableList.>builder() - .add(function) - .add(functions) - .build()); - } - - /** - * Returns a new ExceptionalFunction which composes two ExceptionalFunctions of compatible types. - * - * @param second function to apply to result of first. - * @param first function to apply to input item. - * @param input type of first. - * @param input type of second. - * @param output type of second. - * @param exception type. - * @return new composed ExceptionalFunction. - */ - public static ExceptionalFunction compose( - final ExceptionalFunction second, - final ExceptionalFunction first) { - return new ExceptionalFunction() { - @Override - public C apply(A item) throws E { - return second.apply(first.apply(item)); - } - }; - } - - /** - * Builds an ExceptionalFunction from {@link com.google.common.base.Function}. - * - * @param function guava Function. - * @param input type. - * @param output type. - * @param exception type. - * @return new ExceptionalFunction. - */ - public static ExceptionalFunction forFunction( - final com.google.common.base.Function function) { - return new ExceptionalFunction() { - @Override - public T apply(S item) { - return function.apply(item); - } - }; - } - - /** - * Builds an ExceptionalFunction from a return value. The returned ExceptionalFunction will always - * return the given value. - * - * @param value value to return. - * @param input type. - * @param output type. - * @param exception type. - * @return new ExceptionalFunction. - */ - public static ExceptionalFunction constant( - final T value) { - return new ExceptionalFunction() { - @Override - public T apply(S item) throws E { - return value; - } - }; - } - - /** - * Builds an ExceptionalFunction from an Exception. The returned ExceptionalFunction will always - * throw the given Exception. - * - * @param exception exception to throw. - * @param input type. - * @param output type. - * @param exception type. - * @return new ExceptionalFunction. - */ - public static ExceptionalFunction forException( - final E exception) { - return new ExceptionalFunction() { - @Override - public T apply(S item) throws E { - throw exception; - } - }; - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/base/SupplierE.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/base/SupplierE.java b/commons/src/main/java/org/apache/aurora/common/base/SupplierE.java deleted file mode 100644 index ecad43e..0000000 --- a/commons/src/main/java/org/apache/aurora/common/base/SupplierE.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Licensed 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.aurora.common.base; - -/** - * A convenience typedef for suppliers that throw multiple exception types. - * - * @param The supplied type. - * - * @author John Sirois - */ -public interface SupplierE extends ExceptionalSupplier { - // typedef -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/collections/Bits.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/collections/Bits.java b/commons/src/main/java/org/apache/aurora/common/collections/Bits.java deleted file mode 100644 index f07e04a..0000000 --- a/commons/src/main/java/org/apache/aurora/common/collections/Bits.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Licensed 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.aurora.common.collections; - -import com.google.common.base.Preconditions; - -/** - * Convenience class for doing bit-level operations on ints and longs. - * - * @author William Farner - */ -public final class Bits { - - private static final int LSB = 0; - private static final int INT_MSB = 31; - private static final int LONG_MSB = 63; - - private Bits() { - // Utility. - } - - /** - * Tests whether a bit is set in an int value. - * - * @param value The bit field to test. - * @param bit The index of the bit to test, where bit 0 is the LSB. - * @return {@code true} if the bit is set, {@code false} otherwise. - */ - public static boolean isBitSet(int value, int bit) { - Preconditions.checkState(bit >= LSB); - Preconditions.checkState(bit <= INT_MSB); - int mask = 1 << bit; - return (value & mask) != 0; - } - - /** - * Tests whether a bit is set in a long value. - * - * @param value The bit field to test. - * @param bit The index of the bit to test, where bit 0 is the LSB. - * @return {@code true} if the bit is set, {@code false} otherwise. - */ - public static boolean isBitSet(long value, int bit) { - Preconditions.checkState(bit >= LSB); - Preconditions.checkState(bit <= LONG_MSB); - long mask = 1L << bit; - return (value & mask) != 0; - } - - /** - * Sets a bit in an int value. - * - * @param value The bit field to modify. - * @param bit The index of the bit to set, where bit 0 is the LSB. - * @return The original value, with the indexed bit set. - */ - public static int setBit(int value, int bit) { - Preconditions.checkState(bit >= LSB); - Preconditions.checkState(bit <= INT_MSB); - int mask = 1 << bit; - return value | mask; - } - - /** - * Sets a bit in a long value. - * - * @param value The bit field to modify. - * @param bit The index of the bit to set, where bit 0 is the LSB. - * @return The original value, with the indexed bit set. - */ - public static long setBit(long value, int bit) { - Preconditions.checkState(bit >= LSB); - Preconditions.checkState(bit <= LONG_MSB); - long mask = 1L << bit; - return value | mask; - } - - /** - * Clears a bit in an int value. - * - * @param value The bit field to modify. - * @param bit The index of the bit to clear, where bit 0 is the LSB. - * @return The original value, with the indexed bit clear. - */ - public static int clearBit(int value, int bit) { - Preconditions.checkState(bit >= LSB); - Preconditions.checkState(bit <= INT_MSB); - int mask = ~setBit(0, bit); - return value & mask; - } - - /** - * Clears a bit in a long value. - * - * @param value The bit field to modify. - * @param bit The index of the bit to clear, where bit 0 is the LSB. - * @return The original value, with the indexed bit clear. - */ - public static long clearBit(long value, int bit) { - Preconditions.checkState(bit >= LSB); - Preconditions.checkState(bit <= LONG_MSB); - long mask = ~setBit(0L, bit); - return value & mask; - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/common/webassets/bootstrap/BootstrapModule.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/common/webassets/bootstrap/BootstrapModule.java b/commons/src/main/java/org/apache/aurora/common/common/webassets/bootstrap/BootstrapModule.java deleted file mode 100644 index 9cb6f54..0000000 --- a/commons/src/main/java/org/apache/aurora/common/common/webassets/bootstrap/BootstrapModule.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Licensed 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.aurora.common.common.webassets.bootstrap; - -import com.google.common.io.Resources; -import com.google.common.net.MediaType; -import com.google.inject.AbstractModule; - -import org.apache.aurora.common.application.http.Registration; - -/** - * A binding module to register bootstrap HTTP assets. - */ -public final class BootstrapModule extends AbstractModule { - /** - * Enum for available Bootstrap versions to choose from. - */ - public enum BootstrapVersion { - VERSION_2_1_1 ("2.1.1"), - VERSION_2_3_2 ("2.3.2"); - - private final String version; - - BootstrapVersion(String s) { - version = s; - } - } - - private final String version; - - /** - * Default constructor. - */ - public BootstrapModule() { - this(BootstrapVersion.VERSION_2_1_1); - } - - /** - * BootstrapModule Constructor. - * - * @param version supplies the bootstrap version to select. - */ - public BootstrapModule(BootstrapVersion version) { - this.version = version.version; - } - - private void register(String mountPath, String resourcePath, String contentType) { - Registration.registerHttpAsset( - binder(), - "/" + mountPath, - Resources.getResource(BootstrapModule.class, resourcePath), - contentType, - true); - } - - @Override - protected void configure() { - register( - "css/bootstrap-responsive.min.css", - version + "/css/bootstrap-responsive.min.css", - MediaType.CSS_UTF_8.toString()); - register( - "css/bootstrap.min.css", - version + "/css/bootstrap.min.css", - MediaType.CSS_UTF_8.toString()); - register( - "img/glyphicons-halflings-white.png", - version + "/img/glyphicons-halflings-white.png", - MediaType.PNG.toString()); - register( - "img/glyphicons-halflings.png", - version + "/img/glyphicons-halflings.png", - MediaType.PNG.toString()); - register( - "js/bootstrap.min.js", - version + "/js/bootstrap.min.js", - MediaType.JAVASCRIPT_UTF_8.toString()); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/common/webassets/jquery/JQueryModule.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/common/webassets/jquery/JQueryModule.java b/commons/src/main/java/org/apache/aurora/common/common/webassets/jquery/JQueryModule.java deleted file mode 100644 index a8e4524..0000000 --- a/commons/src/main/java/org/apache/aurora/common/common/webassets/jquery/JQueryModule.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Licensed 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.aurora.common.common.webassets.jquery; - -import com.google.common.io.Resources; -import com.google.common.net.MediaType; -import com.google.inject.AbstractModule; - -import org.apache.aurora.common.application.http.Registration; - -/** - * A binding module to register jQuery HTTP assets. - */ -public final class JQueryModule extends AbstractModule { - - @Override - protected void configure() { - Registration.registerHttpAsset( - binder(), - "/js/jquery.min.js", - Resources.getResource(JQueryModule.class, "js/jquery-1.8.2.min.js"), - MediaType.JAVASCRIPT_UTF_8.toString(), - true); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/inject/DefaultProvider.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/inject/DefaultProvider.java b/commons/src/main/java/org/apache/aurora/common/inject/DefaultProvider.java deleted file mode 100644 index 38fbe4d..0000000 --- a/commons/src/main/java/org/apache/aurora/common/inject/DefaultProvider.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * Licensed 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.aurora.common.inject; - -import com.google.common.base.Preconditions; -import com.google.inject.AbstractModule; -import com.google.inject.Binder; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.Provider; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Named; -import com.google.inject.name.Names; - -/** - * Provider that has a default value which can be overridden. - * - * The intended use of this class is: - *
- * Default installer:
- *   bind(DefaultProvider.makeDefaultKey(Runnable.class, "mykey").toInstance(defaultRunnable);
- *   DefaultProvider.bindOrElse(Runnable.class, "mykey", binder());
- *
- * Custom override:
- *     bind(DefaultProvider.makeCustomKey(Runnable.class, "mykey")).toInstance(myCustomRunnable);
- *
- * Injection:
- *     {@literal Inject} Named("myKey") Runnable runnable;
- *
- * 
- * - * @param the type of object this provides - * - * @author William Farner - * @author John Sirois - */ -public class DefaultProvider implements Provider { - private static final String DEFAULT_BINDING_KEY_SUFFIX = "_default"; - private static final String CUSTOM_BINDING_KEY_SUFFIX = "_custom"; - - private final Key defaultProviderKey; - private final Key customProviderKey; - - private Injector injector; - - public DefaultProvider(Key defaultProviderKey, Key customProviderKey) { - this.defaultProviderKey = Preconditions.checkNotNull(defaultProviderKey); - this.customProviderKey = Preconditions.checkNotNull(customProviderKey); - Preconditions.checkArgument(!defaultProviderKey.equals(customProviderKey)); - } - - @Inject - public void setInjector(Injector injector) { - this.injector = injector; - } - - @Override - public T get() { - Preconditions.checkNotNull(injector); - return injector.getBindings().containsKey(customProviderKey) - ? injector.getInstance(customProviderKey) - : injector.getInstance(defaultProviderKey); - } - - /** - * Creates a DefaultProvider and installs a new module to {@code binder}, which will serve as - * an indirection layer for swapping the default binding with a custom one. - * - * @param customBinding The custom binding key. - * @param defaultBinding The default binding key. - * @param exposedBinding The exposed binding key. - * @param binder The binder to install bindings to. - * @param The type of binding to make. - */ - public static void bindOrElse(final Key customBinding, final Key defaultBinding, - final Key exposedBinding, Binder binder) { - Preconditions.checkNotNull(customBinding); - Preconditions.checkNotNull(defaultBinding); - Preconditions.checkNotNull(exposedBinding); - Preconditions.checkArgument(!customBinding.equals(defaultBinding) - && !customBinding.equals(exposedBinding)); - - binder.install(new AbstractModule() { - @Override protected void configure() { - Provider defaultProvider = new DefaultProvider(defaultBinding, customBinding); - requestInjection(defaultProvider); - bind(exposedBinding).toProvider(defaultProvider); - } - }); - } - - /** - * Convenience function for creating and installing a DefaultProvider. This will use internal - * suffixes to create names for the custom and default bindings. When bound this way, callers - * should use one of the functions such as {@link #makeDefaultBindingKey(String)} to set default - * and custom bindings. - * - * @param type The type of object to bind. - * @param exposedKey The exposed key. - * @param binder The binder to install to. - * @param The type of binding to make. - */ - public static void bindOrElse(TypeLiteral type, String exposedKey, Binder binder) { - bindOrElse(Key.get(type, Names.named(makeCustomBindingKey(exposedKey))), - Key.get(type, Names.named(makeDefaultBindingKey(exposedKey))), - Key.get(type, Names.named(exposedKey)), - binder); - } - - /** - * Convenience method for calls to {@link #bindOrElse(TypeLiteral, String, Binder)}, that are not - * binding a parameterized type. - * - * @param type The class of the object to bind. - * @param exposedKey The exposed key. - * @param binder The binder to install to. - * @param The type of binding to make. - */ - public static void bindOrElse(Class type, String exposedKey, Binder binder) { - bindOrElse(TypeLiteral.get(type), exposedKey, binder); - } - - public static String makeDefaultBindingKey(String rootKey) { - return rootKey + DEFAULT_BINDING_KEY_SUFFIX; - } - - public static Named makeDefaultBindingName(String rootKey) { - return Names.named(makeDefaultBindingKey(rootKey)); - } - - public static Key makeDefaultKey(TypeLiteral type, String rootKey) { - return Key.get(type, makeDefaultBindingName(rootKey)); - } - - public static Key makeDefaultKey(Class type, String rootKey) { - return makeDefaultKey(TypeLiteral.get(type), rootKey); - } - - public static String makeCustomBindingKey(String rootKey) { - return rootKey + CUSTOM_BINDING_KEY_SUFFIX; - } - - public static Named makeCustomBindingName(String rootKey) { - return Names.named(makeCustomBindingKey(rootKey)); - } - - public static Key makeCustomKey(Class type, String rootKey) { - return Key.get(type, makeCustomBindingName(rootKey)); - } - - public static Key makeCustomKey(TypeLiteral type, String rootKey) { - return Key.get(type, makeCustomBindingName(rootKey)); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/356eeac9/commons/src/main/java/org/apache/aurora/common/inject/ProviderMethodModule.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/inject/ProviderMethodModule.java b/commons/src/main/java/org/apache/aurora/common/inject/ProviderMethodModule.java deleted file mode 100644 index 7543ff1..0000000 --- a/commons/src/main/java/org/apache/aurora/common/inject/ProviderMethodModule.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed 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.aurora.common.inject; - -import com.google.inject.AbstractModule; - -/** - * A convenience base class for modules that do all their binding via provider methods. - * - * @author John Sirois - */ -public abstract class ProviderMethodModule extends AbstractModule { - - /** - * Does no binding; subclasses should implement provider methods. - */ - @Override - protected final void configure() { - // noop - } -}