2121
2222import org .apache .commons .logging .Log ;
2323import org .apache .commons .logging .LogFactory ;
24+ import org .apache .log4j .Level ;
25+ import org .apache .log4j .Logger ;
2426import org .apache .sysds .api .jmlc .Connection ;
2527
28+ import py4j .DefaultGatewayServerListener ;
2629import py4j .GatewayServer ;
27- import py4j .GatewayServerListener ;
2830import py4j .Py4JNetworkException ;
29- import py4j . Py4JServerConnection ;
31+
3032
3133public class PythonDMLScript {
3234
3335 private static final Log LOG = LogFactory .getLog (PythonDMLScript .class .getName ());
3436 final private Connection _connection ;
37+ public static GatewayServer GwS ;
3538
3639 /**
3740 * Entry point for Python API.
@@ -42,7 +45,7 @@ public class PythonDMLScript {
4245 public static void main (String [] args ) throws Exception {
4346 final DMLOptions dmlOptions = DMLOptions .parseCLArguments (args );
4447 DMLScript .loadConfiguration (dmlOptions .configFile );
45- final GatewayServer GwS = new GatewayServer (new PythonDMLScript (), dmlOptions .pythonPort );
48+ GwS = new GatewayServer (new PythonDMLScript (), dmlOptions .pythonPort );
4649 GwS .addListener (new DMLGateWayListener ());
4750 try {
4851 GwS .start ();
@@ -67,38 +70,20 @@ private PythonDMLScript() {
6770 _connection = new Connection ();
6871 }
6972
73+ public static void setDMLGateWayListenerLoggerLevel (Level l ){
74+ Logger .getLogger (DMLGateWayListener .class ).setLevel (l );
75+ }
76+
7077 public Connection getConnection () {
7178 return _connection ;
7279 }
7380
74- protected static class DMLGateWayListener implements GatewayServerListener {
81+ protected static class DMLGateWayListener extends DefaultGatewayServerListener {
7582 private static final Log LOG = LogFactory .getLog (DMLGateWayListener .class .getName ());
7683
77- @ Override
78- public void connectionError (Exception e ) {
79- LOG .warn ("Connection error: " + e .getMessage ());
80- System .exit (1 );
81- }
82-
83- @ Override
84- public void connectionStarted (Py4JServerConnection gatewayConnection ) {
85- LOG .debug ("Connection Started: " + gatewayConnection .toString ());
86- }
87-
88- @ Override
89- public void connectionStopped (Py4JServerConnection gatewayConnection ) {
90- LOG .debug ("Connection stopped: " + gatewayConnection .toString ());
91- }
92-
93- @ Override
94- public void serverError (Exception e ) {
95- LOG .error ("Server Error " + e .getMessage ());
96- }
97-
9884 @ Override
9985 public void serverPostShutdown () {
10086 LOG .info ("Shutdown done" );
101- System .exit (0 );
10287 }
10388
10489 @ Override
@@ -108,13 +93,12 @@ public void serverPreShutdown() {
10893
10994 @ Override
11095 public void serverStarted () {
111- LOG .info ("GatewayServer Started " );
96+ LOG .info ("GatewayServer started " );
11297 }
11398
11499 @ Override
115100 public void serverStopped () {
116- LOG .info ("GatewayServer Stopped" );
117- System .exit (0 );
101+ LOG .info ("GatewayServer stopped" );
118102 }
119103 }
120104
0 commit comments