using System;
//using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace MQ
{
public class MessageQueue
{
private static LinkedList<string> lls;
static int msgCount = 10;
static object obj;
public static void InitialMessageQueue(int count)
{
lls = new LinkedList<string>();
msgCount = count;
obj = new object();
}
public static bool CheckMsgRemove(string key)
{
try
{
//return false;
lock (obj)
{
Console.WriteLine("- Begin Msg Link Count is " + lls.Count.ToString());
if (lls.Contains(key))
{
Console.WriteLine(" * Remove duplicate Key_" + key);
lls.Remove(key);
Console.WriteLine("- End Msg Link Count is " + lls.Count.ToString());
return true;
}
else
{
if (lls.Count > msgCount)
{
Console.WriteLine(" * Remove last Key_" + lls.Last.Value);
lls.RemoveLast();
}
lls.AddFirst(key);
Console.WriteLine(" * Add first Key_" + key);
}
Console.WriteLine("- End Msg Link Count is " + lls.Count.ToString());
}
return false;
}
catch (Exception ex)
{
return false;
}
}
}
}