Package org.tanukisoftware.wrapper

Examples of org.tanukisoftware.wrapper.WrapperProcessConfig


                                    String input = command.substring(5);
                                    System.out.println( getRes().getString( "Starting a simple application: " ) + input );
                                  
                                    if ( input != null && input.length() > 0 )
                                    {
                                        WrapperManager.exec( input, new WrapperProcessConfig().setDetached( false ) );
                                        System.out.println( getRes().getString( "Successfully executed!") );
                                    }
                                }
                                catch ( SecurityException e )
                                {
View Full Code Here


            {
                public void run()
                {
                    try
                    {
                        WrapperProcessConfig wpConfig = new WrapperProcessConfig();
                        wpConfig.setDetached( m_childDetached );
                        final WrapperProcess wProcess = WrapperManager.exec( m_childCommand, wpConfig );
                        System.out.println( Main.getRes().getString( "Launched child process with PID={0} : {1}", new Integer( wProcess.getPID() ), m_childCommand ) );
                       
                        Thread outRunner = new Thread()
                        {
View Full Code Here

                    WrapperProcess proc;
                    System.out.println( i + Main.getRes().getString( " first, try to vfork..." ) );
                    if ( WrapperProcessConfig.isSupported( WrapperProcessConfig.VFORK_EXEC ) )
                    {
                        System.out.println( i + Main.getRes().getString( " vfork is supported" ) );
                        proc = WrapperManager.exec( "../test/simplewaiter " + ( rand.nextInt( 200 ) + 1 ) + " " + rand.nextInt( 30 ), new WrapperProcessConfig().setStartType(WrapperProcessConfig.VFORK_EXEC) );                     
                    }
                    else
                    {
                        System.out.println( i + Main.getRes().getString( " vfork is not supported" ) );
                        proc = WrapperManager.exec( "../test/simplewaiter " + ( rand.nextInt( 200 ) + 1 ) + " " + rand.nextInt( 30 ) );
                    }
                   
                    System.out.println( i + Main.getRes().getString( " longrunning child process {0} is alive {1}" , new Object[]{ new Integer( proc.getPID() ), new Boolean( proc.isAlive() ) } ) );
                    // System.out.println( i + " process ( PID= " + proc.getPID() + " ) finished with code " + proc.waitFor() );
                }
                catch ( IOException e )
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;

            case 3:
                try
                {
                    System.out.println( i + Main.getRes().getString( " spawn a small child process..." ) );
                    WrapperProcess p;
                    if ( WrapperProcessConfig.isSupported( WrapperProcessConfig.POSIX_SPAWN ) )
                    {
                        System.out.println( i + Main.getRes().getString( " posix_spawn is supported." ) );
                        p = WrapperManager.exec( "../test/simplewaiter 0 15", new WrapperProcessConfig().setStartType(WrapperProcessConfig.POSIX_SPAWN) );
                    }
                    else
                    {
                        System.out.println( i + Main.getRes().getString( " spawn is not supported." ) );
                        p = WrapperManager.exec( "../test/simplewaiter 0 15" );
                    }
                    // System.out.println(i + " " + p.toString() + " exit " + p.waitFor());
                    BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
                    try
                    {
                        String line = "";
                        while ( ( line = br.readLine() ) != null )
                        {
                            System.out.println( i + " out..:" +  line );
                        }
                    }
                    finally
                    {
                        br.close();
                    }
                }
                catch ( Exception e )
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;

            case 4:
                System.out.println( i + Main.getRes().getString( " start a small child process, change the environment and read output..." ) );
                try
                {
                    WrapperProcessConfig wpm = new WrapperProcessConfig();
                    java.util.Map environment = wpm.getEnvironment();
                    System.out.println( i + Main.getRes().getString( " size of Environment map (before calling clear()) = " ) + environment.size() );
                    environment.clear();
                    environment.put( "TEST", "TEST123" );
                    System.out.println( i + Main.getRes().getString( " size of Environment map = " ) + environment.size() );
                    WrapperProcess proc = WrapperManager.exec( "../test/simplewaiter "+ rand.nextInt(200) +" 3", wpm );
                    proc.getOutputStream().close();

                    System.out.println( i + Main.getRes().getString( " small child process {0} is alive {1}" , new Object[]{ new Integer( proc.getPID() ), new Boolean( proc.isAlive() ) } ) );
                    BufferedReader br = new BufferedReader( new InputStreamReader( proc.getInputStream() ) );
                    try
                    {
                        String line = "";
                        while ( ( line = br.readLine() ) != null )
                        {
                            System.out.println( i + " out..:" +  line );
                        }
                    }
                    finally
                    {
                        br.close();
                    }

                    br = new BufferedReader( new InputStreamReader( proc.getErrorStream() ) );
                    try
                    {
                        String line = "";
                        while ((line = br.readLine()) != null )
                        {
                            System.out.println( line );
                        }
                    }
                    finally
                    {
                        br.close();
                    }
                }
                catch ( IOException e )
                {
                  
                    e.printStackTrace();
                }
                break;
            case 5:
                System.out.println( i + Main.getRes().getString( " start longrunning child process, change working dir, call waitFor and finally read output..." ) );
                try
                {
                    WrapperProcessConfig wpm = new WrapperProcessConfig();
                    if ( WrapperProcessConfig.isSupported( WrapperProcessConfig.FORK_EXEC ) || WrapperProcessConfig.isSupported( WrapperProcessConfig.VFORK_EXEC ) )
                    {
                        wpm.setStartType( WrapperProcessConfig.isSupported( WrapperProcessConfig.FORK_EXEC ) ? WrapperProcessConfig.FORK_EXEC : WrapperProcessConfig.VFORK_EXEC );
                        System.out.println( i + Main.getRes().getString( " changing the working directory is supported" ) );
                        wpm.setWorkingDirectory( new File("..") );
                    }
                    else
                    {
                        System.out.println( i + Main.getRes().getString( " changing the working directory is not supported" ) );
                    }
                    WrapperProcess proc;
                    try
                    {
                        System.out.println( i + Main.getRes().getString( " try to call dir" ) );
                        proc = WrapperManager.exec( "cmd.exe /c dir", wpm );
                    }
                    catch ( IOException e )
                    {
                        System.out.println( i + Main.getRes().getString" dir failed. most likely we are not on Windows, try ls -l before giving up." ) );
                        proc = WrapperManager.exec( "ls -l", wpm );
                    }

                    System.out.println( i + " PID = " + proc.getPID() );
                    System.out.println( i + Main.getRes().getString( " child process (PID= {0}) finished with code " , new Integer( proc.getPID() ) ) +  proc.waitFor() );

                    System.out.println( i + Main.getRes().getString( " now read the output" ) );
                    BufferedReader br = new BufferedReader( new InputStreamReader( proc.getInputStream() ) );
                    try
                    {
                        String line = "";
                        while ( ( line = br.readLine() ) != null )
                        {
                            System.out.println( i + " out..:" + line );
                        }
                    }
                    finally
                    {
                        br.close();
                    }
                }
                catch ( InterruptedException e )
                {
                    e.printStackTrace();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                break;

            case 6:
                try
                {
                    System.out.println( i + Main.getRes().getString( " start a small child process by Runtime.exec and put a wrapperexec in between.." ) );
                    Process p = Runtime.getRuntime().exec( "../test/simplewaiter " + ( rand.nextInt( 200 ) + 1 ) + " " + ( rand.nextInt( 20 ) + 1 ));
                   
                    WrapperProcess proc = WrapperManager.exec( "../test/simplewaiter 4 4" );
                    proc.getOutputStream().close();
                    System.out.println( i + Main.getRes().getString( " small child process {0} is alive {1}" , new Object[]{ new Integer( proc.getPID() ), new Boolean( proc.isAlive() ) } ) );
                    // System.out.println(i + " Main.getRes (PID= " + proc.getPID() + " ) finished with code " + proc.waitFor() );
                    BufferedReader br = new BufferedReader( new InputStreamReader( proc.getInputStream() ) );
                    try
                    {
                        String line = "";
                        while ((line = br.readLine()) != null )
                        {
                            System.out.println( i + " out..:" + line );
                        }
                    }
                    finally
                    {
                        br.close();
                    }

                    System.out.println( i + " " + p.toString() + Main.getRes().getString( " Runtime.exec exit " ) + p.waitFor() );
                }
                catch ( IOException e )
                {
                    e.printStackTrace();
                }
                catch ( InterruptedException e )
                {
                    e.printStackTrace();
                }
                break;

            case 7:
                System.out.println( i + Main.getRes().getString" start invalid child process..." ) );
                try
                {
                    WrapperProcess proc = WrapperManager.exec( "invalid" );
                    System.out.println( i + Main.getRes().getString( " invalid child process is alive "  )+ proc.isAlive() );
                }
                catch ( IOException e )
                {
                    System.out.println( i + Main.getRes().getString( " caught an invalid child process..." ) );
                }
                break;
            }
        }
        try {
            System.out.println( Main.getRes().getString( "finally start a long-running child process attached to the wrapper, the wrapper will shut down soon, so the child process should get killed by the wrapper..." ) );
            WrapperProcess p = WrapperManager.exec( "../test/simplewaiter 2 1000" , new WrapperProcessConfig().setDetached(false));
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NullPointerException e) {
            // TODO Auto-generated catch block
View Full Code Here

TOP

Related Classes of org.tanukisoftware.wrapper.WrapperProcessConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.