-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add kafka announcement only logic (#1027)
- Loading branch information
1 parent
af7f497
commit bd54a98
Showing
6 changed files
with
150 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
d2/src/main/java/com/linkedin/d2/balancer/servers/ConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.linkedin.d2.balancer.servers; | ||
|
||
import com.linkedin.common.callback.Callback; | ||
import com.linkedin.common.callback.Callbacks; | ||
import com.linkedin.common.util.None; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* ConnectionManager is an abstract class responsible for managing connections to external systems. | ||
* It can be extended to handle specific service registries (e.g., Zookeeper). | ||
* For example, see {@link com.linkedin.d2.balancer.servers.ZooKeeperConnectionManager} for managing Zookeeper | ||
* connections during D2 server announcements. | ||
* This class provides basic functionalities such as start, shutdown, markDownAllServers, and markUpAllServers which | ||
* is called during D2 server announcements/de-announcement. | ||
*/ | ||
public abstract class ConnectionManager | ||
{ | ||
private final ZooKeeperAnnouncer[] _servers; | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ConnectionManager.class); | ||
|
||
protected ConnectionManager(ZooKeeperAnnouncer[] servers) | ||
{ | ||
_servers = servers; | ||
} | ||
|
||
abstract public void start(Callback<None> callback); | ||
|
||
abstract public void shutdown(final Callback<None> callback); | ||
|
||
abstract public String getAnnouncementTargetIdentifier(); | ||
|
||
public void markDownAllServers(final Callback<None> callback) | ||
{ | ||
Callback<None> markDownCallback; | ||
if (callback != null) | ||
{ | ||
markDownCallback = callback; | ||
} | ||
else | ||
{ | ||
markDownCallback = new Callback<None>() | ||
{ | ||
@Override | ||
public void onError(Throwable e) | ||
{ | ||
LOG.error("failed to mark down servers", e); | ||
} | ||
|
||
@Override | ||
public void onSuccess(None result) | ||
{ | ||
LOG.info("mark down all servers successful"); | ||
} | ||
}; | ||
} | ||
Callback<None> multiCallback = Callbacks.countDown(markDownCallback, _servers.length); | ||
for (ZooKeeperAnnouncer server : _servers) | ||
{ | ||
server.markDown(multiCallback); | ||
} | ||
} | ||
|
||
public void markUpAllServers(final Callback<None> callback) | ||
{ | ||
Callback<None> markUpCallback; | ||
if (callback != null) | ||
{ | ||
markUpCallback = callback; | ||
} | ||
else | ||
{ | ||
markUpCallback = new Callback<None>() | ||
{ | ||
@Override | ||
public void onError(Throwable e) | ||
{ | ||
LOG.error("failed to mark up servers", e); | ||
} | ||
|
||
@Override | ||
public void onSuccess(None result) | ||
{ | ||
LOG.info("mark up all servers successful"); | ||
} | ||
}; | ||
} | ||
Callback<None> multiCallback = Callbacks.countDown(markUpCallback, _servers.length); | ||
for (ZooKeeperAnnouncer server : _servers) | ||
{ | ||
server.markUp(multiCallback); | ||
} | ||
|
||
} | ||
|
||
public ZooKeeperAnnouncer[] getAnnouncers() | ||
{ | ||
return _servers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters