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

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

package io.datakernel.di.impl;

import io.datakernel.di.core.Key;

import java.util.concurrent.atomic.AtomicReferenceArray;

public final class PlainCompiler implements BindingCompiler {
	private final Key to;

	public PlainCompiler(Key to) {
		this.to = to;
	}

	public Key getDestination() {
		return to;
	}

	@Override
	public CompiledBinding compile(CompiledBindingLocator compiledBindings, boolean threadsafe, int scope, int index) {
		return new CompiledBinding() {
			final CompiledBinding compiledBinding = compiledBindings.get(to);

			@SuppressWarnings("unchecked")
			@Override
			public R getInstance(AtomicReferenceArray[] scopedInstances, int synchronizedScope) {
				R instance = compiledBinding.getInstance(scopedInstances, synchronizedScope);
				scopedInstances[scope].lazySet(index, instance);
				return instance;
			}

			@Override
			public R createInstance(AtomicReferenceArray[] scopedInstances, int synchronizedScope) {
				return compiledBinding.createInstance(scopedInstances, synchronizedScope);
			}
		};
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy