Skip to content

Commit

Permalink
3.3.5发布
Browse files Browse the repository at this point in the history
  • Loading branch information
tywo45 committed Jul 12, 2019
1 parent 670c8a8 commit 31479e5
Show file tree
Hide file tree
Showing 30 changed files with 238 additions and 148 deletions.
2 changes: 1 addition & 1 deletion src/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.t-io</groupId>
<artifactId>tio-parent</artifactId>
<version>3.3.4.v20190705-RELEASE</version>
<version>3.3.5.v20190712-RELEASE</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down
107 changes: 88 additions & 19 deletions src/core/src/main/java/org/tio/server/TioServer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.tio.server;

import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.StandardSocketOptions;
import java.net.URL;
import java.nio.channels.AsynchronousChannelGroup;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand All @@ -15,26 +19,23 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.Node;
import org.tio.utils.IoUtils;
import org.tio.utils.SysConst;
import org.tio.utils.date.DateUtils;
import org.tio.utils.hutool.DateUtil;
import org.tio.utils.hutool.StrUtil;

/**
* @author tanyaowu
*
*/
public class TioServer {
private static Logger log = LoggerFactory.getLogger(TioServer.class);

private ServerGroupContext serverGroupContext;

private AsynchronousServerSocketChannel serverSocketChannel;

private AsynchronousChannelGroup channelGroup = null;

private Node serverNode;

private boolean isWaitingStop = false;
private static Logger log = LoggerFactory.getLogger(TioServer.class);
private ServerGroupContext serverGroupContext;
private AsynchronousServerSocketChannel serverSocketChannel;
private AsynchronousChannelGroup channelGroup = null;
private Node serverNode;
private boolean isWaitingStop = false;
private boolean checkLastVersion = true;

/**
*
Expand Down Expand Up @@ -123,14 +124,15 @@ public void start(String serverIp, int serverPort) throws IOException {
int xxLen = 18;
int aaLen = baseLen - 3;
List<String> infoList = new ArrayList<>();
infoList.add(StrUtil.fillAfter("Tio on github", ' ', xxLen) + "| " + SysConst.TIO_URL_GITHUB);
infoList.add(StrUtil.fillAfter("Tio site address", ' ', xxLen) + "| " + SysConst.TIO_URL_SITE);
infoList.add(StrUtil.fillAfter("Tio version", ' ', xxLen) + "| " + SysConst.TIO_CORE_VERSION);
infoList.add(StrUtil.fillAfter("t-io site", ' ', xxLen) + "| " + SysConst.TIO_URL_SITE);
infoList.add(StrUtil.fillAfter("t-io on gitee", ' ', xxLen) + "| " + SysConst.TIO_URL_GITEE);
infoList.add(StrUtil.fillAfter("t-io on github", ' ', xxLen) + "| " + SysConst.TIO_URL_GITHUB);
infoList.add(StrUtil.fillAfter("t-io version", ' ', xxLen) + "| " + SysConst.TIO_CORE_VERSION);

infoList.add(StrUtil.fillAfter("-", '-', aaLen));

infoList.add(StrUtil.fillAfter("GroupContext name", ' ', xxLen) + "| " + serverGroupContext.getName());
infoList.add(StrUtil.fillAfter("Started at", ' ', xxLen) + "| " + DateUtils.formatDateTime(new Date()));
infoList.add(StrUtil.fillAfter("Started at", ' ', xxLen) + "| " + DateUtil.formatDateTime(new Date()));
infoList.add(StrUtil.fillAfter("Listen on", ' ', xxLen) + "| " + this.serverNode);
infoList.add(StrUtil.fillAfter("Main Class", ' ', xxLen) + "| " + se.getClassName());

Expand All @@ -140,10 +142,9 @@ public void start(String serverIp, int serverPort) throws IOException {
String pid = runtimeName.split("@")[0];
long startTime = runtimeMxBean.getStartTime();
long startCost = System.currentTimeMillis() - startTime;
infoList.add(StrUtil.fillAfter("Jvm start time", ' ', xxLen) + "| " + startCost + " ms");
infoList.add(StrUtil.fillAfter("Tio start time", ' ', xxLen) + "| " + (System.currentTimeMillis() - start) + " ms");
infoList.add(StrUtil.fillAfter("Jvm start time", ' ', xxLen) + "| " + startCost + "ms");
infoList.add(StrUtil.fillAfter("Tio start time", ' ', xxLen) + "| " + (System.currentTimeMillis() - start) + "ms");
infoList.add(StrUtil.fillAfter("Pid", ' ', xxLen) + "| " + pid);

} catch (Exception e) {

}
Expand All @@ -159,6 +160,8 @@ public void start(String serverIp, int serverPort) throws IOException {
} else {
System.out.println(printStr);
}

checkLastVersion();
}

/**
Expand Down Expand Up @@ -204,4 +207,70 @@ public boolean stop() {
log.info(this.serverNode + " stopped");
return ret;
}

private void checkLastVersion() {
if (checkLastVersion) {
serverGroupContext.groupExecutor.execute(new Runnable() {
@Override
public void run() {
try {
URL url = new URL(SysConst.CHECK_LASTVERSION_URL_1);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(10 * 1000);
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = connection.getInputStream();
String result = IoUtils.streamToString(inputStream);

connection.disconnect();

url = new URL(SysConst.CHECK_LASTVERSION_URL_2 + result);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(10 * 1000);
connection.connect();
responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
inputStream = connection.getInputStream();
result = IoUtils.streamToString(inputStream);

if (SysConst.TIO_CORE_VERSION.equals(result)) {
log.info("The version you are using is the latest");
} else {
log.info("t-io latest version:{},your version:{}", result, SysConst.TIO_CORE_VERSION);
//3.3.5.v20190712-RELEASE
String myVersionDateStr = SysConst.TIO_CORE_VERSION.substring(SysConst.TIO_CORE_VERSION.length() - 16, SysConst.TIO_CORE_VERSION.length() - 8);
String latestVersionDateStr = result.substring(result.length() - 16, result.length() - 8);

SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");

Date myVersionDate = format.parse(myVersionDateStr);
Date latestVersionDate = format.parse(latestVersionDateStr);
Integer days = DateUtil.daysBetween(myVersionDate, latestVersionDate);

log.info("You haven't upgraded in {} days", days);
}
}

connection.disconnect();

}
} catch (Exception e) {
log.error("", e);
//
}
}
});
}
}

public boolean isCheckLastVersion() {
return checkLastVersion;
}

public void setCheckLastVersion(boolean checkLastVersion) {
this.checkLastVersion = checkLastVersion;
}
}
4 changes: 2 additions & 2 deletions src/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.t-io</groupId>
<artifactId>tio-parent</artifactId>
<packaging>pom</packaging>
<version>3.3.4.v20190705-RELEASE</version>
<version>3.3.5.v20190712-RELEASE</version>
<name>${project.artifactId}</name>
<url>http://maven.apache.org</url>

Expand Down Expand Up @@ -35,7 +35,7 @@

<properties>
<maven-jar-plugin.version>3.1.0</maven-jar-plugin.version>
<tio-utils.version>3.3.4.v20190705-RELEASE</tio-utils.version>
<tio-utils.version>3.3.5.v20190712-RELEASE</tio-utils.version>
<tio-core.version>${tio-utils.version}</tio-core.version>
<tio-flash-policy-server.version>${tio-utils.version}</tio-flash-policy-server.version>

Expand Down
2 changes: 1 addition & 1 deletion src/utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.t-io</groupId>
<artifactId>tio-parent</artifactId>
<version>3.3.4.v20190705-RELEASE</version>
<version>3.3.5.v20190712-RELEASE</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down
14 changes: 14 additions & 0 deletions src/utils/src/main/java/org/tio/utils/IoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,18 @@ public static int copy(final InputStream input, final OutputStream output) throw
}
return (int) count;
}

public static String streamToString(InputStream inputStream) {
try {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString(org.tio.utils.SysConst.DEFAULT_ENCODING);
} catch (Exception e) {
return null;
}
}
}
55 changes: 29 additions & 26 deletions src/utils/src/main/java/org/tio/utils/SysConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,80 @@
* 2018年7月1日 下午10:51:59
*/
public interface SysConst {
String TIO_URL_GITHUB = "https://github.com/tywo45/t-io";
String TIO_URL_SITE = "https://www.t-io.org/";
String TIO_CORE_VERSION = "3.3.4.v20190705-RELEASE";
String TIO_CORE_VERSION = "3.3.5.v20190712-RELEASE";
String TIO_URL_GITEE = "https://gitee.com/tywo45/t-io";
String TIO_URL_GITHUB = "https://github.com/tywo45/t-io";
String TIO_URL_SITE = "https://www.t-io.org";
String CHECK_LASTVERSION_URL_1 = TIO_URL_SITE + "/mytio/open/lastVersion1.tio_x?v=" + TIO_CORE_VERSION;
String CHECK_LASTVERSION_URL_2 = TIO_URL_SITE + "/mytio/open/lastVersion2.tio_x?id=";
/**
* 空串
*/
String BLANK = "";
String BLANK = "";
/**
* \r
*/
byte CR = 13;
byte CR = 13;
/**
* \n
*/
byte LF = 10;
byte LF = 10;
/**
* =
*/
byte EQ = '=';
byte EQ = '=';
/**
* =
*/
String STR_EQ = "=";
String STR_EQ = "=";
/**
* &
*/
byte AMP = '&';
byte AMP = '&';
/**
* &
*/
String STR_AMP = "&";
String STR_AMP = "&";
/**
* :
*/
byte COL = ':';
byte COL = ':';
/**
* :
*/
String STR_COL = ":";
String STR_COL = ":";
/**
* ;
*/
byte SEMI_COL = ';';
byte SEMI_COL = ';';
/**
* 一个空格
*/
byte SPACE = ' ';
byte SPACE = ' ';
/**
* 左括号
*/
byte LEFT_BRACKET = '(';
byte LEFT_BRACKET = '(';
/**
* 右括号
*/
byte RIGHT_BRACKET = ')';
byte RIGHT_BRACKET = ')';
/**
* ?
*/
byte ASTERISK = '?';
byte[] CR_LF_CR_LF = { CR, LF, CR, LF };
byte[] CR_LF = { CR, LF };
byte[] LF_LF = { LF, LF };
byte[] SPACE_ = { SPACE };
byte[] CR_ = { CR };
byte[] LF_ = { LF };
byte[] NULL = { 'n', 'u', 'l', 'l' };
byte ASTERISK = '?';
byte[] CR_LF_CR_LF = { CR, LF, CR, LF };
byte[] CR_LF = { CR, LF };
byte[] LF_LF = { LF, LF };
byte[] SPACE_ = { SPACE };
byte[] CR_ = { CR };
byte[] LF_ = { LF };
byte[] NULL = { 'n', 'u', 'l', 'l' };
/**
* \r\n
*/
String CRLF = "\r\n";
String DEFAULT_ENCODING = "utf-8";
String CRLF = "\r\n";
String DEFAULT_ENCODING = "utf-8";

Charset DEFAULT_CHARSET = Charset.forName(DEFAULT_ENCODING);
}
56 changes: 0 additions & 56 deletions src/utils/src/main/java/org/tio/utils/date/DateUtils.java

This file was deleted.

Loading

0 comments on commit 31479e5

Please sign in to comment.