diff --git a/cim_for_mina/cim-boot-server/libs/cim-server-sdk-3.6.jar b/cim_for_mina/cim-boot-server/libs/cim-server-sdk-3.6.jar index eaa557e..8d2c84a 100644 Binary files a/cim_for_mina/cim-boot-server/libs/cim-server-sdk-3.6.jar and b/cim_for_mina/cim-boot-server/libs/cim-server-sdk-3.6.jar differ diff --git a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/CIMConfig.java b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/CIMConfig.java index e527ee9..28d36b9 100644 --- a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/CIMConfig.java +++ b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/CIMConfig.java @@ -16,7 +16,7 @@ import com.farsunset.cim.handler.SessionClosedHandler; import com.farsunset.cim.sdk.server.handler.CIMNioSocketAcceptor; import com.farsunset.cim.sdk.server.handler.CIMRequestHandler; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; @Configuration public class CIMConfig implements CIMRequestHandler { diff --git a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/admin/controller/SessionController.java b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/admin/controller/SessionController.java index 2e378fd..74b1c00 100644 --- a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/admin/controller/SessionController.java +++ b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/admin/controller/SessionController.java @@ -27,17 +27,18 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; -import com.farsunset.cim.service.impl.CIMSessionServiceImpl; +import com.farsunset.cim.service.CIMSessionService; + @Controller @RequestMapping("/console/session") public class SessionController { @Resource - private CIMSessionServiceImpl sessionManager; + private CIMSessionService memorySessionService; @RequestMapping(value = "/list.action") public String list(Model model) { - model.addAttribute("sessionList", sessionManager.queryAll()); + model.addAttribute("sessionList", memorySessionService.list()); return "console/session/manage"; } } diff --git a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/handler/BindHandler.java b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/handler/BindHandler.java index 73aedb1..da7e908 100644 --- a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/handler/BindHandler.java +++ b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/handler/BindHandler.java @@ -30,14 +30,14 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import com.farsunset.cim.push.CIMMessagePusher; import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.handler.CIMRequestHandler; import com.farsunset.cim.sdk.server.model.Message; import com.farsunset.cim.sdk.server.model.ReplyBody; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; -import com.farsunset.cim.service.impl.CIMSessionServiceImpl; -import com.farsunset.cim.util.StringUtil; +import com.farsunset.cim.sdk.server.model.CIMSession; +import com.farsunset.cim.service.CIMSessionService; /** @@ -51,57 +51,57 @@ public class BindHandler implements CIMRequestHandler { protected final Logger logger = LoggerFactory.getLogger(BindHandler.class); @Resource - private CIMSessionServiceImpl sessionManager; + private CIMSessionService memorySessionService; @Value("${server.host}") private String host; + @Resource + private CIMMessagePusher defaultMessagePusher; - public void process(CIMSession newSession, SentBody message) { + public void process(CIMSession newSession, SentBody body) { ReplyBody reply = new ReplyBody(); - reply.setKey(message.getKey()); + reply.setKey(body.getKey()); reply.setCode(CIMConstant.ReturnCode.CODE_200); + reply.setTimestamp(System.currentTimeMillis()); + try { - String account = message.get("account"); - newSession.setGid(StringUtil.getUUID()); + String account = body.get("account"); newSession.setAccount(account); - newSession.setDeviceId(message.get("deviceId")); + newSession.setDeviceId(body.get("deviceId")); newSession.setHost(host); - newSession.setChannel(message.get("channel")); - newSession.setDeviceModel(message.get("device")); - newSession.setClientVersion(message.get("version")); - newSession.setSystemVersion(message.get("osVersion")); + newSession.setChannel(body.get("channel")); + newSession.setDeviceModel(body.get("device")); + newSession.setClientVersion(body.get("version")); + newSession.setSystemVersion(body.get("osVersion")); newSession.setBindTime(System.currentTimeMillis()); - newSession.setPackageName(message.get("packageName")); - newSession.setHeartbeat(System.currentTimeMillis()); - - /** + /* * 由于客户端断线服务端可能会无法获知的情况,客户端重连时,需要关闭旧的连接 */ - CIMSession oldSession = sessionManager.get(account); + CIMSession oldSession = memorySessionService.get(account); - // 如果是账号已经在另一台终端登录。则让另一个终端下线 + /* + * 如果是账号已经在另一台终端登录。则让另一个终端下线 + */ if (oldSession != null && fromOtherDevice(newSession,oldSession) && oldSession.isConnected()) { sendForceOfflineMessage(oldSession, account, newSession.getDeviceModel()); } - - - /** + + /* * 有可能是同一个设备重复连接,则关闭旧的链接,这种情况一般是客户端断网,联网又重新链接上来,之前的旧链接没有来得及通过心跳机制关闭,在这里手动关闭 * 条件1,连接来自是同一个设备 * 条件2.2个连接都是同一台服务器 */ if (oldSession != null && !fromOtherDevice(newSession,oldSession) && Objects.equals(oldSession.getHost(),host)) { - oldSession.removeAttribute(CIMConstant.SESSION_KEY); - oldSession.closeOnFlush(); + closeQuietly(oldSession); } - - sessionManager.add(newSession); + memorySessionService.save(newSession); + } catch (Exception e) { reply.setCode(CIMConstant.ReturnCode.CODE_500); @@ -124,15 +124,17 @@ public class BindHandler implements CIMRequestHandler { msg.setSender("system"); msg.setContent(deviceModel); msg.setId(System.currentTimeMillis()); - closeQuietly(oldSession,msg); + + defaultMessagePusher.push(msg); + + closeQuietly(oldSession); } // 不同设备同一账号登录时关闭旧的连接 - private void closeQuietly(CIMSession oldSession,Message msg) { + private void closeQuietly(CIMSession oldSession) { if (oldSession.isConnected() && Objects.equals(host, oldSession.getHost())) { - oldSession.write(msg); - oldSession.removeAttribute(CIMConstant.SESSION_KEY); + oldSession.setAttribute(CIMConstant.KEY_QUIETLY_CLOSE,true); oldSession.closeOnFlush(); } } diff --git a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/handler/SessionClosedHandler.java b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/handler/SessionClosedHandler.java index 4e00c77..c41b547 100644 --- a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/handler/SessionClosedHandler.java +++ b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/handler/SessionClosedHandler.java @@ -22,6 +22,8 @@ package com.farsunset.cim.handler; +import java.util.Objects; + import javax.annotation.Resource; import org.slf4j.Logger; @@ -31,8 +33,8 @@ import org.springframework.stereotype.Component; import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.handler.CIMRequestHandler; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; -import com.farsunset.cim.service.impl.CIMSessionServiceImpl; +import com.farsunset.cim.sdk.server.model.CIMSession; +import com.farsunset.cim.service.CIMSessionService; /** @@ -46,17 +48,28 @@ public class SessionClosedHandler implements CIMRequestHandler { protected final Logger logger = LoggerFactory.getLogger(SessionClosedHandler.class); @Resource - private CIMSessionServiceImpl sessionManager; + private CIMSessionService memorySessionService; public void process(CIMSession ios, SentBody message) { + Object quietly = ios.getAttribute(CIMConstant.KEY_QUIETLY_CLOSE); + if (Objects.equals(quietly, true)) { + return; + } - Object account = ios.getAttribute(CIMConstant.SESSION_KEY); + Object account = ios.getAttribute(CIMConstant.KEY_ACCOUNT); if (account == null) { return; } - ios.removeAttribute(CIMConstant.SESSION_KEY); - sessionManager.remove(account.toString()); + CIMSession oldSession = memorySessionService.get(account.toString()); + + if (oldSession == null || oldSession.isApnsOpend()) { + return; + } + + oldSession.setState(CIMSession.STATE_DISABLED); + oldSession.setNid(null); + memorySessionService.save(oldSession); } } diff --git a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/push/DefaultMessagePusher.java b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/push/DefaultMessagePusher.java index 67962d0..e0e49bc 100644 --- a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/push/DefaultMessagePusher.java +++ b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/push/DefaultMessagePusher.java @@ -29,10 +29,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.farsunset.cim.sdk.server.model.Message; -import com.farsunset.cim.sdk.server.session.CIMSession; -import com.farsunset.cim.sdk.server.session.DefaultSessionManager; +import com.farsunset.cim.sdk.server.model.CIMSession; import com.farsunset.cim.service.ApnsService; -import com.farsunset.cim.service.impl.MessageDispatcherImpl; +import com.farsunset.cim.service.CIMSessionService; /** * 消息发送实现类 @@ -45,10 +44,8 @@ public class DefaultMessagePusher implements CIMMessagePusher { private String host; @Resource - private DefaultSessionManager sessionManager; + private CIMSessionService memorySessionService; - @Resource - private MessageDispatcherImpl messageDispatcher; @Resource @@ -61,31 +58,39 @@ public class DefaultMessagePusher implements CIMMessagePusher { * @param msg */ public void push(Message message) { - CIMSession session = sessionManager.get(message.getReceiver()); + CIMSession session = memorySessionService.get(message.getReceiver()); - /** - * 服务器集群时,可以在此 判断当前session是否连接于本台服务器,如果是,继续往下走,如果不是,将此消息发往当前session连接的服务器并 - */ - if (session.isConnected() && !Objects.equals(host, session.getHost())) { - messageDispatcher.forward(message, session.getHost()); + if(session == null) { return; } - /** - * 如果是在当前服务器则直接推送 + /* + * IOS设备,如果开启了apns,则使用apns推送 */ - if (session.isConnected() && Objects.equals(host, session.getHost())) { - session.write(message); + if (session.isIOSChannel() && session.isApnsOpend()) { + apnsService.push(message, session.getDeviceId()); return; } - /** - * ios设备流程特别处理,如果长链接断开了,并且ApnsAble为打开状态的话优走apns + /* + * 服务器集群时,判断当前session是否连接于本台服务器 + * 如果连接到了其他服务器则转发请求到目标服务器 */ - if (Objects.equals(session.getChannel(), CIMSession.CHANNEL_IOS) && Objects.equals(session.getApnsAble(), CIMSession.APNS_ON)) { - apnsService.push(message, session.getDeviceId()); + if (session.isConnected() && !Objects.equals(host, session.getHost())) { + /** + * @TODO + * 在此调用目标服务器接口来发送 + */ + return; } + /* + * 如果是Android,浏览器或者windows客户端则直接发送 + */ + if (session.isConnected() && Objects.equals(host, session.getHost())) { + session.write(message); + } + } } diff --git a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/MessageDispatcher.java b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/CIMSessionService.java similarity index 67% rename from cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/MessageDispatcher.java rename to cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/CIMSessionService.java index 911bfbc..45fb9c8 100644 --- a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/MessageDispatcher.java +++ b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/CIMSessionService.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2013-2019 Xia Jun(3979434@qq.com). * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,8 +21,23 @@ */ package com.farsunset.cim.service; -import com.farsunset.cim.sdk.server.model.Message; +import java.util.List; + +import com.farsunset.cim.sdk.server.model.CIMSession; + + +/** + * 集群 session管理实现示例, 各位可以自行实现 AbstractSessionManager接口来实现自己的 session管理 服务器集群时 + * 须要将CIMSession 信息存入数据库或者redis中 等 第三方存储空间中,便于所有服务器都可以访问 + */ +public interface CIMSessionService { + + void save(CIMSession session); + + CIMSession get(String account); + + List list(); + + void remove(String account); -public interface MessageDispatcher { - void forward(final Message msg, final String ip); } diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/session/ClusterSessionManager.java b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/ClusterSessionServiceImpl.java similarity index 60% rename from cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/session/ClusterSessionManager.java rename to cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/ClusterSessionServiceImpl.java index 988ca24..d6beb00 100644 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/session/ClusterSessionManager.java +++ b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/ClusterSessionServiceImpl.java @@ -19,47 +19,54 @@ * * *************************************************************************************** */ -package com.farsunset.cim.session; +package com.farsunset.cim.service.impl; + import java.util.List; -import com.farsunset.cim.sdk.server.session.CIMSession; -import com.farsunset.cim.sdk.server.session.SessionManager; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; + +import com.farsunset.cim.sdk.server.handler.CIMNioSocketAcceptor; +import com.farsunset.cim.sdk.server.model.CIMSession; +import com.farsunset.cim.service.CIMSessionService; + /** - * 集群 session管理实现示例, 各位可以自行实现 AbstractSessionManager接口来实现自己的 session管理 服务器集群时 - * 须要将CIMSession 信息存入数据库或者nosql 等 第三方存储空间中,便于所有服务器都可以访问 + * 集群情况下,数据库或者redis存储实现 + * 自行实现存储管理 + * */ -public class ClusterSessionManager implements SessionManager { +@Service("clusterSessionService") +public class ClusterSessionServiceImpl implements CIMSessionService { - public CIMSession get(String account) { - - // 这里查询数据库 - /* - * CIMSession session = database.getSession(account); - * session.setIoSession(ContextHolder.getBean(CIMNioSocketAcceptor.class). - * getManagedSessions().get(session.getNid())); return session; - */ - return null; + @Resource + private CIMNioSocketAcceptor nioSocketAcceptor; + + @Override + public void save(CIMSession session) { } @Override - public List queryAll() { + public CIMSession get(String account) { + + /* + * CIMSession session = database.getSession(account); + * session.setIoSession(nioSocketAcceptor.getManagedSessions().get(session.getNid())); + * return session; + */ + return null; } - + @Override public void remove(String account) { - } @Override - public void update(CIMSession session) { - + public List list() { + return null; } - - @Override - public void add(CIMSession arg0) { - - } - + } diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/CIMSessionServiceImpl.java b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MemorySessionServiceImpl.java similarity index 56% rename from cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/CIMSessionServiceImpl.java rename to cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MemorySessionServiceImpl.java index 94c3d2b..57ba29c 100644 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/CIMSessionServiceImpl.java +++ b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MemorySessionServiceImpl.java @@ -21,11 +21,45 @@ */ package com.farsunset.cim.service.impl; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + import org.springframework.stereotype.Service; -import com.farsunset.cim.sdk.server.session.DefaultSessionManager; +import com.farsunset.cim.sdk.server.model.CIMSession; +import com.farsunset.cim.service.CIMSessionService; -@Service -public class CIMSessionServiceImpl extends DefaultSessionManager { + +/** + * 单机,内存存储实现 + * + */ +@Service("memorySessionService") +public class MemorySessionServiceImpl implements CIMSessionService { + + private ConcurrentHashMap sessionMap = new ConcurrentHashMap(); + + @Override + public void save(CIMSession session) { + sessionMap.put(session.getAccount(), session); + } + + @Override + public CIMSession get(String account) { + return sessionMap.get(account); + } + + @Override + public void remove(String account) { + sessionMap.remove(account); + } + + @Override + public List list() { + List onlineList = new ArrayList<>(); + onlineList.addAll(sessionMap.values()); + return onlineList; + } } diff --git a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MessageDispatcherImpl.java b/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MessageDispatcherImpl.java deleted file mode 100644 index 3f7ab3c..0000000 --- a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MessageDispatcherImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright 2013-2019 Xia Jun(3979434@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *************************************************************************************** - * * - * Website : http://www.farsunset.com * - * * - *************************************************************************************** - */ -package com.farsunset.cim.service.impl; - -import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; - -import org.apache.commons.io.IOUtils; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import com.farsunset.cim.sdk.server.model.Message; -import com.farsunset.cim.service.MessageDispatcher; - -import okhttp3.FormBody; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -@Component -public class MessageDispatcherImpl implements MessageDispatcher{ - - private static final Logger logger = Logger.getLogger(MessageDispatcherImpl.class.getName()); - - @Value("${sys.message.dispatch.url}") - private String dispatchUrl; - - @Override - public void forward(final Message msg, final String ip) { - String apiUrl = String.format(dispatchUrl, ip); - try { - String response = httpPost(apiUrl, msg); - logger.info("消息转发目标服务器{" + ip + "},结果:" + response); - } catch (Exception e) { - e.printStackTrace(); - logger.severe("消息转发目标服务器" + apiUrl + "message:" + e.getMessage()); - } - } - - @SuppressWarnings("deprecation") - private String httpPost(String url, Message msg) throws Exception { - - OkHttpClient httpclient = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).build(); - FormBody.Builder build = new FormBody.Builder(); - - build.add("id", String.valueOf(msg.getId())); - build.add("action", msg.getAction()); - build.add("title", msg.getTitle()); - build.add("content", msg.getContent()); - build.add("sender", msg.getSender()); - build.add("receiver", msg.getReceiver()); - build.add("format", msg.getFormat()); - build.add("extra", msg.getExtra()); - build.add("timestamp", String.valueOf(msg.getTimestamp())); - Request request = new Request.Builder().url(url).post(build.build()).build(); - - Response response = httpclient.newCall(request).execute(); - String data = response.body().string(); - IOUtils.closeQuietly(response); - return data; - } - - -} diff --git a/cim_for_mina/cim-server-sdk/.classpath b/cim_for_mina/cim-server-sdk/.classpath index 508ecfa..8e97c67 100644 --- a/cim_for_mina/cim-server-sdk/.classpath +++ b/cim_for_mina/cim-server-sdk/.classpath @@ -3,11 +3,11 @@ - + + - diff --git a/cim_for_mina/cim-server-sdk/.settings/org.eclipse.jdt.core.prefs b/cim_for_mina/cim-server-sdk/.settings/org.eclipse.jdt.core.prefs index c537b63..0c68a61 100644 --- a/cim_for_mina/cim-server-sdk/.settings/org.eclipse.jdt.core.prefs +++ b/cim_for_mina/cim-server-sdk/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,7 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/cim_for_mina/cim-server-sdk/.settings/org.eclipse.wst.common.project.facet.core.xml b/cim_for_mina/cim-server-sdk/.settings/org.eclipse.wst.common.project.facet.core.xml index 10c580d..c56e134 100644 --- a/cim_for_mina/cim-server-sdk/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/cim_for_mina/cim-server-sdk/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,5 +1,5 @@ - + diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/constant/CIMConstant.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/constant/CIMConstant.java index 8f18c16..b4c6299 100644 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/constant/CIMConstant.java +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/constant/CIMConstant.java @@ -40,9 +40,14 @@ public interface CIMConstant { } - String SESSION_KEY = "account"; - String HEARTBEAT_KEY = "heartbeat"; + String KEY_ACCOUNT = "account"; + String KEY_QUIETLY_CLOSE = "quietlyClose"; + + String CLIENT_WEBSOCKET_HANDSHAKE = "client_websocket_handshake"; + + String CLIENT_CONNECT_CLOSED = "client_closed"; + public static interface ProtobufType { byte S_H_RQ = 1; byte C_H_RS = 0; diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/CIMLoggingFilter.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/CIMLoggingFilter.java index 1fb01e9..0fe9970 100644 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/CIMLoggingFilter.java +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/CIMLoggingFilter.java @@ -96,8 +96,8 @@ public class CIMLoggingFilter extends IoFilterAdapter { builder.append(" R:").append(session.getRemoteAddress().toString()); } - if (session.containsAttribute(CIMConstant.SESSION_KEY)) { - builder.append(" account:").append(session.getAttribute(CIMConstant.SESSION_KEY)); + if (session.containsAttribute(CIMConstant.KEY_ACCOUNT)) { + builder.append(" account:").append(session.getAttribute(CIMConstant.KEY_ACCOUNT)); } builder.append("]"); return builder.toString(); diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageEncoder.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageEncoder.java index 3b7a74a..5bca279 100644 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageEncoder.java +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageEncoder.java @@ -31,7 +31,7 @@ import org.apache.mina.filter.codec.ProtocolEncoderOutput; import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.model.HandshakerResponse; import com.farsunset.cim.sdk.server.model.feature.EncodeFormatable; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; /** * 服务端发送消息前编码 diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/AppMessageDecoder.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/AppMessageDecoder.java index 07df1f6..540d71d 100644 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/AppMessageDecoder.java +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/AppMessageDecoder.java @@ -33,7 +33,7 @@ import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.model.HeartbeatResponse; import com.farsunset.cim.sdk.server.model.SentBody; import com.farsunset.cim.sdk.server.model.proto.SentBodyProto; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; /** * 原生app发送的消息解码器 diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/WebMessageDecoder.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/WebMessageDecoder.java index 3ba0813..1dc7d5e 100644 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/WebMessageDecoder.java +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/WebMessageDecoder.java @@ -30,11 +30,10 @@ import org.apache.mina.filter.codec.ProtocolDecoderOutput; import org.apache.mina.filter.codec.demux.MessageDecoderAdapter; import org.apache.mina.filter.codec.demux.MessageDecoderResult; import com.farsunset.cim.sdk.server.constant.CIMConstant; -import com.farsunset.cim.sdk.server.handler.CIMNioSocketAcceptor; import com.farsunset.cim.sdk.server.model.HeartbeatResponse; import com.farsunset.cim.sdk.server.model.SentBody; import com.farsunset.cim.sdk.server.model.proto.SentBodyProto; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; import com.google.protobuf.InvalidProtocolBufferException; /** @@ -203,7 +202,7 @@ public class WebMessageDecoder extends MessageDecoderAdapter { iosession.setAttribute(CIMSession.PROTOCOL,CIMSession.WEBSOCKET); SentBody body = new SentBody(); - body.setKey(CIMNioSocketAcceptor.WEBSOCKET_HANDLER_KEY); + body.setKey(CIMConstant.CLIENT_WEBSOCKET_HANDSHAKE); body.setTimestamp(System.currentTimeMillis()); body.put("key", getSecWebSocketKey(message)); out.write(body); diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMNioSocketAcceptor.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMNioSocketAcceptor.java index eb3468e..d49383d 100644 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMNioSocketAcceptor.java +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMNioSocketAcceptor.java @@ -1,5 +1,5 @@ /** - * Copyright 2013-2019 Xia Jun(3979434@qq.com). + * Copyright 2013-2023 Xia Jun(3979434@qq.com). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.apache.mina.core.service.IoAcceptor; @@ -38,24 +39,16 @@ import org.apache.mina.filter.keepalive.KeepAliveMessageFactory; import org.apache.mina.transport.socket.DefaultSocketSessionConfig; import org.apache.mina.transport.socket.nio.NioSocketAcceptor; +import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.filter.CIMLoggingFilter; import com.farsunset.cim.sdk.server.filter.ServerMessageCodecFactory; import com.farsunset.cim.sdk.server.model.HeartbeatRequest; import com.farsunset.cim.sdk.server.model.HeartbeatResponse; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; public class CIMNioSocketAcceptor extends IoHandlerAdapter implements KeepAliveMessageFactory { - /** - * websocket特有的握手处理handler - */ - public final static String WEBSOCKET_HANDLER_KEY = "client_websocket_handshake"; - /** - * 连接关闭处理handler - */ - public final static String CIMSESSION_CLOSED_HANDLER_KEY = "client_closed"; - private HashMap innerHandlerMap = new HashMap(); private CIMRequestHandler outerRequestHandler; private IoAcceptor acceptor; @@ -69,7 +62,7 @@ public class CIMNioSocketAcceptor extends IoHandlerAdapter implements KeepAliveM /** * 预制websocket握手请求的处理 */ - innerHandlerMap.put(WEBSOCKET_HANDLER_KEY, new WebsocketHandler()); + innerHandlerMap.put(CIMConstant.CLIENT_WEBSOCKET_HANDSHAKE, new WebsocketHandler()); acceptor = new NioSocketAcceptor(); acceptor.getSessionConfig().setReadBufferSize(READ_BUFFER_SIZE); @@ -81,11 +74,16 @@ public class CIMNioSocketAcceptor extends IoHandlerAdapter implements KeepAliveM keepAliveFilter.setRequestTimeout(TIME_OUT); keepAliveFilter.setForwardEvent(true); - acceptor.getFilterChain().addLast("executor", new ExecutorFilter(Executors.newCachedThreadPool())); + ExecutorService executor = Executors.newCachedThreadPool(runnable -> { + Thread thread = Executors.defaultThreadFactory().newThread(runnable); + thread.setName("mina-thread-" + thread.getId()); + return thread; + }); + acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ServerMessageCodecFactory())); acceptor.getFilterChain().addLast("logger", new CIMLoggingFilter()); acceptor.getFilterChain().addLast("heartbeat", keepAliveFilter); - + acceptor.getFilterChain().addLast("executor", new ExecutorFilter(executor)); acceptor.setHandler(this); acceptor.bind(new InetSocketAddress(port)); @@ -93,6 +91,7 @@ public class CIMNioSocketAcceptor extends IoHandlerAdapter implements KeepAliveM public void unbind() { acceptor.unbind(); + acceptor.dispose(); } /** @@ -126,13 +125,12 @@ public class CIMNioSocketAcceptor extends IoHandlerAdapter implements KeepAliveM @Override public void sessionClosed(IoSession ios) { - + CIMSession session = new CIMSession(ios); SentBody body = new SentBody(); - body.setKey(CIMSESSION_CLOSED_HANDLER_KEY); + body.setKey(CIMConstant.CLIENT_CONNECT_CLOSED); outerRequestHandler.process(session, body); } - @Override public Object getRequest(IoSession session) { diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMRequestHandler.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMRequestHandler.java index 16aa5b8..0f49b39 100644 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMRequestHandler.java +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMRequestHandler.java @@ -26,7 +26,7 @@ package com.farsunset.cim.sdk.server.handler; * @author 3979434@qq.com */ import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; public interface CIMRequestHandler { diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/WebsocketHandler.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/WebsocketHandler.java index cd84899..6731762 100644 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/WebsocketHandler.java +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/WebsocketHandler.java @@ -25,7 +25,7 @@ import java.security.MessageDigest; import com.farsunset.cim.sdk.server.model.SentBody; import com.farsunset.cim.sdk.server.model.HandshakerResponse; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; /** * 处理websocket握手请求,返回响应的报文给浏览器 diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/CIMSession.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/CIMSession.java similarity index 63% rename from cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/CIMSession.java rename to cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/CIMSession.java index 1a2a834..d3dcfb8 100644 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/CIMSession.java +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/CIMSession.java @@ -1,5 +1,5 @@ /** - * Copyright 2013-2019 Xia Jun(3979434@qq.com). + * Copyright 2013-2023 Xia Jun(3979434@qq.com). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,35 +19,33 @@ * * *************************************************************************************** */ -package com.farsunset.cim.sdk.server.session; +package com.farsunset.cim.sdk.server.model; import java.io.Serializable; -import java.net.InetAddress; import java.net.SocketAddress; -import java.net.UnknownHostException; +import java.util.Objects; import org.apache.mina.core.future.WriteFuture; import org.apache.mina.core.session.IoSession; import com.farsunset.cim.sdk.server.constant.CIMConstant; +import com.farsunset.cim.sdk.server.model.proto.SessionProto; +import com.google.protobuf.InvalidProtocolBufferException; /** * IoSession包装类,集群时 将此对象存入表中 */ - public class CIMSession implements Serializable { - /** - * - */ private transient static final long serialVersionUID = 1L; - + public transient static String PROTOCOL = "protocol"; public transient static String WEBSOCKET = "websocket"; public transient static String NATIVEAPP = "nativeapp"; - public transient static final int STATUS_ENABLED = 0; - public transient static final int STATUS_DISABLED = 1; + public transient static String HOST = "HOST"; + public transient static final int STATE_ENABLED = 0; + public transient static final int STATE_DISABLED = 1; public transient static final int APNS_ON = 1; public transient static final int APNS_OFF = 0; @@ -59,22 +57,19 @@ public class CIMSession implements Serializable { private transient IoSession session; - private String gid;// session全局ID + private String account;// session绑定的账号,主键,一个账号同一时间之内在一个设备在线 private Long nid;// session在本台服务器上的ID private String deviceId;// 客户端ID (设备号码+应用包名),ios为devicetoken private String host;// session绑定的服务器IP - private String account;// session绑定的账号 private String channel;// 终端设备类型 private String deviceModel;// 终端设备型号 private String clientVersion;// 终端应用版本 private String systemVersion;// 终端系统版本 - private String packageName;// 终端应用包名 private Long bindTime;// 登录时间 - private Long heartbeat;// 心跳时间 private Double longitude;// 经度 private Double latitude;// 维度 private String location;// 位置 - private int apnsAble;// apns推送状态 + private int apns;// apns推送状态 private int state;// 状态 public CIMSession(IoSession session) { @@ -93,7 +88,7 @@ public class CIMSession implements Serializable { public void setAccount(String account) { this.account = account; - setAttribute(CIMConstant.SESSION_KEY, account); + setAttribute(CIMConstant.KEY_ACCOUNT, account); } public Double getLongitude() { @@ -120,17 +115,6 @@ public class CIMSession implements Serializable { this.location = location; } - public String getGid() { - return gid; - } - - public void setGid(String gid) { - - this.gid = gid; - - setAttribute("gid", gid); - } - public Long getNid() { return nid; } @@ -161,7 +145,6 @@ public class CIMSession implements Serializable { public void setDeviceId(String deviceId) { this.deviceId = deviceId; - } public String getHost() { @@ -192,25 +175,16 @@ public class CIMSession implements Serializable { this.systemVersion = systemVersion; } - public Long getHeartbeat() { - return heartbeat; - } - - public void setHeartbeat(Long heartbeat) { - this.heartbeat = heartbeat; - setAttribute(CIMConstant.HEARTBEAT_KEY, heartbeat); - } - public void setHost(String host) { this.host = host; } - public int getApnsAble() { - return apnsAble; + public int getApns() { + return apns; } - public void setApnsAble(int apnsAble) { - this.apnsAble = apnsAble; + public void setApns(int apns) { + this.apns = apns; } public int getState() { @@ -260,27 +234,7 @@ public class CIMSession implements Serializable { } public boolean isConnected() { - if (session != null) { - return session.isConnected(); - } - - if (!isLocalhost()) { - return state == STATUS_ENABLED; - } - - return false; - } - - public boolean isLocalhost() { - - try { - String ip = InetAddress.getLocalHost().getHostAddress(); - return ip.equals(host); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - return false; - + return (session != null && session.isConnected()) || state == STATE_ENABLED; } public void closeNow() { @@ -293,70 +247,111 @@ public class CIMSession implements Serializable { session.closeOnFlush(); } - public void setPackageName(String packageName) { - this.packageName = packageName; + public boolean isIOSChannel() { + return Objects.equals(channel, CHANNEL_IOS); } - public String getPackageName() { - return packageName; + public boolean isAndroidChannel() { + return Objects.equals(channel, CHANNEL_ANDROID); } + public boolean isWindowsChannel() { + return Objects.equals(channel, CHANNEL_WINDOWS); + } + + public boolean isApnsOpend() { + return Objects.equals(apns, APNS_ON); + } + + @Override public int hashCode() { - - return (deviceId + nid + host).hashCode(); + return getClass().hashCode(); } + @Override public boolean equals(Object o) { - if (o instanceof CIMSession) { - return hashCode() == o.hashCode(); + CIMSession target = (CIMSession) o; + return Objects.equals(target.deviceId, deviceId) && Objects.equals(target.nid, nid) + && Objects.equals(target.host, host); } return false; } - public boolean fromOtherDevice(Object o) { - - if (o instanceof CIMSession) { - - CIMSession t = (CIMSession) o; - if (t.deviceId != null && deviceId != null) { - return !t.deviceId.equals(deviceId); - } - } - return false; - } - - public boolean fromCurrentDevice(Object o) { - - return !fromOtherDevice(o); - } - - public void setIoSession(IoSession session) { - this.session = session; - } - - public IoSession getIoSession() { + public IoSession getSession() { return session; } - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("{"); - - buffer.append("\"").append("gid").append("\":").append("\"").append(gid).append("\"").append(","); - buffer.append("\"").append("nid").append("\":").append(nid).append(","); - buffer.append("\"").append("deviceId").append("\":").append("\"").append(deviceId).append("\"").append(","); - buffer.append("\"").append("host").append("\":").append("\"").append(host).append("\"").append(","); - buffer.append("\"").append("account").append("\":").append("\"").append(account).append("\"").append(","); - buffer.append("\"").append("channel").append("\":").append("\"").append(channel).append("\"").append(","); - buffer.append("\"").append("deviceModel").append("\":").append("\"").append(deviceModel).append("\"").append(","); - buffer.append("\"").append("status").append("\":").append(state).append(","); - buffer.append("\"").append("apnsAble").append("\":").append(apnsAble).append(","); - buffer.append("\"").append("bindTime").append("\":").append(bindTime).append(","); - buffer.append("\"").append("heartbeat").append("\":").append(heartbeat); - buffer.append("}"); - return buffer.toString(); - + public void setSession(IoSession session) { + this.session = session; } + public byte[] getProtobufBody() { + SessionProto.Model.Builder builder = SessionProto.Model.newBuilder(); + if (account != null) { + builder.setAccount(account); + } + if (nid != null) { + builder.setNid(nid); + } + if (deviceId != null) { + builder.setDeviceId(deviceId); + } + if (host != null) { + builder.setHost(host); + } + if (channel != null) { + builder.setChannel(channel); + } + if (deviceModel != null) { + builder.setDeviceModel(deviceModel); + } + if (clientVersion != null) { + builder.setClientVersion(clientVersion); + } + if (systemVersion != null) { + builder.setSystemVersion(systemVersion); + } + if (bindTime != null) { + builder.setBindTime(bindTime); + } + if (longitude != null) { + builder.setLongitude(longitude); + } + if (latitude != null) { + builder.setLatitude(latitude); + } + if (location != null) { + builder.setLocation(location); + } + builder.setState(state); + builder.setApns(apns); + return builder.build().toByteArray(); + } + + + public static CIMSession decode(byte[] protobufBody) throws InvalidProtocolBufferException { + if(protobufBody == null) { + return null; + } + SessionProto.Model proto = SessionProto.Model.parseFrom(protobufBody); + CIMSession session = new CIMSession(); + session.setApns(proto.getApns()); + session.setBindTime(proto.getBindTime()); + session.setChannel(proto.getChannel()); + session.setClientVersion(proto.getClientVersion()); + session.setDeviceId(proto.getDeviceId()); + session.setDeviceModel(proto.getDeviceModel()); + session.setHost(proto.getHost()); + session.setLatitude(proto.getLatitude()); + session.setLongitude(proto.getLongitude()); + session.setLocation(proto.getLocation()); + session.setNid(proto.getNid()); + session.setSystemVersion(proto.getSystemVersion()); + session.setState(proto.getState()); + session.setAccount(proto.getAccount()); + return session; + } + + } diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/Session.proto b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/Session.proto new file mode 100644 index 0000000..edce10d --- /dev/null +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/Session.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package com.farsunset.cim.sdk.server.model.proto; +option java_outer_classname="SessionProto"; +message Model { + string account = 1; + int64 nid = 2; + string deviceId = 3; + string host = 4; + string channel = 5; + string deviceModel = 6; + string clientVersion = 7; + string systemVersion = 8; + int64 bindTime = 9; + double longitude = 10; + double latitude = 11; + string location = 12; + int32 apns = 13; + int32 state = 14; +} diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/SessionProto.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/SessionProto.java new file mode 100644 index 0000000..8b2b859 --- /dev/null +++ b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/SessionProto.java @@ -0,0 +1,1932 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: Session.proto + +package com.farsunset.cim.sdk.server.model.proto; + +public final class SessionProto { + private SessionProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + public interface ModelOrBuilder extends + // @@protoc_insertion_point(interface_extends:com.farsunset.cim.sdk.server.model.proto.Model) + com.google.protobuf.MessageOrBuilder { + + /** + * string account = 1; + */ + java.lang.String getAccount(); + /** + * string account = 1; + */ + com.google.protobuf.ByteString + getAccountBytes(); + + /** + * int64 nid = 2; + */ + long getNid(); + + /** + * string deviceId = 3; + */ + java.lang.String getDeviceId(); + /** + * string deviceId = 3; + */ + com.google.protobuf.ByteString + getDeviceIdBytes(); + + /** + * string host = 4; + */ + java.lang.String getHost(); + /** + * string host = 4; + */ + com.google.protobuf.ByteString + getHostBytes(); + + /** + * string channel = 5; + */ + java.lang.String getChannel(); + /** + * string channel = 5; + */ + com.google.protobuf.ByteString + getChannelBytes(); + + /** + * string deviceModel = 6; + */ + java.lang.String getDeviceModel(); + /** + * string deviceModel = 6; + */ + com.google.protobuf.ByteString + getDeviceModelBytes(); + + /** + * string clientVersion = 7; + */ + java.lang.String getClientVersion(); + /** + * string clientVersion = 7; + */ + com.google.protobuf.ByteString + getClientVersionBytes(); + + /** + * string systemVersion = 8; + */ + java.lang.String getSystemVersion(); + /** + * string systemVersion = 8; + */ + com.google.protobuf.ByteString + getSystemVersionBytes(); + + /** + * int64 bindTime = 9; + */ + long getBindTime(); + + /** + * double longitude = 10; + */ + double getLongitude(); + + /** + * double latitude = 11; + */ + double getLatitude(); + + /** + * string location = 12; + */ + java.lang.String getLocation(); + /** + * string location = 12; + */ + com.google.protobuf.ByteString + getLocationBytes(); + + /** + * int32 apns = 13; + */ + int getApns(); + + /** + * int32 state = 14; + */ + int getState(); + } + /** + * Protobuf type {@code com.farsunset.cim.sdk.server.model.proto.Model} + */ + public static final class Model extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:com.farsunset.cim.sdk.server.model.proto.Model) + ModelOrBuilder { + private static final long serialVersionUID = 0L; + // Use Model.newBuilder() to construct. + private Model(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private Model() { + account_ = ""; + nid_ = 0L; + deviceId_ = ""; + host_ = ""; + channel_ = ""; + deviceModel_ = ""; + clientVersion_ = ""; + systemVersion_ = ""; + bindTime_ = 0L; + longitude_ = 0D; + latitude_ = 0D; + location_ = ""; + apns_ = 0; + state_ = 0; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private Model( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownFieldProto3( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + account_ = s; + break; + } + case 16: { + + nid_ = input.readInt64(); + break; + } + case 26: { + java.lang.String s = input.readStringRequireUtf8(); + + deviceId_ = s; + break; + } + case 34: { + java.lang.String s = input.readStringRequireUtf8(); + + host_ = s; + break; + } + case 42: { + java.lang.String s = input.readStringRequireUtf8(); + + channel_ = s; + break; + } + case 50: { + java.lang.String s = input.readStringRequireUtf8(); + + deviceModel_ = s; + break; + } + case 58: { + java.lang.String s = input.readStringRequireUtf8(); + + clientVersion_ = s; + break; + } + case 66: { + java.lang.String s = input.readStringRequireUtf8(); + + systemVersion_ = s; + break; + } + case 72: { + + bindTime_ = input.readInt64(); + break; + } + case 81: { + + longitude_ = input.readDouble(); + break; + } + case 89: { + + latitude_ = input.readDouble(); + break; + } + case 98: { + java.lang.String s = input.readStringRequireUtf8(); + + location_ = s; + break; + } + case 104: { + + apns_ = input.readInt32(); + break; + } + case 112: { + + state_ = input.readInt32(); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.class, com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.Builder.class); + } + + public static final int ACCOUNT_FIELD_NUMBER = 1; + private volatile java.lang.Object account_; + /** + * string account = 1; + */ + public java.lang.String getAccount() { + java.lang.Object ref = account_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + account_ = s; + return s; + } + } + /** + * string account = 1; + */ + public com.google.protobuf.ByteString + getAccountBytes() { + java.lang.Object ref = account_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + account_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int NID_FIELD_NUMBER = 2; + private long nid_; + /** + * int64 nid = 2; + */ + public long getNid() { + return nid_; + } + + public static final int DEVICEID_FIELD_NUMBER = 3; + private volatile java.lang.Object deviceId_; + /** + * string deviceId = 3; + */ + public java.lang.String getDeviceId() { + java.lang.Object ref = deviceId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + deviceId_ = s; + return s; + } + } + /** + * string deviceId = 3; + */ + public com.google.protobuf.ByteString + getDeviceIdBytes() { + java.lang.Object ref = deviceId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + deviceId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int HOST_FIELD_NUMBER = 4; + private volatile java.lang.Object host_; + /** + * string host = 4; + */ + public java.lang.String getHost() { + java.lang.Object ref = host_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + host_ = s; + return s; + } + } + /** + * string host = 4; + */ + public com.google.protobuf.ByteString + getHostBytes() { + java.lang.Object ref = host_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + host_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int CHANNEL_FIELD_NUMBER = 5; + private volatile java.lang.Object channel_; + /** + * string channel = 5; + */ + public java.lang.String getChannel() { + java.lang.Object ref = channel_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + channel_ = s; + return s; + } + } + /** + * string channel = 5; + */ + public com.google.protobuf.ByteString + getChannelBytes() { + java.lang.Object ref = channel_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + channel_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int DEVICEMODEL_FIELD_NUMBER = 6; + private volatile java.lang.Object deviceModel_; + /** + * string deviceModel = 6; + */ + public java.lang.String getDeviceModel() { + java.lang.Object ref = deviceModel_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + deviceModel_ = s; + return s; + } + } + /** + * string deviceModel = 6; + */ + public com.google.protobuf.ByteString + getDeviceModelBytes() { + java.lang.Object ref = deviceModel_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + deviceModel_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int CLIENTVERSION_FIELD_NUMBER = 7; + private volatile java.lang.Object clientVersion_; + /** + * string clientVersion = 7; + */ + public java.lang.String getClientVersion() { + java.lang.Object ref = clientVersion_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + clientVersion_ = s; + return s; + } + } + /** + * string clientVersion = 7; + */ + public com.google.protobuf.ByteString + getClientVersionBytes() { + java.lang.Object ref = clientVersion_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + clientVersion_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int SYSTEMVERSION_FIELD_NUMBER = 8; + private volatile java.lang.Object systemVersion_; + /** + * string systemVersion = 8; + */ + public java.lang.String getSystemVersion() { + java.lang.Object ref = systemVersion_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + systemVersion_ = s; + return s; + } + } + /** + * string systemVersion = 8; + */ + public com.google.protobuf.ByteString + getSystemVersionBytes() { + java.lang.Object ref = systemVersion_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + systemVersion_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int BINDTIME_FIELD_NUMBER = 9; + private long bindTime_; + /** + * int64 bindTime = 9; + */ + public long getBindTime() { + return bindTime_; + } + + public static final int LONGITUDE_FIELD_NUMBER = 10; + private double longitude_; + /** + * double longitude = 10; + */ + public double getLongitude() { + return longitude_; + } + + public static final int LATITUDE_FIELD_NUMBER = 11; + private double latitude_; + /** + * double latitude = 11; + */ + public double getLatitude() { + return latitude_; + } + + public static final int LOCATION_FIELD_NUMBER = 12; + private volatile java.lang.Object location_; + /** + * string location = 12; + */ + public java.lang.String getLocation() { + java.lang.Object ref = location_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + location_ = s; + return s; + } + } + /** + * string location = 12; + */ + public com.google.protobuf.ByteString + getLocationBytes() { + java.lang.Object ref = location_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + location_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int APNS_FIELD_NUMBER = 13; + private int apns_; + /** + * int32 apns = 13; + */ + public int getApns() { + return apns_; + } + + public static final int STATE_FIELD_NUMBER = 14; + private int state_; + /** + * int32 state = 14; + */ + public int getState() { + return state_; + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!getAccountBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, account_); + } + if (nid_ != 0L) { + output.writeInt64(2, nid_); + } + if (!getDeviceIdBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, deviceId_); + } + if (!getHostBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 4, host_); + } + if (!getChannelBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 5, channel_); + } + if (!getDeviceModelBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 6, deviceModel_); + } + if (!getClientVersionBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 7, clientVersion_); + } + if (!getSystemVersionBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 8, systemVersion_); + } + if (bindTime_ != 0L) { + output.writeInt64(9, bindTime_); + } + if (longitude_ != 0D) { + output.writeDouble(10, longitude_); + } + if (latitude_ != 0D) { + output.writeDouble(11, latitude_); + } + if (!getLocationBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 12, location_); + } + if (apns_ != 0) { + output.writeInt32(13, apns_); + } + if (state_ != 0) { + output.writeInt32(14, state_); + } + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!getAccountBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, account_); + } + if (nid_ != 0L) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(2, nid_); + } + if (!getDeviceIdBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, deviceId_); + } + if (!getHostBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, host_); + } + if (!getChannelBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, channel_); + } + if (!getDeviceModelBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, deviceModel_); + } + if (!getClientVersionBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, clientVersion_); + } + if (!getSystemVersionBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, systemVersion_); + } + if (bindTime_ != 0L) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(9, bindTime_); + } + if (longitude_ != 0D) { + size += com.google.protobuf.CodedOutputStream + .computeDoubleSize(10, longitude_); + } + if (latitude_ != 0D) { + size += com.google.protobuf.CodedOutputStream + .computeDoubleSize(11, latitude_); + } + if (!getLocationBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(12, location_); + } + if (apns_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(13, apns_); + } + if (state_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(14, state_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.farsunset.cim.sdk.server.model.proto.SessionProto.Model)) { + return super.equals(obj); + } + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model other = (com.farsunset.cim.sdk.server.model.proto.SessionProto.Model) obj; + + boolean result = true; + result = result && getAccount() + .equals(other.getAccount()); + result = result && (getNid() + == other.getNid()); + result = result && getDeviceId() + .equals(other.getDeviceId()); + result = result && getHost() + .equals(other.getHost()); + result = result && getChannel() + .equals(other.getChannel()); + result = result && getDeviceModel() + .equals(other.getDeviceModel()); + result = result && getClientVersion() + .equals(other.getClientVersion()); + result = result && getSystemVersion() + .equals(other.getSystemVersion()); + result = result && (getBindTime() + == other.getBindTime()); + result = result && ( + java.lang.Double.doubleToLongBits(getLongitude()) + == java.lang.Double.doubleToLongBits( + other.getLongitude())); + result = result && ( + java.lang.Double.doubleToLongBits(getLatitude()) + == java.lang.Double.doubleToLongBits( + other.getLatitude())); + result = result && getLocation() + .equals(other.getLocation()); + result = result && (getApns() + == other.getApns()); + result = result && (getState() + == other.getState()); + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + ACCOUNT_FIELD_NUMBER; + hash = (53 * hash) + getAccount().hashCode(); + hash = (37 * hash) + NID_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getNid()); + hash = (37 * hash) + DEVICEID_FIELD_NUMBER; + hash = (53 * hash) + getDeviceId().hashCode(); + hash = (37 * hash) + HOST_FIELD_NUMBER; + hash = (53 * hash) + getHost().hashCode(); + hash = (37 * hash) + CHANNEL_FIELD_NUMBER; + hash = (53 * hash) + getChannel().hashCode(); + hash = (37 * hash) + DEVICEMODEL_FIELD_NUMBER; + hash = (53 * hash) + getDeviceModel().hashCode(); + hash = (37 * hash) + CLIENTVERSION_FIELD_NUMBER; + hash = (53 * hash) + getClientVersion().hashCode(); + hash = (37 * hash) + SYSTEMVERSION_FIELD_NUMBER; + hash = (53 * hash) + getSystemVersion().hashCode(); + hash = (37 * hash) + BINDTIME_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getBindTime()); + hash = (37 * hash) + LONGITUDE_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + java.lang.Double.doubleToLongBits(getLongitude())); + hash = (37 * hash) + LATITUDE_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + java.lang.Double.doubleToLongBits(getLatitude())); + hash = (37 * hash) + LOCATION_FIELD_NUMBER; + hash = (53 * hash) + getLocation().hashCode(); + hash = (37 * hash) + APNS_FIELD_NUMBER; + hash = (53 * hash) + getApns(); + hash = (37 * hash) + STATE_FIELD_NUMBER; + hash = (53 * hash) + getState(); + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(com.farsunset.cim.sdk.server.model.proto.SessionProto.Model prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code com.farsunset.cim.sdk.server.model.proto.Model} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:com.farsunset.cim.sdk.server.model.proto.Model) + com.farsunset.cim.sdk.server.model.proto.SessionProto.ModelOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.class, com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.Builder.class); + } + + // Construct using com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + account_ = ""; + + nid_ = 0L; + + deviceId_ = ""; + + host_ = ""; + + channel_ = ""; + + deviceModel_ = ""; + + clientVersion_ = ""; + + systemVersion_ = ""; + + bindTime_ = 0L; + + longitude_ = 0D; + + latitude_ = 0D; + + location_ = ""; + + apns_ = 0; + + state_ = 0; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor; + } + + public com.farsunset.cim.sdk.server.model.proto.SessionProto.Model getDefaultInstanceForType() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.getDefaultInstance(); + } + + public com.farsunset.cim.sdk.server.model.proto.SessionProto.Model build() { + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public com.farsunset.cim.sdk.server.model.proto.SessionProto.Model buildPartial() { + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model result = new com.farsunset.cim.sdk.server.model.proto.SessionProto.Model(this); + result.account_ = account_; + result.nid_ = nid_; + result.deviceId_ = deviceId_; + result.host_ = host_; + result.channel_ = channel_; + result.deviceModel_ = deviceModel_; + result.clientVersion_ = clientVersion_; + result.systemVersion_ = systemVersion_; + result.bindTime_ = bindTime_; + result.longitude_ = longitude_; + result.latitude_ = latitude_; + result.location_ = location_; + result.apns_ = apns_; + result.state_ = state_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.farsunset.cim.sdk.server.model.proto.SessionProto.Model) { + return mergeFrom((com.farsunset.cim.sdk.server.model.proto.SessionProto.Model)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.farsunset.cim.sdk.server.model.proto.SessionProto.Model other) { + if (other == com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.getDefaultInstance()) return this; + if (!other.getAccount().isEmpty()) { + account_ = other.account_; + onChanged(); + } + if (other.getNid() != 0L) { + setNid(other.getNid()); + } + if (!other.getDeviceId().isEmpty()) { + deviceId_ = other.deviceId_; + onChanged(); + } + if (!other.getHost().isEmpty()) { + host_ = other.host_; + onChanged(); + } + if (!other.getChannel().isEmpty()) { + channel_ = other.channel_; + onChanged(); + } + if (!other.getDeviceModel().isEmpty()) { + deviceModel_ = other.deviceModel_; + onChanged(); + } + if (!other.getClientVersion().isEmpty()) { + clientVersion_ = other.clientVersion_; + onChanged(); + } + if (!other.getSystemVersion().isEmpty()) { + systemVersion_ = other.systemVersion_; + onChanged(); + } + if (other.getBindTime() != 0L) { + setBindTime(other.getBindTime()); + } + if (other.getLongitude() != 0D) { + setLongitude(other.getLongitude()); + } + if (other.getLatitude() != 0D) { + setLatitude(other.getLatitude()); + } + if (!other.getLocation().isEmpty()) { + location_ = other.location_; + onChanged(); + } + if (other.getApns() != 0) { + setApns(other.getApns()); + } + if (other.getState() != 0) { + setState(other.getState()); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.farsunset.cim.sdk.server.model.proto.SessionProto.Model) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object account_ = ""; + /** + * string account = 1; + */ + public java.lang.String getAccount() { + java.lang.Object ref = account_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + account_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string account = 1; + */ + public com.google.protobuf.ByteString + getAccountBytes() { + java.lang.Object ref = account_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + account_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string account = 1; + */ + public Builder setAccount( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + account_ = value; + onChanged(); + return this; + } + /** + * string account = 1; + */ + public Builder clearAccount() { + + account_ = getDefaultInstance().getAccount(); + onChanged(); + return this; + } + /** + * string account = 1; + */ + public Builder setAccountBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + account_ = value; + onChanged(); + return this; + } + + private long nid_ ; + /** + * int64 nid = 2; + */ + public long getNid() { + return nid_; + } + /** + * int64 nid = 2; + */ + public Builder setNid(long value) { + + nid_ = value; + onChanged(); + return this; + } + /** + * int64 nid = 2; + */ + public Builder clearNid() { + + nid_ = 0L; + onChanged(); + return this; + } + + private java.lang.Object deviceId_ = ""; + /** + * string deviceId = 3; + */ + public java.lang.String getDeviceId() { + java.lang.Object ref = deviceId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + deviceId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string deviceId = 3; + */ + public com.google.protobuf.ByteString + getDeviceIdBytes() { + java.lang.Object ref = deviceId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + deviceId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string deviceId = 3; + */ + public Builder setDeviceId( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + deviceId_ = value; + onChanged(); + return this; + } + /** + * string deviceId = 3; + */ + public Builder clearDeviceId() { + + deviceId_ = getDefaultInstance().getDeviceId(); + onChanged(); + return this; + } + /** + * string deviceId = 3; + */ + public Builder setDeviceIdBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + deviceId_ = value; + onChanged(); + return this; + } + + private java.lang.Object host_ = ""; + /** + * string host = 4; + */ + public java.lang.String getHost() { + java.lang.Object ref = host_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + host_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string host = 4; + */ + public com.google.protobuf.ByteString + getHostBytes() { + java.lang.Object ref = host_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + host_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string host = 4; + */ + public Builder setHost( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + host_ = value; + onChanged(); + return this; + } + /** + * string host = 4; + */ + public Builder clearHost() { + + host_ = getDefaultInstance().getHost(); + onChanged(); + return this; + } + /** + * string host = 4; + */ + public Builder setHostBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + host_ = value; + onChanged(); + return this; + } + + private java.lang.Object channel_ = ""; + /** + * string channel = 5; + */ + public java.lang.String getChannel() { + java.lang.Object ref = channel_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + channel_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string channel = 5; + */ + public com.google.protobuf.ByteString + getChannelBytes() { + java.lang.Object ref = channel_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + channel_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string channel = 5; + */ + public Builder setChannel( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + channel_ = value; + onChanged(); + return this; + } + /** + * string channel = 5; + */ + public Builder clearChannel() { + + channel_ = getDefaultInstance().getChannel(); + onChanged(); + return this; + } + /** + * string channel = 5; + */ + public Builder setChannelBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + channel_ = value; + onChanged(); + return this; + } + + private java.lang.Object deviceModel_ = ""; + /** + * string deviceModel = 6; + */ + public java.lang.String getDeviceModel() { + java.lang.Object ref = deviceModel_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + deviceModel_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string deviceModel = 6; + */ + public com.google.protobuf.ByteString + getDeviceModelBytes() { + java.lang.Object ref = deviceModel_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + deviceModel_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string deviceModel = 6; + */ + public Builder setDeviceModel( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + deviceModel_ = value; + onChanged(); + return this; + } + /** + * string deviceModel = 6; + */ + public Builder clearDeviceModel() { + + deviceModel_ = getDefaultInstance().getDeviceModel(); + onChanged(); + return this; + } + /** + * string deviceModel = 6; + */ + public Builder setDeviceModelBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + deviceModel_ = value; + onChanged(); + return this; + } + + private java.lang.Object clientVersion_ = ""; + /** + * string clientVersion = 7; + */ + public java.lang.String getClientVersion() { + java.lang.Object ref = clientVersion_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + clientVersion_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string clientVersion = 7; + */ + public com.google.protobuf.ByteString + getClientVersionBytes() { + java.lang.Object ref = clientVersion_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + clientVersion_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string clientVersion = 7; + */ + public Builder setClientVersion( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + clientVersion_ = value; + onChanged(); + return this; + } + /** + * string clientVersion = 7; + */ + public Builder clearClientVersion() { + + clientVersion_ = getDefaultInstance().getClientVersion(); + onChanged(); + return this; + } + /** + * string clientVersion = 7; + */ + public Builder setClientVersionBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + clientVersion_ = value; + onChanged(); + return this; + } + + private java.lang.Object systemVersion_ = ""; + /** + * string systemVersion = 8; + */ + public java.lang.String getSystemVersion() { + java.lang.Object ref = systemVersion_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + systemVersion_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string systemVersion = 8; + */ + public com.google.protobuf.ByteString + getSystemVersionBytes() { + java.lang.Object ref = systemVersion_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + systemVersion_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string systemVersion = 8; + */ + public Builder setSystemVersion( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + systemVersion_ = value; + onChanged(); + return this; + } + /** + * string systemVersion = 8; + */ + public Builder clearSystemVersion() { + + systemVersion_ = getDefaultInstance().getSystemVersion(); + onChanged(); + return this; + } + /** + * string systemVersion = 8; + */ + public Builder setSystemVersionBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + systemVersion_ = value; + onChanged(); + return this; + } + + private long bindTime_ ; + /** + * int64 bindTime = 9; + */ + public long getBindTime() { + return bindTime_; + } + /** + * int64 bindTime = 9; + */ + public Builder setBindTime(long value) { + + bindTime_ = value; + onChanged(); + return this; + } + /** + * int64 bindTime = 9; + */ + public Builder clearBindTime() { + + bindTime_ = 0L; + onChanged(); + return this; + } + + private double longitude_ ; + /** + * double longitude = 10; + */ + public double getLongitude() { + return longitude_; + } + /** + * double longitude = 10; + */ + public Builder setLongitude(double value) { + + longitude_ = value; + onChanged(); + return this; + } + /** + * double longitude = 10; + */ + public Builder clearLongitude() { + + longitude_ = 0D; + onChanged(); + return this; + } + + private double latitude_ ; + /** + * double latitude = 11; + */ + public double getLatitude() { + return latitude_; + } + /** + * double latitude = 11; + */ + public Builder setLatitude(double value) { + + latitude_ = value; + onChanged(); + return this; + } + /** + * double latitude = 11; + */ + public Builder clearLatitude() { + + latitude_ = 0D; + onChanged(); + return this; + } + + private java.lang.Object location_ = ""; + /** + * string location = 12; + */ + public java.lang.String getLocation() { + java.lang.Object ref = location_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + location_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string location = 12; + */ + public com.google.protobuf.ByteString + getLocationBytes() { + java.lang.Object ref = location_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + location_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string location = 12; + */ + public Builder setLocation( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + location_ = value; + onChanged(); + return this; + } + /** + * string location = 12; + */ + public Builder clearLocation() { + + location_ = getDefaultInstance().getLocation(); + onChanged(); + return this; + } + /** + * string location = 12; + */ + public Builder setLocationBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + location_ = value; + onChanged(); + return this; + } + + private int apns_ ; + /** + * int32 apns = 13; + */ + public int getApns() { + return apns_; + } + /** + * int32 apns = 13; + */ + public Builder setApns(int value) { + + apns_ = value; + onChanged(); + return this; + } + /** + * int32 apns = 13; + */ + public Builder clearApns() { + + apns_ = 0; + onChanged(); + return this; + } + + private int state_ ; + /** + * int32 state = 14; + */ + public int getState() { + return state_; + } + /** + * int32 state = 14; + */ + public Builder setState(int value) { + + state_ = value; + onChanged(); + return this; + } + /** + * int32 state = 14; + */ + public Builder clearState() { + + state_ = 0; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFieldsProto3(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:com.farsunset.cim.sdk.server.model.proto.Model) + } + + // @@protoc_insertion_point(class_scope:com.farsunset.cim.sdk.server.model.proto.Model) + private static final com.farsunset.cim.sdk.server.model.proto.SessionProto.Model DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.farsunset.cim.sdk.server.model.proto.SessionProto.Model(); + } + + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public Model parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new Model(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public com.farsunset.cim.sdk.server.model.proto.SessionProto.Model getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\rSession.proto\022(com.farsunset.cim.sdk.s" + + "erver.model.proto\"\377\001\n\005Model\022\017\n\007account\030\001" + + " \001(\t\022\013\n\003nid\030\002 \001(\003\022\020\n\010deviceId\030\003 \001(\t\022\014\n\004h" + + "ost\030\004 \001(\t\022\017\n\007channel\030\005 \001(\t\022\023\n\013deviceMode" + + "l\030\006 \001(\t\022\025\n\rclientVersion\030\007 \001(\t\022\025\n\rsystem" + + "Version\030\010 \001(\t\022\020\n\010bindTime\030\t \001(\003\022\021\n\tlongi" + + "tude\030\n \001(\001\022\020\n\010latitude\030\013 \001(\001\022\020\n\010location" + + "\030\014 \001(\t\022\014\n\004apns\030\r \001(\005\022\r\n\005state\030\016 \001(\005B\016B\014S" + + "essionProtob\006proto3" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor, + new java.lang.String[] { "Account", "Nid", "DeviceId", "Host", "Channel", "DeviceModel", "ClientVersion", "SystemVersion", "BindTime", "Longitude", "Latitude", "Location", "Apns", "State", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/DefaultSessionManager.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/DefaultSessionManager.java deleted file mode 100644 index ba537c4..0000000 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/DefaultSessionManager.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2013-2019 Xia Jun(3979434@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *************************************************************************************** - * * - * Website : http://www.farsunset.com * - * * - *************************************************************************************** - */ -package com.farsunset.cim.sdk.server.session; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import com.farsunset.cim.sdk.server.constant.CIMConstant; - -/** - * 自带默认 session管理实现, 各位可以自行实现 AbstractSessionManager接口来实现自己的 session管理 服务器集群时 - * 须要将CIMSession 信息存入数据库或者nosql 等 第三方存储空间中,便于所有服务器都可以访问 - */ -public class DefaultSessionManager implements SessionManager { - - private static HashMap sessions = new HashMap(); - - private static final AtomicInteger connectionsCounter = new AtomicInteger(0); - - /** - * - */ - public void add(CIMSession session) { - if (session != null) { - session.setAttribute(CIMConstant.SESSION_KEY, session.getAccount()); - sessions.put(session.getAccount(), session); - connectionsCounter.incrementAndGet(); - } - - } - - public CIMSession get(String account) { - - return sessions.get(account); - } - - public List queryAll() { - List list = new ArrayList(); - list.addAll(sessions.values()); - return list; - } - - public void remove(CIMSession session) { - - sessions.remove(session.getAttribute(CIMConstant.SESSION_KEY)); - } - - public void remove(String account) { - - sessions.remove(account); - - } - - public boolean containsCIMSession(String account) { - return sessions.containsKey(account); - } - - @Override - public void update(CIMSession session) { - sessions.put(session.getAccount(), session); - } - -} diff --git a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/SessionManager.java b/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/SessionManager.java deleted file mode 100644 index d067129..0000000 --- a/cim_for_mina/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/SessionManager.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2013-2019 Xia Jun(3979434@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *************************************************************************************** - * * - * Website : http://www.farsunset.com * - * * - *************************************************************************************** - */ -package com.farsunset.cim.sdk.server.session; - -import java.util.List; - -/** - * 客户端的 session管理接口 可自行实现此接口管理session - */ - -public interface SessionManager { - - /** - * 添加新的session - */ - public void add(CIMSession session); - - /** - * 更新session - */ - public void update(CIMSession session); - - /** - * - * @param account - * 客户端session的 key 一般可用 用户账号来对应session - * @return - */ - CIMSession get(String account); - - /** - * 获取所有session - * - * @return - */ - public List queryAll(); - - /** - * 删除session - * - * @param session - */ - public void remove(String account); - -} diff --git a/cim_for_netty/cim-boot-server/libs/cim-android-sdk-3.6.jar b/cim_for_netty/cim-boot-server/libs/cim-server-sdk-3.6.jar similarity index 52% rename from cim_for_netty/cim-boot-server/libs/cim-android-sdk-3.6.jar rename to cim_for_netty/cim-boot-server/libs/cim-server-sdk-3.6.jar index 525cec3..1041428 100644 Binary files a/cim_for_netty/cim-boot-server/libs/cim-android-sdk-3.6.jar and b/cim_for_netty/cim-boot-server/libs/cim-server-sdk-3.6.jar differ diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/CIMConfig.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/CIMConfig.java index a78b1b1..28d36b9 100644 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/CIMConfig.java +++ b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/CIMConfig.java @@ -16,7 +16,7 @@ import com.farsunset.cim.handler.SessionClosedHandler; import com.farsunset.cim.sdk.server.handler.CIMNioSocketAcceptor; import com.farsunset.cim.sdk.server.handler.CIMRequestHandler; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; @Configuration public class CIMConfig implements CIMRequestHandler { @@ -28,7 +28,7 @@ public class CIMConfig implements CIMRequestHandler { @Resource private SessionClosedHandler closedHandler; - + @Resource private ApplicationContext applicationContext; @@ -55,7 +55,6 @@ public class CIMConfig implements CIMRequestHandler { return nioSocketAcceptor; } - @Override public void process(CIMSession session, SentBody body) { @@ -75,6 +74,5 @@ public class CIMConfig implements CIMRequestHandler { return applicationContext.getBean(handlerClass); } - } \ No newline at end of file diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/admin/controller/SessionController.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/admin/controller/SessionController.java index 2e378fd..74b1c00 100644 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/admin/controller/SessionController.java +++ b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/admin/controller/SessionController.java @@ -27,17 +27,18 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; -import com.farsunset.cim.service.impl.CIMSessionServiceImpl; +import com.farsunset.cim.service.CIMSessionService; + @Controller @RequestMapping("/console/session") public class SessionController { @Resource - private CIMSessionServiceImpl sessionManager; + private CIMSessionService memorySessionService; @RequestMapping(value = "/list.action") public String list(Model model) { - model.addAttribute("sessionList", sessionManager.queryAll()); + model.addAttribute("sessionList", memorySessionService.list()); return "console/session/manage"; } } diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/api/controller/MessageController.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/api/controller/MessageController.java index 4dc1f15..c42ed85 100644 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/api/controller/MessageController.java +++ b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/api/controller/MessageController.java @@ -32,7 +32,6 @@ import com.farsunset.cim.push.DefaultMessagePusher; import com.farsunset.cim.push.SystemMessagePusher; import com.farsunset.cim.sdk.server.model.Message; import com.farsunset.cim.util.Constants; -import com.farsunset.cim.util.StringUtil; @RestController diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/handler/BindHandler.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/handler/BindHandler.java index a789322..da7e908 100644 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/handler/BindHandler.java +++ b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/handler/BindHandler.java @@ -30,14 +30,14 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import com.farsunset.cim.push.CIMMessagePusher; import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.handler.CIMRequestHandler; import com.farsunset.cim.sdk.server.model.Message; import com.farsunset.cim.sdk.server.model.ReplyBody; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; -import com.farsunset.cim.service.impl.CIMSessionServiceImpl; -import com.farsunset.cim.util.StringUtil; +import com.farsunset.cim.sdk.server.model.CIMSession; +import com.farsunset.cim.service.CIMSessionService; /** @@ -51,59 +51,57 @@ public class BindHandler implements CIMRequestHandler { protected final Logger logger = LoggerFactory.getLogger(BindHandler.class); @Resource - private CIMSessionServiceImpl sessionManager; + private CIMSessionService memorySessionService; @Value("${server.host}") private String host; + @Resource + private CIMMessagePusher defaultMessagePusher; - public void process(CIMSession newSession, SentBody message) { + public void process(CIMSession newSession, SentBody body) { ReplyBody reply = new ReplyBody(); - reply.setKey(message.getKey()); + reply.setKey(body.getKey()); reply.setCode(CIMConstant.ReturnCode.CODE_200); + reply.setTimestamp(System.currentTimeMillis()); + try { - String account = message.get("account"); - newSession.setGid(StringUtil.getUUID()); + String account = body.get("account"); newSession.setAccount(account); - newSession.setDeviceId(message.get("deviceId")); + newSession.setDeviceId(body.get("deviceId")); newSession.setHost(host); - newSession.setChannel(message.get("channel")); - newSession.setDeviceModel(message.get("device")); - newSession.setClientVersion(message.get("version")); - newSession.setSystemVersion(message.get("osVersion")); + newSession.setChannel(body.get("channel")); + newSession.setDeviceModel(body.get("device")); + newSession.setClientVersion(body.get("version")); + newSession.setSystemVersion(body.get("osVersion")); newSession.setBindTime(System.currentTimeMillis()); - newSession.setPackageName(message.get("packageName")); - - /** + /* * 由于客户端断线服务端可能会无法获知的情况,客户端重连时,需要关闭旧的连接 */ - CIMSession oldSession = sessionManager.get(account); + CIMSession oldSession = memorySessionService.get(account); - // 如果是账号已经在另一台终端登录。则让另一个终端下线 + /* + * 如果是账号已经在另一台终端登录。则让另一个终端下线 + */ if (oldSession != null && fromOtherDevice(newSession,oldSession) && oldSession.isConnected()) { sendForceOfflineMessage(oldSession, account, newSession.getDeviceModel()); } - - - /** + + /* * 有可能是同一个设备重复连接,则关闭旧的链接,这种情况一般是客户端断网,联网又重新链接上来,之前的旧链接没有来得及通过心跳机制关闭,在这里手动关闭 * 条件1,连接来自是同一个设备 * 条件2.2个连接都是同一台服务器 */ if (oldSession != null && !fromOtherDevice(newSession,oldSession) && Objects.equals(oldSession.getHost(),host)) { - oldSession.removeAttribute(CIMConstant.SESSION_KEY); - oldSession.closeNow(); + closeQuietly(oldSession); } - // 第一次设置心跳时间为登录时间 - newSession.setBindTime(System.currentTimeMillis()); - newSession.setHeartbeat(System.currentTimeMillis()); - - sessionManager.add(newSession); + memorySessionService.save(newSession); + } catch (Exception e) { reply.setCode(CIMConstant.ReturnCode.CODE_500); @@ -126,16 +124,18 @@ public class BindHandler implements CIMRequestHandler { msg.setSender("system"); msg.setContent(deviceModel); msg.setId(System.currentTimeMillis()); - closeQuietly(oldSession,msg); + + defaultMessagePusher.push(msg); + + closeQuietly(oldSession); } // 不同设备同一账号登录时关闭旧的连接 - private void closeQuietly(CIMSession oldSession,Message msg) { + private void closeQuietly(CIMSession oldSession) { if (oldSession.isConnected() && Objects.equals(host, oldSession.getHost())) { - oldSession.write(msg); - oldSession.removeAttribute(CIMConstant.SESSION_KEY); - oldSession.closeNow(); + oldSession.setAttribute(CIMConstant.KEY_QUIETLY_CLOSE,true); + oldSession.closeOnFlush(); } } diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/handler/SessionClosedHandler.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/handler/SessionClosedHandler.java index 4e00c77..c41b547 100644 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/handler/SessionClosedHandler.java +++ b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/handler/SessionClosedHandler.java @@ -22,6 +22,8 @@ package com.farsunset.cim.handler; +import java.util.Objects; + import javax.annotation.Resource; import org.slf4j.Logger; @@ -31,8 +33,8 @@ import org.springframework.stereotype.Component; import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.handler.CIMRequestHandler; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; -import com.farsunset.cim.service.impl.CIMSessionServiceImpl; +import com.farsunset.cim.sdk.server.model.CIMSession; +import com.farsunset.cim.service.CIMSessionService; /** @@ -46,17 +48,28 @@ public class SessionClosedHandler implements CIMRequestHandler { protected final Logger logger = LoggerFactory.getLogger(SessionClosedHandler.class); @Resource - private CIMSessionServiceImpl sessionManager; + private CIMSessionService memorySessionService; public void process(CIMSession ios, SentBody message) { + Object quietly = ios.getAttribute(CIMConstant.KEY_QUIETLY_CLOSE); + if (Objects.equals(quietly, true)) { + return; + } - Object account = ios.getAttribute(CIMConstant.SESSION_KEY); + Object account = ios.getAttribute(CIMConstant.KEY_ACCOUNT); if (account == null) { return; } - ios.removeAttribute(CIMConstant.SESSION_KEY); - sessionManager.remove(account.toString()); + CIMSession oldSession = memorySessionService.get(account.toString()); + + if (oldSession == null || oldSession.isApnsOpend()) { + return; + } + + oldSession.setState(CIMSession.STATE_DISABLED); + oldSession.setNid(null); + memorySessionService.save(oldSession); } } diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/push/DefaultMessagePusher.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/push/DefaultMessagePusher.java index 67962d0..e0e49bc 100644 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/push/DefaultMessagePusher.java +++ b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/push/DefaultMessagePusher.java @@ -29,10 +29,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.farsunset.cim.sdk.server.model.Message; -import com.farsunset.cim.sdk.server.session.CIMSession; -import com.farsunset.cim.sdk.server.session.DefaultSessionManager; +import com.farsunset.cim.sdk.server.model.CIMSession; import com.farsunset.cim.service.ApnsService; -import com.farsunset.cim.service.impl.MessageDispatcherImpl; +import com.farsunset.cim.service.CIMSessionService; /** * 消息发送实现类 @@ -45,10 +44,8 @@ public class DefaultMessagePusher implements CIMMessagePusher { private String host; @Resource - private DefaultSessionManager sessionManager; + private CIMSessionService memorySessionService; - @Resource - private MessageDispatcherImpl messageDispatcher; @Resource @@ -61,31 +58,39 @@ public class DefaultMessagePusher implements CIMMessagePusher { * @param msg */ public void push(Message message) { - CIMSession session = sessionManager.get(message.getReceiver()); + CIMSession session = memorySessionService.get(message.getReceiver()); - /** - * 服务器集群时,可以在此 判断当前session是否连接于本台服务器,如果是,继续往下走,如果不是,将此消息发往当前session连接的服务器并 - */ - if (session.isConnected() && !Objects.equals(host, session.getHost())) { - messageDispatcher.forward(message, session.getHost()); + if(session == null) { return; } - /** - * 如果是在当前服务器则直接推送 + /* + * IOS设备,如果开启了apns,则使用apns推送 */ - if (session.isConnected() && Objects.equals(host, session.getHost())) { - session.write(message); + if (session.isIOSChannel() && session.isApnsOpend()) { + apnsService.push(message, session.getDeviceId()); return; } - /** - * ios设备流程特别处理,如果长链接断开了,并且ApnsAble为打开状态的话优走apns + /* + * 服务器集群时,判断当前session是否连接于本台服务器 + * 如果连接到了其他服务器则转发请求到目标服务器 */ - if (Objects.equals(session.getChannel(), CIMSession.CHANNEL_IOS) && Objects.equals(session.getApnsAble(), CIMSession.APNS_ON)) { - apnsService.push(message, session.getDeviceId()); + if (session.isConnected() && !Objects.equals(host, session.getHost())) { + /** + * @TODO + * 在此调用目标服务器接口来发送 + */ + return; } + /* + * 如果是Android,浏览器或者windows客户端则直接发送 + */ + if (session.isConnected() && Objects.equals(host, session.getHost())) { + session.write(message); + } + } } diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/MessageDispatcher.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/CIMSessionService.java similarity index 67% rename from cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/MessageDispatcher.java rename to cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/CIMSessionService.java index 911bfbc..45fb9c8 100644 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/MessageDispatcher.java +++ b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/CIMSessionService.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2013-2019 Xia Jun(3979434@qq.com). * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,8 +21,23 @@ */ package com.farsunset.cim.service; -import com.farsunset.cim.sdk.server.model.Message; +import java.util.List; + +import com.farsunset.cim.sdk.server.model.CIMSession; + + +/** + * 集群 session管理实现示例, 各位可以自行实现 AbstractSessionManager接口来实现自己的 session管理 服务器集群时 + * 须要将CIMSession 信息存入数据库或者redis中 等 第三方存储空间中,便于所有服务器都可以访问 + */ +public interface CIMSessionService { + + void save(CIMSession session); + + CIMSession get(String account); + + List list(); + + void remove(String account); -public interface MessageDispatcher { - void forward(final Message msg, final String ip); } diff --git a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/session/ClusterSessionManager.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/ClusterSessionServiceImpl.java similarity index 60% rename from cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/session/ClusterSessionManager.java rename to cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/ClusterSessionServiceImpl.java index 988ca24..6dacf53 100644 --- a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/session/ClusterSessionManager.java +++ b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/ClusterSessionServiceImpl.java @@ -19,47 +19,54 @@ * * *************************************************************************************** */ -package com.farsunset.cim.session; +package com.farsunset.cim.service.impl; + import java.util.List; -import com.farsunset.cim.sdk.server.session.CIMSession; -import com.farsunset.cim.sdk.server.session.SessionManager; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; + +import com.farsunset.cim.sdk.server.handler.CIMNioSocketAcceptor; +import com.farsunset.cim.sdk.server.model.CIMSession; +import com.farsunset.cim.service.CIMSessionService; + /** - * 集群 session管理实现示例, 各位可以自行实现 AbstractSessionManager接口来实现自己的 session管理 服务器集群时 - * 须要将CIMSession 信息存入数据库或者nosql 等 第三方存储空间中,便于所有服务器都可以访问 + * 集群情况下,数据库或者redis存储实现 + * 自行实现存储管理 + * */ -public class ClusterSessionManager implements SessionManager { +@Service("clusterSessionService") +public class ClusterSessionServiceImpl implements CIMSessionService { - public CIMSession get(String account) { - - // 这里查询数据库 - /* - * CIMSession session = database.getSession(account); - * session.setIoSession(ContextHolder.getBean(CIMNioSocketAcceptor.class). - * getManagedSessions().get(session.getNid())); return session; - */ - return null; + @Resource + private CIMNioSocketAcceptor nioSocketAcceptor; + + @Override + public void save(CIMSession session) { } @Override - public List queryAll() { + public CIMSession get(String account) { + + /* + * CIMSession session = database.getSession(account); + * session.setIoSession(nioSocketAcceptor.getManagedChannel().get(session.getNid())); + * return session; + */ + return null; } - + @Override public void remove(String account) { - } @Override - public void update(CIMSession session) { - + public List list() { + return null; } - - @Override - public void add(CIMSession arg0) { - - } - + } diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MemorySessionServiceImpl.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MemorySessionServiceImpl.java new file mode 100644 index 0000000..57ba29c --- /dev/null +++ b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MemorySessionServiceImpl.java @@ -0,0 +1,65 @@ +/** + * Copyright 2013-2019 Xia Jun(3979434@qq.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *************************************************************************************** + * * + * Website : http://www.farsunset.com * + * * + *************************************************************************************** + */ +package com.farsunset.cim.service.impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import org.springframework.stereotype.Service; + +import com.farsunset.cim.sdk.server.model.CIMSession; +import com.farsunset.cim.service.CIMSessionService; + + +/** + * 单机,内存存储实现 + * + */ +@Service("memorySessionService") +public class MemorySessionServiceImpl implements CIMSessionService { + + private ConcurrentHashMap sessionMap = new ConcurrentHashMap(); + + @Override + public void save(CIMSession session) { + sessionMap.put(session.getAccount(), session); + } + + @Override + public CIMSession get(String account) { + return sessionMap.get(account); + } + + @Override + public void remove(String account) { + sessionMap.remove(account); + } + + @Override + public List list() { + List onlineList = new ArrayList<>(); + onlineList.addAll(sessionMap.values()); + return onlineList; + } + +} diff --git a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MessageDispatcherImpl.java b/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MessageDispatcherImpl.java deleted file mode 100644 index 3f7ab3c..0000000 --- a/cim_for_netty/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/MessageDispatcherImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright 2013-2019 Xia Jun(3979434@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *************************************************************************************** - * * - * Website : http://www.farsunset.com * - * * - *************************************************************************************** - */ -package com.farsunset.cim.service.impl; - -import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; - -import org.apache.commons.io.IOUtils; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import com.farsunset.cim.sdk.server.model.Message; -import com.farsunset.cim.service.MessageDispatcher; - -import okhttp3.FormBody; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -@Component -public class MessageDispatcherImpl implements MessageDispatcher{ - - private static final Logger logger = Logger.getLogger(MessageDispatcherImpl.class.getName()); - - @Value("${sys.message.dispatch.url}") - private String dispatchUrl; - - @Override - public void forward(final Message msg, final String ip) { - String apiUrl = String.format(dispatchUrl, ip); - try { - String response = httpPost(apiUrl, msg); - logger.info("消息转发目标服务器{" + ip + "},结果:" + response); - } catch (Exception e) { - e.printStackTrace(); - logger.severe("消息转发目标服务器" + apiUrl + "message:" + e.getMessage()); - } - } - - @SuppressWarnings("deprecation") - private String httpPost(String url, Message msg) throws Exception { - - OkHttpClient httpclient = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).build(); - FormBody.Builder build = new FormBody.Builder(); - - build.add("id", String.valueOf(msg.getId())); - build.add("action", msg.getAction()); - build.add("title", msg.getTitle()); - build.add("content", msg.getContent()); - build.add("sender", msg.getSender()); - build.add("receiver", msg.getReceiver()); - build.add("format", msg.getFormat()); - build.add("extra", msg.getExtra()); - build.add("timestamp", String.valueOf(msg.getTimestamp())); - Request request = new Request.Builder().url(url).post(build.build()).build(); - - Response response = httpclient.newCall(request).execute(); - String data = response.body().string(); - IOUtils.closeQuietly(response); - return data; - } - - -} diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/constant/CIMConstant.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/constant/CIMConstant.java index 119eb83..b670335 100644 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/constant/CIMConstant.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/constant/CIMConstant.java @@ -25,6 +25,8 @@ package com.farsunset.cim.sdk.server.constant; * 常量 */ public interface CIMConstant { + // 消息头长度为3个字节,第一个字节为消息类型,第二,第三字节 转换int后为消息长度 + int DATA_HEADER_LENGTH = 3; public static interface ReturnCode { @@ -38,30 +40,30 @@ public interface CIMConstant { } - String SESSION_KEY = "account"; + String KEY_ACCOUNT = "account"; + + String KEY_QUIETLY_CLOSE = "quietlyClose"; + String HEARTBEAT_KEY = "heartbeat"; + + String CLIENT_WEBSOCKET_HANDSHAKE = "client_websocket_handshake"; + String CLIENT_HEARTBEAT = "client_heartbeat"; - - // 消息头长度为3个字节,第一个字节为消息类型,第二,第三字节 转换int后为消息长度 - int DATA_HEADER_LENGTH = 3; - // WEBSOCKET消息头长度为2个字节 - int WS_DATA_HEADER_LENGTH = 2; - + + String CLIENT_CONNECT_CLOSED = "client_closed"; + public static interface ProtobufType { - byte C_H_RS = 0; byte S_H_RQ = 1; + byte C_H_RS = 0; byte MESSAGE = 2; byte SENTBODY = 3; byte REPLYBODY = 4; } public static interface MessageAction { - // 被其他设备登录挤下线消息 String ACTION_999 = "999"; - // 被系统禁用消息 - String ACTION_444 = "444"; } } diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageDecoder.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageDecoder.java index ba61075..1a283c4 100644 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageDecoder.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageDecoder.java @@ -26,11 +26,11 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.filter.decoder.AppMessageDecoder; import com.farsunset.cim.sdk.server.filter.decoder.WebMessageDecoder; -import com.farsunset.cim.sdk.server.handler.CIMNioSocketAcceptor; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -95,7 +95,7 @@ public class ServerMessageDecoder extends ByteToMessageDecoder { arg0.channel().attr(AttributeKey.valueOf(CIMSession.PROTOCOL)).set(CIMSession.WEBSOCKET); SentBody body = new SentBody(); - body.setKey(CIMNioSocketAcceptor.WEBSOCKET_HANDLER_KEY); + body.setKey(CIMConstant.CLIENT_WEBSOCKET_HANDSHAKE); body.setTimestamp(System.currentTimeMillis()); body.put("key", secKey); queue.add(body); diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageEncoder.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageEncoder.java index 004e819..593cac6 100644 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageEncoder.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/ServerMessageEncoder.java @@ -26,7 +26,7 @@ import java.util.Objects; import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.model.HandshakerResponse; import com.farsunset.cim.sdk.server.model.feature.EncodeFormatable; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/AppMessageDecoder.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/AppMessageDecoder.java index c83c422..102bbfe 100644 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/AppMessageDecoder.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/AppMessageDecoder.java @@ -26,7 +26,7 @@ import java.util.List; import com.farsunset.cim.sdk.server.constant.CIMConstant; import com.farsunset.cim.sdk.server.model.SentBody; import com.farsunset.cim.sdk.server.model.proto.SentBodyProto; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/WebMessageDecoder.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/WebMessageDecoder.java index aedd48a..651fde9 100644 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/WebMessageDecoder.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/filter/decoder/WebMessageDecoder.java @@ -21,11 +21,9 @@ */ package com.farsunset.cim.sdk.server.filter.decoder; -import java.nio.charset.Charset; import java.util.List; import com.farsunset.cim.sdk.server.constant.CIMConstant; -import com.farsunset.cim.sdk.server.model.HeartbeatResponse; import com.farsunset.cim.sdk.server.model.SentBody; import com.farsunset.cim.sdk.server.model.proto.SentBodyProto; import com.google.protobuf.InvalidProtocolBufferException; @@ -124,8 +122,10 @@ public class WebMessageDecoder extends ByteToMessageDecoder { * 只处理心跳响应以及,sentbody消息 */ if (type == CIMConstant.ProtobufType.C_H_RS) { - HeartbeatResponse response = HeartbeatResponse.getInstance(); - queue.add(response); + SentBody body = new SentBody(); + body.setKey(CIMConstant.CLIENT_HEARTBEAT); + body.setTimestamp(System.currentTimeMillis()); + queue.add(body); } if (type == CIMConstant.ProtobufType.SENTBODY) { diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMNioSocketAcceptor.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMNioSocketAcceptor.java index 759a972..25518cf 100644 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMNioSocketAcceptor.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMNioSocketAcceptor.java @@ -30,7 +30,7 @@ import com.farsunset.cim.sdk.server.filter.ServerMessageDecoder; import com.farsunset.cim.sdk.server.filter.ServerMessageEncoder; import com.farsunset.cim.sdk.server.model.HeartbeatRequest; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; @@ -54,14 +54,6 @@ import io.netty.util.AttributeKey; @Sharable public class CIMNioSocketAcceptor extends SimpleChannelInboundHandler { - /** - * websocket特有的握手处理handler - */ - public final static String WEBSOCKET_HANDLER_KEY = "client_websocket_handshake"; - /** - * 连接关闭处理handler - */ - public final static String CIMSESSION_CLOSED_HANDLER_KEY = "client_closed"; private HashMap innerHandlerMap = new HashMap(); private CIMRequestHandler outerRequestHandler; @@ -81,8 +73,9 @@ public class CIMNioSocketAcceptor extends SimpleChannelInboundHandler /** * 预制websocket握手请求的处理 */ - innerHandlerMap.put(WEBSOCKET_HANDLER_KEY, new WebsocketHandler()); - + innerHandlerMap.put(CIMConstant.CLIENT_WEBSOCKET_HANDSHAKE, new WebsocketHandler()); + innerHandlerMap.put(CIMConstant.CLIENT_HEARTBEAT, new HeartbeatHandler()); + ServerBootstrap bootstrap = new ServerBootstrap(); EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); @@ -123,7 +116,7 @@ public class CIMNioSocketAcceptor extends SimpleChannelInboundHandler } @Override - protected void channelRead0(ChannelHandlerContext ctx, SentBody body) throws Exception { + protected void channelRead0(ChannelHandlerContext ctx, SentBody body) { CIMSession session = new CIMSession(ctx.channel()); @@ -148,7 +141,7 @@ public class CIMNioSocketAcceptor extends SimpleChannelInboundHandler CIMSession session = new CIMSession(ctx.channel()); SentBody body = new SentBody(); - body.setKey(CIMSESSION_CLOSED_HANDLER_KEY); + body.setKey(CIMConstant.CLIENT_CONNECT_CLOSED); outerRequestHandler.process(session, body); } @@ -188,4 +181,5 @@ public class CIMNioSocketAcceptor extends SimpleChannelInboundHandler } return channelGroup.get(id); } + } diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMRequestHandler.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMRequestHandler.java index 16aa5b8..0f49b39 100644 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMRequestHandler.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/CIMRequestHandler.java @@ -26,7 +26,7 @@ package com.farsunset.cim.sdk.server.handler; * @author 3979434@qq.com */ import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; public interface CIMRequestHandler { diff --git a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/CIMSessionServiceImpl.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/HeartbeatHandler.java similarity index 75% rename from cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/CIMSessionServiceImpl.java rename to cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/HeartbeatHandler.java index 94c3d2b..86c4f92 100644 --- a/cim_for_mina/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/CIMSessionServiceImpl.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/HeartbeatHandler.java @@ -19,13 +19,15 @@ * * *************************************************************************************** */ -package com.farsunset.cim.service.impl; +package com.farsunset.cim.sdk.server.handler; -import org.springframework.stereotype.Service; -import com.farsunset.cim.sdk.server.session.DefaultSessionManager; +import com.farsunset.cim.sdk.server.model.SentBody; +import com.farsunset.cim.sdk.server.model.CIMSession; -@Service -public class CIMSessionServiceImpl extends DefaultSessionManager { - +/** + * 心跳handler,主要是让netty重置cheannel的空闲时间 + */ +public class HeartbeatHandler implements CIMRequestHandler { + public void process(CIMSession session, SentBody body) {} } diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/WebsocketHandler.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/WebsocketHandler.java index 1f7aab2..a9e73ea 100644 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/WebsocketHandler.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/handler/WebsocketHandler.java @@ -26,12 +26,10 @@ import java.util.Base64; import com.farsunset.cim.sdk.server.model.HandshakerResponse; import com.farsunset.cim.sdk.server.model.SentBody; -import com.farsunset.cim.sdk.server.session.CIMSession; +import com.farsunset.cim.sdk.server.model.CIMSession; /** * 处理websocket握手请求,返回响应的报文给浏览器 - * - * @author Iraid * */ public class WebsocketHandler implements CIMRequestHandler { diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/CIMSession.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/CIMSession.java similarity index 60% rename from cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/CIMSession.java rename to cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/CIMSession.java index b8f13d4..2b980f1 100644 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/CIMSession.java +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/CIMSession.java @@ -1,5 +1,5 @@ /** - * Copyright 2013-2019 Xia Jun(3979434@qq.com). + * Copyright 2013-2023 Xia Jun(3979434@qq.com). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,35 +19,34 @@ * * *************************************************************************************** */ -package com.farsunset.cim.sdk.server.session; +package com.farsunset.cim.sdk.server.model; import java.io.Serializable; -import java.net.InetAddress; import java.net.SocketAddress; -import java.net.UnknownHostException; +import java.util.Objects; + import com.farsunset.cim.sdk.server.constant.CIMConstant; +import com.farsunset.cim.sdk.server.model.proto.SessionProto; +import com.google.protobuf.InvalidProtocolBufferException; import io.netty.channel.Channel; import io.netty.util.AttributeKey; /** - * Channel包装类,集群时 将此对象存入表中 + * IoSession包装类,集群时 将此对象存入表中 */ - public class CIMSession implements Serializable { - /** - * - */ private transient static final long serialVersionUID = 1L; public transient static String PROTOCOL = "protocol"; public transient static String WEBSOCKET = "websocket"; public transient static String NATIVEAPP = "nativeapp"; - public transient static final int STATUS_ENABLED = 0; - public transient static final int STATUS_DISABLED = 1; + public transient static String HOST = "HOST"; + public transient static final int STATE_ENABLED = 0; + public transient static final int STATE_DISABLED = 1; public transient static final int APNS_ON = 1; public transient static final int APNS_OFF = 0; @@ -56,31 +55,31 @@ public class CIMSession implements Serializable { public transient static String CHANNEL_WINDOWS = "windows"; public transient static String CHANNEL_WP = "wp"; public transient static String CHANNEL_BROWSER = "browser"; + private transient Channel session; - private String gid;// session全局ID + private String account;// session绑定的账号,主键,一个账号同一时间之内在一个设备在线 private String nid;// session在本台服务器上的ID private String deviceId;// 客户端ID (设备号码+应用包名),ios为devicetoken private String host;// session绑定的服务器IP - private String account;// session绑定的账号 private String channel;// 终端设备类型 private String deviceModel;// 终端设备型号 private String clientVersion;// 终端应用版本 private String systemVersion;// 终端系统版本 - private String packageName;// 终端应用包名 private Long bindTime;// 登录时间 - private Long heartbeat;// 心跳时间 private Double longitude;// 经度 private Double latitude;// 维度 private String location;// 位置 - private int apnsAble;// apns推送状态 - private int status;// 状态 + private int apns;// apns推送状态 + private int state;// 状态 + public CIMSession(Channel session) { this.session = session; this.nid = session.id().asShortText(); } + public CIMSession() { } @@ -91,7 +90,8 @@ public class CIMSession implements Serializable { public void setAccount(String account) { this.account = account; - setAttribute(CIMConstant.SESSION_KEY, account); + + setAttribute(CIMConstant.KEY_ACCOUNT, account); } public Double getLongitude() { @@ -118,14 +118,6 @@ public class CIMSession implements Serializable { this.location = location; } - public String getGid() { - return gid; - } - - public void setGid(String gid) { - this.gid = gid; - } - public String getNid() { return nid; } @@ -186,37 +178,24 @@ public class CIMSession implements Serializable { this.systemVersion = systemVersion; } - public Long getHeartbeat() { - return heartbeat; - } - - public void setHeartbeat(Long heartbeat) { - this.heartbeat = heartbeat; - setAttribute(CIMConstant.HEARTBEAT_KEY, heartbeat); - } - public void setHost(String host) { this.host = host; } - public void setChannel(Channel session) { - this.session = session; + public int getApns() { + return apns; } - public int getApnsAble() { - return apnsAble; + public void setApns(int apns) { + this.apns = apns; } - public void setApnsAble(int apnsAble) { - this.apnsAble = apnsAble; + public int getState() { + return state; } - public int getStatus() { - return status; - } - - public void setStatus(int status) { - this.status = status; + public void setState(int state) { + this.state = state; } public void setAttribute(String key, Object value) { @@ -248,36 +227,16 @@ public class CIMSession implements Serializable { return null; } + public boolean write(Object msg) { if (session != null && session.isActive()) { return session.writeAndFlush(msg).awaitUninterruptibly(5000); } - return false; } public boolean isConnected() { - if (session != null) { - return session.isActive(); - } - - if (!isLocalhost()) { - return status == STATUS_ENABLED; - } - - return false; - } - - public boolean isLocalhost() { - - try { - String ip = InetAddress.getLocalHost().getHostAddress(); - return ip.equals(host); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - return false; - + return (session != null && session.isActive()) || state == STATE_ENABLED; } public void closeNow() { @@ -285,63 +244,108 @@ public class CIMSession implements Serializable { session.close(); } - public void setPackageName(String packageName) { - this.packageName = packageName; + public void closeOnFlush() { + if (session != null) + session.close(); } - public String getPackageName() { - return packageName; + public boolean isIOSChannel() { + return Objects.equals(channel, CHANNEL_IOS); } + public boolean isAndroidChannel() { + return Objects.equals(channel, CHANNEL_ANDROID); + } + + public boolean isWindowsChannel() { + return Objects.equals(channel, CHANNEL_WINDOWS); + } + + public boolean isApnsOpend() { + return Objects.equals(apns, APNS_ON); + } + + @Override public int hashCode() { - - return (deviceId + nid + host).hashCode(); + return getClass().hashCode(); } + @Override public boolean equals(Object o) { - if (o instanceof CIMSession) { - return hashCode() == o.hashCode(); + CIMSession target = (CIMSession) o; + return Objects.equals(target.deviceId, deviceId) && Objects.equals(target.nid, nid) + && Objects.equals(target.host, host); } return false; } - public boolean fromOtherDevice(Object o) { - - if (o instanceof CIMSession) { - - CIMSession t = (CIMSession) o; - if (t.deviceId != null && deviceId != null) { - return !t.deviceId.equals(deviceId); - } + public byte[] getProtobufBody() { + SessionProto.Model.Builder builder = SessionProto.Model.newBuilder(); + if (account != null) { + builder.setAccount(account); } - return false; + if (nid != null) { + builder.setNid(nid); + } + if (deviceId != null) { + builder.setDeviceId(deviceId); + } + if (host != null) { + builder.setHost(host); + } + if (channel != null) { + builder.setChannel(channel); + } + if (deviceModel != null) { + builder.setDeviceModel(deviceModel); + } + if (clientVersion != null) { + builder.setClientVersion(clientVersion); + } + if (systemVersion != null) { + builder.setSystemVersion(systemVersion); + } + if (bindTime != null) { + builder.setBindTime(bindTime); + } + if (longitude != null) { + builder.setLongitude(longitude); + } + if (latitude != null) { + builder.setLatitude(latitude); + } + if (location != null) { + builder.setLocation(location); + } + builder.setState(state); + builder.setApns(apns); + return builder.build().toByteArray(); } - - public boolean fromCurrentDevice(Object o) { - - return !fromOtherDevice(o); - } - - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("{"); - - buffer.append("\"").append("gid").append("\":").append("\"").append(gid).append("\"").append(","); - buffer.append("\"").append("nid").append("\":").append(nid).append(","); - buffer.append("\"").append("deviceId").append("\":").append("\"").append(deviceId).append("\"").append(","); - buffer.append("\"").append("host").append("\":").append("\"").append(host).append("\"").append(","); - buffer.append("\"").append("account").append("\":").append("\"").append(account).append("\"").append(","); - buffer.append("\"").append("channel").append("\":").append("\"").append(channel).append("\"").append(","); - buffer.append("\"").append("deviceModel").append("\":").append("\"").append(deviceModel).append("\"") - .append(","); - buffer.append("\"").append("status").append("\":").append(status).append(","); - buffer.append("\"").append("apnsAble").append("\":").append(apnsAble).append(","); - buffer.append("\"").append("bindTime").append("\":").append(bindTime).append(","); - buffer.append("\"").append("heartbeat").append("\":").append(heartbeat); - buffer.append("}"); - return buffer.toString(); - + + + public static CIMSession decode(byte[] protobufBody) throws InvalidProtocolBufferException { + if(protobufBody == null) { + return null; + } + SessionProto.Model proto = SessionProto.Model.parseFrom(protobufBody); + CIMSession session = new CIMSession(); + session.setApns(proto.getApns()); + session.setBindTime(proto.getBindTime()); + session.setChannel(proto.getChannel()); + session.setClientVersion(proto.getClientVersion()); + session.setDeviceId(proto.getDeviceId()); + session.setDeviceModel(proto.getDeviceModel()); + session.setHost(proto.getHost()); + session.setLatitude(proto.getLatitude()); + session.setLongitude(proto.getLongitude()); + session.setLocation(proto.getLocation()); + session.setNid(proto.getNid()); + session.setSystemVersion(proto.getSystemVersion()); + session.setState(proto.getState()); + session.setAccount(proto.getAccount()); + return session; } + } diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/Session.proto b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/Session.proto new file mode 100644 index 0000000..da000b8 --- /dev/null +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/Session.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package com.farsunset.cim.sdk.server.model.proto; +option java_outer_classname="SessionProto"; +message Model { + string account = 1; + string nid = 2; + string deviceId = 3; + string host = 4; + string channel = 5; + string deviceModel = 6; + string clientVersion = 7; + string systemVersion = 8; + int64 bindTime = 9; + double longitude = 10; + double latitude = 11; + string location = 12; + int32 apns = 13; + int32 state = 14; +} diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/SessionProto.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/SessionProto.java new file mode 100644 index 0000000..966c489 --- /dev/null +++ b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/model/proto/SessionProto.java @@ -0,0 +1,2022 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: Session.proto + +package com.farsunset.cim.sdk.server.model.proto; + +public final class SessionProto { + private SessionProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + public interface ModelOrBuilder extends + // @@protoc_insertion_point(interface_extends:com.farsunset.cim.sdk.server.model.proto.Model) + com.google.protobuf.MessageOrBuilder { + + /** + * string account = 1; + */ + java.lang.String getAccount(); + /** + * string account = 1; + */ + com.google.protobuf.ByteString + getAccountBytes(); + + /** + * string nid = 2; + */ + java.lang.String getNid(); + /** + * string nid = 2; + */ + com.google.protobuf.ByteString + getNidBytes(); + + /** + * string deviceId = 3; + */ + java.lang.String getDeviceId(); + /** + * string deviceId = 3; + */ + com.google.protobuf.ByteString + getDeviceIdBytes(); + + /** + * string host = 4; + */ + java.lang.String getHost(); + /** + * string host = 4; + */ + com.google.protobuf.ByteString + getHostBytes(); + + /** + * string channel = 5; + */ + java.lang.String getChannel(); + /** + * string channel = 5; + */ + com.google.protobuf.ByteString + getChannelBytes(); + + /** + * string deviceModel = 6; + */ + java.lang.String getDeviceModel(); + /** + * string deviceModel = 6; + */ + com.google.protobuf.ByteString + getDeviceModelBytes(); + + /** + * string clientVersion = 7; + */ + java.lang.String getClientVersion(); + /** + * string clientVersion = 7; + */ + com.google.protobuf.ByteString + getClientVersionBytes(); + + /** + * string systemVersion = 8; + */ + java.lang.String getSystemVersion(); + /** + * string systemVersion = 8; + */ + com.google.protobuf.ByteString + getSystemVersionBytes(); + + /** + * int64 bindTime = 9; + */ + long getBindTime(); + + /** + * double longitude = 10; + */ + double getLongitude(); + + /** + * double latitude = 11; + */ + double getLatitude(); + + /** + * string location = 12; + */ + java.lang.String getLocation(); + /** + * string location = 12; + */ + com.google.protobuf.ByteString + getLocationBytes(); + + /** + * int32 apns = 13; + */ + int getApns(); + + /** + * int32 state = 14; + */ + int getState(); + } + /** + * Protobuf type {@code com.farsunset.cim.sdk.server.model.proto.Model} + */ + public static final class Model extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:com.farsunset.cim.sdk.server.model.proto.Model) + ModelOrBuilder { + private static final long serialVersionUID = 0L; + // Use Model.newBuilder() to construct. + private Model(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private Model() { + account_ = ""; + nid_ = ""; + deviceId_ = ""; + host_ = ""; + channel_ = ""; + deviceModel_ = ""; + clientVersion_ = ""; + systemVersion_ = ""; + location_ = ""; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private Model( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + account_ = s; + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); + + nid_ = s; + break; + } + case 26: { + java.lang.String s = input.readStringRequireUtf8(); + + deviceId_ = s; + break; + } + case 34: { + java.lang.String s = input.readStringRequireUtf8(); + + host_ = s; + break; + } + case 42: { + java.lang.String s = input.readStringRequireUtf8(); + + channel_ = s; + break; + } + case 50: { + java.lang.String s = input.readStringRequireUtf8(); + + deviceModel_ = s; + break; + } + case 58: { + java.lang.String s = input.readStringRequireUtf8(); + + clientVersion_ = s; + break; + } + case 66: { + java.lang.String s = input.readStringRequireUtf8(); + + systemVersion_ = s; + break; + } + case 72: { + + bindTime_ = input.readInt64(); + break; + } + case 81: { + + longitude_ = input.readDouble(); + break; + } + case 89: { + + latitude_ = input.readDouble(); + break; + } + case 98: { + java.lang.String s = input.readStringRequireUtf8(); + + location_ = s; + break; + } + case 104: { + + apns_ = input.readInt32(); + break; + } + case 112: { + + state_ = input.readInt32(); + break; + } + default: { + if (!parseUnknownField( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.class, com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.Builder.class); + } + + public static final int ACCOUNT_FIELD_NUMBER = 1; + private volatile java.lang.Object account_; + /** + * string account = 1; + */ + public java.lang.String getAccount() { + java.lang.Object ref = account_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + account_ = s; + return s; + } + } + /** + * string account = 1; + */ + public com.google.protobuf.ByteString + getAccountBytes() { + java.lang.Object ref = account_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + account_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int NID_FIELD_NUMBER = 2; + private volatile java.lang.Object nid_; + /** + * string nid = 2; + */ + public java.lang.String getNid() { + java.lang.Object ref = nid_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + nid_ = s; + return s; + } + } + /** + * string nid = 2; + */ + public com.google.protobuf.ByteString + getNidBytes() { + java.lang.Object ref = nid_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + nid_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int DEVICEID_FIELD_NUMBER = 3; + private volatile java.lang.Object deviceId_; + /** + * string deviceId = 3; + */ + public java.lang.String getDeviceId() { + java.lang.Object ref = deviceId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + deviceId_ = s; + return s; + } + } + /** + * string deviceId = 3; + */ + public com.google.protobuf.ByteString + getDeviceIdBytes() { + java.lang.Object ref = deviceId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + deviceId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int HOST_FIELD_NUMBER = 4; + private volatile java.lang.Object host_; + /** + * string host = 4; + */ + public java.lang.String getHost() { + java.lang.Object ref = host_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + host_ = s; + return s; + } + } + /** + * string host = 4; + */ + public com.google.protobuf.ByteString + getHostBytes() { + java.lang.Object ref = host_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + host_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int CHANNEL_FIELD_NUMBER = 5; + private volatile java.lang.Object channel_; + /** + * string channel = 5; + */ + public java.lang.String getChannel() { + java.lang.Object ref = channel_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + channel_ = s; + return s; + } + } + /** + * string channel = 5; + */ + public com.google.protobuf.ByteString + getChannelBytes() { + java.lang.Object ref = channel_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + channel_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int DEVICEMODEL_FIELD_NUMBER = 6; + private volatile java.lang.Object deviceModel_; + /** + * string deviceModel = 6; + */ + public java.lang.String getDeviceModel() { + java.lang.Object ref = deviceModel_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + deviceModel_ = s; + return s; + } + } + /** + * string deviceModel = 6; + */ + public com.google.protobuf.ByteString + getDeviceModelBytes() { + java.lang.Object ref = deviceModel_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + deviceModel_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int CLIENTVERSION_FIELD_NUMBER = 7; + private volatile java.lang.Object clientVersion_; + /** + * string clientVersion = 7; + */ + public java.lang.String getClientVersion() { + java.lang.Object ref = clientVersion_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + clientVersion_ = s; + return s; + } + } + /** + * string clientVersion = 7; + */ + public com.google.protobuf.ByteString + getClientVersionBytes() { + java.lang.Object ref = clientVersion_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + clientVersion_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int SYSTEMVERSION_FIELD_NUMBER = 8; + private volatile java.lang.Object systemVersion_; + /** + * string systemVersion = 8; + */ + public java.lang.String getSystemVersion() { + java.lang.Object ref = systemVersion_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + systemVersion_ = s; + return s; + } + } + /** + * string systemVersion = 8; + */ + public com.google.protobuf.ByteString + getSystemVersionBytes() { + java.lang.Object ref = systemVersion_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + systemVersion_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int BINDTIME_FIELD_NUMBER = 9; + private long bindTime_; + /** + * int64 bindTime = 9; + */ + public long getBindTime() { + return bindTime_; + } + + public static final int LONGITUDE_FIELD_NUMBER = 10; + private double longitude_; + /** + * double longitude = 10; + */ + public double getLongitude() { + return longitude_; + } + + public static final int LATITUDE_FIELD_NUMBER = 11; + private double latitude_; + /** + * double latitude = 11; + */ + public double getLatitude() { + return latitude_; + } + + public static final int LOCATION_FIELD_NUMBER = 12; + private volatile java.lang.Object location_; + /** + * string location = 12; + */ + public java.lang.String getLocation() { + java.lang.Object ref = location_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + location_ = s; + return s; + } + } + /** + * string location = 12; + */ + public com.google.protobuf.ByteString + getLocationBytes() { + java.lang.Object ref = location_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + location_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int APNS_FIELD_NUMBER = 13; + private int apns_; + /** + * int32 apns = 13; + */ + public int getApns() { + return apns_; + } + + public static final int STATE_FIELD_NUMBER = 14; + private int state_; + /** + * int32 state = 14; + */ + public int getState() { + return state_; + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!getAccountBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, account_); + } + if (!getNidBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, nid_); + } + if (!getDeviceIdBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, deviceId_); + } + if (!getHostBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 4, host_); + } + if (!getChannelBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 5, channel_); + } + if (!getDeviceModelBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 6, deviceModel_); + } + if (!getClientVersionBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 7, clientVersion_); + } + if (!getSystemVersionBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 8, systemVersion_); + } + if (bindTime_ != 0L) { + output.writeInt64(9, bindTime_); + } + if (longitude_ != 0D) { + output.writeDouble(10, longitude_); + } + if (latitude_ != 0D) { + output.writeDouble(11, latitude_); + } + if (!getLocationBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 12, location_); + } + if (apns_ != 0) { + output.writeInt32(13, apns_); + } + if (state_ != 0) { + output.writeInt32(14, state_); + } + unknownFields.writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!getAccountBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, account_); + } + if (!getNidBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, nid_); + } + if (!getDeviceIdBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, deviceId_); + } + if (!getHostBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, host_); + } + if (!getChannelBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, channel_); + } + if (!getDeviceModelBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, deviceModel_); + } + if (!getClientVersionBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, clientVersion_); + } + if (!getSystemVersionBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, systemVersion_); + } + if (bindTime_ != 0L) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(9, bindTime_); + } + if (longitude_ != 0D) { + size += com.google.protobuf.CodedOutputStream + .computeDoubleSize(10, longitude_); + } + if (latitude_ != 0D) { + size += com.google.protobuf.CodedOutputStream + .computeDoubleSize(11, latitude_); + } + if (!getLocationBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(12, location_); + } + if (apns_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(13, apns_); + } + if (state_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(14, state_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.farsunset.cim.sdk.server.model.proto.SessionProto.Model)) { + return super.equals(obj); + } + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model other = (com.farsunset.cim.sdk.server.model.proto.SessionProto.Model) obj; + + if (!getAccount() + .equals(other.getAccount())) return false; + if (!getNid() + .equals(other.getNid())) return false; + if (!getDeviceId() + .equals(other.getDeviceId())) return false; + if (!getHost() + .equals(other.getHost())) return false; + if (!getChannel() + .equals(other.getChannel())) return false; + if (!getDeviceModel() + .equals(other.getDeviceModel())) return false; + if (!getClientVersion() + .equals(other.getClientVersion())) return false; + if (!getSystemVersion() + .equals(other.getSystemVersion())) return false; + if (getBindTime() + != other.getBindTime()) return false; + if (java.lang.Double.doubleToLongBits(getLongitude()) + != java.lang.Double.doubleToLongBits( + other.getLongitude())) return false; + if (java.lang.Double.doubleToLongBits(getLatitude()) + != java.lang.Double.doubleToLongBits( + other.getLatitude())) return false; + if (!getLocation() + .equals(other.getLocation())) return false; + if (getApns() + != other.getApns()) return false; + if (getState() + != other.getState()) return false; + if (!unknownFields.equals(other.unknownFields)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + ACCOUNT_FIELD_NUMBER; + hash = (53 * hash) + getAccount().hashCode(); + hash = (37 * hash) + NID_FIELD_NUMBER; + hash = (53 * hash) + getNid().hashCode(); + hash = (37 * hash) + DEVICEID_FIELD_NUMBER; + hash = (53 * hash) + getDeviceId().hashCode(); + hash = (37 * hash) + HOST_FIELD_NUMBER; + hash = (53 * hash) + getHost().hashCode(); + hash = (37 * hash) + CHANNEL_FIELD_NUMBER; + hash = (53 * hash) + getChannel().hashCode(); + hash = (37 * hash) + DEVICEMODEL_FIELD_NUMBER; + hash = (53 * hash) + getDeviceModel().hashCode(); + hash = (37 * hash) + CLIENTVERSION_FIELD_NUMBER; + hash = (53 * hash) + getClientVersion().hashCode(); + hash = (37 * hash) + SYSTEMVERSION_FIELD_NUMBER; + hash = (53 * hash) + getSystemVersion().hashCode(); + hash = (37 * hash) + BINDTIME_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getBindTime()); + hash = (37 * hash) + LONGITUDE_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + java.lang.Double.doubleToLongBits(getLongitude())); + hash = (37 * hash) + LATITUDE_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + java.lang.Double.doubleToLongBits(getLatitude())); + hash = (37 * hash) + LOCATION_FIELD_NUMBER; + hash = (53 * hash) + getLocation().hashCode(); + hash = (37 * hash) + APNS_FIELD_NUMBER; + hash = (53 * hash) + getApns(); + hash = (37 * hash) + STATE_FIELD_NUMBER; + hash = (53 * hash) + getState(); + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(com.farsunset.cim.sdk.server.model.proto.SessionProto.Model prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code com.farsunset.cim.sdk.server.model.proto.Model} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:com.farsunset.cim.sdk.server.model.proto.Model) + com.farsunset.cim.sdk.server.model.proto.SessionProto.ModelOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.class, com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.Builder.class); + } + + // Construct using com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + @java.lang.Override + public Builder clear() { + super.clear(); + account_ = ""; + + nid_ = ""; + + deviceId_ = ""; + + host_ = ""; + + channel_ = ""; + + deviceModel_ = ""; + + clientVersion_ = ""; + + systemVersion_ = ""; + + bindTime_ = 0L; + + longitude_ = 0D; + + latitude_ = 0D; + + location_ = ""; + + apns_ = 0; + + state_ = 0; + + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor; + } + + @java.lang.Override + public com.farsunset.cim.sdk.server.model.proto.SessionProto.Model getDefaultInstanceForType() { + return com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.getDefaultInstance(); + } + + @java.lang.Override + public com.farsunset.cim.sdk.server.model.proto.SessionProto.Model build() { + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.farsunset.cim.sdk.server.model.proto.SessionProto.Model buildPartial() { + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model result = new com.farsunset.cim.sdk.server.model.proto.SessionProto.Model(this); + result.account_ = account_; + result.nid_ = nid_; + result.deviceId_ = deviceId_; + result.host_ = host_; + result.channel_ = channel_; + result.deviceModel_ = deviceModel_; + result.clientVersion_ = clientVersion_; + result.systemVersion_ = systemVersion_; + result.bindTime_ = bindTime_; + result.longitude_ = longitude_; + result.latitude_ = latitude_; + result.location_ = location_; + result.apns_ = apns_; + result.state_ = state_; + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.farsunset.cim.sdk.server.model.proto.SessionProto.Model) { + return mergeFrom((com.farsunset.cim.sdk.server.model.proto.SessionProto.Model)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.farsunset.cim.sdk.server.model.proto.SessionProto.Model other) { + if (other == com.farsunset.cim.sdk.server.model.proto.SessionProto.Model.getDefaultInstance()) return this; + if (!other.getAccount().isEmpty()) { + account_ = other.account_; + onChanged(); + } + if (!other.getNid().isEmpty()) { + nid_ = other.nid_; + onChanged(); + } + if (!other.getDeviceId().isEmpty()) { + deviceId_ = other.deviceId_; + onChanged(); + } + if (!other.getHost().isEmpty()) { + host_ = other.host_; + onChanged(); + } + if (!other.getChannel().isEmpty()) { + channel_ = other.channel_; + onChanged(); + } + if (!other.getDeviceModel().isEmpty()) { + deviceModel_ = other.deviceModel_; + onChanged(); + } + if (!other.getClientVersion().isEmpty()) { + clientVersion_ = other.clientVersion_; + onChanged(); + } + if (!other.getSystemVersion().isEmpty()) { + systemVersion_ = other.systemVersion_; + onChanged(); + } + if (other.getBindTime() != 0L) { + setBindTime(other.getBindTime()); + } + if (other.getLongitude() != 0D) { + setLongitude(other.getLongitude()); + } + if (other.getLatitude() != 0D) { + setLatitude(other.getLatitude()); + } + if (!other.getLocation().isEmpty()) { + location_ = other.location_; + onChanged(); + } + if (other.getApns() != 0) { + setApns(other.getApns()); + } + if (other.getState() != 0) { + setState(other.getState()); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.farsunset.cim.sdk.server.model.proto.SessionProto.Model parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.farsunset.cim.sdk.server.model.proto.SessionProto.Model) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object account_ = ""; + /** + * string account = 1; + */ + public java.lang.String getAccount() { + java.lang.Object ref = account_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + account_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string account = 1; + */ + public com.google.protobuf.ByteString + getAccountBytes() { + java.lang.Object ref = account_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + account_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string account = 1; + */ + public Builder setAccount( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + account_ = value; + onChanged(); + return this; + } + /** + * string account = 1; + */ + public Builder clearAccount() { + + account_ = getDefaultInstance().getAccount(); + onChanged(); + return this; + } + /** + * string account = 1; + */ + public Builder setAccountBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + account_ = value; + onChanged(); + return this; + } + + private java.lang.Object nid_ = ""; + /** + * string nid = 2; + */ + public java.lang.String getNid() { + java.lang.Object ref = nid_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + nid_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string nid = 2; + */ + public com.google.protobuf.ByteString + getNidBytes() { + java.lang.Object ref = nid_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + nid_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string nid = 2; + */ + public Builder setNid( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + nid_ = value; + onChanged(); + return this; + } + /** + * string nid = 2; + */ + public Builder clearNid() { + + nid_ = getDefaultInstance().getNid(); + onChanged(); + return this; + } + /** + * string nid = 2; + */ + public Builder setNidBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + nid_ = value; + onChanged(); + return this; + } + + private java.lang.Object deviceId_ = ""; + /** + * string deviceId = 3; + */ + public java.lang.String getDeviceId() { + java.lang.Object ref = deviceId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + deviceId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string deviceId = 3; + */ + public com.google.protobuf.ByteString + getDeviceIdBytes() { + java.lang.Object ref = deviceId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + deviceId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string deviceId = 3; + */ + public Builder setDeviceId( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + deviceId_ = value; + onChanged(); + return this; + } + /** + * string deviceId = 3; + */ + public Builder clearDeviceId() { + + deviceId_ = getDefaultInstance().getDeviceId(); + onChanged(); + return this; + } + /** + * string deviceId = 3; + */ + public Builder setDeviceIdBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + deviceId_ = value; + onChanged(); + return this; + } + + private java.lang.Object host_ = ""; + /** + * string host = 4; + */ + public java.lang.String getHost() { + java.lang.Object ref = host_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + host_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string host = 4; + */ + public com.google.protobuf.ByteString + getHostBytes() { + java.lang.Object ref = host_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + host_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string host = 4; + */ + public Builder setHost( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + host_ = value; + onChanged(); + return this; + } + /** + * string host = 4; + */ + public Builder clearHost() { + + host_ = getDefaultInstance().getHost(); + onChanged(); + return this; + } + /** + * string host = 4; + */ + public Builder setHostBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + host_ = value; + onChanged(); + return this; + } + + private java.lang.Object channel_ = ""; + /** + * string channel = 5; + */ + public java.lang.String getChannel() { + java.lang.Object ref = channel_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + channel_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string channel = 5; + */ + public com.google.protobuf.ByteString + getChannelBytes() { + java.lang.Object ref = channel_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + channel_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string channel = 5; + */ + public Builder setChannel( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + channel_ = value; + onChanged(); + return this; + } + /** + * string channel = 5; + */ + public Builder clearChannel() { + + channel_ = getDefaultInstance().getChannel(); + onChanged(); + return this; + } + /** + * string channel = 5; + */ + public Builder setChannelBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + channel_ = value; + onChanged(); + return this; + } + + private java.lang.Object deviceModel_ = ""; + /** + * string deviceModel = 6; + */ + public java.lang.String getDeviceModel() { + java.lang.Object ref = deviceModel_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + deviceModel_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string deviceModel = 6; + */ + public com.google.protobuf.ByteString + getDeviceModelBytes() { + java.lang.Object ref = deviceModel_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + deviceModel_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string deviceModel = 6; + */ + public Builder setDeviceModel( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + deviceModel_ = value; + onChanged(); + return this; + } + /** + * string deviceModel = 6; + */ + public Builder clearDeviceModel() { + + deviceModel_ = getDefaultInstance().getDeviceModel(); + onChanged(); + return this; + } + /** + * string deviceModel = 6; + */ + public Builder setDeviceModelBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + deviceModel_ = value; + onChanged(); + return this; + } + + private java.lang.Object clientVersion_ = ""; + /** + * string clientVersion = 7; + */ + public java.lang.String getClientVersion() { + java.lang.Object ref = clientVersion_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + clientVersion_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string clientVersion = 7; + */ + public com.google.protobuf.ByteString + getClientVersionBytes() { + java.lang.Object ref = clientVersion_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + clientVersion_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string clientVersion = 7; + */ + public Builder setClientVersion( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + clientVersion_ = value; + onChanged(); + return this; + } + /** + * string clientVersion = 7; + */ + public Builder clearClientVersion() { + + clientVersion_ = getDefaultInstance().getClientVersion(); + onChanged(); + return this; + } + /** + * string clientVersion = 7; + */ + public Builder setClientVersionBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + clientVersion_ = value; + onChanged(); + return this; + } + + private java.lang.Object systemVersion_ = ""; + /** + * string systemVersion = 8; + */ + public java.lang.String getSystemVersion() { + java.lang.Object ref = systemVersion_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + systemVersion_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string systemVersion = 8; + */ + public com.google.protobuf.ByteString + getSystemVersionBytes() { + java.lang.Object ref = systemVersion_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + systemVersion_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string systemVersion = 8; + */ + public Builder setSystemVersion( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + systemVersion_ = value; + onChanged(); + return this; + } + /** + * string systemVersion = 8; + */ + public Builder clearSystemVersion() { + + systemVersion_ = getDefaultInstance().getSystemVersion(); + onChanged(); + return this; + } + /** + * string systemVersion = 8; + */ + public Builder setSystemVersionBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + systemVersion_ = value; + onChanged(); + return this; + } + + private long bindTime_ ; + /** + * int64 bindTime = 9; + */ + public long getBindTime() { + return bindTime_; + } + /** + * int64 bindTime = 9; + */ + public Builder setBindTime(long value) { + + bindTime_ = value; + onChanged(); + return this; + } + /** + * int64 bindTime = 9; + */ + public Builder clearBindTime() { + + bindTime_ = 0L; + onChanged(); + return this; + } + + private double longitude_ ; + /** + * double longitude = 10; + */ + public double getLongitude() { + return longitude_; + } + /** + * double longitude = 10; + */ + public Builder setLongitude(double value) { + + longitude_ = value; + onChanged(); + return this; + } + /** + * double longitude = 10; + */ + public Builder clearLongitude() { + + longitude_ = 0D; + onChanged(); + return this; + } + + private double latitude_ ; + /** + * double latitude = 11; + */ + public double getLatitude() { + return latitude_; + } + /** + * double latitude = 11; + */ + public Builder setLatitude(double value) { + + latitude_ = value; + onChanged(); + return this; + } + /** + * double latitude = 11; + */ + public Builder clearLatitude() { + + latitude_ = 0D; + onChanged(); + return this; + } + + private java.lang.Object location_ = ""; + /** + * string location = 12; + */ + public java.lang.String getLocation() { + java.lang.Object ref = location_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + location_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string location = 12; + */ + public com.google.protobuf.ByteString + getLocationBytes() { + java.lang.Object ref = location_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + location_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string location = 12; + */ + public Builder setLocation( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + location_ = value; + onChanged(); + return this; + } + /** + * string location = 12; + */ + public Builder clearLocation() { + + location_ = getDefaultInstance().getLocation(); + onChanged(); + return this; + } + /** + * string location = 12; + */ + public Builder setLocationBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + location_ = value; + onChanged(); + return this; + } + + private int apns_ ; + /** + * int32 apns = 13; + */ + public int getApns() { + return apns_; + } + /** + * int32 apns = 13; + */ + public Builder setApns(int value) { + + apns_ = value; + onChanged(); + return this; + } + /** + * int32 apns = 13; + */ + public Builder clearApns() { + + apns_ = 0; + onChanged(); + return this; + } + + private int state_ ; + /** + * int32 state = 14; + */ + public int getState() { + return state_; + } + /** + * int32 state = 14; + */ + public Builder setState(int value) { + + state_ = value; + onChanged(); + return this; + } + /** + * int32 state = 14; + */ + public Builder clearState() { + + state_ = 0; + onChanged(); + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:com.farsunset.cim.sdk.server.model.proto.Model) + } + + // @@protoc_insertion_point(class_scope:com.farsunset.cim.sdk.server.model.proto.Model) + private static final com.farsunset.cim.sdk.server.model.proto.SessionProto.Model DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.farsunset.cim.sdk.server.model.proto.SessionProto.Model(); + } + + public static com.farsunset.cim.sdk.server.model.proto.SessionProto.Model getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public Model parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new Model(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.farsunset.cim.sdk.server.model.proto.SessionProto.Model getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\rSession.proto\022(com.farsunset.cim.sdk.s" + + "erver.model.proto\"\377\001\n\005Model\022\017\n\007account\030\001" + + " \001(\t\022\013\n\003nid\030\002 \001(\t\022\020\n\010deviceId\030\003 \001(\t\022\014\n\004h" + + "ost\030\004 \001(\t\022\017\n\007channel\030\005 \001(\t\022\023\n\013deviceMode" + + "l\030\006 \001(\t\022\025\n\rclientVersion\030\007 \001(\t\022\025\n\rsystem" + + "Version\030\010 \001(\t\022\020\n\010bindTime\030\t \001(\003\022\021\n\tlongi" + + "tude\030\n \001(\001\022\020\n\010latitude\030\013 \001(\001\022\020\n\010location" + + "\030\014 \001(\t\022\014\n\004apns\030\r \001(\005\022\r\n\005state\030\016 \001(\005B\016B\014S" + + "essionProtob\006proto3" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_com_farsunset_cim_sdk_server_model_proto_Model_descriptor, + new java.lang.String[] { "Account", "Nid", "DeviceId", "Host", "Channel", "DeviceModel", "ClientVersion", "SystemVersion", "BindTime", "Longitude", "Latitude", "Location", "Apns", "State", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/DefaultSessionManager.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/DefaultSessionManager.java deleted file mode 100644 index ba537c4..0000000 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/DefaultSessionManager.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2013-2019 Xia Jun(3979434@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *************************************************************************************** - * * - * Website : http://www.farsunset.com * - * * - *************************************************************************************** - */ -package com.farsunset.cim.sdk.server.session; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import com.farsunset.cim.sdk.server.constant.CIMConstant; - -/** - * 自带默认 session管理实现, 各位可以自行实现 AbstractSessionManager接口来实现自己的 session管理 服务器集群时 - * 须要将CIMSession 信息存入数据库或者nosql 等 第三方存储空间中,便于所有服务器都可以访问 - */ -public class DefaultSessionManager implements SessionManager { - - private static HashMap sessions = new HashMap(); - - private static final AtomicInteger connectionsCounter = new AtomicInteger(0); - - /** - * - */ - public void add(CIMSession session) { - if (session != null) { - session.setAttribute(CIMConstant.SESSION_KEY, session.getAccount()); - sessions.put(session.getAccount(), session); - connectionsCounter.incrementAndGet(); - } - - } - - public CIMSession get(String account) { - - return sessions.get(account); - } - - public List queryAll() { - List list = new ArrayList(); - list.addAll(sessions.values()); - return list; - } - - public void remove(CIMSession session) { - - sessions.remove(session.getAttribute(CIMConstant.SESSION_KEY)); - } - - public void remove(String account) { - - sessions.remove(account); - - } - - public boolean containsCIMSession(String account) { - return sessions.containsKey(account); - } - - @Override - public void update(CIMSession session) { - sessions.put(session.getAccount(), session); - } - -} diff --git a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/SessionManager.java b/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/SessionManager.java deleted file mode 100644 index d067129..0000000 --- a/cim_for_netty/cim-server-sdk/src/com/farsunset/cim/sdk/server/session/SessionManager.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2013-2019 Xia Jun(3979434@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *************************************************************************************** - * * - * Website : http://www.farsunset.com * - * * - *************************************************************************************** - */ -package com.farsunset.cim.sdk.server.session; - -import java.util.List; - -/** - * 客户端的 session管理接口 可自行实现此接口管理session - */ - -public interface SessionManager { - - /** - * 添加新的session - */ - public void add(CIMSession session); - - /** - * 更新session - */ - public void update(CIMSession session); - - /** - * - * @param account - * 客户端session的 key 一般可用 用户账号来对应session - * @return - */ - CIMSession get(String account); - - /** - * 获取所有session - * - * @return - */ - public List queryAll(); - - /** - * 删除session - * - * @param session - */ - public void remove(String account); - -}