@Test(expected = LeaseException.class) public void leaseNotGranted() throws Exception { when(leaseRequestResult.isConnectionGood()).thenReturn(true); when(leaseRequestResult.isLeaseGranted()).thenReturn(false); leaseAcquirer.acquireLease(); }
@Override public long acquireLease() throws LeaseException, InterruptedException { long currentConnectionSequenceNumber = connectionSequenceNumber.get(); if (reconnecting) { throw new LeaseReconnectingException("Will not attempt to acquire a lease as a reconnection is taking place"); } try { InvokeFuture<LeaseResponse> invokeFuture = endpoint.beginInvoke() .message(new LeaseRequest(currentConnectionSequenceNumber)) .replicate(false) .ackCompleted() .invoke(); LeaseRequestResult leaseRequestResult = (LeaseRequestResult) invokeFuture.get(); if (!leaseRequestResult.isConnectionGood()) { throw new LeaseReconnectingException("Attempted to acquire a lease but fail-over occurred"); } if (!leaseRequestResult.isLeaseGranted()) { throw new LeaseException("Unable to obtain lease, the connection is being closed because the lease was not renewed soon enough"); } return leaseRequestResult.getLeaseLength(); } catch (MessageCodecException e) { throw new LeaseException(e); } catch (EntityException e) { throw new LeaseException(e); } }
LeaseAcquirerImpl implements LeaseAcquirer, LeaseReconnectListener, LeaseReconnectDataSupplier { @Override public long acquireLease() throws LeaseException, InterruptedException { long currentConnectionSequenceNumber = connectionSequenceNumber.get(); if (reconnecting) { throw new LeaseReconnectingException("Will not attempt to acquire a lease as a reconnection is taking place"); } try { InvokeFuture<LeaseResponse> invokeFuture = endpoint.beginInvoke() .message(new LeaseRequest(currentConnectionSequenceNumber)) .replicate(false) .ackCompleted() .invoke(); LeaseRequestResult leaseRequestResult = (LeaseRequestResult) invokeFuture.get(); if (!leaseRequestResult.isConnectionGood()) { throw new LeaseReconnectingException("Attempted to acquire a lease but fail-over occurred"); } if (!leaseRequestResult.isLeaseGranted()) { throw new LeaseException("Unable to obtain lease, the connection is being closed because the lease was not renewed soon enough"); } return leaseRequestResult.getLeaseLength(); } catch (MessageCodecException e) { throw new LeaseException(e); } catch (EntityException e) { throw new LeaseException(e); } } }
LeaseAcquirerImpl implements LeaseAcquirer, LeaseReconnectListener, LeaseReconnectDataSupplier { @Override public long acquireLease() throws LeaseException, InterruptedException { long currentConnectionSequenceNumber = connectionSequenceNumber.get(); if (reconnecting) { throw new LeaseReconnectingException("Will not attempt to acquire a lease as a reconnection is taking place"); } try { InvokeFuture<LeaseResponse> invokeFuture = endpoint.beginInvoke() .message(new LeaseRequest(currentConnectionSequenceNumber)) .replicate(false) .ackCompleted() .invoke(); LeaseRequestResult leaseRequestResult = (LeaseRequestResult) invokeFuture.get(); if (!leaseRequestResult.isConnectionGood()) { throw new LeaseReconnectingException("Attempted to acquire a lease but fail-over occurred"); } if (!leaseRequestResult.isLeaseGranted()) { throw new LeaseException("Unable to obtain lease, the connection is being closed because the lease was not renewed soon enough"); } return leaseRequestResult.getLeaseLength(); } catch (MessageCodecException e) { throw new LeaseException(e); } catch (EntityException e) { throw new LeaseException(e); } } LeaseAcquirerImpl(EntityClientEndpoint<LeaseMessage, LeaseResponse> endpoint, LeaseReconnectListener reconnectListener); }
LeaseAcquirerImpl implements LeaseAcquirer, LeaseReconnectListener, LeaseReconnectDataSupplier { @Override public long acquireLease() throws LeaseException, InterruptedException { long currentConnectionSequenceNumber = connectionSequenceNumber.get(); if (reconnecting) { throw new LeaseReconnectingException("Will not attempt to acquire a lease as a reconnection is taking place"); } try { InvokeFuture<LeaseResponse> invokeFuture = endpoint.beginInvoke() .message(new LeaseRequest(currentConnectionSequenceNumber)) .replicate(false) .ackCompleted() .invoke(); LeaseRequestResult leaseRequestResult = (LeaseRequestResult) invokeFuture.get(); if (!leaseRequestResult.isConnectionGood()) { throw new LeaseReconnectingException("Attempted to acquire a lease but fail-over occurred"); } if (!leaseRequestResult.isLeaseGranted()) { throw new LeaseException("Unable to obtain lease, the connection is being closed because the lease was not renewed soon enough"); } return leaseRequestResult.getLeaseLength(); } catch (MessageCodecException e) { throw new LeaseException(e); } catch (EntityException e) { throw new LeaseException(e); } } LeaseAcquirerImpl(EntityClientEndpoint<LeaseMessage, LeaseResponse> endpoint, LeaseReconnectListener reconnectListener); @Override long acquireLease(); @Override void close(); @Override void reconnecting(); @Override void reconnected(); @Override LeaseReconnectData getReconnectData(); }
LeaseAcquirerImpl implements LeaseAcquirer, LeaseReconnectListener, LeaseReconnectDataSupplier { @Override public long acquireLease() throws LeaseException, InterruptedException { long currentConnectionSequenceNumber = connectionSequenceNumber.get(); if (reconnecting) { throw new LeaseReconnectingException("Will not attempt to acquire a lease as a reconnection is taking place"); } try { InvokeFuture<LeaseResponse> invokeFuture = endpoint.beginInvoke() .message(new LeaseRequest(currentConnectionSequenceNumber)) .replicate(false) .ackCompleted() .invoke(); LeaseRequestResult leaseRequestResult = (LeaseRequestResult) invokeFuture.get(); if (!leaseRequestResult.isConnectionGood()) { throw new LeaseReconnectingException("Attempted to acquire a lease but fail-over occurred"); } if (!leaseRequestResult.isLeaseGranted()) { throw new LeaseException("Unable to obtain lease, the connection is being closed because the lease was not renewed soon enough"); } return leaseRequestResult.getLeaseLength(); } catch (MessageCodecException e) { throw new LeaseException(e); } catch (EntityException e) { throw new LeaseException(e); } } LeaseAcquirerImpl(EntityClientEndpoint<LeaseMessage, LeaseResponse> endpoint, LeaseReconnectListener reconnectListener); @Override long acquireLease(); @Override void close(); @Override void reconnecting(); @Override void reconnected(); @Override LeaseReconnectData getReconnectData();  }