23 changed files with 279 additions and 25 deletions
@ -0,0 +1,27 @@ |
|||||||
|
package net.sopod.soim.client.handler.cmd; |
||||||
|
|
||||||
|
import com.google.inject.Inject; |
||||||
|
import com.google.inject.Singleton; |
||||||
|
import net.sopod.soim.client.cmd.handler.NonArgsHandler; |
||||||
|
import net.sopod.soim.client.session.SoImSession; |
||||||
|
import net.sopod.soim.data.msg.user.Friend; |
||||||
|
|
||||||
|
/** |
||||||
|
* FriendsHandler |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-05-23 22:58 |
||||||
|
*/ |
||||||
|
@Singleton |
||||||
|
public class FriendsHandler extends NonArgsHandler { |
||||||
|
|
||||||
|
@Inject |
||||||
|
private SoImSession soImSession; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handle() { |
||||||
|
Friend.ReqFriendList req = Friend.ReqFriendList.newBuilder().build(); |
||||||
|
soImSession.send(req); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
package net.sopod.soim.client.handler.msg; |
||||||
|
|
||||||
|
import com.google.inject.Singleton; |
||||||
|
import net.sopod.soim.client.logger.Logger; |
||||||
|
import net.sopod.soim.client.session.MessageHandler; |
||||||
|
import net.sopod.soim.data.msg.user.Friend; |
||||||
|
|
||||||
|
/** |
||||||
|
* ResAddFriendHandler |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-05-23 21:42 |
||||||
|
*/ |
||||||
|
@Singleton |
||||||
|
public class ResAddFriendHandler implements MessageHandler<Friend.ResAddFriend> { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handleMsg(Friend.ResAddFriend res) { |
||||||
|
System.out.println(res); |
||||||
|
if (res.getSuccess()) { |
||||||
|
Logger.info("添加好友成功"); |
||||||
|
} else { |
||||||
|
Logger.error("添加失败:{}", res.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
package net.sopod.soim.client.handler.msg; |
||||||
|
|
||||||
|
import com.google.inject.Singleton; |
||||||
|
import net.sopod.soim.client.logger.Logger; |
||||||
|
import net.sopod.soim.client.session.MessageHandler; |
||||||
|
import net.sopod.soim.data.msg.user.Friend; |
||||||
|
import net.sopod.soim.data.msg.user.UserMsg; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* ResFriendListHandler |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-05-23 22:59 |
||||||
|
*/ |
||||||
|
@Singleton |
||||||
|
public class ResFriendListHandler implements MessageHandler<Friend.ResFriendList> { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handleMsg(Friend.ResFriendList res) { |
||||||
|
List<UserMsg.UserInfo> friendsList = res.getFriendsList(); |
||||||
|
List<String> userLines = friendsList.stream() |
||||||
|
.map(u -> u.getUid() + "|" + u.getAccount() + "|" + u.getNickname()) |
||||||
|
.collect(Collectors.toList()); |
||||||
|
Logger.logList("好友列表", userLines); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,50 @@ |
|||||||
|
package net.sopod.soim.entry.worker; |
||||||
|
|
||||||
|
import net.sopod.soim.common.util.netty.FastThreadLocalThreadFactory; |
||||||
|
|
||||||
|
import java.util.concurrent.Executor; |
||||||
|
import java.util.concurrent.LinkedBlockingQueue; |
||||||
|
import java.util.concurrent.ThreadPoolExecutor; |
||||||
|
import java.util.concurrent.TimeUnit; |
||||||
|
|
||||||
|
/** |
||||||
|
* FutureExecutor |
||||||
|
* |
||||||
|
* @author tmy |
||||||
|
* @date 2022-05-23 23:03 |
||||||
|
*/ |
||||||
|
public class FutureExecutor implements Executor { |
||||||
|
|
||||||
|
private static FutureExecutor INSTANCE; |
||||||
|
|
||||||
|
private final ThreadPoolExecutor threadPoolExecutor; |
||||||
|
|
||||||
|
private FutureExecutor() { |
||||||
|
int cpus = Runtime.getRuntime().availableProcessors(); |
||||||
|
threadPoolExecutor = new ThreadPoolExecutor( |
||||||
|
2, |
||||||
|
cpus * 4, |
||||||
|
0, |
||||||
|
TimeUnit.MILLISECONDS, |
||||||
|
new LinkedBlockingQueue<Runnable>(), |
||||||
|
new FastThreadLocalThreadFactory("future-exec-%d", Thread.NORM_PRIORITY) |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void execute(Runnable command) { |
||||||
|
threadPoolExecutor.execute(command); |
||||||
|
} |
||||||
|
|
||||||
|
public static FutureExecutor getInstance() { |
||||||
|
if (INSTANCE == null) { |
||||||
|
synchronized (FutureExecutor.class) { |
||||||
|
if (INSTANCE == null) { |
||||||
|
INSTANCE = new FutureExecutor(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return INSTANCE; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue