diff --git a/src/net/KNet/KNetCore.cs b/src/net/KNet/KNetCore.cs index b5ed8a5cb7..f452400aa3 100644 --- a/src/net/KNet/KNetCore.cs +++ b/src/net/KNet/KNetCore.cs @@ -21,6 +21,8 @@ using System.Collections.Generic; using System.IO; using MASES.JNet; +using MASES.JCOBridge.C2JBridge; +using System.Linq; namespace MASES.KNet { @@ -303,6 +305,67 @@ protected override IList PathToParse } } + /// + /// Launch the class with the arguments + /// + /// A type which is defined as Main-Class + /// The arguments of the main method + public static new void Launch(params string[] args) + where TClass : IJVMBridgeMain + { + Launch(typeof(TClass), args); + } + + /// + /// Launch the with the arguments + /// + /// The extending + /// The arguments of the main method + public static new void Launch(Type type, params string[] args) + { + if (type == null) throw new ArgumentNullException(nameof(type)); + + try + { + JNetCore.Launch(type, args); + } + catch (ArgumentException) + { + if (type.GetInterface(typeof(IJVMBridgeMain).Name) == null) throw; + var execType = type; + do + { + if (args.Length == 0) + { + System.Reflection.MethodInfo method = execType.GetMethods().FirstOrDefault(method => method.Name == "SExecute" & method.GetParameters().Length == 2 & method.IsGenericMethod == false); + if (method != null) + { + method.Invoke(null, new object[] { "main", new object[] { args } }); + return; + } + } + else + { + System.Reflection.MethodInfo method = execType.GetMethod("Main", new Type[] { typeof(Java.Lang.String[]) }); + if (method != null) + { + Java.Lang.String[] strings = new Java.Lang.String[args.Length]; + for (int i = 0; i < args.Length; i++) + { + strings[i] = args[i]; + } + method.Invoke(null, new object[] { strings }); + } + return; + } + execType = execType.BaseType; + } + while (execType != null && execType != typeof(object)); + + } + throw new ArgumentException($"{type} does not define any IJVMBridgeMain type or interface", "type"); + } + #if DEBUG /// public override bool EnableDebug => true; diff --git a/src/net/KNetConnect/Program.cs b/src/net/KNetConnect/Program.cs index 04c392483a..9bb6986372 100644 --- a/src/net/KNetConnect/Program.cs +++ b/src/net/KNetConnect/Program.cs @@ -79,7 +79,7 @@ static void ShowHelp(string errorString = null) var assembly = typeof(Program).Assembly; Console.WriteLine("KNetConnect - KNet Connect command line interface - Version " + assembly.GetName().Version.ToString()); - Console.WriteLine(assembly.GetName().Name + " -[d|s] connect-standalone.properties [-KafkaLocation kafkaFolder] "); + Console.WriteLine(assembly.GetName().Name + " -[d|s] [-k] connect-standalone.properties [-KafkaLocation kafkaFolder] "); Console.WriteLine(); if (!string.IsNullOrEmpty(errorString)) { @@ -88,6 +88,7 @@ static void ShowHelp(string errorString = null) Console.WriteLine("s: start Connect in standalone mode. "); Console.WriteLine("d: start Connect in distributed mode. "); + Console.WriteLine("k: start Connect in distributed/standalone mode using KNet version. "); Console.WriteLine("KafkaLocation: The folder where Kafka package is available. Default consider this application uses the package jars folder."); Console.WriteLine("ScalaVersion: the scala version to be used. The default version (2.13.6) is binded to the deafult Apache Kafka version available in the package."); Console.WriteLine("Log4JConfiguration: the log4j configuration file; the default uses the file within the package."); @@ -95,7 +96,8 @@ static void ShowHelp(string errorString = null) Console.WriteLine("ClassArguments: the arguments of the class. Depends on the ClassToRun value, to obtain them runs the application or look at Apache Kafka documentation."); Console.WriteLine(); Console.WriteLine("Examples:"); - Console.WriteLine(assembly.GetName().Name + " -ClassToRun ConsoleConsumer --bootstrap-server SERVER-ADDRESS:9093 --topic topic_name --from-beginning"); + Console.WriteLine(assembly.GetName().Name + " -s connect-standalone.properties specific-connector.properties"); + Console.WriteLine(assembly.GetName().Name + " -d connect-distributed.properties"); } } } \ No newline at end of file diff --git a/src/net/KNetPS/Cmdlet/KafkaClassToRunCmdletCommandBase.cs b/src/net/KNetPS/Cmdlet/KafkaClassToRunCmdletCommandBase.cs index 2a14a62f88..d851177f95 100644 --- a/src/net/KNetPS/Cmdlet/KafkaClassToRunCmdletCommandBase.cs +++ b/src/net/KNetPS/Cmdlet/KafkaClassToRunCmdletCommandBase.cs @@ -50,7 +50,7 @@ protected override void OnAfterCreateGlobalInstance() try { - JNetPSHelper.Launch(KNetPSCore.MainClassToRun, arguments); + KNetPSHelper.Launch(KNetPSCore.MainClassToRun, arguments); } catch (TargetInvocationException tie) { diff --git a/src/net/KNetPS/KNetPSHelper.cs b/src/net/KNetPS/KNetPSHelper.cs index 6dbc3bc0ca..59821bcb8a 100644 --- a/src/net/KNetPS/KNetPSHelper.cs +++ b/src/net/KNetPS/KNetPSHelper.cs @@ -37,5 +37,10 @@ public static class KNetPSHelper where TClass : KNetCore public static void SetScalaVersion(string scalaVersion) { JNetPSHelper.Set(typeof(KNetCore<>), nameof(KNetPSCore.ApplicationScalaVersion), scalaVersion); } public static void SetDisableJMX(bool? disableJMX) { JNetPSHelper.Set(typeof(KNetCore<>), nameof(KNetPSCore.ApplicationDisableJMX), disableJMX); } + + public static void Launch(System.Type type, params string[] args) + { + typeof(TClass).RunStaticMethodOn(typeof(KNetCore), "Launch", type, args); + } } } \ No newline at end of file