use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class CustomEntryConcurrentHashMap method clear.
/**
* Removes all of the mappings from this map.
*/
@Override
public void clear() {
ArrayList<HashEntry<?, ?>> entries = null;
try {
for (int i = 0; i < this.segments.length; ++i) {
entries = this.segments[i].clear(entries);
}
} finally {
if (entries != null) {
final ArrayList<HashEntry<?, ?>> clearedEntries = entries;
final Runnable runnable = new Runnable() {
public void run() {
for (HashEntry<?, ?> he : clearedEntries) {
for (HashEntry<?, ?> p = he; p != null; p = p.getNextEntry()) {
synchronized (p) {
((OffHeapRegionEntry) p).release();
}
}
}
}
};
boolean submitted = false;
InternalDistributedSystem ids = InternalDistributedSystem.getConnectedInstance();
if (ids != null) {
try {
ids.getDistributionManager().getWaitingThreadPool().execute(runnable);
submitted = true;
} catch (RejectedExecutionException e) {
// fall through with submitted false
} catch (CancelException e) {
// fall through with submitted false
} catch (NullPointerException e) {
// fall through with submitted false
}
}
if (!submitted) {
String name = this.getClass().getSimpleName() + "@" + this.hashCode() + " Clear Thread";
Thread thread = new Thread(runnable, name);
thread.setDaemon(true);
thread.start();
}
}
}
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class DistributedSystem method connect.
//////////////////////// Static Methods ////////////////////////
/**
* Connects to a GemFire distributed system with a configuration supplemented by the given
* properties. See {@linkplain ConfigurationProperties} for available GemFire properties and their
* meanings.
* <P>
* The actual configuration attribute values used to connect comes from the following sources:
* <OL>
* <LI>System properties. If a system property named "<code>gemfire.</code><em>propertyName</em>"
* is defined and its value is not an empty string then its value will be used for the named
* configuration attribute.
*
* <LI>Code properties. Otherwise if a property is defined in the <code>config</code> parameter
* object and its value is not an empty string then its value will be used for that configuration
* attribute.
* <LI>File properties. Otherwise if a property is defined in a configuration property file found
* by this application and its value is not an empty string then its value will be used for that
* configuration attribute. A configuration property file may not exist. See the following section
* for how configuration property files are found.
* <LI>Defaults. Otherwise a default value is used.
* </OL>
* <P>
* The name of the property file can be specified using the "gemfirePropertyFile" system property.
* If the system property is set to a relative file name then it is searched for in following
* locations. If the system property is set to an absolute file name then that file is used as the
* property file. If the system property is not set, then the name of the property file defaults
* to "gemfire.properties". The configuration file is searched for in the following locations:
*
* <OL>
* <LI>Current directory (directory in which the VM was launched)</LI>
* <LI>User's home directory</LI>
* <LI>Class path (loaded as a {@linkplain ClassLoader#getResource(String) system resource})</LI>
* </OL>
*
* If the configuration file cannot be located, then the property will have its default value as
* described <a href="#configuration">above</a>.
*
* @param config The <a href="#configuration">configuration properties</a> used when connecting to
* the distributed system
*
* @throws IllegalArgumentException If <code>config</code> contains an unknown configuration
* property or a configuration property does not have an allowed value. Note that the
* values of boolean properties are parsed using
* {@link Boolean#valueOf(java.lang.String)}. Therefore all values other than "true"
* values will be considered <code>false</code> -- an exception will not be thrown.
* @throws IllegalStateException If a <code>DistributedSystem</code> with a different
* configuration has already been created in this VM or if this VM is
* {@link org.apache.geode.admin.AdminDistributedSystem administering} a distributed
* system.
* @throws org.apache.geode.GemFireIOException Problems while reading configuration properties
* file or while opening the log file.
* @throws org.apache.geode.GemFireConfigException The distribution transport is not configured
* correctly
*
* @deprecated as of 6.5 use {@link CacheFactory#create} or {@link ClientCacheFactory#create}
* instead.
*
*/
public static DistributedSystem connect(Properties config) {
if (config == null) {
// fix for bug 33992
config = new Properties();
}
synchronized (existingSystemsLock) {
if (DistributionManager.isDedicatedAdminVM) {
// For a dedicated admin VM, check to see if there is already
// a connect that will suit our purposes.
DistributedSystem existingSystem = getConnection(config);
if (existingSystem != null) {
return existingSystem;
}
} else {
boolean existingSystemDisconnecting = true;
boolean isReconnecting = false;
while (!existingSystems.isEmpty() && existingSystemDisconnecting && !isReconnecting) {
Assert.assertTrue(existingSystems.size() == 1);
InternalDistributedSystem existingSystem = (InternalDistributedSystem) existingSystems.get(0);
existingSystemDisconnecting = existingSystem.isDisconnecting();
// a reconnecting DS will block on GemFireCache.class and a ReconnectThread
// holds that lock and invokes this method, so we break out of the loop
// if we detect this condition
isReconnecting = existingSystem.isReconnectingDS();
if (existingSystemDisconnecting) {
boolean interrupted = Thread.interrupted();
try {
// no notify for existingSystemsLock, just to release the sync
existingSystemsLock.wait(50);
} catch (InterruptedException ex) {
interrupted = true;
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
} else if (existingSystem.isConnected()) {
existingSystem.validateSameProperties(config, existingSystem.isConnected());
return existingSystem;
} else {
// existingSystem.isDisconnecting()==false
throw new AssertionError("system should not be disconnecting==false and isConnected==falsed");
}
}
}
// Make a new connection to the distributed system
InternalDistributedSystem newSystem = InternalDistributedSystem.newInstance(config);
addSystem(newSystem);
return newSystem;
}
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class AdminDistributedSystemFactory method defineDistributedSystem.
/**
* Defines a distributed system configuration for administering the distributed system to which
* this VM is currently connected. The <code>DistributedSystem</code> is used to configure the
* discovery mechanism (multicast or locators), bind address, SSL attributes, as well as the
* logger of the <code>DistributedSystemConfig</code>. Note that the distributed system will not
* be able to be administered until the {@link AdminDistributedSystem#connect connect} method is
* invoked.
*
* @param system A connection to the distributed system
* @param remoteCommand The shell command that is used to launch processes that run on remote
* machines. If <code>null</code>, then the
* {@linkplain DistributedSystemConfig#DEFAULT_REMOTE_COMMAND default} will be used.
*
* @since GemFire 4.0
*/
public static DistributedSystemConfig defineDistributedSystem(DistributedSystem system, String remoteCommand) throws AdminException {
InternalDistributedSystem internal = (InternalDistributedSystem) system;
if (remoteCommand == null) {
remoteCommand = DistributedSystemConfig.DEFAULT_REMOTE_COMMAND;
}
DistributedSystemConfigImpl impl = new DistributedSystemConfigImpl(internal.getConfig(), remoteCommand);
return impl;
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class GemFireMemberStatus method initializePeers.
protected void initializePeers(DistributedSystem distributedSystem) {
InternalDistributedSystem ids = (InternalDistributedSystem) distributedSystem;
DM dm = ids.getDistributionManager();
Set connections = dm.getOtherNormalDistributionManagerIds();
Set connectionsIDs = new HashSet(connections.size());
for (Iterator iter = connections.iterator(); iter.hasNext(); ) {
InternalDistributedMember idm = (InternalDistributedMember) iter.next();
connectionsIDs.add(idm.getId());
}
setConnectedPeers(connectionsIDs);
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class RestAPITestBase method createCacheWithGroups.
String createCacheWithGroups(final String hostName, final String groups, final String context) {
RestAPITestBase test = new RestAPITestBase();
final int servicePort = AvailablePortHelper.getRandomAvailableTCPPort();
Properties props = new Properties();
if (groups != null) {
props.put(GROUPS, groups);
}
props.setProperty(START_DEV_REST_API, "true");
props.setProperty(HTTP_SERVICE_BIND_ADDRESS, hostName);
props.setProperty(HTTP_SERVICE_PORT, String.valueOf(servicePort));
InternalDistributedSystem ds = test.getSystem(props);
cache = CacheFactory.create(ds);
return "http://" + hostName + ":" + servicePort + context + "/v1";
}
Aggregations