| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | } |
| | | |
| | | private void checkForHeartBeat() { |
| | | if (sync.isHeldExclusively()) { |
| | | if (sync.isHeld()) { |
| | | /* |
| | | * A heart beat is still in progress, but it should have |
| | | * completed by now. Let's avoid aggressively terminating the |
| | | * connection, because the heart beat may simply have been |
| | | * delayed by a sudden surge of activity. Therefore, only flag |
| | | * the connection as failed if no activity has been seen on the |
| | | * connection since the heart beat was sent. |
| | | * A heart beat or bind/startTLS is still in progress, but it |
| | | * should have completed by now. Let's avoid aggressively |
| | | * terminating the connection, because the heart beat may simply |
| | | * have been delayed by a sudden surge of activity. Therefore, |
| | | * only flag the connection as failed if no activity has been |
| | | * seen on the connection since the heart beat was sent. |
| | | */ |
| | | final long currentTimeMillis = timeSource.currentTimeMillis(); |
| | | if (lastResponseTimestamp < (currentTimeMillis - timeoutMS)) { |
| | |
| | | if (sync.tryLockExclusively()) { |
| | | try { |
| | | connection.searchAsync(heartBeatRequest, null, heartBeatHandler); |
| | | return true; |
| | | } catch (final IllegalStateException e) { |
| | | /* |
| | | * This may happen when we attempt to send the heart beat |
| | |
| | | releaseHeartBeatLock(); |
| | | } |
| | | } |
| | | return false; |
| | | /* |
| | | * Indicate that a the heartbeat should be checked even if a |
| | | * bind/startTLS is in progress, since these operations will |
| | | * effectively act as the heartbeat. |
| | | */ |
| | | return true; |
| | | } |
| | | |
| | | private <R> R timestamp(final R response) { |
| | |
| | | return getState() == LOCKED_EXCLUSIVELY; |
| | | } |
| | | |
| | | boolean isHeld() { |
| | | return getState() != 0; |
| | | } |
| | | |
| | | @Override |
| | | protected boolean tryAcquire(final int ignored) { |
| | | if (compareAndSetState(UNLOCKED, LOCKED_EXCLUSIVELY)) { |