Skip to content

Commit

Permalink
优化Zookeeper工具。
Browse files Browse the repository at this point in the history
  • Loading branch information
xwintop committed Apr 10, 2019
1 parent 886ed6e commit 4b8c151
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ xJavaFxTool是使用javaFx开发的实用小工具集,目前项目刚刚建立

39、DecompilerWxApkgTool:微信小程序反编译工具(一键反编译微信小程序包);

40、ZookeeperTool:Zookeeper工具(方便对zookeeper的一系列操作,包括新增、修改、删除(包括子文件)、重命名、复制、添加变更通知);

项目开发中,以后会陆续添加新工具,欢迎大家参与其中,多提提意见,谢谢。


Expand Down Expand Up @@ -217,3 +219,4 @@ xJavaFxTool
![输入图片说明](https://git.oschina.net/xwintop/xJavaFxTool/raw/master/images/图片转码工具.png "图片转码工具.png")
![输入图片说明](https://git.oschina.net/xwintop/xJavaFxTool/raw/master/images/Cmd调试工具.png "Cmd调试工具.png")
![输入图片说明](https://git.oschina.net/xwintop/xJavaFxTool/raw/master/images/短信群发工具.png "短信群发工具.png")
![输入图片说明](https://git.oschina.net/xwintop/xJavaFxTool/raw/master/images/zookeeper工具.png "zookeeper工具.png")
Binary file added images/zookeeper工具.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.xwintop.xJavaFxTool.controller.debugTools;

import com.easipass.gateway.entity.TaskConfig;
import com.xwintop.xJavaFxTool.services.debugTools.ZookeeperToolService;
import com.xwintop.xJavaFxTool.utils.JavaFxViewUtil;
import com.xwintop.xJavaFxTool.view.debugTools.ZookeeperToolView;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand All @@ -12,10 +12,8 @@
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.net.URL;
import java.util.Date;
import java.util.ResourceBundle;

/**
Expand All @@ -39,6 +37,7 @@ public void initialize(URL location, ResourceBundle resources) {
}

private void initView() {
JavaFxViewUtil.setSpinnerValueFactory(connectionTimeoutSpinner, 0, Integer.MAX_VALUE, 5000);
TreeItem<String> treeItem = new TreeItem<String>("/");
nodeTreeView.setRoot(treeItem);
}
Expand Down Expand Up @@ -67,6 +66,11 @@ private void initEvent() {
});
});
ContextMenu contextMenu = new ContextMenu(menu_UnfoldAll, menu_FoldAll);
MenuItem menu_AddNode = new MenuItem("添加子节点");
menu_AddNode.setOnAction(event1 -> {
zookeeperToolService.addNodeOnAction();
});
contextMenu.getItems().add(menu_AddNode);
MenuItem menu_Rename = new MenuItem("重命名节点");
menu_Rename.setOnAction(event1 -> {
zookeeperToolService.renameNodeOnAction(false);
Expand All @@ -77,11 +81,6 @@ private void initEvent() {
zookeeperToolService.renameNodeOnAction(true);
});
contextMenu.getItems().add(menu_Copy);
MenuItem menu_AddNode = new MenuItem("添加子节点");
menu_AddNode.setOnAction(event1 -> {
zookeeperToolService.addNodeOnAction();
});
contextMenu.getItems().add(menu_AddNode);
MenuItem menu_RemoveNode = new MenuItem("删除");
menu_RemoveNode.setOnAction(event1 -> {
zookeeperToolService.deleteNodeOnAction();
Expand Down Expand Up @@ -120,16 +119,6 @@ private void refreshOnAction(ActionEvent event) {
zookeeperToolService.refreshOnAction();
}

@FXML
private void deleteNodeOnAction(ActionEvent event) {
zookeeperToolService.deleteNodeOnAction();
}

@FXML
private void addNodeOnAction(ActionEvent event) {
zookeeperToolService.addNodeOnAction();
}

@FXML
private void nodeDataSaveOnAction(ActionEvent event) {
zookeeperToolService.nodeDataSaveOnAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public ZookeeperToolService(ZookeeperToolController zookeeperToolController) {

public void connectOnAction() {
if (zkClient == null) {
zkClient = new ZkClient(zookeeperToolController.getZkServersTextField().getText().trim());
try {
zkClient = new ZkClient(zookeeperToolController.getZkServersTextField().getText().trim(), zookeeperToolController.getConnectionTimeoutSpinner().getValue());
} catch (Exception e) {
TooltipUtil.showToast("连接失败!!!");
zkClient = null;
}
zkClient.setZkSerializer(new ZkSerializer() {
@Override
public byte[] serialize(Object data) throws ZkMarshallingError {
Expand All @@ -68,6 +73,22 @@ public Object deserialize(byte[] bytes) throws ZkMarshallingError {
}
}
});
// zkClient.subscribeStateChanges(new IZkStateListener() {
// @Override
// public void handleStateChanged(Watcher.Event.KeeperState state) throws Exception {
// log.info("连接状态", state);
// }
//
// @Override
// public void handleNewSession() throws Exception {
// log.info("handleNewSession");
// }
//
// @Override
// public void handleSessionEstablishmentError(Throwable error) throws Exception {
// log.warn("handleSessionEstablishmentError:", error);
// }
// });
}
zookeeperToolController.getNodeTreeView().getRoot().getChildren().clear();
this.addNodeTree("/", zookeeperToolController.getNodeTreeView().getRoot());
Expand All @@ -77,7 +98,6 @@ public Object deserialize(byte[] bytes) throws ZkMarshallingError {
private void addNodeTree(String path, TreeItem<String> treeItem) {
List<String> list = zkClient.getChildren(path);
for (String name : list) {
log.info("获取到文件:" + path + "/" + name);
TreeItem<String> treeItem2 = new TreeItem<>(name);
treeItem.getChildren().add(treeItem2);
this.addNodeTree(StringUtils.appendIfMissing(path, "/", "/") + name, treeItem2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeView;
import javafx.scene.control.*;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -22,16 +19,14 @@ public abstract class ZookeeperToolView implements Initializable {
@FXML
protected TextField zkServersTextField;
@FXML
protected Spinner<Integer> connectionTimeoutSpinner;
@FXML
protected Button connectButton;
@FXML
protected Button disconnectButton;
@FXML
protected Button refreshButton;
@FXML
protected Button addNodeButton;
@FXML
protected Button deleteNodeButton;
@FXML
protected TreeView<String> nodeTreeView;
@FXML
protected Button nodeDataSaveButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
Expand All @@ -24,11 +25,11 @@
<children>
<Label text="zkServers" />
<TextField fx:id="zkServersTextField" text="localhost:2181" />
<Label text="connectionTimeout" />
<Spinner fx:id="connectionTimeoutSpinner" prefHeight="23.0" prefWidth="84.0" />
<Button fx:id="connectButton" mnemonicParsing="false" onAction="#connectOnAction" text="连接" />
<Button fx:id="disconnectButton" mnemonicParsing="false" onAction="#disconnectOnAction" text="关闭" />
<Button fx:id="refreshButton" mnemonicParsing="false" onAction="#refreshOnAction" text="刷新" />
<Button fx:id="addNodeButton" mnemonicParsing="false" onAction="#addNodeOnAction" text="添加子结点" />
<Button fx:id="deleteNodeButton" mnemonicParsing="false" onAction="#deleteNodeOnAction" text="删除" />
</children>
<BorderPane.margin>
<Insets bottom="10.0" />
Expand Down

0 comments on commit 4b8c151

Please sign in to comment.