Package org.web3j.protocol
Interface Web3jService
- All Known Implementing Classes:
HttpService
,IpcService
,Service
,UnixIpcService
,WebSocketService
,WindowsIpcService
public interface Web3jService
Services API.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes resources used by the service.<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.
-
Method Details
-
send
Perform a synchronous JSON-RPC request.- 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
Performs an asynchronous JSON-RPC request.- 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:
- CompletableFuture that will be completed when a result is returned or if a request has failed
-
sendBatch
Perform a synchronous JSON-RPC batch requests.- Parameters:
batchRequest
- requests to perform- Returns:
- deserialized JSON-RPC responses
- Throws:
IOException
- thrown if failed to perform a batch request
-
sendBatchAsync
Performs an asynchronous JSON-RPC batch requests.- Parameters:
batchRequest
- batch request to perform- Returns:
- CompletableFuture that will be completed when a result is returned or if a request has failed
-
subscribe
<T extends Notification<?>> io.reactivex.Flowable<T> subscribe(Request request, String unsubscribeMethod, Class<T> responseType) Subscribe 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.
- 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
Flowable
instance that emits incoming events
-
close
Closes resources used by the service.- Throws:
IOException
- thrown if a service failed to close all resources
-