All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.datakernel.di.impl.AbstractRootCompiledBinding Maven / Gradle / Ivy

Go to download

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 AbstractRootCompiledBinding implements CompiledBinding {
	private volatile R instance;
	protected final int index;

	protected AbstractRootCompiledBinding(int index) {
		this.index = index;
	}

	@SuppressWarnings("unchecked")
	@Override
	public final R getInstance(AtomicReferenceArray[] scopedInstances, int synchronizedScope) {
		R localInstance = instance;
		if (localInstance != null) return localInstance;
		synchronized (this) {
			localInstance = instance;
			if (localInstance != null) return localInstance;
			localInstance = (R) scopedInstances[0].get(index);
			if (localInstance != null) return instance = localInstance;
			instance = doCreateInstance(scopedInstances, synchronizedScope);
		}
		scopedInstances[0].lazySet(index, instance);
		return instance;
	}

	protected abstract R doCreateInstance(AtomicReferenceArray[] scopedInstances, int synchronizedScope);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy