Skip to content

Commit 23c0446

Browse files
authored
ZOOKEEPER-4962: Export bound client port for ZooKeeperServerEmbedded
Reviewers: anmolnar Author: kezhuw Closes #2302 from kezhuw/ZOOKEEPER-4962-ZooKeeperServerEmbedded-getClientPort
1 parent 2b1808b commit 23c0446

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServerMain.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,13 @@ ServerCnxnFactory getSecureCnxnFactory() {
242242
return secureCnxnFactory;
243243
}
244244

245-
// VisibleForTesting
246245
public int getClientPort() {
247246
if (cnxnFactory != null) {
248247
return cnxnFactory.getLocalPort();
249248
}
250249
return 0;
251250
}
252251

253-
// VisibleForTesting
254252
public int getSecureClientPort() {
255253
if (secureCnxnFactory != null) {
256254
return secureCnxnFactory.getLocalPort();

zookeeper-server/src/main/java/org/apache/zookeeper/server/embedded/ZooKeeperServerEmbedded.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ static ZookKeeperServerEmbeddedBuilder builder() {
116116
*/
117117
void start(long startupTimeout) throws Exception;
118118

119+
/**
120+
* Get client port for no secure connection.
121+
*/
122+
int getClientPort();
123+
124+
/**
125+
* Get client port for secure connection.
126+
*/
127+
int getSecureClientPort();
128+
119129
/**
120130
* Get a connection string useful for the client.
121131
* @return the connection string

zookeeper-server/src/main/java/org/apache/zookeeper/server/embedded/ZooKeeperServerEmbeddedImpl.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ protected QuorumPeer getQuorumPeer() throws SaslException {
107107
@Override
108108
public void start() {
109109
super.start();
110-
boundClientPort = getClientPort();
111-
boundSecureClientPort = getSecureClientPort();
110+
boundClientPort = super.getClientPort();
111+
boundSecureClientPort = super.getSecureClientPort();
112112
LOG.info("ZK Server {} started", this);
113113
started.complete(null);
114114
}
@@ -148,8 +148,8 @@ public void run() {
148148
@Override
149149
public void serverStarted() {
150150
LOG.info("ZK Server started");
151-
boundClientPort = getClientPort();
152-
boundSecureClientPort = getSecureClientPort();
151+
boundClientPort = super.getClientPort();
152+
boundSecureClientPort = super.getSecureClientPort();
153153
started.complete(null);
154154
}
155155
};
@@ -190,6 +190,16 @@ public void run() {
190190
}
191191
}
192192

193+
@Override
194+
public int getClientPort() {
195+
return boundClientPort;
196+
}
197+
198+
@Override
199+
public int getSecureClientPort() {
200+
return boundSecureClientPort;
201+
}
202+
193203
@Override
194204
public String getConnectionString() {
195205
return prettifyConnectionString(config.getClientPortAddress(), boundClientPort);

0 commit comments

Comments
 (0)