//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.function.ThrowingFunction<org.neo4j.kernel.impl.transaction.log.LogPosition,org.neo4j.kernel.impl.transaction.log.TransactionCursor,java.io.IOException> log(int... transactionCounts) throws java.io.IOException private ThrowingFunction <LogPosition, TransactionCursor, IOException> Log(params int[] transactionCounts) { long baseOffset = LogPosition.start(0).ByteOffset; //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") org.neo4j.function.ThrowingFunction<org.neo4j.kernel.impl.transaction.log.LogPosition,org.neo4j.kernel.impl.transaction.log.TransactionCursor,java.io.IOException> result = mock(org.neo4j.function.ThrowingFunction.class); ThrowingFunction <LogPosition, TransactionCursor, IOException> result = mock(typeof(ThrowingFunction)); AtomicLong txId = new AtomicLong(0); CommittedTransactionRepresentation[][] logs = new CommittedTransactionRepresentation[transactionCounts.Length][]; for (int logVersion = 0; logVersion < transactionCounts.Length; logVersion++) { logs[logVersion] = Transactions(transactionCounts[logVersion], txId); } when(result.Apply(any(typeof(LogPosition)))).thenAnswer(invocation => { LogPosition position = invocation.getArgument(0); if (position == null) { // A mockito issue when calling the "when" methods, I believe return(null); } // For simplicity the offset means, in this test, the array offset CommittedTransactionRepresentation[] transactions = logs[toIntExact(position.LogVersion)]; CommittedTransactionRepresentation[] subset = copyOfRange(transactions, toIntExact(position.ByteOffset - baseOffset), transactions.Length); ArrayUtil.reverse(subset); return(given(subset)); }); return(result); }
internal ProcedureGDSFactory(PlatformModule platform, DataSourceModule dataSource, CoreAPIAvailabilityGuard coreAPIAvailabilityGuard, TokenHolders tokenHolders, ThreadToStatementContextBridge bridge) { this._platform = platform; this._dataSource = dataSource; this._availability = coreAPIAvailabilityGuard; this._urlValidator = url => platform.UrlAccessRule.validate(platform.Config, url); this._tokenHolders = tokenHolders; this._bridge = bridge; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SafeVarargs public static <IN,OUT> org.neo4j.collection.RawIterator<OUT,java.io.IOException> iterator(org.neo4j.function.ThrowingFunction<IN,OUT,java.io.IOException> converter, IN... items) public static RawIterator <OUT, IOException> Iterator <IN, OUT>(ThrowingFunction <IN, OUT, IOException> converter, params IN[] items) { if (items.Length == 0) { throw new System.InvalidOperationException("No source items specified"); } return(new RawIteratorAnonymousInnerClass(converter, items)); }
public virtual IList <Future <TO> > Multiple <FROM, TO, EX>(int threads, ThrowingFunction <FROM, TO, EX> function, FROM parameter) where EX : Exception { IList <Future <TO> > result = new List <Future <TO> >(threads); for (int i = 0; i < threads; i++) { result.Add(_executor.submit(Task(function, function.ToString() + ":task=" + i, parameter, NULL_CONSUMER))); } return(result); }
public ProcedureGDBFacadeSPI(DataSourceModule sourceModule, DependencyResolver resolver, CoreAPIAvailabilityGuard availability, ThrowingFunction <URL, URL, URLAccessValidationError> urlValidator, SecurityContext securityContext, ThreadToStatementContextBridge threadToTransactionBridge) { this._databaseLayout = sourceModule.NeoStoreDataSource.DatabaseLayout; this._sourceModule = sourceModule; this._resolver = resolver; this._availability = availability; this._urlValidator = urlValidator; this._securityContext = securityContext; this._threadToTransactionBridge = threadToTransactionBridge; }
private int MapToken(ThrowingFunction <Token, int, KernelException> f) { try { using (Transaction tx = beginTransaction()) { return(f.Apply(tx.Token())); } } catch (KernelException e) { fail("Unwanted exception: " + e.Message); return(-1); // unreachable } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public <FROM, TO, EX extends Exception> java.util.concurrent.Future<TO> executeAndAwait(org.neo4j.function.ThrowingFunction<FROM,TO,EX> function, FROM parameter, System.Predicate<Thread> threadCondition, long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException public virtual Future <TO> ExecuteAndAwait <FROM, TO, EX>(ThrowingFunction <FROM, TO, EX> function, FROM parameter, System.Predicate <Thread> threadCondition, long timeout, TimeUnit unit) where EX : Exception { FailableConcurrentTransfer <Thread> transfer = new FailableConcurrentTransfer <Thread>(); Future <TO> future = _executor.submit(Task(function, function.ToString(), parameter, transfer)); try { Predicates.awaitEx(transfer, throwingPredicate(threadCondition), timeout, unit); } catch (Exception e) { throw new ExecutionException(e); } return(future); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void withConstraint(org.neo4j.function.ThrowingFunction<java.util.concurrent.CyclicBarrier,org.neo4j.graphdb.Node,Exception> action) throws Exception private void WithConstraint(ThrowingFunction <CyclicBarrier, Node, Exception> action) { // given Db.execute("CREATE CONSTRAINT ON (foo:Foo) ASSERT foo.bar IS UNIQUE"); CyclicBarrier barrier = new CyclicBarrier(2); Node node = MergeNode(); // when IList <Node> result = await(Threads.multiple(barrier.Parties, action, barrier)); // then assertEquals("size of result", 2, result.Count); assertEquals(node, result[0]); assertEquals(node, result[1]); }
public static bool HasFunctionThrown <ExceptionType>(ThrowingFunction func) where ExceptionType : Exception { bool hasThrown = false; try { func(); } catch (ExceptionType) { hasThrown = true; } catch (TargetInvocationException e) { hasThrown = (e.InnerException is ExceptionType); } return(hasThrown); }
/// <summary> /// Utility method for creating a <seealso cref="ReversedMultiFileTransactionCursor"/> with a <seealso cref="LogFile"/> as the source of /// <seealso cref="TransactionCursor"/> for each log version. /// </summary> /// <param name="logFile"> <seealso cref="LogFile"/> to supply log entries forming transactions. </param> /// <param name="backToPosition"> <seealso cref="LogPosition"/> to read backwards to. </param> /// <param name="failOnCorruptedLogFiles"> fail reading from log files as soon as first error is encountered </param> /// <param name="monitor"> reverse transaction cursor monitor </param> /// <returns> a <seealso cref="TransactionCursor"/> which returns transactions from the end of the log stream and backwards to /// and including transaction starting at <seealso cref="LogPosition"/>. </returns> /// <exception cref="IOException"> on I/O error. </exception> public static TransactionCursor FromLogFile(LogFiles logFiles, LogFile logFile, LogPosition backToPosition, bool failOnCorruptedLogFiles, ReversedTransactionCursorMonitor monitor) { long highestVersion = logFiles.HighestLogVersion; LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); ThrowingFunction <LogPosition, TransactionCursor, IOException> factory = position => { ReadableLogChannel channel = logFile.GetReader(position, NO_MORE_CHANNELS); if (channel is ReadAheadLogChannel) { // This is a channel which can be positioned explicitly and is the typical case for such channels // Let's take advantage of this fact and use a bit smarter reverse implementation return(new ReversedSingleFileTransactionCursor(( ReadAheadLogChannel )channel, logEntryReader, failOnCorruptedLogFiles, monitor)); } // Fall back to simply eagerly reading each single log file and reversing in memory return(eagerlyReverse(new PhysicalTransactionCursor <>(channel, logEntryReader))); }; return(new ReversedMultiFileTransactionCursor(factory, highestVersion, backToPosition)); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private static <FROM, TO, EX extends Exception> java.util.concurrent.Callable<TO> task(final org.neo4j.function.ThrowingFunction<FROM,TO,EX> function, String name, final FROM parameter, final org.neo4j.function.FailableConsumer<Thread> threadConsumer) private static Callable <TO> Task <FROM, TO, EX>(ThrowingFunction <FROM, TO, EX> function, string name, FROM parameter, FailableConsumer <Thread> threadConsumer) where EX : Exception { return(() => { Thread thread = Thread.CurrentThread; string previousName = thread.Name; thread.Name = name; threadConsumer.accept(thread); try { return function.Apply(parameter); } catch (Exception failure) { threadConsumer.Fail(failure); throw failure; } finally { thread.Name = previousName; } }); }
public static bool HasFunctionThrown <ExceptionType>(ThrowingFunction function) where ExceptionType : Exception { bool hasThrown = false; try { function(); } catch (ExceptionType) { hasThrown = true; } catch (System.Reflection.TargetInvocationException ti) { hasThrown = (null != ti.InnerException as ExceptionType); if (!hasThrown) { throw; } } return(hasThrown); }
public virtual Future <TO> Execute <FROM, TO, EX>(ThrowingFunction <FROM, TO, EX> function, FROM parameter) where EX : Exception { return(_executor.submit(Task(function, function.ToString(), parameter, NULL_CONSUMER))); }
public RawIteratorAnonymousInnerClass(ThrowingFunction <IN, OUT, IOException> converter, IN[] items) { this._converter = converter; this._items = items; }
/// <param name="cursorFactory"> creates <seealso cref="TransactionCursor"/> from a given <seealso cref="LogPosition"/>. The returned cursor must /// return transactions from the end of that <seealso cref="LogPosition.getLogVersion() log version"/> and backwards in reverse order /// to, and including, the transaction at the <seealso cref="LogPosition"/> given to it. </param> /// <param name="highestVersion"> highest log version right now. </param> /// <param name="backToPosition"> the start position of the last transaction to return from this cursor. </param> internal ReversedMultiFileTransactionCursor(ThrowingFunction <LogPosition, TransactionCursor, IOException> cursorFactory, long highestVersion, LogPosition backToPosition) { this._cursorFactory = cursorFactory; this._backToPosition = backToPosition; this._currentVersion = highestVersion + 1; }
public abstract System.Func <T, R> CatchThrown(Type clazz, ThrowingFunction <T, R, E> throwing);
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint: //ORIGINAL LINE: public static <FROM, TO, EX extends Exception> org.neo4j.collection.RawIterator<TO, EX> map(org.neo4j.function.ThrowingFunction<? super FROM, ? extends TO, EX> function, org.neo4j.collection.RawIterator<FROM, EX> from) public static RawIterator <TO, EX> Map <FROM, TO, EX, T1>(ThrowingFunction <T1> function, RawIterator <FROM, EX> from) where EX : Exception where T1 : TO { return(new RawMapIterator <TO, EX>(from, function)); }