Sha256: d4e908ff17eb80caf04a84e04ffd196b96343d94e83db98e4990cf4a858232a1

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

using System.Net;
using System.Net.Sockets;
using System;
using  ProtoBuf;
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Entity = GameMachine.Messages.Entity;
using GameMachine;
using System.Collections.Concurrent;
using NLog;

namespace GameMachine
{
    public class MessageRouter
    {
        public ConcurrentDictionary<string,Callable> callables = new ConcurrentDictionary<string,Callable>();
        public static Logger logger = LogManager.GetLogger("GameMachine");
		
        public Entity Route(string klass, Entity message)
        {
            try
            {
                Callable callable;
                string typeName = klass;
                string threadId = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
                string id = typeName + threadId;

                if (callables.TryGetValue(id, out callable))
                {
                    return callable.call(message);
                } else
                {
                    Type type = Type.GetType(typeName);
                    if (type == null)
                    {
                        MessageRouter.logger.Info(typeName + " is null");
                        return null;
                    }
                    callable = Activator.CreateInstance(type) as Callable;
                    MessageRouter.logger.Info("Callable created with id " + id);
                    if (callables.TryAdd(id, callable))
                    {
                        return callable.call(message);
                    } else
                    {
                        MessageRouter.logger.Info("Unable to add callable " + id);
                        return null;
                    }
                }
            } catch (Exception ex)
            {
                MessageRouter.logger.Info(ex.Message);
                return null;
            }
        }

    }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
game_machine-1.0.4 mono/server/message_router.cs
game_machine-1.0.2 mono/server/message_router.cs