diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/ChoreDraft.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/ChoreDraft.java index af3549ffc..d3192b1b9 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/ChoreDraft.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/ChoreDraft.java @@ -20,6 +20,7 @@ import org.eclipse.passage.lic.internal.api.EvaluationInstructions; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.net.handle.Chore; +import org.eclipse.passage.lic.internal.net.handle.Failure; import org.eclipse.passage.lic.internal.net.handle.NetResponse; abstract class ChoreDraft implements Chore { diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/FloatingCycle.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/FloatingCycle.java index 1d1e1bd22..ea1815f6c 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/FloatingCycle.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/FloatingCycle.java @@ -12,54 +12,21 @@ *******************************************************************************/ package org.eclipse.passage.lbc.internal.base; -import java.util.HashMap; import java.util.Map; import java.util.function.Function; import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.internal.api.PassageAction; -import org.eclipse.passage.lic.internal.net.LicensingAction; import org.eclipse.passage.lic.internal.net.handle.Chore; -import org.eclipse.passage.lic.internal.net.handle.Chores; -import org.eclipse.passage.lic.internal.net.handle.NetResponse; +import org.eclipse.passage.lic.internal.net.handle.NetServices; -final class FloatingCycle implements Chores { +final class FloatingCycle extends NetServices { - private final Map> chores = new HashMap<>(); - - FloatingCycle() { + @Override + protected void defineChores(Map> chores) { chores.put(new PassageAction.Mine(), Mine::new); chores.put(new PassageAction.Acquire(), Acquire::new); chores.put(new PassageAction.Release(), Release::new); } - @Override - public NetResponse workOut(RawRequest request) { - LicensingAction action = action(request); - return chores// - .getOrDefault(// - action.get().get(), // - unknown -> new Failing(action))// - .apply(request)// - .getDone(); - } - - private LicensingAction action(RawRequest request) { - return new LicensingAction(key -> new PassageAction.Of(String.valueOf(request.parameter(key)))); - } - - private final class Failing implements Chore { - private final LicensingAction actual; - - Failing(LicensingAction actual) { - this.actual = actual; - } - - @Override - public NetResponse getDone() { - return new Failure.BadRequestUnknownAction(actual.get().get().name()); - } - - } - } diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/Acquisition.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/Acquisition.java index 8bf688250..1e08c8546 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/Acquisition.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/Acquisition.java @@ -20,17 +20,16 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.passage.lbc.internal.base.EObjectTransfer; -import org.eclipse.passage.lbc.internal.base.Failure; -import org.eclipse.passage.lbc.internal.base.Failure.NoGrantsAvailable; -import org.eclipse.passage.lbc.internal.base.api.Grants; import org.eclipse.passage.lbc.internal.base.PlainSuceess; import org.eclipse.passage.lbc.internal.base.ProductUserRequest; +import org.eclipse.passage.lbc.internal.base.api.Grants; import org.eclipse.passage.lic.floating.model.api.GrantAcqisition; import org.eclipse.passage.lic.floating.model.meta.FloatingPackage; -import org.eclipse.passage.lic.internal.api.PassageAction; import org.eclipse.passage.lic.internal.api.LicensingException; +import org.eclipse.passage.lic.internal.api.PassageAction; import org.eclipse.passage.lic.internal.base.FeatureIdentifier; import org.eclipse.passage.lic.internal.emf.EObjectFromBytes; +import org.eclipse.passage.lic.internal.net.handle.Failure; import org.eclipse.passage.lic.internal.net.handle.NetResponse; public final class Acquisition { @@ -70,7 +69,7 @@ public NetResponse returnBack() throws LicensingException { } boolean released = grants().release(data.product().get(), acquisition); if (!released) { - return new Failure.NotReleased(data.product().get(), acquisition); + return new NotReleased(data.product().get(), acquisition); } return new PlainSuceess(); @@ -93,8 +92,8 @@ private Grants grants() { return data.raw().state().grants(); } - private NoGrantsAvailable noGrants(String feature) { - return new Failure.NoGrantsAvailable(data.product().get(), feature); + private Failure noGrants(String feature) { + return new NoGrantsAvailable(data.product().get(), feature); } } diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/NoGrantsAvailable.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/NoGrantsAvailable.java new file mode 100644 index 000000000..b3edd4ea4 --- /dev/null +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/NoGrantsAvailable.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2020, 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lbc.internal.base.acquire; + +import org.eclipse.passage.lic.internal.api.LicensedProduct; +import org.eclipse.passage.lic.internal.net.handle.Failure; + +/** + * Public only for test purposes + */ +public final class NoGrantsAvailable extends Failure { + + public NoGrantsAvailable(LicensedProduct product, String feature) { + super(611, String.format("No license grants available for feature %s of product %s", feature, product)); //$NON-NLS-1$ + } + +} \ No newline at end of file diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/NotReleased.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/NotReleased.java new file mode 100644 index 000000000..b0a5ab596 --- /dev/null +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/acquire/NotReleased.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2020, 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lbc.internal.base.acquire; + +import org.eclipse.passage.lic.floating.model.api.GrantAcqisition; +import org.eclipse.passage.lic.internal.api.LicensedProduct; +import org.eclipse.passage.lic.internal.net.handle.Failure; + +/** + * Public only for test purposes + */ +public final class NotReleased extends Failure { + + public NotReleased(LicensedProduct product, GrantAcqisition acqisition) { + super(612, String.format("Failed to release grant %s acquisition for feature %s of product %s", //$NON-NLS-1$ + acqisition.getGrant(), acqisition.getFeature(), product)); + } + +} \ No newline at end of file diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/Conditions.java b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/Conditions.java index 227dad067..ce83dc65c 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/Conditions.java +++ b/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/mine/Conditions.java @@ -20,11 +20,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.passage.lbc.internal.base.EObjectTransfer; -import org.eclipse.passage.lbc.internal.base.Failure; import org.eclipse.passage.lbc.internal.base.ProductUserRequest; import org.eclipse.passage.lic.floating.FloatingFileExtensions; -import org.eclipse.passage.lic.internal.api.PassageAction; import org.eclipse.passage.lic.internal.api.LicensedProduct; +import org.eclipse.passage.lic.internal.api.PassageAction; import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; import org.eclipse.passage.lic.internal.api.conditions.ConditionMiningTarget; import org.eclipse.passage.lic.internal.api.conditions.ConditionPack; @@ -34,6 +33,7 @@ import org.eclipse.passage.lic.internal.base.io.LicensingFolder; import org.eclipse.passage.lic.internal.base.io.PathFromLicensedProduct; import org.eclipse.passage.lic.internal.base.io.UserHomePath; +import org.eclipse.passage.lic.internal.net.handle.Failure; import org.eclipse.passage.lic.internal.net.handle.NetResponse; import org.eclipse.passage.lic.licenses.model.api.LicensePack; diff --git a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/Failure.java b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/Failure.java similarity index 77% rename from bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/Failure.java rename to bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/Failure.java index 4da7333dc..1c5d2234e 100644 --- a/bundles/org.eclipse.passage.lbc.base/src/org/eclipse/passage/lbc/internal/base/Failure.java +++ b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/Failure.java @@ -10,12 +10,9 @@ * Contributors: * ArSysOp - initial API and implementation *******************************************************************************/ -package org.eclipse.passage.lbc.internal.base; +package org.eclipse.passage.lic.internal.net.handle; -import org.eclipse.passage.lic.floating.model.api.GrantAcqisition; -import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType; -import org.eclipse.passage.lic.internal.net.handle.NetResponse; public abstract class Failure implements NetResponse { @@ -123,20 +120,4 @@ public OperationFailed(String name, String details) { } - public static final class NoGrantsAvailable extends Failure { - - public NoGrantsAvailable(LicensedProduct product, String feature) { - super(611, String.format("No license grants available for feature %s of product %s", feature, product)); //$NON-NLS-1$ - } - - } - - public static final class NotReleased extends Failure { - - public NotReleased(LicensedProduct product, GrantAcqisition acqisition) { - super(612, String.format("Failed to release grant %s acquisition for feature %s of product %s", //$NON-NLS-1$ - acqisition.getGrant(), acqisition.getFeature(), product)); - } - - } } diff --git a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/NetServices.java b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/NetServices.java new file mode 100644 index 000000000..dd94aefa2 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/handle/NetServices.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lic.internal.net.handle; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +import org.eclipse.passage.lic.internal.api.PassageAction; +import org.eclipse.passage.lic.internal.net.LicensingAction; + +public abstract class NetServices implements Chores { + + private final Map> chores = new HashMap<>(); + + protected NetServices() { + defineChores(chores); + } + + protected abstract void defineChores(Map> services); + + @Override + public NetResponse workOut(R request) { + LicensingAction action = action(request); + return chores// + .getOrDefault(// + action.get().get(), // + unknown -> new Failing(action))// + .apply(request)// + .getDone(); + } + + private LicensingAction action(R request) { + return new LicensingAction(key -> new PassageAction.Of(String.valueOf(request.parameter(key)))); + } + + private final class Failing implements Chore { + + private final LicensingAction actual; + + Failing(LicensingAction actual) { + this.actual = actual; + } + + @Override + public NetResponse getDone() { + return new Failure.BadRequestUnknownAction(actual.get().get().name()); + } + + } +} diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/BaseFlotingRequestHandledTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/BaseFlotingRequestHandledTest.java index c3b155207..f1025d0df 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/BaseFlotingRequestHandledTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/BaseFlotingRequestHandledTest.java @@ -17,9 +17,9 @@ import static org.junit.Assert.assertTrue; import org.eclipse.passage.lbc.internal.base.BaseFlotingRequestHandled; -import org.eclipse.passage.lbc.internal.base.Failure; import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.internal.api.PassageAction; +import org.eclipse.passage.lic.internal.net.handle.Failure; import org.eclipse.passage.lic.internal.net.handle.NetResponse; import org.junit.Test; diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveAcquiringTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveAcquiringTest.java index 384f11773..c26bf8dfd 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveAcquiringTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveAcquiringTest.java @@ -25,9 +25,9 @@ import java.util.stream.IntStream; import org.eclipse.passage.lbc.internal.base.EagerFloatingState; -import org.eclipse.passage.lbc.internal.base.Failure; import org.eclipse.passage.lbc.internal.base.ProductUserRequest; import org.eclipse.passage.lbc.internal.base.acquire.Acquisition; +import org.eclipse.passage.lbc.internal.base.acquire.NoGrantsAvailable; import org.eclipse.passage.lbc.internal.base.api.FloatingState; import org.eclipse.passage.lic.internal.api.LicensingException; import org.eclipse.passage.lic.internal.api.PassageAction; @@ -63,7 +63,7 @@ private Set> runConcurrentAcquireRequest(int amount) throws private int[] countGainsAndLates(Set> futures) throws InterruptedException { int gains = 0; int lates = 0; - int none = new Failure.NoGrantsAvailable(data.product(), data.feature()).error().code(); + int none = new NoGrantsAvailable(data.product(), data.feature()).error().code(); for (Future future : futures) { NetResponse response; try { diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveReleaseTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveReleaseTest.java index 0df94775b..e0a4f0e64 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveReleaseTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ExtensiveReleaseTest.java @@ -30,9 +30,9 @@ import java.util.stream.IntStream; import org.eclipse.passage.lbc.internal.base.EagerFloatingState; -import org.eclipse.passage.lbc.internal.base.Failure; import org.eclipse.passage.lbc.internal.base.ProductUserRequest; import org.eclipse.passage.lbc.internal.base.acquire.Acquisition; +import org.eclipse.passage.lbc.internal.base.acquire.NoGrantsAvailable; import org.eclipse.passage.lbc.internal.base.api.FloatingState; import org.eclipse.passage.lic.floating.model.api.GrantAcqisition; import org.eclipse.passage.lic.floating.model.meta.FloatingPackage; @@ -45,7 +45,7 @@ public final class ExtensiveReleaseTest { private final TestData data = new TestData(); - private final int noGrants = new Failure.NoGrantsAvailable(data.product(), data.feature()).error().code(); + private final int noGrants = new NoGrantsAvailable(data.product(), data.feature()).error().code(); @Test public void concurrentAcquireAndRelease() throws InterruptedException, ExecutionException { diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FloatingCycleActionsDryRunTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FloatingCycleActionsDryRunTest.java index 816cc7dab..af67d7709 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FloatingCycleActionsDryRunTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/FloatingCycleActionsDryRunTest.java @@ -22,7 +22,8 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.passage.lbc.internal.base.BaseFlotingRequestHandled; -import org.eclipse.passage.lbc.internal.base.Failure; +import org.eclipse.passage.lbc.internal.base.acquire.NoGrantsAvailable; +import org.eclipse.passage.lbc.internal.base.acquire.NotReleased; import org.eclipse.passage.lbc.internal.base.api.RawRequest; import org.eclipse.passage.lic.floating.model.api.GrantAcqisition; import org.eclipse.passage.lic.floating.model.meta.FloatingFactory; @@ -50,7 +51,7 @@ public void mineNothing() throws LicensingException, IOException { public void acquireNothing() throws LicensingException, IOException { NetResponse response = new BaseFlotingRequestHandled(request(new PassageAction.Acquire())).get(); assertTrue(response.failed()); - assertEquals(new Failure.NoGrantsAvailable(product, feature).error().code(), response.error().code()); + assertEquals(new NoGrantsAvailable(product, feature).error().code(), response.error().code()); } @Test @@ -59,7 +60,7 @@ public void releaseInVain() throws LicensingException, IOException { NetResponse response = new BaseFlotingRequestHandled(// request(new PassageAction.Release(), Optional.of(acqisition))).get(); assertTrue(response.failed()); - assertEquals(new Failure.NotReleased(product, acqisition).error().code(), response.error().code()); + assertEquals(new NotReleased(product, acqisition).error().code(), response.error().code()); } private RawRequest request(PassageAction action) throws LicensingException { diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/MineTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/MineTest.java index b1b739e58..9a16ca4ee 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/MineTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/MineTest.java @@ -18,7 +18,6 @@ import java.util.Arrays; import org.eclipse.passage.lbc.internal.base.BaseFlotingRequestHandled; -import org.eclipse.passage.lbc.internal.base.Failure; import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationExpression; import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationType; import org.eclipse.passage.lic.internal.api.EvaluationType; @@ -26,6 +25,7 @@ import org.eclipse.passage.lic.internal.base.ProductIdentifier; import org.eclipse.passage.lic.internal.base.ProductVersion; import org.eclipse.passage.lic.internal.base.StringNamedData; +import org.eclipse.passage.lic.internal.net.handle.Failure; import org.eclipse.passage.lic.internal.net.handle.NetResponse; import org.junit.Test; diff --git a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ServerAuthenticationTest.java b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ServerAuthenticationTest.java index dbab6a919..2c58d844a 100644 --- a/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ServerAuthenticationTest.java +++ b/tests/org.eclipse.passage.lbc.base.tests/src/org/eclipse/passage/lbc/base/tests/ServerAuthenticationTest.java @@ -16,12 +16,12 @@ import static org.junit.Assert.assertTrue; import org.eclipse.passage.lbc.internal.base.BaseFlotingRequestHandled; -import org.eclipse.passage.lbc.internal.base.Failure; import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationExpression; import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationType; import org.eclipse.passage.lic.internal.api.EvaluationType; import org.eclipse.passage.lic.internal.api.PassageAction; import org.eclipse.passage.lic.internal.base.StringNamedData; +import org.eclipse.passage.lic.internal.net.handle.Failure; import org.eclipse.passage.lic.internal.net.handle.NetResponse; import org.junit.Test;