Skip to content

Commit

Permalink
Bug 571190 build the solution on Framework services host
Browse files Browse the repository at this point in the history
Substitute artificial inheritance with delegation

Signed-off-by: eparovyshnaya <[email protected]>
  • Loading branch information
eparovyshnaya committed Feb 15, 2021
1 parent f242aee commit 8910c42
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* 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.base.registry;

import java.util.Collection;
import java.util.Collections;

import org.eclipse.passage.lic.internal.api.registry.Registry;
import org.eclipse.passage.lic.internal.api.registry.Service;
import org.eclipse.passage.lic.internal.api.registry.ServiceId;

/**
* Begets new instance of a service for each {@code service} request.
*/
public abstract class ProducingRegistry<I extends ServiceId, S extends Service<I>> implements Registry<I, S> {

@Override
public boolean hasService(I id) {
return true;
}

@Override
public S service(I id) {
return brandNew(id);
}

@Override
public Collection<S> services() {
return Collections.emptyList();
}

protected abstract S brandNew(I id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@
import org.eclipse.passage.lic.internal.api.Framework;
import org.eclipse.passage.lic.internal.api.inspection.RuntimeEnvironment;

public final class Environments extends SuppliedFrameworkAware implements Supplier<Collection<RuntimeEnvironment>> {
public final class Environments implements Supplier<Collection<RuntimeEnvironment>> {

private final FrameworkAware<?> delegate;

public Environments() {
this(new SuppliedFrameworkAware());
}

public Environments(FrameworkAware<?> delegate) {
this.delegate = delegate;
}

@Override
public Collection<RuntimeEnvironment> get() {
return withFramework(this::environments).orElseGet(Collections::emptySet);
return delegate.withFramework(this::environments).orElseGet(Collections::emptySet);
}

private Collection<RuntimeEnvironment> environments(Framework framework) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,36 @@
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.internal.base.access.Access;

public final class EquinoxPassage extends SuppliedFrameworkAware implements Passage {
public final class EquinoxPassage implements Passage {

private final FrameworkAware<?> delegate;

public EquinoxPassage() {
this(new SuppliedFrameworkAware());
}

public EquinoxPassage(FrameworkAware<?> delegate) {
this.delegate = delegate;
}

@Override
public boolean canUse(String feature) {
return withFramework(framework -> new Access(framework).canUse(feature)).orElse(Boolean.FALSE);
return delegate.withFramework(framework -> new Access(framework).canUse(feature)).orElse(Boolean.FALSE);
}

@Override
public ServiceInvocationResult<GrantLockAttempt> acquireLicense(String feature) {
return withFrameworkService(framework -> new Access(framework).acquire(feature));
return delegate.withFrameworkService(framework -> new Access(framework).acquire(feature));
}

@Override
public ServiceInvocationResult<Boolean> releaseLicense(GrantLockAttempt lock) {
return withFrameworkService(framework -> new Access(framework).release(lock));
return delegate.withFrameworkService(framework -> new Access(framework).release(lock));
}

@Override
public ServiceInvocationResult<LicensedProduct> product() {
return withFrameworkService(framework -> new BaseServiceInvocationResult<>(framework.product()));
return delegate.withFrameworkService(framework -> new BaseServiceInvocationResult<>(framework.product()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@
import org.eclipse.passage.lic.internal.api.restrictions.ExaminationCertificate;
import org.eclipse.passage.lic.internal.base.access.Access;

public final class EquinoxPassageLicenseCoverage extends SuppliedFrameworkAware implements PassageLicenseCoverage {
public final class EquinoxPassageLicenseCoverage implements PassageLicenseCoverage {

private final FrameworkAware<?> delegate;

public EquinoxPassageLicenseCoverage() {
this(new SuppliedFrameworkAware());
}

public EquinoxPassageLicenseCoverage(FrameworkAware<?> delegate) {
this.delegate = delegate;
}

@Override
public ServiceInvocationResult<ExaminationCertificate> assess() {
return withFrameworkService(framework -> new Access(framework).assess());
return delegate.withFrameworkService(framework -> new Access(framework).assess());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected FrameworkAware(Class<S> cls, Function<S, Optional<Framework>> construc
this.constructor = constructor;
}

protected final <T> ServiceInvocationResult<T> withFrameworkService(
public final <T> ServiceInvocationResult<T> withFrameworkService(
Function<Framework, ServiceInvocationResult<T>> invoke) {
return withReference(//
reference -> //
Expand All @@ -65,7 +65,7 @@ protected final <T> ServiceInvocationResult<T> withFrameworkService(
this::severalFrameworks);
}

protected final <T> Optional<T> withFramework(Function<Framework, T> invoke) {
public final <T> Optional<T> withFramework(Function<Framework, T> invoke) {
return withReference(//
reference -> //
Optional.ofNullable(context.getService(reference))//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@
import org.eclipse.passage.lic.internal.api.conditions.mining.LicenseReadingService;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;

public final class LicenseReadingServiceRequest extends SuppliedFrameworkAware
implements Supplier<ServiceInvocationResult<LicenseReadingService>> {
public final class LicenseReadingServiceRequest implements Supplier<ServiceInvocationResult<LicenseReadingService>> {

private final FrameworkAware<?> delegate;

public LicenseReadingServiceRequest() {
this(new SuppliedFrameworkAware());
}

public LicenseReadingServiceRequest(FrameworkAware<?> delegate) {
this.delegate = delegate;
}

@Override
public ServiceInvocationResult<LicenseReadingService> get() {
return withFrameworkService(framework -> new BaseServiceInvocationResult<>(framework.licenseReader()));
return delegate.withFrameworkService(framework -> new BaseServiceInvocationResult<>(framework.licenseReader()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* Use {@code withFrameworkService} to implement client level secondary services
* or {@code withFramework} to retrieve parts of configuration directly.
*/
public abstract class SuppliedFrameworkAware extends FrameworkAware<FrameworkSupplier> {
public final class SuppliedFrameworkAware extends FrameworkAware<FrameworkSupplier> {

protected SuppliedFrameworkAware() {
public SuppliedFrameworkAware() {
super(FrameworkSupplier.class, FrameworkSupplier::get);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@
import org.eclipse.passage.lic.internal.api.Framework;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.io.StreamCodec;
import org.eclipse.passage.lic.internal.equinox.FrameworkAware;
import org.eclipse.passage.lic.internal.equinox.SuppliedFrameworkAware;

@SuppressWarnings("restriction")
public final class CodecSupplier extends SuppliedFrameworkAware implements Supplier<Optional<StreamCodec>> {
public final class CodecSupplier implements Supplier<Optional<StreamCodec>> {

private final LicensedProduct product;
private final FrameworkAware<?> delegate;

public CodecSupplier(LicensedProduct product) {
this(product, new SuppliedFrameworkAware());
}

public CodecSupplier(LicensedProduct product, FrameworkAware<?> delegate) {
this.product = product;
this.delegate = delegate;
}

@Override
public Optional<StreamCodec> get() {
return withFramework(this::codec);
return delegate.withFramework(this::codec);
}

private StreamCodec codec(Framework framework) {
Expand Down

0 comments on commit 8910c42

Please sign in to comment.