io.datakernel.di.impl.AbstractUnsyncCompiledBinding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datakernel-di Show documentation
Show all versions of datakernel-di Show documentation
DataKernel has an extremely lightweight DI with ground-breaking design principles.
It supports nested scopes, singletons, object factories, modules and plugins which
allow to transform graph of dependencies at startup time without any reflection.
The newest version!
package io.datakernel.di.impl;
import java.util.concurrent.atomic.AtomicReferenceArray;
public abstract class AbstractUnsyncCompiledBinding implements CompiledBinding {
protected final int scope;
protected final int index;
protected AbstractUnsyncCompiledBinding(int scope, int index) {
this.scope = scope;
this.index = index;
}
@SuppressWarnings("unchecked")
@Override
public final R getInstance(AtomicReferenceArray[] scopedInstances, int synchronizedScope) {
AtomicReferenceArray array = scopedInstances[scope];
R instance = (R) array.get(index);
if (instance != null) return instance;
instance = doCreateInstance(scopedInstances, synchronizedScope);
array.lazySet(index, instance);
return instance;
}
protected abstract R doCreateInstance(AtomicReferenceArray[] scopedInstances, int synchronizedScope);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy