/**
  * Returns the number of seconds from now until this servers next channel will expire, or zero if
  * no unexpired channels found.
  */
 public long getSecondsUntilExpiry(Sha256Hash id) {
   lock.lock();
   try {
     final Set<StoredClientChannel> setChannels = mapChannels.get(id);
     final long nowSeconds = Utils.currentTimeSeconds();
     int earliestTime = Integer.MAX_VALUE;
     for (StoredClientChannel channel : setChannels) {
       synchronized (channel) {
         if (channel.expiryTimeSeconds() > nowSeconds)
           earliestTime = Math.min(earliestTime, (int) channel.expiryTimeSeconds());
       }
     }
     return earliestTime == Integer.MAX_VALUE ? 0 : earliestTime - nowSeconds;
   } finally {
     lock.unlock();
   }
 }
 // Adds this channel and optionally notifies the wallet of an update to this extension (used
 // during deserialize)
 private void putChannel(final StoredClientChannel channel, boolean updateWallet) {
   lock.lock();
   try {
     mapChannels.put(channel.id, channel);
     channelTimeoutHandler.schedule(
         new TimerTask() {
           @Override
           public void run() {
             TransactionBroadcaster announcePeerGroup = getAnnouncePeerGroup();
             removeChannel(channel);
             announcePeerGroup.broadcastTransaction(channel.contract);
             announcePeerGroup.broadcastTransaction(channel.refund);
           }
           // Add the difference between real time and Utils.now() so that test-cases can use a
           // mock clock.
         },
         new Date(
             channel.expiryTimeSeconds() * 1000
                 + (System.currentTimeMillis() - Utils.currentTimeMillis())));
   } finally {
     lock.unlock();
   }
   if (updateWallet) updatedChannel(channel);
 }