use of org.apache.geode.internal.util.concurrent.FutureResult in project geode by apache.
the class AdminDistributedSystemImpl method addCacheServer.
public CacheServer addCacheServer() throws AdminException {
CacheServerConfigImpl conf = new CacheServerConfigImpl();
CacheServer server = createCacheServer(conf);
setDistributionParameters(server);
synchronized (this.cacheServerSet) {
this.cacheServerSet.add(new FutureResult(server));
}
return server;
}
use of org.apache.geode.internal.util.concurrent.FutureResult in project geode by apache.
the class AdminDistributedSystemImpl method addDistributionLocator.
/**
* Adds a new, unstarted <code>DistributionLocator</code> to this distributed system.
*/
public DistributionLocator addDistributionLocator() {
DistributionLocatorConfig conf = new DistributionLocatorConfigImpl();
DistributionLocator locator = createDistributionLocatorImpl(conf);
synchronized (this.locatorSet) {
this.locatorSet.add(new FutureResult(locator));
}
// update locators string...
setLocators(parseLocatorSet());
return locator;
}
use of org.apache.geode.internal.util.concurrent.FutureResult in project geode by apache.
the class AdminDistributedSystemImpl method connect.
/**
* Connects to the currently configured system. This method is public for internal use only
* (testing, for example).
*
* <p>
*
* See {@link org.apache.geode.distributed.DistributedSystem#connect} for a list of exceptions
* that may be thrown.
*
* @param logWriter the InternalLogWriter to use for any logging
*/
public void connect(InternalLogWriter logWriter) {
synchronized (CONNECTION_SYNC) {
// automatically.
if (this.gfManagerAgent != null) {
if (this.gfManagerAgent.isListening()) {
if (logger.isDebugEnabled()) {
logger.debug("The RemoteGfManagerAgent is already listening for this AdminDistributedSystem.");
}
return;
}
this.disconnect();
}
if (thisAdminDS != null) {
// TODO: beef up toString and add thisAdminDS
throw new IllegalStateException(LocalizedStrings.AdminDistributedSystemImpl_ONLY_ONE_ADMINDISTRIBUTEDSYSTEM_CONNECTION_CAN_BE_MADE_AT_ONCE.toLocalizedString());
}
// added for feature requests #32887
thisAdminDS = this;
if (this.getLocators().length() == 0) {
this.id = this.getMcastAddress() + "[" + this.getMcastPort() + "]";
} else {
this.id = this.getLocators();
}
if (this.config instanceof DistributedSystemConfigImpl) {
((DistributedSystemConfigImpl) this.config).validate();
((DistributedSystemConfigImpl) this.config).setDistributedSystem(this);
}
// LOG: passes the AdminDistributedSystemImpl LogWriterLogger into GfManagerAgentConfig for
// RemoteGfManagerAgent
GfManagerAgent agent = GfManagerAgentFactory.getManagerAgent(buildAgentConfig(logWriter));
this.gfManagerAgent = agent;
// sync to prevent bug 33341 Admin API can double-represent system members
synchronized (this.membershipListenerLock) {
// build the list of applications...
ApplicationVM[] apps = this.gfManagerAgent.listApplications();
for (int i = 0; i < apps.length; i++) {
try {
nodeJoined(null, apps[i]);
} catch (RuntimeAdminException e) {
this.logWriter.warning("encountered a problem processing member " + apps[i]);
}
}
}
// Build admin objects for all locators (see bug 31959)
String locators = this.getLocators();
StringTokenizer st = new StringTokenizer(locators, ",");
NEXT: while (st.hasMoreTokens()) {
String locator = st.nextToken();
int first = locator.indexOf("[");
int last = locator.indexOf("]");
String host = locator.substring(0, first);
int colidx = host.lastIndexOf('@');
if (colidx < 0) {
colidx = host.lastIndexOf(':');
}
String bindAddr = null;
if (colidx > 0 && colidx < (host.length() - 1)) {
String orig = host;
bindAddr = host.substring(colidx + 1, host.length());
host = host.substring(0, colidx);
// parsed an ipv6 address incorrectly - try again
if (host.indexOf(':') >= 0) {
int bindidx = orig.lastIndexOf('@');
if (bindidx >= 0) {
host = orig.substring(0, bindidx);
bindAddr = orig.substring(bindidx + 1);
} else {
host = orig;
bindAddr = null;
}
}
}
int port = Integer.parseInt(locator.substring(first + 1, last));
synchronized (this.locatorSet) {
LOCATORS: for (Iterator iter = this.locatorSet.iterator(); iter.hasNext(); ) {
Future future = (Future) iter.next();
DistributionLocatorImpl impl = null;
for (; ; ) {
checkCancellation();
boolean interrupted = Thread.interrupted();
try {
impl = (DistributionLocatorImpl) future.get();
// success
break;
} catch (InterruptedException ex) {
interrupted = true;
// keep trying
continue;
} catch (CancellationException ex) {
continue LOCATORS;
} catch (ExecutionException ex) {
handle(ex);
continue LOCATORS;
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
// for
DistributionLocatorConfig conf = impl.getConfig();
InetAddress host1 = InetAddressUtil.toInetAddress(host);
InetAddress host2 = InetAddressUtil.toInetAddress(conf.getHost());
if (port == conf.getPort() && host1.equals(host2)) {
// Already have an admin object for this locator
continue NEXT;
}
}
}
// None of the existing locators matches the locator in the
// string. Contact the locator to get information and create
// an admin object for it.
InetAddress bindAddress = null;
if (bindAddr != null) {
bindAddress = InetAddressUtil.toInetAddress(bindAddr);
}
DistributionLocatorConfig conf = DistributionLocatorConfigImpl.createConfigFor(host, port, bindAddress);
if (conf != null) {
DistributionLocator impl = createDistributionLocatorImpl(conf);
synchronized (this.locatorSet) {
this.locatorSet.add(new FutureResult(impl));
}
}
}
}
}
use of org.apache.geode.internal.util.concurrent.FutureResult in project geode by apache.
the class AdminDistributedSystemImpl method initializeDistributionLocators.
// -------------------------------------------------------------------------
// Initialization
// -------------------------------------------------------------------------
/**
* Creates DistributionLocator instances for every locator entry in the
* {@link org.apache.geode.admin.DistributedSystemConfig}
*/
private void initializeDistributionLocators() {
DistributionLocatorConfig[] configs = this.config.getDistributionLocatorConfigs();
if (configs.length == 0) {
// No work to do
return;
}
for (int i = 0; i < configs.length; i++) {
// the Locator impl may vary in this class from the config...
DistributionLocatorConfig conf = configs[i];
DistributionLocator locator = createDistributionLocatorImpl(conf);
this.locatorSet.add(new FutureResult(locator));
}
// update locators string...
setLocators(parseLocatorSet());
}
use of org.apache.geode.internal.util.concurrent.FutureResult in project geode by apache.
the class DLockService method becomeLockGrantor.
/**
* @param predecessor non-null if a predecessor asked us to take over for him
*/
void becomeLockGrantor(InternalDistributedMember predecessor) {
Assert.assertTrue(predecessor == null);
boolean ownLockGrantorFutureResult = false;
FutureResult lockGrantorFutureResultRef = null;
final boolean isDebugEnabled_DLS = logger.isTraceEnabled(LogMarker.DLS);
LockGrantorId myLockGrantorId = null;
try {
// terminate loop if this thread gets control of lockGrantorFutureResult
while (!ownLockGrantorFutureResult) {
Assert.assertHoldsLock(this.destroyLock, false);
synchronized (this.lockGrantorIdLock) {
if (isCurrentlyOrIsMakingLockGrantor()) {
return;
} else if (this.lockGrantorFutureResult != null) {
// need to wait for other thread controlling lockGrantorFutureResult
lockGrantorFutureResultRef = this.lockGrantorFutureResult;
} else {
// this thread is in control and will procede to become grantor
// create new lockGrantorFutureResult for other threads to block on
ownLockGrantorFutureResult = true;
lockGrantorFutureResultRef = new FutureResult(this.dm.getCancelCriterion());
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "[becomeLockGrantor] creating lockGrantorFutureResult");
}
this.lockGrantorFutureResult = lockGrantorFutureResultRef;
}
}
if (!ownLockGrantorFutureResult) {
waitForLockGrantorFutureResult(lockGrantorFutureResultRef, 0, TimeUnit.MILLISECONDS);
continue;
}
}
// this thread is now in charge of the lockGrantorFutureResult future
getStats().incBecomeGrantorRequests();
// create the new grantor instance in non-ready state...
long tempGrantorVersion = -1;
LockGrantorId tempLockGrantorId = new LockGrantorId(this.dm, this.dm.getId(), tempGrantorVersion, getSerialNumber());
DLockGrantor myGrantor = DLockGrantor.createGrantor(this, tempGrantorVersion);
try {
synchronized (this.lockGrantorIdLock) {
Assert.assertTrue(setLockGrantorId(tempLockGrantorId, myGrantor));
}
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "become set lockGrantorId to {} for service {}", this.lockGrantorId, this.serviceName);
}
InternalDistributedMember elder = getElderId();
Assert.assertTrue(elder != null);
// NOTE: elder currently returns GrantorInfo for the previous grantor
// CONSIDER: add elderCommunicatedWith to GrantorInfo
GrantorInfo gi = becomeGrantor(predecessor);
boolean needsRecovery = gi.needsRecovery();
long myGrantorVersion = gi.getVersionId() + 1;
myGrantor.setVersionId(myGrantorVersion);
myLockGrantorId = new LockGrantorId(this.dm, this.dm.getId(), myGrantorVersion, getSerialNumber());
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "[becomeLockGrantor] Calling makeLocalGrantor");
}
if (!makeLocalGrantor(elder, needsRecovery, myLockGrantorId, myGrantor)) {
return;
}
} finally {
Assert.assertTrue(myGrantor == null || !myGrantor.isInitializing() || this.dm.getCancelCriterion().isCancelInProgress() || isDestroyed(), "BecomeLockGrantor failed and left grantor non-ready");
}
} finally {
synchronized (this.lockGrantorIdLock) {
if (ownLockGrantorFutureResult) {
// this thread is doing the real work and must finish the future
Assert.assertTrue(this.lockGrantorFutureResult == lockGrantorFutureResultRef);
boolean getLockGrantorIdFailed = myLockGrantorId == null;
if (getLockGrantorIdFailed) {
// failed so cancel lockGrantorFutureResult
// interrupt waiting threads
lockGrantorFutureResultRef.cancel(true);
} else {
// don't succeed if shutting
this.dm.getCancelCriterion().checkCancelInProgress(null);
// down
// succeeded so set lockGrantorFutureResult
lockGrantorFutureResultRef.set(myLockGrantorId);
}
// null out the reference so it is free for next usage
this.lockGrantorFutureResult = null;
}
}
}
}
Aggregations