Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

<groupId>cc.bitky.clustermanage</groupId>
<artifactId>clustermanage-client</artifactId>
<version>0.7.0-SNAPSHOT</version>
<version>0.8.5-SNAPSHOT</version>
<packaging>jar</packaging>

<name>clustermanage-client</name>
<name>clustermanage-client-console</name>
<url>http://maven.apache.org</url>

<properties>
Expand Down
25 changes: 25 additions & 0 deletions clustermanage-client-javafx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
target/
test/
.mvn/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
86 changes: 86 additions & 0 deletions clustermanage-client-javafx/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>cc.bitky.clustermanage</groupId>
<artifactId>clustermanage-client</artifactId>
<version>0.8.6-SNAPSHOT</version>
<packaging>jar</packaging>

<name>clustermanage-client-javafx</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.12</junit.version>
<netty.version>4.1.9.Final</netty.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>${netty.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!-- append assembly id in release file name -->
<appendAssemblyId>true</appendAssemblyId>
<!--构建可执行的 Jar-->
<archive>
<manifest>
<mainClass>cc.bitky.clustermanage.MainLauncher</mainClass>
</manifest>
</archive>
<!--使用「Jar集成依赖」的描述符-->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
</includes>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cc.bitky.clustermanage;

public class KySetting {
//------------------系统---------------------------
public static final String VERSION = "v0.8.6";

//----------------网络连接--------------------------
public static final String HOST_NAME = "localhost";
public static final int PORT = 30232;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cc.bitky.clustermanage;

import cc.bitky.clustermanage.view.MainView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MainLauncher extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
startApp(primaryStage);
}

private void startApp(Stage primaryStage) {
primaryStage.setTitle("设备模拟客户端");
primaryStage.setScene(new Scene(MainView.getInstance()));
primaryStage.setMaximized(true);
primaryStage.setOnCloseRequest(event -> NettyLauncher.getInstance().shutdown());
primaryStage.show();
MainView.getInstance().updateGroupCount(10);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cc.bitky.clustermanage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Scanner;

import cc.bitky.clustermanage.netty.NettyClient;
import cc.bitky.clustermanage.view.MainView;

public class NettyLauncher {
private static Logger logger = LoggerFactory.getLogger(NettyLauncher.class);
private static NettyLauncher nettyLauncher;
private Scanner scanner = new Scanner(System.in);
private NettyClient nettyClient;

private NettyLauncher() {
}

public static NettyLauncher getInstance() {
if (nettyLauncher == null) nettyLauncher = new NettyLauncher();
return nettyLauncher;
}

public void start(String hostName, int port) {
nettyClient = new NettyClient();
nettyClient.setLaunchSuccessfulListener(isSuccess -> {
MainView.getInstance().setLabelConnStatus(isSuccess);
});
nettyClient.setFinishSuccessfulListener(isSuccess -> {
System.out.println("客户端优雅关闭成功");
System.exit(0);
});
nettyClient.start(hostName, port);
}

void shutdown() {
if (nettyClient != null)
nettyClient.shutdown();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cc.bitky.clustermanage.netty;

import java.net.InetSocketAddress;

import cc.bitky.clustermanage.netty.handler.KyChannelInitializer;
import cc.bitky.clustermanage.utils.SuccessfulListener;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.Future;

public class NettyClient {

private SuccessfulListener launchListener;
private SuccessfulListener finishListener;
private EventLoopGroup group;


public void start(String hostName, int port) {
new Thread(() -> {
group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group)
.channel(NioSocketChannel.class)
.handler(new KyChannelInitializer());
if (hostName != null && !hostName.equals(""))
bootstrap.remoteAddress(new InetSocketAddress(hostName, port));
else
bootstrap.remoteAddress(new InetSocketAddress(port));
ChannelFuture channelFuture = null;

try {
channelFuture = bootstrap.connect().sync();
} catch (InterruptedException e) {
e.printStackTrace();
}

startListenerHandle(channelFuture, launchListener);
}).start();
}

private void startListenerHandle(Future future, SuccessfulListener listener) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!future.isSuccess()) future.cause().printStackTrace();
if (listener != null) listener.onSuccess(future.isSuccess());
}

public void setLaunchSuccessfulListener(
SuccessfulListener successfulListener) {
this.launchListener = successfulListener;
}

public void setFinishSuccessfulListener(
SuccessfulListener finishListener) {
this.finishListener = finishListener;
}

public void shutdown() {
if (group != null) {
Future<?> futureShutdown = group.shutdownGracefully();
futureShutdown.addListener(future -> startListenerHandle(future, finishListener));
}
}
}
Loading