我正在使用javaeventing编写一个偶数驱动的 shell 来访问数据库。所以,我的用例是:
- 在命令行中打开 shell。
- 现在,shell 连接到数据库并监听传入的命令。
- 当它收到一个命令时,它会执行它并返回所需的输出。
现在,我怎样才能避免while(!exit){ //do stuff }
这种循环呢?如何正确使用 Java 事件?
直接的方法可以是:
while(!exit)
{
exit = myClass.execute("command"); //when command is exit, return true.
}
但是,我正在寻找 java eventing 是否可以提供更好的解决方案。
更新1:
这是我想要实现的:
1我的应用程序是一个 shell(如 mongodb shell)来尝试一个键值数据库。
2简单代码:
init(); //Initialize the connection with database
while(!exit)
{
//exit = myClass.execute("put(5)"); //This returns false
exit = myClass.execute("exit"); //returns true, i.e. the user wants to exit the shell
}
现在,在这里我没有看到 java eventing 的使用,我解决了我的问题,你能告诉我,java eventing 将如何出现在这里?我希望用户触发事件。