* @param contex
* Callback context
*/
private void doRemoteSubscribe(final HedwigHubClient client, final ByteString topic, final boolean synchronous,
final Callback<Void> mcb, final Object context) {
final HedwigSubscriber sub = client.getSubscriber();
try {
if (sub.hasSubscription(topic, mySubId)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[" + myRegion.toStringUtf8() + "] cross-region subscription for topic "
+ topic.toStringUtf8() + " has existed before.");
}
mcb.operationFinished(null, null);
return;
}
} catch (PubSubException e) {
LOGGER.error("[" + myRegion.toStringUtf8() + "] checking cross-region subscription for topic "
+ topic.toStringUtf8() + " failed (this is should not happen): ", e);
mcb.operationFailed(context, e);
return;
}
sub.asyncSubscribe(topic, mySubId, CreateOrAttach.CREATE_OR_ATTACH, new Callback<Void>() {
@Override
public void operationFinished(Object ctx, Void resultOfOperation) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("[" + myRegion.toStringUtf8() + "] cross-region subscription done for topic " + topic.toStringUtf8());
try {
sub.startDelivery(topic, mySubId, new MessageHandler() {
@Override
public void deliver(final ByteString topic, ByteString subscriberId, Message msg,
final Callback<Void> callback, final Object context) {
// When messages are first published
// locally, the PublishHandler sets the