123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using CommonLang.Log;
- using CommonServer.Server;
- using CommonServer_ICE.Server;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CommonServer_ICE.Session
- {
-
-
-
- internal class TcpSessionManager : Glacier2.SessionManagerDisp_
- {
- private static Logger log = LoggerFactory.GetLogger("TcpSessionManager");
-
- private Dictionary<string, ISession> sessionIdKeyMap = new Dictionary<string, ISession>();
-
- private IceTcpServer tcpServer;
- public TcpSessionManager(IceTcpServer tcpServer)
- {
- this.tcpServer = tcpServer;
- tcpServer.TcpSessionManager = this;
- }
-
-
-
-
-
-
-
- public override Glacier2.SessionPrx create(string userId, Glacier2.SessionControlPrx control, Ice.Current current)
- {
- Ice.TCPConnectionInfo tcpConInfo = (Ice.TCPConnectionInfo)current.con.getInfo();
- IceServerIoSession session = new IceServerIoSession(tcpServer);
- session.TcpSessionManager = this;
- session.RemoteIp = tcpConInfo.remoteAddress;
- session.ClientSentDataPort = tcpConInfo.remotePort;
- sessionIdKeyMap.Add(session.ID, session);
-
- try
- {
- tcpServer.OnNewSessionConnected(session);
- }
- catch (Exception e)
- {
- log.Error("建立新会话发生异常:" + e.Message);
- }
- Ice.ObjectPrx objectPrx = current.adapter.addWithUUID(session);
- session.ClientIdentity = objectPrx.ice_getIdentity();
- return Glacier2.SessionPrxHelper.uncheckedCast(current.adapter.addWithUUID(session));
- }
-
-
-
-
- public void RemoveSession(IceServerIoSession session)
- {
- sessionIdKeyMap.Remove(session.ID);
- }
-
-
-
-
-
-
- private string getSessionKey(string ip, int port)
- {
- return ip + ":" + port;
- }
-
-
-
-
- public int getSessionCount()
- {
- return sessionIdKeyMap.Count;
- }
-
-
-
-
- public List<ISession> getAllSession()
- {
- return sessionIdKeyMap.Values.ToList();
- }
-
-
-
-
-
- public ISession getSession(string sessionId)
- {
- ISession ret;
- if (sessionIdKeyMap.TryGetValue(sessionId, out ret))
- {
- return ret;
- }
- return null;
- }
-
-
-
-
-
-
- public ISession getSession(String ip, int port)
- {
- return null;
- }
-
-
-
-
-
- public bool hasSession(string sessionId)
- {
- if (sessionIdKeyMap.ContainsKey(sessionId))
- {
- return true;
- }
- return false;
- }
-
-
-
-
-
- public bool hasSession(ISession session)
- {
- return hasSession(session.ID);
- }
-
-
-
-
-
-
- public bool hasSession(String ip, int port)
- {
- return false;
- }
- }
- }
|