public bool Initialize(string strProcessNodeName, int iPortNumber) { try { TcpChannel tcpChannel = new TcpChannel(); ChannelServices.RegisterChannel(tcpChannel, true); } catch (System.Runtime.Remoting.RemotingException) { // We have already registered a channel } catch (Exception) { // Other error return(false); } try { m_jobAgent = Activator.GetObject( typeof(IJobAgent), "tcp://" + strProcessNodeName + ":" + iPortNumber.ToString() + "/GalaxyJobAgent") as IJobAgent; } catch (Exception) { return(false); } return(true); }
public virtual void Run(string[] args) { if (args.Length == 0) { Logger.Fatal(this, "Command Line Instance Name Not Specified"); System.Console.WriteLine("One of the following instance names must be specified:"); foreach (var name in Factory().GetInstanceNames()) { System.Console.WriteLine(name); } } else { Logger.Info(this, string.Format("Command Line Specified Instance Name: {0}", args[0])); IJobAgent jobAgent = Factory().Create(args[0]); Logger.Info(this, "Executing the Job"); jobAgent.Execute(); Logger.Info(this, string.Format("Job Execution Complete: {0}", args[0])); } }
protected override void OnStart(string[] args) { // TODO: Add log entries // Get the configurations List <JobAgentDataDir> dataDirs = new List <JobAgentDataDir>(); int iPortNumber = Int32.Parse(ConfigurationManager.AppSettings["Port"]); int iMaxConcurrentJobCount = Int32.Parse(ConfigurationManager.AppSettings["MaxJobCount"]); int iMaximumJobIdleTime = Int32.Parse(ConfigurationManager.AppSettings["MaximumJobIdleTime"]); int iDataDirCount = Int32.Parse(ConfigurationManager.AppSettings["DataDirCount"]); for (int i = 1; i <= iDataDirCount; i++) { JobAgentDataDir dataDir = new JobAgentDataDir(); dataDir.DataDirName = ConfigurationManager.AppSettings["DataDir" + i.ToString()]; dataDir.DataDirShareName = ConfigurationManager.AppSettings["DataDirShareName" + i.ToString()]; dataDirs.Add(dataDir); } // Register the channel try { BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider(); IDictionary props = new Hashtable(); props["port"] = iPortNumber; TcpChannel tcpChannel = new TcpChannel(props, clientProv, serverProv); ChannelServices.RegisterChannel(tcpChannel, true); } catch (RemotingException) { // Console.WriteLine("The channel tcp:" + iPortNumber.ToString() + " is already existed!"); return; } catch (System.Net.Sockets.SocketException) { // Console.WriteLine("The port number:" + iPortNumber + " is busy!"); return; } catch (Exception) { // Console.WriteLine("Error occurs when registering the channel!"); return; } // Register the remote object try { RemotingConfiguration.RegisterWellKnownServiceType( Type.GetType("Galaxy.ProcessNode.JobStatusManager, RemoteImpLib"), "GalaxyJobStatusManager", WellKnownObjectMode.Singleton); RemotingConfiguration.RegisterWellKnownServiceType( Type.GetType("Galaxy.ProcessNode.JobAgent, RemoteImpLib"), "GalaxyJobAgent", WellKnownObjectMode.Singleton); } catch (Exception) { // Console.WriteLine("Error occurs when registering the remote object!"); return; } // Run the job agent IJobAgent jobAgent = Activator.GetObject( typeof(IJobAgent), "tcp://localhost:" + iPortNumber.ToString() + "/GalaxyJobAgent") as IJobAgent; jobAgent.MaximumJobIdleTime = iMaximumJobIdleTime; JobAgentRunHandler jobAgentRun = new JobAgentRunHandler(jobAgent.Run); jobAgentRun.BeginInvoke(iPortNumber, dataDirs, iMaxConcurrentJobCount, null, null); }
static void Main(string[] args) { // TODO Guomao: Read the port from the configuration file if (args.Length != 8) { Console.WriteLine("ProcessNode.exe -port xxx -datadir xxx -datadirsharename xxx -jobcount xxx"); return; } if (args[0].ToLower().CompareTo("-port") != 0) { Console.WriteLine("ProcessNode.exe -port xxx -datadir xxx -datadirsharename xxx -jobcount xxx"); return; } int iPortNumber = Int32.Parse(args[1]); if (args[2].ToLower().CompareTo("-datadir") != 0) { Console.WriteLine("ProcessNode.exe -port xxx -datadir xxx -datadirsharename xxx -jobcount xxx"); return; } string strDataRootDir = args[3]; if (args[4].ToLower().CompareTo("-datadirsharename") != 0) { Console.WriteLine("ProcessNode.exe -port xxx -datadir xxx -datadirsharename xxx -jobcount xxx"); return; } string strDataRootDirShareName = args[5]; if (args[6].ToLower().CompareTo("-jobcount") != 0) { Console.WriteLine("ProcessNode.exe -port xxx -datadir xxx -datadirsharename xxx -jobcount xxx"); return; } int iMaxConcurrentJobCount = Int32.Parse(args[7]); // Register the channel try { BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider(); IDictionary props = new Hashtable(); props["port"] = iPortNumber; TcpChannel tcpChannel = new TcpChannel(props, clientProv, serverProv); ChannelServices.RegisterChannel(tcpChannel, true); } catch (RemotingException) { Console.WriteLine("The channel tcp:" + iPortNumber.ToString() + " is already existed!"); return; } catch (System.Net.Sockets.SocketException) { Console.WriteLine("The port number:" + iPortNumber + " is busy!"); return; } catch (Exception) { Console.WriteLine("Error occurs when registering the channel!"); return; } // Register the remote object try { RemotingConfiguration.RegisterWellKnownServiceType( Type.GetType("Galaxy.ProcessNode.JobStatusManager, RemoteImpLib"), "GalaxyJobStatusManager", WellKnownObjectMode.Singleton); RemotingConfiguration.RegisterWellKnownServiceType( Type.GetType("Galaxy.ProcessNode.JobAgent, RemoteImpLib"), "GalaxyJobAgent", WellKnownObjectMode.Singleton); } catch (Exception) { Console.WriteLine("Error occurs when registering the remote object!"); return; } // Run the job agent List <JobAgentDataDir> dataDirs = new List <JobAgentDataDir>(); JobAgentDataDir dataDir = new JobAgentDataDir(); dataDir.DataDirName = strDataRootDir; dataDir.DataDirShareName = strDataRootDirShareName; dataDirs.Add(dataDir); IJobAgent jobAgent = Activator.GetObject( typeof(IJobAgent), "tcp://localhost:" + iPortNumber.ToString() + "/GalaxyJobAgent") as IJobAgent; jobAgent.MaximumJobIdleTime = 2; if (jobAgent.Run(iPortNumber, dataDirs, iMaxConcurrentJobCount) != 0) { Console.WriteLine("Process node instance run error!"); } }
public JobAgentHelper() { m_jobAgent = null; }