java.lang.Object
io.hotmoka.nodes.AbstractNode
- All Implemented Interfaces:
Node,AutoCloseable
A generic implementation of a node. The goal of this class is to provide
some shared machinery that can be useful in subclasses.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.hotmoka.nodes.Node
Node.CodeSupplier<V extends StorageValue>, Node.JarSupplier, Node.Subscription -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilds an abstract node.protectedAbstractNode(AbstractNode parent) Builds a shallow clone of the given node. -
Method Summary
Modifier and TypeMethodDescriptionprotected final Node.CodeSupplier<StorageReference>constructorSupplierFor(TransactionReference reference) Yields a code supplier that polls for the outcome of a transaction that ran a constructor.protected final Node.JarSupplierjarSupplierFor(TransactionReference reference) Yields a jar supplier that polls for the outcome of a transaction that installed a jar in the store of the node.protected final Node.CodeSupplier<StorageValue>methodSupplierFor(TransactionReference reference) Yields a code supplier that polls for the outcome of a transaction that ran a method.protected final voidnotifyEvent(StorageReference creator, StorageReference event) Notifies the given event to all event handlers for the given creator.final Node.SubscriptionsubscribeToEvents(StorageReference creator, BiConsumer<StorageReference, StorageReference> handler) Subscribes the given handler for events with the given creator.protected static <T> TwrapInCaseOfExceptionFull(Callable<T> what) Runs a callable and wraps any exception into anTransactionRejectedException, if it is not aTransactionExceptionnor aCodeExecutionException.protected static <T> TwrapInCaseOfExceptionMedium(Callable<T> what) Runs a callable and wraps any exception into anTransactionRejectedException, if it is not aTransactionException.protected static <T> TwrapInCaseOfExceptionSimple(Callable<T> what) Runs a callable and wraps any exception into anTransactionRejectedException.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.AutoCloseable
closeMethods inherited from interface io.hotmoka.nodes.Node
addConstructorCallTransaction, addGameteCreationTransaction, addInitializationTransaction, addInstanceMethodCallTransaction, addJarStoreInitialTransaction, addJarStoreTransaction, addStaticMethodCallTransaction, getClassTag, getManifest, getNameOfSignatureAlgorithmForRequests, getNodeInfo, getPolledResponse, getRequest, getResponse, getState, getTakamakaCode, postConstructorCallTransaction, postInstanceMethodCallTransaction, postJarStoreTransaction, postStaticMethodCallTransaction, runInstanceMethodCallTransaction, runStaticMethodCallTransaction
-
Field Details
-
logger
-
-
Constructor Details
-
AbstractNode
protected AbstractNode()Builds an abstract node. -
AbstractNode
Builds a shallow clone of the given node.- Parameters:
parent- the node to clone
-
-
Method Details
-
subscribeToEvents
public final Node.Subscription subscribeToEvents(StorageReference creator, BiConsumer<StorageReference, StorageReference> handler) throws UnsupportedOperationExceptionDescription copied from interface:NodeSubscribes the given handler for events with the given creator.- Specified by:
subscribeToEventsin interfaceNode- Parameters:
creator- the creator of the events that will be forwarded to the handler; if this isnull, all events will be forwarded to the handlerhandler- a handler that gets executed when an event with the given creator occurs; a handler can be subscribed to more creators; for each event, it receives its creator and the event itself- Returns:
- the subscription, that can be used later to stop event handling with
handler - Throws:
UnsupportedOperationException
-
notifyEvent
Notifies the given event to all event handlers for the given creator.- Parameters:
creator- the creator of the eventevent- the event to notify
-
jarSupplierFor
Yields a jar supplier that polls for the outcome of a transaction that installed a jar in the store of the node.- Parameters:
reference- the reference of the request of the transaction- Returns:
- the jar supplier
-
constructorSupplierFor
protected final Node.CodeSupplier<StorageReference> constructorSupplierFor(TransactionReference reference) Yields a code supplier that polls for the outcome of a transaction that ran a constructor.- Parameters:
reference- the reference of the request of the transaction- Returns:
- the code supplier
-
methodSupplierFor
Yields a code supplier that polls for the outcome of a transaction that ran a method.- Parameters:
reference- the reference of the request of the transaction- Returns:
- the code supplier
-
wrapInCaseOfExceptionSimple
protected static <T> T wrapInCaseOfExceptionSimple(Callable<T> what) throws TransactionRejectedException Runs a callable and wraps any exception into anTransactionRejectedException.- Type Parameters:
T- the return type of the callable- Parameters:
what- the callable- Returns:
- the return value of the callable
- Throws:
TransactionRejectedException- the wrapped exception
-
wrapInCaseOfExceptionMedium
protected static <T> T wrapInCaseOfExceptionMedium(Callable<T> what) throws TransactionRejectedException, TransactionException Runs a callable and wraps any exception into anTransactionRejectedException, if it is not aTransactionException.- Type Parameters:
T- the return type of the callable- Parameters:
what- the callable- Returns:
- the return value of the callable
- Throws:
TransactionRejectedException- the wrapped exceptionTransactionException- if the callable throws this
-
wrapInCaseOfExceptionFull
protected static <T> T wrapInCaseOfExceptionFull(Callable<T> what) throws TransactionRejectedException, TransactionException, CodeExecutionException Runs a callable and wraps any exception into anTransactionRejectedException, if it is not aTransactionExceptionnor aCodeExecutionException.- Type Parameters:
T- the return type of the callable- Parameters:
what- the callable- Returns:
- the return value of the callable
- Throws:
TransactionRejectedException- the wrapped exceptionTransactionException- if the callable throws thisCodeExecutionException- if the callable throws this
-