Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
夜色 committed Jan 23, 2017
1 parent 959a3a9 commit e5ff572
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions mpush-api/src/main/java/com/mpush/api/protocol/Packet.java
Expand Up @@ -31,6 +31,7 @@
*
* @author ohun@live.cn
*/
@SuppressWarnings("unchecked")
public class Packet {
public static final int HEADER_LEN = 13;

Expand Down
Expand Up @@ -143,14 +143,14 @@ private void reconnect(Connection connection, String hostAndPort) {
HostAndPort h_p = HostAndPort.fromString(hostAndPort);
connections.get(hostAndPort).remove(connection);
connection.close();
addConnection(h_p.getHostText(), h_p.getPort());
addConnection(h_p.getHost(), h_p.getPort());
}

private void removeClient(ServiceNode node) {
if (node != null) {
List<Connection> clients = connections.remove(getHostAndPort(node.getHost(), node.getPort()));
if (clients != null) {
clients.forEach(Connection::close);
List<Connection> list = connections.remove(getHostAndPort(node.getHost(), node.getPort()));
if (list != null) {
list.forEach(Connection::close);
}
}
}
Expand All @@ -175,6 +175,7 @@ void on(ConnectionConnectEvent event) {
InetSocketAddress address = (InetSocketAddress) connection.getChannel().remoteAddress();
String hostAndPort = getHostAndPort(address.getAddress().getHostAddress(), address.getPort());
connections.computeIfAbsent(hostAndPort, key -> new ArrayList<>(gateway_client_num)).add(connection);
logger.info("one gateway conn connect, hostAndPort={}, conn={}", hostAndPort, connection);
}

private static String getHostAndPort(String host, int port) {
Expand Down
Expand Up @@ -54,7 +54,7 @@ public final class WebSocketServer extends NettyTCPServer {

public static WebSocketServer I() {
if (I == null) {
synchronized (ConnectionServer.class) {
synchronized (WebSocketServer.class) {
if (I == null) {
I = new WebSocketServer();
}
Expand Down
2 changes: 1 addition & 1 deletion mpush-tools/src/main/java/com/mpush/tools/Utils.java
Expand Up @@ -112,7 +112,7 @@ public static String getInetAddress(boolean getLocal) {
}
}
}
LOGGER.debug("getInetAddress is null");
LOGGER.debug("getInetAddress is null, getLocal={}", getLocal);
return getLocal ? "127.0.0.1" : null;
} catch (Throwable e) {
LOGGER.error("getInetAddress exception", e);
Expand Down

0 comments on commit e5ff572

Please sign in to comment.