use of org.glassfish.grizzly.impl.FutureImpl in project Payara by payara.
the class DynamicConfigListener method releaseListenerLock.
private void releaseListenerLock(Lock lock) {
final boolean isLoggingFinest = logger.isLoggable(Level.FINEST);
reconfigLock.lock();
try {
final int[] ports = lock.getPorts();
if (isLoggingFinest) {
logger.log(Level.FINEST, "Release reconfig lock for ports: {0}", Arrays.toString(ports));
}
FutureImpl future = null;
for (int port : ports) {
if (port != -1) {
future = reconfigByPortLock.remove(port);
}
}
if (future != null) {
if (isLoggingFinest) {
logger.log(Level.FINEST, "Release reconfig lock, set result: {0}", future);
}
future.result(new Result<Thread>(Thread.currentThread()));
}
} finally {
reconfigLock.unlock();
}
}
use of org.glassfish.grizzly.impl.FutureImpl in project Payara by payara.
the class DynamicConfigListener method acquirePortLock.
/**
* Lock TCP ports, which will take part in the reconfiguration to avoid
* collisions
*/
private Lock acquirePortLock(NetworkListener listener) throws InterruptedException, TimeoutException {
final boolean isLoggingFinest = logger.isLoggable(Level.FINEST);
final int port = getPort(listener);
try {
while (true) {
logger.finest("Aquire reconfig lock");
if (reconfigLock.tryLock(RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS)) {
Future lock = reconfigByPortLock.get(port);
if (isLoggingFinest) {
logger.log(Level.FINEST, "Reconfig lock for port: {0} is {1}", new Object[] { port, lock });
}
int proxyPort = -1;
if (lock == null) {
final NetworkProxy runningProxy = grizzlyService.lookupNetworkProxy(listener);
if (runningProxy != null) {
proxyPort = runningProxy.getPort();
if (port != proxyPort) {
lock = reconfigByPortLock.get(proxyPort);
if (isLoggingFinest) {
logger.log(Level.FINEST, "Reconfig lock for proxyport: {0} is {1}", new Object[] { proxyPort, lock });
}
} else {
proxyPort = -1;
}
}
}
if (lock != null) {
reconfigLock.unlock();
try {
logger.finest("Waiting on reconfig lock");
lock.get(RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
} catch (ExecutionException e) {
throw new IllegalStateException(e);
}
} else {
final FutureImpl future = SafeFutureImpl.create();
if (isLoggingFinest) {
logger.log(Level.FINEST, "Set reconfig lock for ports: {0} and {1}: {2}", new Object[] { port, proxyPort, future });
}
reconfigByPortLock.put(port, future);
if (proxyPort != -1) {
reconfigByPortLock.put(proxyPort, future);
}
return new Lock(port, proxyPort);
}
} else {
throw new TimeoutException("Lock timeout");
}
}
} finally {
if (reconfigLock.isHeldByCurrentThread()) {
reconfigLock.unlock();
}
}
}
Aggregations