Making a service like webservice using Bitcoinj library

In my project I need three type of monitoring on Blockchain network:

  1. Monitor all the transactions
  2. Monitor all new blocks
  3. Calculate confirmations for each hash exactly does the same thing, but it’s not very stable sometimes and I need to apply my own to customization also.

1) Using Bitcoinj, monitoring transactions is easy:

NetworkParameters params = MainNetParams.get(); BlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, blockStore); PeerGroup peerGroup = new PeerGroup(params, chain); peerGroup.start(); peerGroup.addPeerDiscovery(new DnsDiscovery(params)); peerGroup.waitForPeers(5).get(); peerGroup.addOnTransactionBroadcastListener((peer, transaction) -> {     // Get all the transactions here (There is an issue here, this listener calls for each transaction two times) }); 

However this one has an issue, it is called two times for each transaction (I have no idea why).

2) I did not find anything to monitor all the blocks.

3) Also, I don’t hove how to calculate confirmations properly.

I would appreciate if anyone could help me.