public ThreadInfo() { _innerThread = new GThread(new ThreadParameter(), ThreadPriorityLevel.Idle); _innerThread.Start(); Id = _innerThread.Id; }
public void Start() { InitThreadObj(); if (workerThread != null) { workerThread.Start(); } }
public BaseListener(IPAddress address, int port, BaseListener.ClientArrivedHandler handler) { _port = port; ClientArrived += handler; _tcpListener = new TcpListener(address, _port); _tcpListener.Start(); _acceptorThread = new GThread(new ThreadStart(_acceptorloop), "Acceptor Loop", true); _acceptorThread.Start(); }
public void Init(Stream inStream, Stream outStream, int maxPackSize = 2048) { _inStream = inStream; _outStream = outStream; _isActive = true; MaxPackSize = maxPackSize; _readerThread = new GThread(new System.Threading.ThreadStart(_readerloop), "Reader-Tread for " + this.ToString(), true); _readerThread.Thread.IsBackground = true; _readerThread.Start(); }
public BaseListener(int port, BaseListener.ClientArrivedHandler handler = null) { _port = port; if (handler != null) { ClientArrived += handler; } _tcpListener = new TcpListener(_port); _tcpListener.Start(); _acceptorThread = new GThread(new ThreadStart(_acceptorloop), "Acceptor Loop", true); _acceptorThread.Start(); }
public GSocketListener(int port, GSocketListener.ClientArrivedHandler handler, bool setReuseAddress = true) { _port = port; ClientArrived += handler; _tcpListener = new TcpListener(_port); if (setReuseAddress) { _tcpListener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); } _tcpListener.Start(); _acceptorThread = new GThread(new ThreadStart(_acceptorloop), "Acceptor Loop", true); _acceptorThread.Start(); }
/// <summary> /// Executes a grid thread in its own Application Domain on the executor node. /// Returns the gridThread as a serialized byte array after execution. This byte array includes the results of execution of the GThread. /// </summary> /// <param name="thread">A byte array representing a serialized gridThread to be executed.</param> /// <returns>A byte array representing a serialized gridThread, after the execution is complete.</returns> public byte[] ExecuteThread(byte[] thread) { // ([email protected]): this should be revised - there is no log listener in this app domain so these logs do not go anywhere //kna: Since this method is actually //called on a different AppDomain, //we can catch exceptions in the caller //since cross-appdomain calls use remoting. //so the exception would be passed back! :) GThread gridThread = (GThread)Utils.DeserializeFromByteArray(thread); logger.Debug("Executor running GThread: " + gridThread.Id); logger.Debug("Working dir=" + AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); gridThread.SetWorkingDirectory(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); gridThread.SetiBOT(_iBot); gridThread.Start(); gridThread.SetiBOT(null); logger.Debug("GThread " + gridThread.Id + " done. Serializing it to send back to the manager..."); return(Utils.SerializeToByteArray(gridThread)); }
//----------------------------------------------------------------------------------------------- //eduGRID Addition //written by Abhishek kumar dated March 5, 2007 //Reason: Inter process communication is not our concern here //we wish to allow communication bw the Gthread and //and the bot wrapper class that runs on executor node private void ExecuteThread() { byte[] rawThread = null; //this will contain the serialized Gthread logger.Info("Started ExecuteThread..."); try { //note: the above statement means that ibot will be initialized only when it //receives its first thread. this means that the response time for the first query //to this GExector will be high. //TODO: put initialize bot else where .. probably in constructor logger.Info("Bot is initialized."); //Get Thread rawThread = Manager.Executor_GetThread(Credentials, _CurTi); logger.Debug("Got thread from manager. executing it: " + _CurTi.ThreadId); //execute it byte[] thread = new byte[rawThread.Length]; rawThread.CopyTo(thread, 0); GThread gridThread = (GThread)Alchemi.Core.Utility.Utils.DeserializeFromByteArray(thread); logger.Debug("Executor running GThread: " + gridThread.Id); logger.Debug("Working dir=" + AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); gridThread.SetWorkingDirectory(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); //eduGRID main link gridThread.SetiBOT(iBot); gridThread.Start(); logger.Debug("GThread " + gridThread.Id + " done. Serializing it to send back to the manager..."); byte[] finishedThread = Alchemi.Core.Utility.Utils.SerializeToByteArray(gridThread); //set its status to finished Manager.Executor_SetFinishedThread(Credentials, _CurTi, finishedThread, null); logger.Info(string.Format("Finished executing grid thread # {0}.{1}", _CurTi.ApplicationId, _CurTi.ThreadId)); } catch (ThreadAbortException) { if (_CurTi != null) { logger.Warn(string.Format("aborted grid thread # {0}.{1}", _CurTi.ApplicationId, _CurTi.ThreadId)); } else { logger.Warn(string.Format("aborted grid thread # {0}.{1}", null, null)); } Thread.ResetAbort(); } catch (Exception e) { logger.Warn(string.Format("grid thread # {0}.{1} failed ({2})", _CurTi.ApplicationId, _CurTi.ThreadId, e.GetType()), e); try { //some exceptions such as Win32Exception caused problems when passed directly into this method. //so better create another new exception object and send it over. Exception eNew = new Exception(e.ToString()); Manager.Executor_SetFinishedThread(Credentials, _CurTi, rawThread, eNew); } catch (Exception ex1) { if (_CurTi != null) { logger.Warn("Error trying to set failed thread for App: " + _CurTi.ApplicationId + ", thread=" + _CurTi.ThreadId + ". Original Exception = \n" + e.ToString(), ex1); } else { logger.Warn("Error trying to set failed thread: Original exception = " + e.ToString(), ex1); } } } finally { _CurTi = null; _ReadyToExecute.Set(); logger.Info("Exited ExecuteThread..."); } }