Package org.web3j.protocol
Class Service
java.lang.Object
org.web3j.protocol.Service
- All Implemented Interfaces:
Web3jService
- Direct Known Subclasses:
HttpService,IpcService
Base service implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.fasterxml.jackson.databind.ObjectMapper -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract InputStream<T extends Response>
TPerform a synchronous JSON-RPC request.<T extends Response>
CompletableFuture<T>Performs an asynchronous JSON-RPC request.sendBatch(BatchRequest batchRequest) Perform a synchronous JSON-RPC batch requests.sendBatchAsync(BatchRequest batchRequest) Performs an asynchronous JSON-RPC batch requests.<T extends Notification<?>>
io.reactivex.Flowable<T>Subscribe to a stream of notifications.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.web3j.protocol.Web3jService
close
-
Field Details
-
objectMapper
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
-
-
Constructor Details
-
Service
public Service(boolean includeRawResponses)
-
-
Method Details
-
performIO
- Throws:
IOException
-
send
Description copied from interface:Web3jServicePerform a synchronous JSON-RPC request.- Specified by:
sendin interfaceWeb3jService- Type Parameters:
T- type of a data item returned by the request- Parameters:
request- request to performresponseType- class of a data item returned by the request- Returns:
- deserialized JSON-RPC response
- Throws:
IOException- thrown if failed to perform a request
-
sendAsync
public <T extends Response> CompletableFuture<T> sendAsync(Request jsonRpc20Request, Class<T> responseType) Description copied from interface:Web3jServicePerforms an asynchronous JSON-RPC request.- Specified by:
sendAsyncin interfaceWeb3jService- Type Parameters:
T- type of a data item returned by the request- Parameters:
jsonRpc20Request- request to performresponseType- class of a data item returned by the request- Returns:
- CompletableFuture that will be completed when a result is returned or if a request has failed
-
sendBatch
Description copied from interface:Web3jServicePerform a synchronous JSON-RPC batch requests.- Specified by:
sendBatchin interfaceWeb3jService- Parameters:
batchRequest- requests to perform- Returns:
- deserialized JSON-RPC responses
- Throws:
IOException- thrown if failed to perform a batch request
-
sendBatchAsync
Description copied from interface:Web3jServicePerforms an asynchronous JSON-RPC batch requests.- Specified by:
sendBatchAsyncin interfaceWeb3jService- Parameters:
batchRequest- batch request to perform- Returns:
- CompletableFuture that will be completed when a result is returned or if a request has failed
-
subscribe
public <T extends Notification<?>> io.reactivex.Flowable<T> subscribe(Request request, String unsubscribeMethod, Class<T> responseType) Description copied from interface:Web3jServiceSubscribe to a stream of notifications. A stream of notifications is opened by by performing a specified JSON-RPC request and is closed by calling the unsubscribe method. Different WebSocket implementations use different pair of subscribe/unsubscribe methods.This method creates an Flowable that can be used to subscribe to new notifications. When a client unsubscribes from this Flowable the service unsubscribes from the underlying stream of events.
- Specified by:
subscribein interfaceWeb3jService- Type Parameters:
T- type of incoming event objects- Parameters:
request- JSON-RPC request that will be send to subscribe to a stream of eventsunsubscribeMethod- method that will be called to unsubscribe from a stream of notificationsresponseType- class of incoming events objects in a stream- Returns:
- a
Flowableinstance that emits incoming events
-