protected override void doRegister(RegisterMeta meta) { string directory = $"/meou/provider/{meta.getGroup()}/{meta.getName()}/{meta.getVersion()}"; try { var result = configClient.ExistsAsync(directory).ConfigureAwait(false).GetAwaiter().GetResult(); if (!result) { configClient.CreateRecursiveAsync(directory, null, org.apache.zookeeper.CreateMode.PERSISTENT).ConfigureAwait(false).GetAwaiter().GetResult(); } } catch (Exception e) { if (logger.IsEnabled(LogLevel.Warning)) { logger.LogWarning($"Create parent path failed, directory: {directory}, {e}."); } } try { string tempPath = $"{directory}/{meta.getHost()}:{meta.getPort()}:{meta.getWeight()}:{meta.getConnCount()}"; // The znode will be deleted upon the client's disconnect. configClient.CreateEphemeralAsync(tempPath).Wait(); } catch (Exception e) { if (logger.IsEnabled(LogLevel.Warning)) { logger.LogWarning($"Create register meta: {meta} path failed, {e}."); } } }
protected override void doUnregister(RegisterMeta meta) { string directory = $"/meou/provider/{meta.getGroup()}/{meta.getName()}/{meta.getVersion()}"; try { var result = configClient.ExistsAsync(directory).ConfigureAwait(false).GetAwaiter().GetResult(); if (result) { return; } } catch (Exception e) { if (logger.IsEnabled(LogLevel.Warning)) { logger.LogWarning($"Check exists with parent path failed, directory: { directory},{e}."); } } try { //meta.setHost(address); string tempPath = $"{directory}/{meta.getHost()}:{meta.getPort()}:{meta.getWeight()}:{meta.getConnCount()}"; // The znode will be deleted upon the client's disconnect. configClient.DeleteAsync(tempPath).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (Exception e) { if (logger.IsEnabled(LogLevel.Warning)) { logger.LogWarning($"Delete register meta: {meta} path failed, {e}."); } } }