ReplicaTransport
Last updated
Last updated
In the context of the Internet Computer blockchain, a Replica refers to the Internet Computer protocol processes running on a node.
To be able to connect remotely to the Internet Computer Canister IC4J implements ReplicaTransport interface over different Java HTTP Client libraries. Developers can choose specific implementations based on their Java application use cases.
ReplicaTransport interface currently supports 4 Internet Computer functions.
Calls in ReplicaTransport interface are asynchronous and return the CompletableFuture response type.
The Apache HTTP 5 library is a robust, stable Java implementation of the HTTP protocol. It allows developers to define advanced features like connection pooling.
The simplest way to create ReplicaTransport is to use ReplicaApacheHttpTransport to create the Method with the IC URL String as a parameter.
For advanced use cases, for example, to create Java server type applications handling a large number of clients and canisters, additional parameters can be defined.
url
Canister URL
maxTotal
Maximum total connections
maxPerRoute
Maximum connections per route
connectionTimeToLive
Time to live for connection in seconds
timeout
Connection timeout in seconds
For even more complex scenarios ReplicaTransport can be created with the explicitly defined Apache HTTP Client connection manager AsyncClientConnectionManager.
For Android development it is recommended to use the OkHttp Client Implementation.
OkHttp is an efficient HTTP & HTTP/2 client for Android and Java applications.
Use ReplicaOkHttpTransport to create the Method with the IC URL String as a parameter to create OkHttp ReplicaTransport
If needed, the Connection Timeout can be explicitly defined :
From Java version 11 and higher, Oracle significantly improved functionality of Java default HTTP Client.
To make core libraries compatible with Java version 1.8, it is recommended that this version of transport is explicitly imported in the Graven or Maven build script.
Use ReplicaJavaHttpTransport to create the Method with the IC URL String as a parameter to create Java 11 ReplicaTransport
If needed the connection timeout can be defined explicitly.