Author: orudyy
Date: Tue Jan 5 22:59:15 2016
New Revision: 1723194
URL: http://svn.apache.org/viewvc?rev=1723194&view=rev
Log:
QPID-6959: Simplify environment mutating operations
Modified:
qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
Modified:
qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java?rev=1723194&r1=1723193&r2=1723194&view=diff
==============================================================================
---
qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
(original)
+++
qpid/java/trunk/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
Tue Jan 5 22:59:15 2016
@@ -721,23 +721,26 @@ public class ReplicatedEnvironmentFacade
void setCacheSizeInternal(long cacheSize)
{
- try
+ final ReplicatedEnvironment environment = _environment.get();
+ if (environment != null)
{
- final ReplicatedEnvironment environment = getEnvironment(false);
- final EnvironmentMutableConfig oldConfig =
environment.getMutableConfig();
- final EnvironmentMutableConfig newConfig =
oldConfig.setCacheSize(cacheSize);
- environment.setMutableConfig(newConfig);
+ try
+ {
+ final EnvironmentMutableConfig oldConfig =
environment.getMutableConfig();
+ final EnvironmentMutableConfig newConfig =
oldConfig.setCacheSize(cacheSize);
+ environment.setMutableConfig(newConfig);
- LOGGER.debug("Node {} cache size has been changed to {}",
_prettyGroupNodeName, cacheSize);
- }
- catch (RuntimeException e)
- {
- RuntimeException handled = handleDatabaseException("Exception on
setting cache size", e);
- if (handled instanceof ConnectionScopedRuntimeException || handled
instanceof ServerScopedRuntimeException)
+ LOGGER.debug("Node {} cache size has been changed to {}",
_prettyGroupNodeName, cacheSize);
+ }
+ catch (RuntimeException e)
{
- throw handled;
+ RuntimeException handled = handleDatabaseException("Exception
on setting cache size", e);
+ if (handled instanceof ConnectionScopedRuntimeException ||
handled instanceof ServerScopedRuntimeException)
+ {
+ throw handled;
+ }
+ throw new ConnectionScopedRuntimeException("Cannot set cache
size to " + cacheSize + " on node " + _prettyGroupNodeName, e);
}
- throw new ConnectionScopedRuntimeException("Cannot set cache size
to " + cacheSize + " on node " + _prettyGroupNodeName, e);
}
}
@@ -858,27 +861,32 @@ public class ReplicatedEnvironmentFacade
void setDesignatedPrimaryInternal(final boolean isPrimary)
{
- try
+ ReplicatedEnvironment environment = _environment.get();
+ if (environment != null)
{
- ReplicatedEnvironment environment = getEnvironment(false);
- final ReplicationMutableConfig oldConfig =
environment.getRepMutableConfig();
- final ReplicationMutableConfig newConfig =
oldConfig.setDesignatedPrimary(isPrimary);
- environment.setRepMutableConfig(newConfig);
-
- if (LOGGER.isInfoEnabled())
+ try
{
- LOGGER.info("Node " + _prettyGroupNodeName + " successfully
set designated primary : " + isPrimary);
+ final ReplicationMutableConfig oldConfig =
environment.getRepMutableConfig();
+ final ReplicationMutableConfig newConfig =
oldConfig.setDesignatedPrimary(isPrimary);
+ environment.setRepMutableConfig(newConfig);
+
+ if (LOGGER.isInfoEnabled())
+ {
+ LOGGER.info("Node " + _prettyGroupNodeName + "
successfully set designated primary : " + isPrimary);
+ }
}
- }
- catch (RuntimeException e)
- {
- RuntimeException handled = handleDatabaseException("Exception on
setting designated primary", e);
- if (handled instanceof ConnectionScopedRuntimeException || handled
instanceof ServerScopedRuntimeException)
+ catch (RuntimeException e)
{
- throw handled;
+ RuntimeException handled = handleDatabaseException("Exception
on setting designated primary", e);
+ if (handled instanceof ConnectionScopedRuntimeException ||
handled instanceof ServerScopedRuntimeException)
+ {
+ throw handled;
+ }
+ throw new ConnectionScopedRuntimeException("Cannot set
designated primary to " +
+ isPrimary + " on
node " + _prettyGroupNodeName, handled);
}
- throw new ConnectionScopedRuntimeException("Cannot set designated
primary to " + isPrimary + " on node " + _prettyGroupNodeName, handled);
}
+
}
int getPriority()
@@ -907,26 +915,33 @@ public class ReplicatedEnvironmentFacade
void setPriorityInternal(int priority)
{
- try
+ final ReplicatedEnvironment environment = _environment.get();
+ if (environment != null)
{
- final ReplicatedEnvironment environment = getEnvironment(false);
- final ReplicationMutableConfig oldConfig =
environment.getRepMutableConfig();
- final ReplicationMutableConfig newConfig =
oldConfig.setNodePriority(priority);
- environment.setRepMutableConfig(newConfig);
-
- if (LOGGER.isDebugEnabled())
+ try
{
- LOGGER.debug("Node " + _prettyGroupNodeName + " priority has
been changed to " + priority);
+ final ReplicationMutableConfig oldConfig =
environment.getRepMutableConfig();
+ final ReplicationMutableConfig newConfig =
oldConfig.setNodePriority(priority);
+ environment.setRepMutableConfig(newConfig);
+
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Node " + _prettyGroupNodeName + " priority
has been changed to " + priority);
+ }
}
- }
- catch (RuntimeException e)
- {
- RuntimeException handled = handleDatabaseException("Exception on
setting priority", e);
- if (handled instanceof ConnectionScopedRuntimeException || handled
instanceof ServerScopedRuntimeException)
+ catch (RuntimeException e)
{
- throw handled;
+ RuntimeException handled = handleDatabaseException("Exception
on setting priority", e);
+ if (handled instanceof ConnectionScopedRuntimeException
+ || handled instanceof ServerScopedRuntimeException)
+ {
+ throw handled;
+ }
+ throw new ConnectionScopedRuntimeException("Cannot set
priority to "
+ + priority
+ + " on node "
+ +
_prettyGroupNodeName, e);
}
- throw new ConnectionScopedRuntimeException("Cannot set priority to
" + priority + " on node " + _prettyGroupNodeName, e);
}
}
@@ -956,26 +971,36 @@ public class ReplicatedEnvironmentFacade
void setElectableGroupSizeOverrideInternal(int electableGroupOverride)
{
- try
+ final ReplicatedEnvironment environment = _environment.get();
+ if (environment != null)
{
- final ReplicatedEnvironment environment = getEnvironment(false);
- final ReplicationMutableConfig oldConfig =
environment.getRepMutableConfig();
- final ReplicationMutableConfig newConfig =
oldConfig.setElectableGroupSizeOverride(electableGroupOverride);
- environment.setRepMutableConfig(newConfig);
-
- if (LOGGER.isDebugEnabled())
+ try
{
- LOGGER.debug("Node " + _prettyGroupNodeName + " electable
group size override has been changed to " + electableGroupOverride);
+ final ReplicationMutableConfig oldConfig =
environment.getRepMutableConfig();
+ final ReplicationMutableConfig newConfig =
oldConfig.setElectableGroupSizeOverride(electableGroupOverride);
+ environment.setRepMutableConfig(newConfig);
+
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Node "
+ + _prettyGroupNodeName
+ + " electable group size override has been
changed to "
+ + electableGroupOverride);
+ }
}
- }
- catch (RuntimeException e)
- {
- RuntimeException handled = handleDatabaseException("Exception on
setting electable group override", e);
- if (handled instanceof ConnectionScopedRuntimeException || handled
instanceof ServerScopedRuntimeException)
+ catch (RuntimeException e)
{
- throw handled;
+ RuntimeException handled = handleDatabaseException("Exception
on setting electable group override", e);
+ if (handled instanceof ConnectionScopedRuntimeException
+ || handled instanceof ServerScopedRuntimeException)
+ {
+ throw handled;
+ }
+ throw new ConnectionScopedRuntimeException("Cannot set
electable group size to "
+ +
electableGroupOverride
+ + " on node "
+ +
_prettyGroupNodeName, e);
}
- throw new ConnectionScopedRuntimeException("Cannot set electable
group size to " + electableGroupOverride + " on node " + _prettyGroupNodeName,
e);
}
}
@@ -1071,12 +1096,7 @@ public class ReplicatedEnvironmentFacade
private ReplicatedEnvironment getEnvironment()
{
- return getEnvironment(true);
- }
-
- private ReplicatedEnvironment getEnvironment(boolean throwOnRestart)
- {
- if (throwOnRestart && getFacadeState() == State.RESTARTING)
+ if (getFacadeState() == State.RESTARTING)
{
throw new ConnectionScopedRuntimeException("Environment is
restarting");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]