From b974d840e4ce71452ed40d316621a881fb3e5ce3 Mon Sep 17 00:00:00 2001 From: Davide Grohmann Date: Tue, 8 Dec 2015 16:52:44 +0100 Subject: [PATCH] Replace Provider with Supplier --- .../org/neo4j/helpers/ConcurrentTransfer.java | 12 +------ .../main/java/org/neo4j/helpers/Provider.java | 34 ------------------- .../applytx/ApplyTransactionsCommand.java | 10 +++--- .../tools/applytx/DatabaseRebuildTool.java | 20 ++--------- .../tools/applytx/DumpRecordsCommand.java | 8 ++--- 5 files changed, 13 insertions(+), 71 deletions(-) delete mode 100644 community/kernel/src/main/java/org/neo4j/helpers/Provider.java diff --git a/community/kernel/src/main/java/org/neo4j/helpers/ConcurrentTransfer.java b/community/kernel/src/main/java/org/neo4j/helpers/ConcurrentTransfer.java index 29665af1ba747..ed23b4901dc9e 100644 --- a/community/kernel/src/main/java/org/neo4j/helpers/ConcurrentTransfer.java +++ b/community/kernel/src/main/java/org/neo4j/helpers/ConcurrentTransfer.java @@ -28,7 +28,7 @@ * Abstracts a meeting point between two threads, where a reference can change hands. It is essentially * a latch where a reference to a value can be set while a thread waits on it. */ -public class ConcurrentTransfer implements Consumer, Provider, Supplier +public class ConcurrentTransfer implements Consumer, Supplier { private final CountDownLatch latch = new CountDownLatch( 1 ); private TYPE value; @@ -40,16 +40,6 @@ public void accept( TYPE value ) latch.countDown(); } - /** - * @deprecated use {@link #get()} instead - */ - @Deprecated - @Override - public TYPE instance() - { - return get(); - } - @Override public TYPE get() { diff --git a/community/kernel/src/main/java/org/neo4j/helpers/Provider.java b/community/kernel/src/main/java/org/neo4j/helpers/Provider.java deleted file mode 100644 index 6b9754e783ad5..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/helpers/Provider.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2002-2015 "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.helpers; - -/** - * Similar to a {@link Factory factory}, but with a different contract. Implementors of this interface do not have to - * create a new instance for every invocation, but are free to return the same instance as they please. How the - * the specific semantics work is up to the implementor. - * - * @param the type of the provider - * @deprecated Use {@link org.neo4j.function.Supplier} instead - */ -@Deprecated -public interface Provider -{ - TYPE instance(); -} diff --git a/tools/src/main/java/org/neo4j/tools/applytx/ApplyTransactionsCommand.java b/tools/src/main/java/org/neo4j/tools/applytx/ApplyTransactionsCommand.java index d13d5aae9e96b..82c613600c4ef 100644 --- a/tools/src/main/java/org/neo4j/tools/applytx/ApplyTransactionsCommand.java +++ b/tools/src/main/java/org/neo4j/tools/applytx/ApplyTransactionsCommand.java @@ -22,11 +22,11 @@ import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.util.function.Supplier; import org.neo4j.graphdb.DependencyResolver; import org.neo4j.helpers.Args; import org.neo4j.helpers.ArrayUtil; -import org.neo4j.helpers.Provider; import org.neo4j.helpers.progress.ProgressListener; import org.neo4j.io.fs.DefaultFileSystemAbstraction; import org.neo4j.io.pagecache.PageCache; @@ -57,9 +57,9 @@ public class ApplyTransactionsCommand extends ArgsCommand { private final File from; - private final Provider to; + private final Supplier to; - public ApplyTransactionsCommand( File from, Provider to ) + public ApplyTransactionsCommand( File from, Supplier to ) { this.from = from; this.to = to; @@ -68,7 +68,7 @@ public ApplyTransactionsCommand( File from, Provider to ) @Override protected void run( Args args, PrintStream out ) throws Exception { - TransactionIdStore txIdStore = to.instance().getDependencyResolver().resolveDependency( + TransactionIdStore txIdStore = to.get().getDependencyResolver().resolveDependency( TransactionIdStore.class ); long fromTx = txIdStore.getLastCommittedTransaction().transactionId(); long toTx; @@ -91,7 +91,7 @@ else if ( whereTo.equals( "last" ) ) toTx = Long.parseLong( whereTo ); } - long lastApplied = applyTransactions( from, to.instance(), fromTx, toTx, out ); + long lastApplied = applyTransactions( from, to.get(), fromTx, toTx, out ); out.println( "Applied transactions up to and including " + lastApplied ); } diff --git a/tools/src/main/java/org/neo4j/tools/applytx/DatabaseRebuildTool.java b/tools/src/main/java/org/neo4j/tools/applytx/DatabaseRebuildTool.java index 5698833690c5d..a34d21144a8b6 100644 --- a/tools/src/main/java/org/neo4j/tools/applytx/DatabaseRebuildTool.java +++ b/tools/src/main/java/org/neo4j/tools/applytx/DatabaseRebuildTool.java @@ -25,13 +25,13 @@ import java.io.PrintStream; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import org.neo4j.consistency.ConsistencyCheckService; import org.neo4j.consistency.ConsistencyCheckService.Result; import org.neo4j.graphdb.factory.GraphDatabaseBuilder; import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.helpers.Args; -import org.neo4j.helpers.Provider; import org.neo4j.helpers.progress.ProgressMonitorFactory; import org.neo4j.io.fs.FileUtils; import org.neo4j.kernel.GraphDatabaseAPI; @@ -188,22 +188,8 @@ private ConsoleInput console( final File fromPath, final GraphDatabaseBuilder db // should be restored. The commands has references to providers of things to accommodate for this. final AtomicReference store = new AtomicReference<>( new Store( dbBuilder ) ); - final Provider storeAccess = new Provider() - { - @Override - public StoreAccess instance() - { - return store.get().access; - } - }; - final Provider dbAccess = new Provider() - { - @Override - public GraphDatabaseAPI instance() - { - return store.get().db; - } - }; + final Supplier storeAccess = () -> store.get().access; + final Supplier dbAccess = () -> store.get().db; ConsoleInput consoleInput = life.add( new ConsoleInput( in, out, prompt ) ); consoleInput.add( "apply", new ApplyTransactionsCommand( fromPath, dbAccess ) ); diff --git a/tools/src/main/java/org/neo4j/tools/applytx/DumpRecordsCommand.java b/tools/src/main/java/org/neo4j/tools/applytx/DumpRecordsCommand.java index c75891226d765..a46725f250d20 100644 --- a/tools/src/main/java/org/neo4j/tools/applytx/DumpRecordsCommand.java +++ b/tools/src/main/java/org/neo4j/tools/applytx/DumpRecordsCommand.java @@ -24,8 +24,8 @@ import io.airlift.airline.Cli.CliBuilder; import java.io.PrintStream; +import java.util.function.Supplier; -import org.neo4j.helpers.Provider; import org.neo4j.kernel.impl.core.Token; import org.neo4j.kernel.impl.store.LabelTokenStore; import org.neo4j.kernel.impl.store.PropertyKeyTokenStore; @@ -54,10 +54,10 @@ private interface Action } private final Cli cli; - private final Provider store; + private final Supplier store; @SuppressWarnings( "unchecked" ) - public DumpRecordsCommand( Provider store ) + public DumpRecordsCommand( Supplier store ) { this.store = store; CliBuilder builder = Cli.builder( NAME ) @@ -79,7 +79,7 @@ public DumpRecordsCommand( Provider store ) @Override public void run( String[] args, PrintStream out ) throws Exception { - cli.parse( args ).run( store.instance(), out ); + cli.parse( args ).run( store.get(), out ); } @Override