Skip to content

Commit

Permalink
cells: move CuratorFramework watchers initialization into Domain
Browse files Browse the repository at this point in the history
Motivation:
Domain#createCuratorFramework sounds alike a natural place apply dcache
specific watchers.

Modification:
move CuratorFramework watchers initialization into Domain class

Result:
CuratorFramework creation and initialization in a single place.

Acked-by: Paul Millar
Acked-by: Lea Morschel
Acked-by: Albert Rossi
Target: master
Require-book: no
Require-notes: no
  • Loading branch information
kofemann committed Jan 14, 2020
1 parent 9138f84 commit 49bc104
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
24 changes: 1 addition & 23 deletions modules/cells/src/main/java/dmg/cells/nucleus/CellGlue.java
Expand Up @@ -6,9 +6,6 @@
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.state.ConnectionState;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.ZooKeeper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -40,7 +37,6 @@ class CellGlue
{
private static final Logger LOGGER =
LoggerFactory.getLogger(CellGlue.class);
private static final Logger EVENT_LOGGER = LoggerFactory.getLogger("org.dcache.zookeeper");

private final String _cellDomainName;
private final ConcurrentMap<String, CellNucleus> _cellList = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -79,7 +75,7 @@ class CellGlue
System.currentTimeMillis();
}
_cellDomainName = cellDomainNameLocal;
_curatorFramework = withMonitoring(curatorFramework);
_curatorFramework = curatorFramework;
_domainAddress = new CellAddressCore("*", _cellDomainName);
_masterThreadGroup = new ThreadGroup("Master-Thread-Group");
_killerThreadGroup = new ThreadGroup("Killer-Thread-Group");
Expand All @@ -99,24 +95,6 @@ class CellGlue
_emergencyKillerExecutor = MoreExecutors.listeningDecorator(emergencyKillerExecutor);
}

private static CuratorFramework withMonitoring(CuratorFramework curator)
{
curator.getConnectionStateListenable().addListener((c,s) ->
EVENT_LOGGER.info("[CURATOR: {}] connection state now {}",
c.getState(), s));

curator.getCuratorListenable().addListener((c,e) ->
EVENT_LOGGER.info("[CURATOR: {}] event: type={}, name={}, "
+ "path={}, rc={}, children={}",
c.getState(), e.getType(), e.getName(), e.getPath(),
e.getResultCode(), e.getChildren()));

curator.getUnhandledErrorListenable().addListener((m,e) ->
EVENT_LOGGER.warn("[CURATOR: {}] unhandled error \"{}\": {}",
curator.getState(), m, e.getMessage()));
return curator;
}

static Thread newThread(ThreadGroup threadGroup, Runnable r)
{
Thread thread = new Thread(threadGroup, r);
Expand Down
19 changes: 18 additions & 1 deletion modules/dcache/src/main/java/org/dcache/boot/Domain.java
Expand Up @@ -54,6 +54,8 @@ public class Domain
private static final Logger _log =
LoggerFactory.getLogger(SystemCell.class);

private static final Logger EVENT_LOGGER = LoggerFactory.getLogger("org.dcache.zookeeper");

private final ConfigurationProperties _properties;
private final List<ConfigurationProperties> _services;
private final ResourceLoader _resourceLoader = new FileSystemResourceLoader();
Expand Down Expand Up @@ -159,9 +161,24 @@ protected CuratorFramework createCuratorFramework()
int sessionTimeoutMs =
getTime(PROPERTY_ZOOKEPER_SESSION_TIMEOUT, PROPERTY_ZOOKEPER_SESSION_TIMEOUT_UNIT);
RetryPolicy retryPolicy = new ExponentialBackoffRetry(baseSleepTimeMs, maxRetries);
return CuratorFrameworkFactory.newClient(zookeeperConnectionString,
CuratorFramework curator = CuratorFrameworkFactory.newClient(zookeeperConnectionString,
sessionTimeoutMs, connectionTimeoutMs,
retryPolicy);

curator.getConnectionStateListenable().addListener((c,s) ->
EVENT_LOGGER.info("[CURATOR: {}] connection state now {}",
c.getState(), s));

curator.getCuratorListenable().addListener((c,e) ->
EVENT_LOGGER.info("[CURATOR: {}] event: type={}, name={}, "
+ "path={}, rc={}, children={}",
c.getState(), e.getType(), e.getName(), e.getPath(),
e.getResultCode(), e.getChildren()));

curator.getUnhandledErrorListenable().addListener((m,e) ->
EVENT_LOGGER.warn("[CURATOR: {}] unhandled error \"{}\": {}",
curator.getState(), m, e.getMessage()));
return curator;
}

private int getTime(String baseProperty, String unitProperty)
Expand Down

0 comments on commit 49bc104

Please sign in to comment.