首页 \ 问答 \ ZooKeeper食谱和Apache Curator(ZooKeeper Recipes and Apache Curator)

ZooKeeper食谱和Apache Curator(ZooKeeper Recipes and Apache Curator)

我试图了解Apache ZooKeeper(“ZK”)解决哪些类型的问题,也许他们的Recipes页面是最好的开始。

首先,我做了以下假设

  • ZooKeeper API(可用Java和C提供)公开了这7种简单的方法 ,然后您可以建立自己的使用模式,即“ZK Recipes”
  • 然后,您可以自己使用这些ZK Recipes来解决分布式编程中的问题
  • 或者,您可以使用Apache Curator附带的那些,而不是构建自己的ZK食谱
  • 因此无论哪种方式,您都在使用ZK Recipes(再次,本地生成或由Curator提供)来解决分布式计算问题

我相信Apache Kafka就是一个例子,Kafka使用ZK创建分布式队列 (这是列出的ZK食谱之一)。 所以如果我的假设是正确的,ZK公开这些API方法,并且Apache Kafka的创建者或者直接使用ZK或者使用Curator来实现“队列”ZK配方。

如果我上面的任何假设都是错误的,请首先纠正我! 假设我或多或少地走上正轨:

看看ZK食谱的清单,我看到以下(非穷举):

  • 障碍
  • 领袖选举

为了让我欣赏这些食谱和他们提供的解决方案,我首先需要感谢他们解决的问题! 我理解基本Java并发的锁是什么,但是我只是没有看到“分布式Lock”何时是必需的用例。 对于领先的选举,我所能想到的 - 作为一个首先需要它的用例 - 就是如果您正在构建一个应用程序,并希望通过内置的主/从或主/辅助功能发货。 也许在这种情况下,你会使用ZK来实现你自己的“领导者选举”配方,或者也许只是使用Curator的领导者锁定开箱即用。 至于障碍,我没有看到这些与Locks有什么不同。 所以我问:

  • 我的主/奴隶问题或主要/次要问题是ZK领导人选举食谱的准确用例吗?
  • 什么是分布式锁的例子? 它解决了什么问题?
  • 同上障碍:锁和障碍有什么区别?

I am trying to understand exactly what types of problems Apache ZooKeeper ("ZK") solves, and perhaps their Recipes page is the best place to start.

First off, I am making the following assumptions:

  • The ZooKeeper API (available in both Java and C) exposes these 7 simple methods which then allow you to build up your own usage patterns, known as "ZK Recipes"
  • It is then up to you to use these ZK Recipes to solve problems in distributed programming yourself
  • Or, instead of building up your own ZK Recipes, you could just use the ones that ship with Apache Curator
  • So either way, you're using ZK Recipes (again, homegrown or provided by Curator) to solve distributed computing problems

I believe Apache Kafka is an example of this, where Kafka uses ZK to create a distributed Queue (which is one of the listed ZK Recipes). So if my assumptions are correct, ZK exposes those API methods, and the creators of Apache Kafka either used ZK directly or used Curator to implement the "Queue" ZK Recipe.

If any of my above assumptions are wrong, please begin by correcting me! Assuming I'm more or less on track:

Looking at the list of ZK Recipes, I see the following (non-exhaustive):

  • Barriers
  • Locks
  • Leader Election

In order for me to appreciate these recipes and the solutions they present, I first need to appreciate the problem that they solve! I understand what a lock is from basic Java concurrency, but I'm just not seeing the use case for when a "distributed Lock" would ever be necessary. For leading election, all I can think of - as a use case for needing it in the first place - would be if you were building an application that you wanted to ship with a built-in master/slave or primary/secondary capability. Perhaps in that case you would use ZK to implement your own "Leader Election" recipe, or perhaps just use Curator's Leader Latch out of the box. As for Barriers, I don't see how those are any different than Locks. So I ask:

  • Is my master/slave or primary/secondary problem an accurate use case for ZK's Leader Election recipe?
  • What would be an example of a distributed Lock? What problem(s) does it solve?
  • Ditto for Barriers: and what's the difference between Locks and Barriers?

原文:https://stackoverflow.com/questions/30871254
更新时间:2024-05-09 20:05

最满意答案

代码中的以下行

MainWindow *mw = new MainWindow(this);

创建一个新的主窗口并更新它的列表。 我认为这确实发生了,但窗口从未显示过,所以你看不到它。 您真正想要做的是更新现有主窗口的列表。

基本上有两种方法。 你可以获得一个指向现有主窗口的指针(可以提供给对话框的构造函数或它自己的方法),也可以使用Qt的Signals and Slots概念,这是我认为的方法。

  1. 首先,在对话框的标题中定义信号:

    ...
    signals:
        void user_registered();
    ...
    
  2. 然后你在函数中发出信号

    //MainWindow *mw = new MainWindow(this);
    //mw->list();
    emit this->user_registered();
    
  3. 确保list()方法在MainWindow标头中声明为SLOT

  4. 连接MainWindow构造函数中的信号以调用list()槽:

    ...
    QObject::connect(this->dialog_test, SIGNAL(user_registered()), this, SLOT(list()));
    ...
    

使用这种方法,对话框根本不需要知道主窗口。 它基本上只是告诉任何对用户注册感兴趣的人,并且主窗口自身完整地对其进行操作。


The following line in your code

MainWindow *mw = new MainWindow(this);

creates a new main window and updates the list of it. I assume this actually happens, but the window is never shown so you do not see any of it. What you actually want to do is update the list of your existing main window.

There are basically two ways of doing that. You can either obtain a pointer to the existing main window (which can be provided to the constructor of the dialog or a method of its own) or use the Signals and Slots concept of Qt which is the way to go in my opinion.

  1. First of all, you define the signal in the header of the dialog:

    ...
    signals:
        void user_registered();
    ...
    
  2. Then you emit the signal in your function

    //MainWindow *mw = new MainWindow(this);
    //mw->list();
    emit this->user_registered();
    
  3. Make sure the list() method is declared as a SLOT in the MainWindow header

  4. Connect the signal in the MainWindow constructor to call the list() slot:

    ...
    QObject::connect(this->dialog_test, SIGNAL(user_registered()), this, SLOT(list()));
    ...
    

With this approach, the dialog does not need to know the main window at all. It basically just tells anyone who is interested that a user registered and the main window acts on it completly by itself.

相关问答

更多
  • 代码中的以下行 MainWindow *mw = new MainWindow(this); 创建一个新的主窗口并更新它的列表。 我认为这确实发生了,但窗口从未显示过,所以你看不到它。 您真正想要做的是更新现有主窗口的列表。 基本上有两种方法。 你可以获得一个指向现有主窗口的指针(可以提供给对话框的构造函数或它自己的方法),也可以使用Qt的Signals and Slots概念,这是我认为的方法。 首先,在对话框的标题中定义信号: ... signals: void user_registered ...
  • 如果它的自定义QDialog只是使函数setData()公开。 这样你就可以在显示对话框之前从MainWindow调用函数传递你的字符串。 然后,您不需要通过构造函数传递任何内容。 像editorplain.h东西 public: void setData(const QString &labelText); 和editorplain.cpp void Editorplain::setData(const QString &labelText) { ui->label_2->setText(label ...
  • 使用object_cast将指针强制转换为MainWindow类型,因为文档没有说使用空指针构造QPointer是安全的,所以你可以做得更安全 MainWindow* ptr = qobject_cast(mw_ptr); if(ptr != 0) mainwindow = ptr; 或者另一种方法是使用信号和插槽在主窗口和对话框之间进行通信。 Use object_cast to cast the pointer into the type of MainWindow ...
  • 我在你的代码的注释中注意到你打算创建一个MainWindow的实例并尝试连接到这个实例,这是一个与前一个实例不同的新实例,所以你将无法获得它。 首先,我们必须创建实例并将其连接起来,以便在构造函数中完成。 MainWindow.cpp MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->checkingAmo ...
  • 做一点测试,打开主窗口,不要关闭它。 打开首选项窗口并关闭它。 您的申请不应该以这种方式退出。 现在关闭主窗口,应用程序将退出。 这是因为QApplication属性“quitOnLastWindowClosed”,默认情况下设置为true。 你应该打电话 int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setQuitOnLastWindowClosed(false); MainWindow w; ...
  • 在以下两行中 q.exec(); MainWindow::close(); 该对话框显示为模式对话框,并阻止事件循环直到它关闭。 因此,除非关闭对话框,否则主窗口的close()函数将不会执行。 In the following two lines q.exec(); MainWindow::close(); The dialog appears as a modal dialog and blocks the event loop until it is closed. So the main win ...
  • 定义一个Window以用作输入对话框: XAML:
    首先,主窗口应该进行订阅没有明显的原因。 我会选择这样的东西: 创建一个封装订阅的服务(并在其构造函数中订阅) 注册为单身人士 让它实现INotifyPropertyChanged (通知消费者对Users的更改) 将服务注入UserListViewModel并观察Users属性(请参阅PropertyObserver ) 当服务中的用户更改时,请更新用户列表视图模型中的用户 最重要的是,这里不需要ObservableCollection :-) 编辑:示例: interface IUserService ...
  • 您需要实现INotifyPropertyChanged以将更改传播到绑定引擎。 如果您能够使用基类,则可以使用: public class Notify : INotifyPropertyChanged { #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; protected void RaisePropertyChanged(Expre ...
  • 您可以使用IsVisibleChanged事件: private void MainWindow_OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if ((bool) e.NewValue == true) { //DO Stuff } } You can use IsVisibleChanged event: ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。