@@ -0,0 +1,2738 @@
+/*%0A * Copyright 2016 Timothy Brooks%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A *%0A */%0A%0Apackage net.uncontended.precipice.samples;%0A%0Aimport net.uncontended.precipice.Failable;%0Aimport net.uncontended.precipice.GuardRail;%0Aimport net.uncontended.precipice.GuardRailBuilder;%0Aimport net.uncontended.precipice.concurrent.CompletionContext;%0Aimport net.uncontended.precipice.factories.CompletableFactory;%0Aimport net.uncontended.precipice.metrics.CountMetrics;%0Aimport net.uncontended.precipice.metrics.MetricCounter;%0Aimport net.uncontended.precipice.semaphore.UnlimitedSemaphore;%0A%0Aimport java.io.InputStream;%0Aimport java.net.URL;%0Aimport java.net.URLConnection;%0A%0Apublic class GuardRailWithFactory %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        CountMetrics%3CResult%3E resultMetrics = new MetricCounter%3C%3E(Result.class);%0A        CountMetrics%3CRejectedReason%3E rejectedMetrics = new MetricCounter%3C%3E(RejectedReason.class);%0A%0A        GuardRailBuilder%3CResult, RejectedReason%3E builder = new GuardRailBuilder%3C%3E();%0A        builder.name(%22Example%22)%0A                .resultMetrics(resultMetrics)%0A                .rejectedMetrics(rejectedMetrics)%0A                .addBackPressure(new UnlimitedSemaphore%3C%3E(RejectedReason.MAX_CONCURRENCY));%0A%0A        GuardRail%3CResult, RejectedReason%3E guardRail = builder.build();%0A%0A        CompletionContext%3CResult, String%3E completable = CompletableFactory.acquirePermitsAndGetCompletable(guardRail, 1L);%0A%0A        try %7B%0A            URL url = new URL(%22http://www.google.com%22);%0A            URLConnection urlConnection = url.openConnection();%0A            completable.complete(Result.SUCCESS, readToString(urlConnection.getInputStream()));%0A        %7D catch (Exception ex) %7B%0A            completable.completeExceptionally(Result.EXCEPTION, ex);%0A        %7D%0A    %7D%0A%0A    private static String readToString(InputStream inputStream) %7B%0A        return %22Http Response%22;%0A    %7D%0A%0A    public enum Result implements Failable %7B%0A        SUCCESS,%0A        EXCEPTION;%0A%0A        @Override%0A        public boolean isFailure() %7B%0A            return this == EXCEPTION;%0A        %7D%0A%0A        @Override%0A        public boolean isSuccess() %7B%0A            return this == SUCCESS;%0A        %7D%0A    %7D%0A%0A    public enum RejectedReason %7B%0A        MAX_CONCURRENCY%0A    %7D%0A%7D%0A

Add example with usage of factory