码迷,mamicode.com
首页 > 其他好文 > 详细

kafka系列一(基本知识)

时间:2020-08-08 17:48:39      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:高可用   消费者   lin   broker   apache   kafka集群   listeners   扩容   数据冗余   

“线”池

利用队列建立DrawLineTools的线池。

当需要绘制线的时候,如果不能从线池中取出DrawLineTools,就Instantiate出一个。

    public class Line
    {
        private static readonly LinePool LinePool = new LinePool(Resources.Load<GameObject>("Prefabs/Line"));
        private static readonly LinePool EndLinePool = new LinePool(Resources.Load<GameObject>("Prefabs/End"));

        // private static LineManager _singleton;
        
        /// <summary>
        /// 创建DrawMeshTools
        /// </summary>
        /// <returns></returns>
        public static DrawLineTools CreateLine()
        {
            return LinePool.GetLine();
        }

        /// <summary>
        /// 连线终点
        /// </summary>
        /// <param name="node">结点</param>
        public static DrawLineTools CreateEnd(TrackNode node)
        {
            DrawLineTools mesh = EndLinePool.GetLine();;
            mesh.LastNode = node;
            return mesh;
        }
        
        /// <summary>
        /// 将临时线回收
        /// </summary>
        /// <param name="line">待回收的DrawLineTools</param>
        public static void ResetLine(DrawLineTools line)
        {
            LinePool.ResetLine(line);
        }
    } 
    
    public class LinePool
    {
        public LinePool(GameObject p)
        {
            lines = new Queue<DrawLineTools>();
            prefab = p;
        }
        
        private Queue<DrawLineTools> lines;
        private GameObject poolRoot;
        private GameObject prefab;
        
        public DrawLineTools GetLine()
        {
            DrawLineTools line;
            if (lines.Count == 0)
            {
                GameObject go = GameObject.Instantiate(prefab);
                line = go.GetComponent<DrawLineTools>();
            }
            else
            {
                line = lines.Dequeue();
                line.gameObject.SetActive(true);
                line.transform.parent = null;
            }

            return line;
        }

        public void ResetLine(DrawLineTools line)
        {
            if (poolRoot == null)
            {
                poolRoot = new GameObject("PoolRoot");
            }
            lines.Enqueue(line);
            line.gameObject.SetActive(false);
            line.transform.parent = poolRoot.transform;
        }
    }

kafka系列一(基本知识)

标签:高可用   消费者   lin   broker   apache   kafka集群   listeners   扩容   数据冗余   

原文地址:https://www.cnblogs.com/liuxingxing/p/13458564.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!