diff --git a/community/common/src/main/java/org/neo4j/function/Suppliers.java b/community/common/src/main/java/org/neo4j/function/Suppliers.java index 79b2f08ccc45c..803a91eb4d603 100644 --- a/community/common/src/main/java/org/neo4j/function/Suppliers.java +++ b/community/common/src/main/java/org/neo4j/function/Suppliers.java @@ -54,9 +54,9 @@ public static Supplier singleton( final T instance ) * @param The object type * @return A {@link Supplier} returning the specified object instance */ - public static Supplier lazySingleton( final Supplier supplier ) + public static Lazy lazySingleton( final Supplier supplier ) { - return new Supplier() + return new Lazy() { volatile T instance; @@ -165,4 +165,8 @@ public String toString() return String.format( "%s on %s", predicate, input ); } } + + public interface Lazy extends Supplier + { + }; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorProgressor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorProgressor.java index aaeeb8f0bc3bc..82312fb7a739b 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorProgressor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorProgressor.java @@ -22,7 +22,7 @@ import org.neo4j.internal.kernel.api.LabelSet; import org.neo4j.values.storable.Value; -public interface IndexCursorProgressor +public interface IndexCursorProgressor extends AutoCloseable { boolean next(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Lazy.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Lazy.java deleted file mode 100644 index 0ccaa7375d9f7..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Lazy.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.impl.newapi; - -import java.util.function.Supplier; - -import static java.util.Objects.requireNonNull; - -/** - * Encapsulates a double checked locking pattern for lazy initialization. - * TODO: move this to some util place or something. - */ -public final class Lazy -{ - private T cache; - private volatile Object state; - - public Lazy( Supplier supplier ) - { - this.state = requireNonNull( supplier, "supplier" ); - } - - public T get() - { - T value = cache; - if ( value == null ) - { - Object s = state; - if ( s instanceof Supplier ) - { - synchronized ( this ) - { - s = state; - if ( s instanceof Supplier ) - { - @SuppressWarnings( "unchecked" ) - Supplier supplier = (Supplier) s; - s = supplier.get(); - } - } - } - @SuppressWarnings( "unchecked" ) - T val = (T) s; - cache = value = val; - } - return value; - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Store.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Store.java index 77be982c4bd22..6fe96b4308827 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Store.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Store.java @@ -23,6 +23,8 @@ import java.nio.ByteOrder; import java.util.function.Supplier; +import org.neo4j.function.Suppliers; +import org.neo4j.function.Suppliers.Lazy; import org.neo4j.internal.kernel.api.Token; import org.neo4j.io.pagecache.PageCursor; import org.neo4j.kernel.api.ExplicitIndex; @@ -80,7 +82,7 @@ class Store extends Read implements Token this.relationshipStore = stores.getRelationshipStore(); this.groupStore = stores.getRelationshipGroupStore(); this.propertyStore = stores.getPropertyStore(); - this.explicitIndexes = new Lazy<>( explicitIndexes ); + this.explicitIndexes = Suppliers.lazySingleton( explicitIndexes ); } @Override