Class DistributedSystem
- All Implemented Interfaces:
StatisticsFactory,StatisticsTypeFactory
DistributedSystem is created by
invoking the connect(java.util.Properties) method with a configuration as described
below. A DistributedSystem is used when calling
CacheFactory.create(). This class should not be confused with the
AdminDistributedSystem interface that is
used for administering a distributed system.
When a program connects to the distributed system, a "distribution manager" is started in this VM and the other members of the distributed system are located. This discovery is performed by contacting "locators" running on a given host and port. All DistributedSystems that are configured to use the same locators are part of the same distributed system.
The current version of GemFire only supports creating one DistributedSystem per
virtual machine. Attempts to connect to multiple distributed systems (that is calling
connect(java.util.Properties) multiple times with different configuration Properties) will result
in an IllegalStateException being thrown (if connect is invoked multiple
times with equivalent Properties, then the same instance of
DistributedSystem will be returned). A common practice is to connect to the
distributed system and store a reference to the DistributedSystem object in a
well-known location such as a static variable. This practice provides access to the
DistributedSystem slightly faster than invoking connect multiple times.
Note that it is always advisable to disconnect() from the distributed system when a
program will no longer access it. Disconnecting frees up certain resources and allows your
application to connect to a different distributed system, if desirable.
Users should never subclass this class.
- Since:
- GemFire 3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static List<org.apache.geode.distributed.internal.InternalDistributedSystem>The instances ofDistributedSystemcreated in this VM.protected static final ObjectThis lock must be changed to add or remove a system.static final StringThe default value ofPROPERTIES_FILE_PROPERTYis"gemfire.properties".static final StringThePROPERTIES_FILE_PROPERTYis the system property that can be used to specify the name of the properties file that the connect method will check for when it looks for a properties file.static final StringDeprecated.static final StringThe default value ofSECURITY_PROPERTIES_FILE_PROPERTYis"gfsecurity.properties".static final StringTheSECURITY_PROPERTIES_FILE_PROPERTYis the system property that can be used to specify the name of the property file that the connect method will check for when it looks for a property file.static final StringDeprecated.As of 9.0, please usegetSecurityPropertiesFile()instead.Fields inherited from interface org.apache.geode.StatisticsTypeFactory
MAX_DESCRIPTORS_PER_TYPE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new instance ofDistributedSystem. -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidaddSystem(org.apache.geode.distributed.internal.InternalDistributedSystem newSystem) static DistributedSystemconnect(Properties config) Deprecated.as of 6.5 useCacheFactory.create()orClientCacheFactory.create()instead.protected static DistributedSystemconnectForAdmin(Properties props) Returns a connection to the distributed system that is appropriate for administration.abstract voidDeprecated.as of 6.5 useCache.close(boolean)orClientCache.close(boolean)instead.abstract DistributedMemberfindDistributedMember(String name) Find the distributed member with the given nameabstract Set<DistributedMember>findDistributedMembers(InetAddress address) Find the set of distributed members running on a given addressabstract Set<DistributedMember>Returns a set of all the other members in this distributed system.abstract CancelCriterionprotected static DistributedSystemgetConnection(Properties config) Returns an existing connection to the distributed system described by the given properties.abstract DistributedMemberReturns theDistributedMemberthat identifies this connection to the distributed system.abstract Set<DistributedMember>getGroupMembers(String group) Returns a set of all the members in the given group.abstract longgetId()Deprecated.getDistributedMember()provides an identity for this connection that is unique across the entire distributed system.abstract LogWriterDeprecated.abstract StringDeprecated.as of GemFire 5.0, usegetDistributedMember()insteadabstract StringgetName()Returns the name of this connection to the distributed system.abstract PropertiesReturns the configuration properties.static StringReturns the current value ofPROPERTIES_FILE_PROPERTYsystem property if set or the default valuePROPERTIES_FILE_DEFAULT.static URLGets anURLfor the properties file, if one can be found, that the connect method will use as its properties file.static URLDeprecated.As of 9.0, please usegetPropertiesFileURL()abstract DistributedSystemReturns the new DistributedSystem if there was an auto-reconnectabstract LogWriterDeprecated.abstract PropertiesReturns the security specific configuration properties.static StringReturns the current value ofSECURITY_PROPERTIES_FILE_PROPERTYsystem property if set or the default valueSECURITY_PROPERTIES_FILE_DEFAULT.static URLGets anURLfor the security properties file, if one can be found, that the connect method will use as its properties file.abstract booleanReturns whether or not thisDistributedSystemis connected to the distributed system.abstract booleanTest to see whether the DistributedSystem is in the process of reconnecting and recreating the cache after it has been removed from the system by other members or has shut down due to missing Roles and is reconnecting.static voidFrees up any socket resources owned by the calling thread.protected static voidremoveSystem(org.apache.geode.distributed.internal.InternalDistributedSystem oldSystem) protected static voidsetEnableAdministrationOnly(boolean adminOnly) static voidsetThreadsSocketPolicy(boolean conserveSockets) Sets the calling thread's socket policy.abstract voidForce the DistributedSystem to stop reconnecting.abstract booleanwaitUntilReconnected(long time, TimeUnit units) Wait for the DistributedSystem to finish reconnecting to the system and recreate the cache.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.geode.StatisticsFactory
createAtomicStatistics, createAtomicStatistics, createAtomicStatistics, createStatistics, createStatistics, createStatistics, findStatisticsByNumericId, findStatisticsByTextId, findStatisticsByTypeMethods inherited from interface org.apache.geode.StatisticsTypeFactory
createDoubleCounter, createDoubleCounter, createDoubleGauge, createDoubleGauge, createIntCounter, createIntCounter, createIntGauge, createIntGauge, createLongCounter, createLongCounter, createLongGauge, createLongGauge, createType, createTypesFromXml, findType
-
Field Details
-
existingSystems
protected static volatile List<org.apache.geode.distributed.internal.InternalDistributedSystem> existingSystemsThe instances ofDistributedSystemcreated in this VM. Presently only one connect to a distributed system is allowed in a VM. This set is never modified in place (it is always read only) but the reference can be updated by holders ofexistingSystemsLock. -
existingSystemsLock
This lock must be changed to add or remove a system. It is notified when a system is removed.- See Also:
-
PROPERTIES_FILE_PROPERTY
ThePROPERTIES_FILE_PROPERTYis the system property that can be used to specify the name of the properties file that the connect method will check for when it looks for a properties file. Unless the value specifies the fully qualified path to the file, the file will be searched for, in order, in the following directories:- the current directory
- the home directory
- the class path
The default value is
PROPERTIES_FILE_DEFAULT. However if thePROPERTIES_FILE_PROPERTYis set then its value will be used instead of the default. If this value is a relative file system path then the above search is done. If it is an absolute file system path then that file must exist; no search for it is done.- Since:
- Geode 1.0
- See Also:
-
PROPERTIES_FILE_DEFAULT
The default value ofPROPERTIES_FILE_PROPERTYis"gemfire.properties". The location of the file will be resolved during connect as described forPROPERTIES_FILE_PROPERTY.- Since:
- Geode 1.0
- See Also:
-
PROPERTY_FILE
Deprecated.As of 9.0, please usegetPropertiesFile()instead.ThePROPERTY_FILEis the name of the properties file that the connect method will check for when it looks for a properties file. The file will be searched for, in order, in the following directories:- the current directory
- the home directory
- the class path
The default value of PROPERTY_FILE is
"gemfire.properties". However if the "gemfirePropertyFile" system property is set then its value is the value of PROPERTY_FILE. If this value is a relative file system path then the above search is done. If it is an absolute file system path then that file must exist; no search for it is done.- Since:
- GemFire 5.0
- See Also:
-
SECURITY_PROPERTIES_FILE_PROPERTY
TheSECURITY_PROPERTIES_FILE_PROPERTYis the system property that can be used to specify the name of the property file that the connect method will check for when it looks for a property file. Unless the value specifies the fully qualified path to the file, the file will be searched for, in order, in the following directories:- the current directory
- the home directory
- the class path
The default value is
SECURITY_PROPERTIES_FILE_DEFAULT. However if theSECURITY_PROPERTIES_FILE_PROPERTYis set then its value will be used instead of the default. If this value is a relative file system path then the above search is done. If it is an absolute file system path then that file must exist; no search for it is done.- Since:
- Geode 1.0
- See Also:
-
SECURITY_PROPERTIES_FILE_DEFAULT
The default value ofSECURITY_PROPERTIES_FILE_PROPERTYis"gfsecurity.properties". The location of the file will be resolved during connect as described forSECURITY_PROPERTIES_FILE_PROPERTY.- Since:
- Geode 1.0
- See Also:
-
SECURITY_PROPERTY_FILE
Deprecated.As of 9.0, please usegetSecurityPropertiesFile()instead.TheSECURITY_PROPERTY_FILEis the name of the property file that the connect method will check for when it looks for a security property file. The file will be searched for, in order, in the following directories:- the current directory
- the home directory
- the class path
The default value of SECURITY_PROPERTY_FILE is
"gfsecurity.properties". However if the "gemfireSecurityPropertyFile" system property is set then its value is the value of SECURITY_PROPERTY_FILE. If this value is a relative file system path then the above search is done. If it is an absolute file system path then that file must exist; no search for it is done.- Since:
- GemFire 6.6.2
- See Also:
-
-
Constructor Details
-
DistributedSystem
protected DistributedSystem()Creates a new instance ofDistributedSystem. This constructor is protected so that it may only be invoked by subclasses.
-
-
Method Details
-
connect
Deprecated.as of 6.5 useCacheFactory.create()orClientCacheFactory.create()instead.Connects to a GemFire distributed system with a configuration supplemented by the given properties. See ConfigurationProperties for available GemFire properties and their meanings.The actual configuration attribute values used to connect comes from the following sources:
- System properties. If a system property named "
gemfire.propertyName" is defined and its value is not an empty string then its value will be used for the named configuration attribute. - Code properties. Otherwise if a property is defined in the
configparameter object and its value is not an empty string then its value will be used for that configuration attribute. - 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.
- Defaults. Otherwise a default value is used.
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:
- Current directory (directory in which the VM was launched)
- User's home directory
- Class path (loaded as a system resource)
- Parameters:
config- The configuration properties used when connecting to the distributed system- Returns:
- a connection to the distributed system that is appropriate for administration
- Throws:
IllegalArgumentException- Ifconfigcontains an unknown configuration property or a configuration property does not have an allowed value. Note that the values of boolean properties are parsed usingBoolean.valueOf(java.lang.String). Therefore all values other than "true" values will be consideredfalse-- an exception will not be thrown.IllegalStateException- If aDistributedSystemwith a different configuration has already been created in this VM or if this VM isadministeringa distributed system.GemFireIOException- Problems while reading configuration properties file or while opening the log file.GemFireConfigException- The distribution transport is not configured correctly
- System properties. If a system property named "
-
addSystem
protected static void addSystem(org.apache.geode.distributed.internal.InternalDistributedSystem newSystem) -
removeSystem
protected static void removeSystem(org.apache.geode.distributed.internal.InternalDistributedSystem oldSystem) -
setThreadsSocketPolicy
public static void setThreadsSocketPolicy(boolean conserveSockets) Sets the calling thread's socket policy. This value will override that default set by theconserve-socketsconfiguration property.- Parameters:
conserveSockets- Iftruethen calling thread will share socket connections with other threads. Iffalsethen calling thread will have its own sockets.- Since:
- GemFire 4.1
-
releaseThreadsSockets
public static void releaseThreadsSockets()Frees up any socket resources owned by the calling thread.- Since:
- GemFire 4.1
-
getConnection
Returns an existing connection to the distributed system described by the given properties.- Parameters:
config- the properties used when creating a connection to the distributed system- Returns:
- a connection to the distributed system that is appropriate for administration
- Since:
- GemFire 4.0
-
connectForAdmin
Returns a connection to the distributed system that is appropriate for administration. This method is for internal use only by the admin API.- Parameters:
props- the properties used when creating a connection to the distributed system- Returns:
- a connection to the distributed system that is appropriate for administration
- Since:
- GemFire 4.0
-
setEnableAdministrationOnly
protected static void setEnableAdministrationOnly(boolean adminOnly) - Parameters:
adminOnly- whether this VM is dedicated to administration- Since:
- GemFire 5.7
-
getLogWriter
Deprecated.Returns theLogWriterused for logging information. See logFile.- Returns:
- the
LogWriterused for logging information - Throws:
IllegalStateException- This VM has disconnected from the distributed system.
-
getSecurityLogWriter
Deprecated.Returns theLogWriterused for logging security related information. See logFile.- Returns:
- the
LogWriterused for logging security related information - Throws:
IllegalStateException- This VM has disconnected from the distributed system.- Since:
- GemFire 5.5
-
getProperties
Returns the configuration properties.- Returns:
- the configuration Properties
-
getSecurityProperties
Returns the security specific configuration properties.- Returns:
- the configuration Properties
- Since:
- GemFire 5.5
-
getCancelCriterion
- Returns:
- the cancel criterion for this system
-
disconnect
Deprecated.as of 6.5 useCache.close(boolean)orClientCache.close(boolean)instead.Disconnects from this distributed system. This operation will close the distribution manager and render theCacheand all distributed collections obtained from this distributed system inoperable. After a disconnect has completed, a VM may connect to another distributed system.Attempts to access a distributed system after a VM has disconnected from it will result in an
IllegalStateExceptionbeing thrown. -
isConnected
public abstract boolean isConnected()Returns whether or not thisDistributedSystemis connected to the distributed system.- Returns:
- whether this
DistributedSystemis connected to the distributed system - See Also:
-
getId
Deprecated.getDistributedMember()provides an identity for this connection that is unique across the entire distributed system.Returns the id of this connection to the distributed system.- Returns:
- the id of this connection to the distributed system
-
getMemberId
Deprecated.as of GemFire 5.0, usegetDistributedMember()insteadReturns a string that uniquely identifies this connection to the distributed system.- Returns:
- a string that uniquely identifies this connection to the distributed system
- Since:
- GemFire 4.0
- See Also:
-
getDistributedMember
Returns theDistributedMemberthat identifies this connection to the distributed system.- Returns:
- the member that represents this distributed system connection.
- Since:
- GemFire 5.0
-
getAllOtherMembers
Returns a set of all the other members in this distributed system.- Returns:
- returns a set of all the other members in this distributed system.
- Since:
- GemFire 7.0
-
getGroupMembers
Returns a set of all the members in the given group. Members join a group by setting the "groups" gemfire property.- Parameters:
group- the group to which the distributed members to find belong- Returns:
- returns a set of all the member in a group.
- Since:
- GemFire 7.0
-
findDistributedMembers
Find the set of distributed members running on a given address- Parameters:
address- the address of the distributed members to find- Returns:
- a set of all DistributedMembers that have any interfaces that match the given IP address. May be empty if there are no members.
- Since:
- GemFire 7.1
-
findDistributedMember
Find the distributed member with the given name- Parameters:
name- the name of the distributed member to find- Returns:
- the distributed member that has the given name, or null if no member is currently running with the given name.
- Since:
- GemFire 7.1
-
getName
Returns the name of this connection to the distributed system.- Returns:
- the name of this connection to the distributed system
-
getPropertiesFile
Returns the current value ofPROPERTIES_FILE_PROPERTYsystem property if set or the default valuePROPERTIES_FILE_DEFAULT.- Returns:
- the current value of
PROPERTIES_FILE_PROPERTYsystem property if set or the default valuePROPERTIES_FILE_DEFAULT - Since:
- Geode 1.0
- See Also:
-
getSecurityPropertiesFile
Returns the current value ofSECURITY_PROPERTIES_FILE_PROPERTYsystem property if set or the default valueSECURITY_PROPERTIES_FILE_DEFAULT.- Returns:
- the current value of
SECURITY_PROPERTIES_FILE_PROPERTYsystem property if set or the default valueSECURITY_PROPERTIES_FILE_DEFAULT - Since:
- Geode 1.0
- See Also:
-
getPropertiesFileURL
Gets anURLfor the properties file, if one can be found, that the connect method will use as its properties file.See
PROPERTIES_FILE_PROPERTYfor information on the name of the properties file and what locations it will be looked for in.- Returns:
- a
URLthat names the GemFire property file. Null is returned if no property file was found. - Since:
- Geode 1.0
- See Also:
-
getPropertyFileURL
Deprecated.As of 9.0, please usegetPropertiesFileURL()Gets anURLfor the property file, if one can be found, that the connect method will use as its property file.See
PROPERTIES_FILE_PROPERTYfor information on the name of the property file and what locations it will be looked for in.- Returns:
- a
URLthat names the GemFire property file. Null is returned if no property file was found. - Since:
- GemFire 5.0
- See Also:
-
getSecurityPropertiesFileURL
Gets anURLfor the security properties file, if one can be found, that the connect method will use as its properties file.See
SECURITY_PROPERTIES_FILE_PROPERTYfor information on the name of the properties file and what locations it will be looked for in.- Returns:
- a
URLthat names the GemFire security properties file. Null is returned if no properties file was found. - Since:
- GemFire 6.6.2
- See Also:
-
isReconnecting
public abstract boolean isReconnecting()Test to see whether the DistributedSystem is in the process of reconnecting and recreating the cache after it has been removed from the system by other members or has shut down due to missing Roles and is reconnecting.This will also return true if the DistributedSystem has finished reconnecting. When reconnect has completed you can use
getReconnectedSystem()to retrieve the new distributed system.- Returns:
- true if the DistributedSystem is attempting to reconnect or has finished reconnecting
-
waitUntilReconnected
Wait for the DistributedSystem to finish reconnecting to the system and recreate the cache. This may throw a DistributedSystemDisconnectedException if reconnect fails. The exception will detail what went wrong.- Parameters:
time- amount of time to wait, or -1 to wait foreverunits- the units associated with the time- Returns:
- true if the system was reconnected
- Throws:
InterruptedException- if the thread is interrupted while waiting
-
stopReconnecting
public abstract void stopReconnecting()Force the DistributedSystem to stop reconnecting. If the DistributedSystem is currently connected this will disconnect it and close the cache. -
getReconnectedSystem
Returns the new DistributedSystem if there was an auto-reconnect- Returns:
- the new DistributedSystem if there was an auto-reconnect
-
getPropertiesFile()instead.