Java class for restoring data

There are two nodes in cluster and an index "books" is there . So one node is primary containing all primary shards and second node is replica containing replica shards. This replica node left the cluster and comeback after few minutes .Meanwhile some data is added to primary node's shards . How will data be pulled back into this node after it comes back. And on what basis is this decided that only certain data has to be pulled and not all . I am looking into java classes to understand it . Can someone please explain theory behind it and also refer me to java class that I should look to understand this restore process.

If new data have been added to the primary, it means that new Lucene segments has been added. When the replica comes back, it basically looks for missing segments and copy them over the network.

Thanks David , can you refer me to java classes for data pulling process like org.elasticsearch.gateway and other required classes .