Search in sources :

Example 71 with InternalDistributedSystem

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();
            }
        }
    }
}
Also used : OffHeapRegionEntry(org.apache.geode.internal.cache.OffHeapRegionEntry) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) CancelException(org.apache.geode.CancelException)

Example 72 with InternalDistributedSystem

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;
    }
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Properties(java.util.Properties) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 73 with InternalDistributedSystem

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;
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystemConfigImpl(org.apache.geode.admin.internal.DistributedSystemConfigImpl)

Example 74 with InternalDistributedSystem

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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator) DM(org.apache.geode.distributed.internal.DM) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) HashSet(java.util.HashSet)

Example 75 with InternalDistributedSystem

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";
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Properties(java.util.Properties)

Aggregations

InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)209 Properties (java.util.Properties)70 Test (org.junit.Test)60 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)58 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)41 IOException (java.io.IOException)35 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)32 DM (org.apache.geode.distributed.internal.DM)30 File (java.io.File)22 HashSet (java.util.HashSet)21 Set (java.util.Set)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)19 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)19 Region (org.apache.geode.cache.Region)17 ArrayList (java.util.ArrayList)16 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)16 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)14 VM (org.apache.geode.test.dunit.VM)14 Cache (org.apache.geode.cache.Cache)13 IgnoredException (org.apache.geode.test.dunit.IgnoredException)13