From 92c9ecc5a64b248ad0db957cf5c67000dc09bd95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=A9=E5=8D=87?= Date: Mon, 14 Jan 2019 19:38:05 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=A2=9E=E5=8A=A0=E7=BE=A4=E7=BB=84?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E5=A4=84=E7=90=86=E5=99=A8=202=E3=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9ImServerAioListener=E5=9C=A8=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8B=E7=9A=84=E7=A9=BA=E6=8C=87?= =?UTF-8?q?=E9=92=88=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- jim-client/pom.xml | 2 +- jim-common/pom.xml | 2 +- .../jim/common/packets/JoinGroupRespBody.java | 2 +- jim-parent/pom.xml | 35 ++++++++----------- jim-server-demo/pom.xml | 2 +- jim-server/pom.xml | 2 +- .../command/handler/JoinGroupReqHandler.java | 24 +++++++++++-- .../processor/group/GroupCmdProcessor.java | 19 ++++++++++ .../server/listener/ImServerAioListener.java | 3 ++ 10 files changed, 65 insertions(+), 28 deletions(-) create mode 100644 jim-server/src/main/java/org/jim/server/command/handler/processor/group/GroupCmdProcessor.java diff --git a/README.md b/README.md index 7ce2c01..4cf8d9b 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ JavaDoc https://apidoc.gitee.com/xchao/j-im/ org.j-im jim-server - 2.5.0.v20181115-RELEASE + 2.6.0.v20190114-RELEASE ``` diff --git a/jim-client/pom.xml b/jim-client/pom.xml index f4fbdda..89bdb91 100644 --- a/jim-client/pom.xml +++ b/jim-client/pom.xml @@ -6,7 +6,7 @@ org.j-im jim-parent - 2.5.0.v20181115-RELEASE + 2.6.0.v20190114-RELEASE ../jim-parent/pom.xml diff --git a/jim-common/pom.xml b/jim-common/pom.xml index e92b12d..76a9eeb 100644 --- a/jim-common/pom.xml +++ b/jim-common/pom.xml @@ -7,7 +7,7 @@ org.j-im jim-parent - 2.5.0.v20181115-RELEASE + 2.6.0.v20190114-RELEASE ../jim-parent/pom.xml diff --git a/jim-common/src/main/java/org/jim/common/packets/JoinGroupRespBody.java b/jim-common/src/main/java/org/jim/common/packets/JoinGroupRespBody.java index bc9bca7..4ca9d0b 100644 --- a/jim-common/src/main/java/org/jim/common/packets/JoinGroupRespBody.java +++ b/jim-common/src/main/java/org/jim/common/packets/JoinGroupRespBody.java @@ -8,7 +8,7 @@ package org.jim.common.packets; * 功能说明: 加入群组响应 * 作者: WChao 创建时间: 2017年7月26日 下午5:09:20 */ -public class JoinGroupRespBody extends Message { +public class JoinGroupRespBody extends RespBody { private static final long serialVersionUID = 6635620192752369689L; public JoinGroupResult result; diff --git a/jim-parent/pom.xml b/jim-parent/pom.xml index 24e975a..340fec6 100644 --- a/jim-parent/pom.xml +++ b/jim-parent/pom.xml @@ -5,7 +5,7 @@ jim-parent pom ${project.artifactId} - 2.5.0.v20181115-RELEASE + 2.6.0.v20190114-RELEASE Jim-parent is the dependent parent project of J-IM communication establishment. http://www.j-im.org/ @@ -34,7 +34,7 @@ ../jim-server-demo - 2.5.0.v20181115-RELEASE + 2.6.0.v20190114-RELEASE 2.4.0.v20180508-RELEASE 2.4.0.v20180508-RELEASE @@ -71,7 +71,19 @@ - + + + + central + libs-release + https://mavenlib.izaodao.com/artifactory/libs-release + + + snapshots + libs-snapshot + https://mavenlib.izaodao.com/artifactory/libs-snapshot + + @@ -281,24 +293,7 @@ true - - org.apache.maven.plugins - maven-jar-plugin - - - - true - - - - - **/*.conf - **/*.xml - - - - diff --git a/jim-server-demo/pom.xml b/jim-server-demo/pom.xml index 342ec5e..de38441 100644 --- a/jim-server-demo/pom.xml +++ b/jim-server-demo/pom.xml @@ -6,7 +6,7 @@ org.j-im jim-parent - 2.5.0.v20181115-RELEASE + 2.6.0.v20190114-RELEASE ../jim-parent/pom.xml diff --git a/jim-server/pom.xml b/jim-server/pom.xml index 7e497e3..1ca88d6 100644 --- a/jim-server/pom.xml +++ b/jim-server/pom.xml @@ -7,7 +7,7 @@ org.j-im jim-parent - 2.5.0.v20181115-RELEASE + 2.6.0.v20190114-RELEASE ../jim-parent/pom.xml diff --git a/jim-server/src/main/java/org/jim/server/command/handler/JoinGroupReqHandler.java b/jim-server/src/main/java/org/jim/server/command/handler/JoinGroupReqHandler.java index 0d580f0..c65dc4d 100644 --- a/jim-server/src/main/java/org/jim/server/command/handler/JoinGroupReqHandler.java +++ b/jim-server/src/main/java/org/jim/server/command/handler/JoinGroupReqHandler.java @@ -1,10 +1,12 @@ package org.jim.server.command.handler; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.jim.common.ImAio; import org.jim.common.ImPacket; import org.jim.common.ImSessionContext; import org.jim.common.ImStatus; +import org.jim.server.command.handler.processor.group.GroupCmdProcessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tio.core.Aio; @@ -19,6 +21,9 @@ import org.jim.common.packets.User; import org.jim.common.utils.ImKit; import org.jim.common.utils.JsonKit; import org.jim.server.command.AbstractCmdHandler; + +import java.util.List; + /** * * 版本: [1.0] @@ -75,11 +80,26 @@ public class JoinGroupReqHandler extends AbstractCmdHandler { Aio.close(channelContext, "group is null when join group"); return null; } - ImAio.bindGroup(channelContext, groupId,imConfig.getMessageHelper().getBindListener()); + //实际绑定之前执行处理器动作 + List groupCmdProcessors = this.getProcessor(channelContext, GroupCmdProcessor.class); - //回一条消息,告诉对方进群结果 + //先定义为操作成功 JoinGroupResult joinGroupResult = JoinGroupResult.JOIN_GROUP_RESULT_OK; JoinGroupRespBody joinGroupRespBody = new JoinGroupRespBody(); + //当有群组处理器时候才会去处理 + if(CollectionUtils.isNotEmpty(groupCmdProcessors)){ + GroupCmdProcessor groupCmdProcessor = groupCmdProcessors.get(0); + joinGroupRespBody = groupCmdProcessor.join(joinGroup, channelContext); + if (joinGroupRespBody == null || JoinGroupResult.JOIN_GROUP_RESULT_OK.getNumber() != joinGroupRespBody.getResult().getNumber()) { + RespBody joinRespBody = new RespBody(Command.COMMAND_JOIN_GROUP_RESP, ImStatus.C10012).setData(joinGroupRespBody); + ImPacket respPacket = ImKit.ConvertRespPacket(joinRespBody, channelContext); + return respPacket; + } + } + //处理完处理器内容后 + ImAio.bindGroup(channelContext, groupId,imConfig.getMessageHelper().getBindListener()); + + //回一条消息,告诉对方进群结果 joinGroupRespBody.setGroup(groupId); joinGroupRespBody.setResult(joinGroupResult); diff --git a/jim-server/src/main/java/org/jim/server/command/handler/processor/group/GroupCmdProcessor.java b/jim-server/src/main/java/org/jim/server/command/handler/processor/group/GroupCmdProcessor.java new file mode 100644 index 0000000..7edf2cc --- /dev/null +++ b/jim-server/src/main/java/org/jim/server/command/handler/processor/group/GroupCmdProcessor.java @@ -0,0 +1,19 @@ +package org.jim.server.command.handler.processor.group; + +import org.jim.common.packets.Group; +import org.jim.common.packets.JoinGroupRespBody; +import org.jim.server.command.handler.processor.CmdProcessor; +import org.tio.core.ChannelContext; + +/** + * @author ensheng + */ +public interface GroupCmdProcessor extends CmdProcessor { + /** + * 加入群组处理 + * @param joinGroup + * @param channelContext + * @return + */ + JoinGroupRespBody join(Group joinGroup, ChannelContext channelContext); +} diff --git a/jim-server/src/main/java/org/jim/server/listener/ImServerAioListener.java b/jim-server/src/main/java/org/jim/server/listener/ImServerAioListener.java index 958883f..9db3797 100644 --- a/jim-server/src/main/java/org/jim/server/listener/ImServerAioListener.java +++ b/jim-server/src/main/java/org/jim/server/listener/ImServerAioListener.java @@ -67,6 +67,9 @@ public class ImServerAioListener implements ServerAioListener { */ @Override public void onBeforeClose(ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove) { + if (imConfig == null) { + return; + } MessageHelper messageHelper = imConfig.getMessageHelper(); if(messageHelper != null){ ImSessionContext imSessionContext = (ImSessionContext)channelContext.getAttribute(); -- Gitee