static void Main(string[] args) { Console.Write("\n Testing Monitor-Based Blocking Queue"); Console.Write("\n ======================================"); SWTools.BlockingQueue <string> q = new SWTools.BlockingQueue <string>(); Thread t = new Thread(() => { string msg; while (true) { msg = q.deQ(); Console.Write("\n child thread received {0}", msg); if (msg == "quit") { break; } } }); t.Start(); string sendMsg = "msg #"; for (int i = 0; i < 20; ++i) { string temp = sendMsg + i.ToString(); Console.Write("\n main thread sending {0}", temp); q.enQ(temp); } q.enQ("quit"); t.Join(); Console.Write("\n\n"); }
public testRequestHandler() { if (testQ == null) { testQ = new SWTools.BlockingQueue <CommMessage>(); } }
public stringSender(string url) { sndQueue = new SWTools.BlockingQueue <string>(); while (true) { try { CreateSendChannel(url); tryCount = 0; break; } catch (Exception ex) { if (++tryCount < maxCount) { Thread.Sleep(100); } else { lasterror = ex.Message; break; } } } sndThrd = new Thread(new ThreadStart(ThreadProc)); sndThrd.Start(); }
public stringReceiver() { if (rcvQueue == null) { rcvQueue = new SWTools.BlockingQueue <string>(); } }
/*----< constructor >------------------------------------------*/ public Receiver() { if (rcvQ == null) { rcvQ = new SWTools.BlockingQueue <CommMessage>(); } }
/*----< constructor >------------------------------------------*/ public Sender(string baseAddress, int listenPort) { port = listenPort; fromAddress = baseAddress + listenPort.ToString() + "/IMessagePassingComm"; sndQ = new SWTools.BlockingQueue <CommMessage>(); sndThread = new Thread(threadProc); sndThread.Start(); }
private void startQueue() { if (queueCount == 1) { queueCount++; queue = new SWTools.BlockingQueue <PostError>(); } }
/*----< constructor >------------------------------------------*/ public Sender(string baseAddress, int listenPort) { port = listenPort; fromAddress = baseAddress + listenPort.ToString() + "/IMessagePassingComm"; sndQ = new SWTools.BlockingQueue <CommMessage>(); TestUtilities.putLine(string.Format("starting Sender on thread {0}", Thread.CurrentThread.ManagedThreadId)); sndThread = new Thread(threadProc); sndThread.Start(); }
void processMessages(SWTools.BlockingQueue <TestData> p, SWTools.BlockingQueue <System.IO.FileStream> q) //getMessage and decode message from Queue, return metadata of the test //p includes test, q include xmlstream. //we need to transfer p to TestLoader { System.IO.FileStream current = q.deQ(); XmlDecoder decoder = new XmlDecoder(); decoder.parse(current, p); }
//----< defines SendThread and its operations >---------------------- /* * - asynchronous function defines Sender sendThread processing * - creates BlockingQueue<Message> to use inside Sender.sendMessage() * - creates and starts a thread executing that processing * - uses msg.toUrl to find or create a proxy for url destination */ public virtual SWTools.BlockingQueue <Message> defineSendProcessing() { SWTools.BlockingQueue <Message> sendQ = new SWTools.BlockingQueue <Message>(); Action sendAction = () => { ThreadStart sendThreadProc = () => { while (true) { try { Message smsg = sendQ.deQ(); if (smsg.content == "closeSender") { break; } if (proxyStore.ContainsKey(smsg.toUrl)) { if (Util.verbose) { Console.Write("\n sender sending message to service {0}", smsg.toUrl); } proxyStore[smsg.toUrl].sendMessage(smsg); } else { if (this.Connect(smsg.toUrl)) // if Connect succeeds it will set proxy and send start msg { if (Util.verbose) { Console.Write("\n sender created proxy and sending message {0}", smsg.toUrl); } proxyStore[smsg.toUrl] = this.proxy; // save proxy proxy.sendMessage(smsg); } else { sendMsgNotify(String.Format("could not connect to {0}\n", smsg.toUrl)); continue; } } } catch (Exception ex) { sendExceptionNotify(ex); continue; } } }; Thread t = new Thread(sendThreadProc); // start the sendThread t.IsBackground = true; t.Start(); }; this.setAction(sendAction); return(sendQ); }
/*----------- creating a Comm that attaches reciever and sender to the MotherBuildServer * -----------Initialise the ready and request queue and start reciever thread ----------*/ MotherBuilder() { initializeEnvironment(); readyQueue = new SWTools.BlockingQueue <CommMessage>(); requestQueue = new SWTools.BlockingQueue <CommMessage>(); comm = new Comm(MotherBuildServer.address, MotherBuildServer.port); rcvThread = new Thread(rcvThreadProc); rcvThread.Start(); }
public Builder(int hostNum) { trdQ = new SWTools.BlockingQueue <string>(); reqQ = new SWTools.BlockingQueue <CommMessage>(); localHost = hostNum; portList = new List <int>(); BldComm = new Comm("http://localhost", localHost); cleanFiles(chdXmlPath); }
} //local testharness public testHarness(string _url) { url = _url; //in project4 the ip address of test harness shoulbe hard coded url = "http://localhost:8080/"; thStrRcvr = url + "THStrRcvr"; thFRcvr = url + "THFRcvr"; q = new BlockingQueue <System.IO.FileStream>(); LogFolder = "../../../THtemp/"; }
//constructor which initializes startport public MBuilder(int startport) { if (readyqueue == null) { readyqueue = new SWTools.BlockingQueue <CommMessage>(); Buildrequestqueue = new SWTools.BlockingQueue <CommMessage>(); } serverip = "http://localhost:" + startport.ToString() + "/IMessagePassingComm"; comm = new Comm("http://localhost", startport); }
public BuildServer(int number) { numberOfProcesses = number; comm = new Comm("http://localhost", port); readyMessagesQ = new SWTools.BlockingQueue <CommMessage>(); buildRequestsQ = new SWTools.BlockingQueue <CommMessage>(); msgHandler = new Thread(processMessages); msgHandler.Start(); spawnNumberOfProcesses(numberOfProcesses); }
/*----< library binding error event handler >------------------*/ /* * This function is an event handler for binding errors when * loading libraries. These occur when a loaded library has * dependent libraries that are not located in the directory * where the Executable is running. */ public TestHarness() { if (TrQ == null) { TrQ = new SWTools.BlockingQueue <string>(); } if (!Directory.Exists(testersLocation)) { Directory.CreateDirectory(testersLocation); } }
//----< defines SendThread and its operations >---------------------- /* * - asynchronous function defines Sender sendThread processing * - creates BlockingQueue<Message> to use inside Sender.sendMessage() * - creates and starts a thread executing that processing * - uses msg.toUrl to find or create a proxy for url destination */ public ThreadStart performSendThreadProc(SWTools.BlockingQueue <Message> sendQ) { ThreadStart sendThreadProc = () => { while (true) { try { Message smsg = sendQ.deQ(); if (smsg.content == "closeSender") { Console.Write("\n send thread quitting\n\n"); break; } if (proxyStore.ContainsKey(smsg.toUrl)) { // proxy already created so use it if (Util.verbose) { Console.Write("\n sender sending message to service {0}", smsg.toUrl); } proxyStore[smsg.toUrl].sendMessage(smsg); } else { // create new proxy with Connect, save it, and use it if (this.Connect(smsg.toUrl)) // if Connect succeeds it will set proxy and send start msg { if (Util.verbose) { Console.Write("\n sender created proxy and sending message {0}", smsg.toUrl); } proxyStore[smsg.toUrl] = this.proxy; // save proxy proxy.sendMessage(smsg); } else { sendMsgNotify(String.Format("could not connect to {0}\n", smsg.toUrl)); continue; } } } catch (Exception ex) { sendExceptionNotify(ex); continue; } } }; return(sendThreadProc); }
public virtual SWTools.BlockingQueue <Message> defineSendProcessing() { SWTools.BlockingQueue <Message> sendQ = new SWTools.BlockingQueue <Message>(); Action sendAction = () => { ThreadStart sendThreadProc = performSendThreadProc(sendQ); Thread t = new Thread(sendThreadProc); // start the sendThread t.IsBackground = true; t.Start(); }; this.setAction(sendAction); return(sendQ); }
public void parse(System.IO.Stream xml, SWTools.BlockingQueue <TestData> q)//decode a xml file and put all test data into a blocking queue { TestData test; doc_ = XDocument.Load(xml); if (doc_ == null) { test = new TestData(); test.success = false; test.author = "unknown"; test.timeStamp = DateTime.Now; test.testName = "END"; q.enQ(test); return; } string datetime = doc_.Descendants("datetime").First().Value; string author = doc_.Descendants("author").First().Value; string repo = doc_.Descendants("reposetory").First().Value; XElement[] xtests = doc_.Descendants("test").ToArray(); int numTests = xtests.Count(); try { for (int i = 0; i < numTests; ++i) { test = new TestData(); test.success = true; test.testCode = new List <string>(); test.author = author; test.datetime = datetime; test.timeStamp = DateTime.Now; test.repo = repo; test.testName = xtests[i].Attribute("name").Value; test.testDriver = xtests[i].Element("testDriver").Value; IEnumerable <XElement> xtestCode = xtests[i].Elements("library"); foreach (var xlibrary in xtestCode) { test.testCode.Add(xlibrary.Value); } q.enQ(test); } } catch (Exception ex) { Console.WriteLine("\n\n {0}", ex.Message); } return; }
// bool flag to indicate whether to span child thread public Client2(bool flag) { "Creating a new instance of Client2".title(); if (inQ_ == null) { inQ_ = new SWTools.BlockingQueue <Message>(); } // CreateClientRecvChannel(clientUrl); // Console.Write("\n Created new client Service to accept http connections"); if (flag == true) { ClientReadThrd = new Thread(ThreadProc); ClientReadThrd.IsBackground = true; ClientReadThrd.Start(); } }
public MthrBuilder() { if (!Directory.Exists(BuildEnvironment.fileStorage)) { Directory.CreateDirectory(BuildEnvironment.fileStorage); } if (BrQ == null) { BrQ = new SWTools.BlockingQueue <string>(); } if (ReadyQ == null) { ReadyQ = new SWTools.BlockingQueue <int>(); } comm = new Comm("http://localhost", 8080); }
public Repository(bool flag) { // Console.Write("\n Creating instance of Repository"); if (inQ_ == null) { inQ_ = new SWTools.BlockingQueue <Message>(); } // CreateRepoRecvChannel(RepoUrl); // Console.Write("\n Created new Repository Service to accept http connections"); if (flag == true) { RepoThrd = new Thread(ThreadProc); RepoThrd.IsBackground = true; RepoThrd.Start(); } }
public ClientWPF() { Console.Title = "DemoWPF"; InitializeComponent(); OnNewMessage += new NewMessage(OnNewMessageHandler); if (inQ_ == null) { inQ_ = new SWTools.BlockingQueue <Message>(); } ClientReadThrd = new Thread(ThreadProc); ClientReadThrd.IsBackground = true; ClientReadThrd.Start(); // "Created a new instance of ClientWPF - Req#11".title(); }
/*----< constructor >------------------------------------------------------*/ BuildServer() { Console.Title = "Build Server"; // start comm if (comm == null) { string baseAddress = "http://localhost"; int port = 8080; comm = new Comm(baseAddress, port); } try { // check initial environment dispatcher = new Dictionary <Command, Handle> ( ); maxProcessNum = 10; allProcessinPool = new List <SingleProcessInfo> ( ); requestedQ = new SWTools.BlockingQueue <RequestInfo> ( ); readQ = new SWTools.BlockingQueue <int> ( ); initializeDispatcher( ); open = comm.open; msgHandlerThread = new Thread(msgHandlerProc); msgHandlerThread.Start( ); builderThread = new Thread(dequeRequest); builderThread.Start( ); Console.Write("\n Successfully create build server..."); } catch (Exception ex) { //errorMessage = "Could not initialize Comm on the specified port (" + port.ToString ( ) + ")."; Console.Write("\n {0}", ex.Message); GC.SuppressFinalize(this); System.Diagnostics.Process.GetCurrentProcess( ).Close( ); } }
// Constructor: // Initializes a comm for mother builder // Starts the message handling thread for getMessage // Spawns the initialized number of child builders and stores their addresses // Starts the buildRequestDispatcher thread public MotherBuilder(string baseAddress, int port, int numProc) { commObj = new MessagePassing.Comm(baseAddress, port); buildRequestQ = new SWTools.BlockingQueue <CommMessage>(); readyStatusQ = new SWTools.BlockingQueue <string>(); base.messageHandlerThread.Start(); numProcess = numProc; int childPortStart = 8085; updateChildProcPorts(baseAddress, childPortStart, numProc); spawnProcess(childProcessAddr, numProcess); messageHandlerThread = new Thread(buildRequestDispatcher); messageHandlerThread.Start(); }
// bool flag to indicate whether to span child thread // or carry out processing by the main thread itself. public Client(bool flag) { "Creating a new instance of Client".title(); if (inQ_ == null) { inQ_ = new SWTools.BlockingQueue <Message>(); } // CreateClientRecvChannel(clientUrl); // call the above function only after creating an object // of client as the child thread might throw an exception. // Console.Write("\n Created new client Service to accept http connections"); // Create a child thread , run in background for processing Messages if (flag == true) { ClientReadThrd = new Thread(ThreadProc); ClientReadThrd.IsBackground = true; ClientReadThrd.Start(); } }
public bool execuate(SWTools.BlockingQueue <System.IO.FileStream> q, string LogFolder)//execute the test { TestLogger.TestLogger log = new TestLogger.TestLogger(); try { SWTools.BlockingQueue <TestData> p = new SWTools.BlockingQueue <TestData>(); TestLoader.TestLoader loader = new TestLoader.TestLoader(); //every testrequest should have its own log log.clear(); log.setFolder(LogFolder); processMessages(p, q); loader.loadTest(p, log); return(true); } catch (Exception ex) { log = new TestLogger.TestLogger(); log.writeLine(ex.Message); log.writeLine("error time" + DateTime.Now); return(false); } }
public void Test1() { Console.Write("\n Testing Monitor-Based Blocking Queue"); Console.Write("\n ======================================"); SWTools.BlockingQueue <string> q = new SWTools.BlockingQueue <string>(); int count = 0; Task t = new Task(() => { string msg; while (true) { msg = q.deQ(); Console.Write("\n child thread received {0}", msg); // Assert.True(msg == "msg #" + count.ToString()); count++; if (msg == "quit") { break; } } //Assert.True(count == 21); }); t.Start(); string sendMsg = "msg #"; for (int i = 0; i < 20; ++i) { string temp = sendMsg + i.ToString(); Console.Write("\n main thread sending {0}", temp); q.enQ(temp); } q.enQ("quit"); t.Wait(); Console.Write("\n\n"); }
//Costructor MotherBuilder(int count) { connectWithRepo(); for (int i = 1; i <= count; ++i) { int portNum = portNumber + i; connectWithChild(portNum); } if (ready == null) { ready = new SWTools.BlockingQueue <string>(); } if (testQueue == null) { testQueue = new SWTools.BlockingQueue <string>(); } Thread t = new Thread(() => { while (true) { if (ready.size() != 0 && testQueue.size() != 0) { string port = ready.deQ(); CommMessage csndMsg2 = new CommMessage(CommMessage.MessageType.testRequest); csndMsg2.command = "show"; csndMsg2.author = "Jim Fawcett"; csndMsg2.to = "http://localhost:" + port + "/IPluggableComm"; csndMsg2.from = fromAddr; csndMsg2.body = testQueue.deQ(); c.postMessage(csndMsg2); } } }); t.Start(); recieveMessages(count); }
//----< define send thread processing and start thread >------------- public Sender(string LocalUrl="http://localhost:8081/CommServer") { localUrl = LocalUrl; sendQ = defineSendProcessing(); startSender(); }
//----< defines SendThread and its operations >---------------------- /* * - asynchronous function defines Sender sendThread processing * - creates BlockingQueue<Message> to use inside Sender.sendMessage() * - creates and starts a thread executing that processing * - uses msg.toUrl to find or create a proxy for url destination */ public virtual SWTools.BlockingQueue<Message> defineSendProcessing() { SWTools.BlockingQueue<Message> sendQ = new SWTools.BlockingQueue<Message>(); Action sendAction = () => { ThreadStart sendThreadProc = () => { while (true) { try { Message smsg = sendQ.deQ(); if (smsg.content == "closeSender") { Console.Write("\n send thread quitting\n\n"); break; } if (proxyStore.ContainsKey(smsg.toUrl)) { // proxy already created so use it if(Util.verbose) Console.Write("\n sender sending message to service {0}", smsg.toUrl); proxyStore[smsg.toUrl].sendMessage(smsg); } else { // create new proxy with Connect, save it, and use it if (this.Connect(smsg.toUrl)) // if Connect succeeds it will set proxy and send start msg { if(Util.verbose) Console.Write("\n sender created proxy and sending message {0}", smsg.toUrl); proxyStore[smsg.toUrl] = this.proxy; // save proxy proxy.sendMessage(smsg); } else { sendMsgNotify(String.Format("could not connect to {0}\n",smsg.toUrl)); continue; } } } catch(Exception ex) { sendExceptionNotify(ex); continue; } } }; Thread t = new Thread(sendThreadProc); // start the sendThread t.IsBackground = true; t.Start(); }; this.setAction(sendAction); return sendQ; }
//----< defines SendThread and its operations >---------------------- /* * - asynchronous function defines Sender sendThread processing * - creates BlockingQueue<Message> to use inside Sender.sendMessage() * - creates and starts a thread executing that processing * - uses msg.toUrl to find or create a proxy for url destination */ public virtual SWTools.BlockingQueue<Message> defineSendProcessing() { SWTools.BlockingQueue<Message> sendQ = new SWTools.BlockingQueue<Message>(); Action sendAction = () => { ThreadStart sendThreadProc = SendThreadMake(sendQ); Thread t = new Thread(sendThreadProc); // start the sendThread t.IsBackground = true; t.Start(); }; this.setAction(sendAction); return sendQ; }
//----< define send thread processing and start thread >------------- public Sender(string LocalUrl = "http://localhost:8081/CommServer") { localUrl = LocalUrl; sendQ = defineSendProcessing(); startSender(); }