Skip to content

Commit

Permalink
日志优化
Browse files Browse the repository at this point in the history
  • Loading branch information
闫逍旭 committed May 29, 2016
1 parent d9f9e69 commit 3a8a9be
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 23 deletions.
3 changes: 1 addition & 2 deletions mpush-boot/src/main/java/com/mpush/bootstrap/Main.java
Expand Up @@ -25,7 +25,7 @@ public class Main {


public static void main(String[] args) { public static void main(String[] args) {
Logs.init(); Logs.init();
Logs.Console.error("launch app..."); Logs.Console.error("launch mpush server...");
ServerLauncher launcher = new ServerLauncher(); ServerLauncher launcher = new ServerLauncher();
launcher.start(); launcher.start();
addHook(launcher); addHook(launcher);
Expand All @@ -39,5 +39,4 @@ public void run() {
} }
}); });
} }

} }
Expand Up @@ -30,8 +30,8 @@
public class LastBoot extends BootJob { public class LastBoot extends BootJob {
@Override @Override
public void run() { public void run() {
UserManager.INSTANCE.clearUserOnlineData(); UserManager.I.clearUserOnlineData();
Logs.Console.error("end run bootstrap chain..."); Logs.Console.error("end run bootstrap chain...");
Logs.Console.error("app start success..."); Logs.Console.error("mpush server start success...");
} }
} }
Expand Up @@ -28,6 +28,8 @@


import java.util.*; import java.util.*;


import static redis.clients.jedis.Protocol.DEFAULT_TIMEOUT;

public class RedisClient { public class RedisClient {
public static final JedisPoolConfig CONFIG = buildConfig(); public static final JedisPoolConfig CONFIG = buildConfig();
private static final Map<RedisServer, JedisPool> POOL_MAP = Maps.newConcurrentMap(); private static final Map<RedisServer, JedisPool> POOL_MAP = Maps.newConcurrentMap();
Expand Down Expand Up @@ -60,7 +62,7 @@ private static JedisPoolConfig buildConfig() {
public static Jedis getClient(RedisServer node) { public static Jedis getClient(RedisServer node) {
JedisPool pool = POOL_MAP.get(node); JedisPool pool = POOL_MAP.get(node);
if (pool == null) { if (pool == null) {
pool = new JedisPool(CONFIG, node.getHost(), node.getPort(), Protocol.DEFAULT_TIMEOUT, node.getPassword()); pool = new JedisPool(CONFIG, node.getHost(), node.getPort(), DEFAULT_TIMEOUT, node.getPassword());
POOL_MAP.put(node, pool); POOL_MAP.put(node, pool);
} }
return pool.getResource(); return pool.getResource();
Expand Down
Expand Up @@ -21,7 +21,7 @@


import com.mpush.cache.redis.RedisKey; import com.mpush.cache.redis.RedisKey;
import com.mpush.cache.redis.manager.RedisManager; import com.mpush.cache.redis.manager.RedisManager;
import com.mpush.tools.Utils; import com.mpush.tools.config.ConfigManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


Expand All @@ -30,9 +30,9 @@
//查询使用 //查询使用
public final class UserManager { public final class UserManager {
private static final Logger LOGGER = LoggerFactory.getLogger(UserManager.class); private static final Logger LOGGER = LoggerFactory.getLogger(UserManager.class);
public static final UserManager INSTANCE = new UserManager(); public static final UserManager I = new UserManager();


private final String ONLINE_KEY = RedisKey.getUserOnlineKey(Utils.getExtranetAddress()); private final String ONLINE_KEY = RedisKey.getUserOnlineKey(ConfigManager.I.getPublicIp());


public UserManager() { public UserManager() {
clearUserOnlineData(); clearUserOnlineData();
Expand All @@ -54,7 +54,8 @@ public void recordUserOffline(String userId) {


//在线用户 //在线用户
public long getOnlineUserNum() { public long getOnlineUserNum() {
return RedisManager.I.zCard(ONLINE_KEY); Long value = RedisManager.I.zCard(ONLINE_KEY);
return value == null ? 0 : value;
} }


//在线用户列表 //在线用户列表
Expand Down
Expand Up @@ -21,9 +21,8 @@


import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.mpush.api.service.Listener; import com.mpush.api.service.Listener;
import com.mpush.cache.redis.RedisKey;
import com.mpush.cache.redis.manager.RedisManager;
import com.mpush.common.router.RemoteRouter; import com.mpush.common.router.RemoteRouter;
import com.mpush.common.user.UserManager;
import com.mpush.core.router.RouterCenter; import com.mpush.core.router.RouterCenter;
import com.mpush.core.server.AdminServer; import com.mpush.core.server.AdminServer;
import com.mpush.tools.Jsons; import com.mpush.tools.Jsons;
Expand Down Expand Up @@ -168,8 +167,7 @@ public Serializable handler(ChannelHandlerContext ctx, String args) {
case "conn": case "conn":
return adminServer.getConnectionServer().getConnectionManager().getConnections().size(); return adminServer.getConnectionServer().getConnectionManager().getConnections().size();
case "online": { case "online": {
Long value = RedisManager.I.zCard(RedisKey.getUserOnlineKey(Utils.getExtranetAddress())); return UserManager.I.getOnlineUserNum();
return value == null ? 0 : value;
} }


} }
Expand Down
Expand Up @@ -43,13 +43,13 @@ public UserOnlineOfflineListener() {


@Subscribe @Subscribe
void on(UserOnlineEvent event) { void on(UserOnlineEvent event) {
UserManager.INSTANCE.recordUserOnline(event.getUserId()); UserManager.I.recordUserOnline(event.getUserId());
RedisManager.I.publish(ONLINE_CHANNEL, event.getUserId()); RedisManager.I.publish(ONLINE_CHANNEL, event.getUserId());
} }


@Subscribe @Subscribe
void on(UserOfflineEvent event) { void on(UserOfflineEvent event) {
UserManager.INSTANCE.recordUserOffline(event.getUserId()); UserManager.I.recordUserOffline(event.getUserId());
RedisManager.I.publish(OFFLINE_CHANNEL, event.getUserId()); RedisManager.I.publish(OFFLINE_CHANNEL, event.getUserId());
} }
} }
Expand Up @@ -38,7 +38,7 @@ public static void main(String[] args) throws Exception {
Logs.init(); Logs.init();
PushSender sender = PushSender.create(); PushSender sender = PushSender.create();
sender.start().get(); sender.start().get();
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 1000; i++) {
PushContent content = PushContent.build(PushType.MESSAGE, "this a first push." + i); PushContent content = PushContent.build(PushType.MESSAGE, "this a first push." + i);
content.setMsgId("msgId_" + (i % 2)); content.setMsgId("msgId_" + (i % 2));
//Thread.sleep(1000); //Thread.sleep(1000);
Expand Down
Expand Up @@ -126,7 +126,7 @@ public Map<String, Executor> getActivePools() {
public static Map<String, Object> getPoolInfo(ThreadPoolExecutor executor) { public static Map<String, Object> getPoolInfo(ThreadPoolExecutor executor) {
Map<String, Object> info = new HashMap<>(); Map<String, Object> info = new HashMap<>();
info.put("corePoolSize", executor.getCorePoolSize()); info.put("corePoolSize", executor.getCorePoolSize());
info.put("maximumPoolSize", executor.getMaximumPoolSize()); info.put("maxPoolSize", executor.getMaximumPoolSize());
info.put("activeCount(workingThread)", executor.getActiveCount()); info.put("activeCount(workingThread)", executor.getActiveCount());
info.put("poolSize(workThread)", executor.getPoolSize()); info.put("poolSize(workThread)", executor.getPoolSize());
info.put("queueSize(blockedTask)", executor.getQueue().size()); info.put("queueSize(blockedTask)", executor.getQueue().size());
Expand Down
7 changes: 1 addition & 6 deletions mpush-zk/src/main/java/com/mpush/zk/ZKClient.java
Expand Up @@ -22,7 +22,6 @@
import com.mpush.api.Constants; import com.mpush.api.Constants;
import com.mpush.api.service.BaseService; import com.mpush.api.service.BaseService;
import com.mpush.api.service.Listener; import com.mpush.api.service.Listener;
import com.mpush.tools.Utils;
import com.mpush.tools.log.Logs; import com.mpush.tools.log.Logs;
import com.mpush.zk.listener.ZKNodeCacheWatcher; import com.mpush.zk.listener.ZKNodeCacheWatcher;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
Expand Down Expand Up @@ -123,11 +122,7 @@ private void registerConnectionLostListener() {
//TODO need close jvm? //TODO need close jvm?
@Override @Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) { public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
if (ConnectionState.LOST == newState) { Logs.ZK.warn("zk connection state changed new state={}, isConnected={}", newState, newState.isConnected());
Logs.ZK.info("{} lost connection", Utils.getInetAddress());
} else if (ConnectionState.RECONNECTED == newState) {
Logs.ZK.info("{} reconnected", Utils.getInetAddress());
}
} }
}); });
} }
Expand Down

0 comments on commit 3a8a9be

Please sign in to comment.