core/src/main/java/eu/darken/rxshell/cmd/RxCmdShell.java
/**
     * Calling this repeatedly will keep returning the same {@link Session} while it is alive.
     * <p> Session creation may be blocking for longer durations, e.g. if the user is shown a root access prompt.
     *
     * @return a {@link Single} that when subscribed to creates a new session.
     */
Calling this repeatedly will keep returning the same  Session while it is alive.
 Session creation may be blocking for longer durations, e.g. if the user is shown a root access prompt.

@return a  Single that when subscribed to creates a new session.
Calling this repeatedly will keep returning the same Session while it is alive . Session creation may be blocking for longer durations e . g . if the user is shown a root access prompt . @return a Single that when subscribed to creates a new session .
public synchronized Single<Session> open() {
        if (RXSDebug.isDebug()) Timber.tag(TAG).v("open()");
        if (session == null) {
            session = Single
                    .create((SingleOnSubscribe<Session>) emitter -> rxShell.open().subscribe(new SingleObserver<RxShell.Session>() {
                        @Override
                        public void onSubscribe(Disposable d) {
                        }
                        @Override
                        public void onSuccess(RxShell.Session shellSession) {
                            try {
                                final Iterator<Map.Entry<String, String>> envIterator = environment.entrySet().iterator();
                                while (envIterator.hasNext()) {
                                    final Map.Entry<String, String> entry = envIterator.next();
                                    shellSession.writeLine(entry.getKey() + "=" + entry.getValue(), !envIterator.hasNext());
                                }
                            } catch (IOException e) {
                                emitter.tryOnError(e);
                                return;
                            }
                            CmdProcessor cmdProcessor = processorFactory.create();
                            cmdProcessor.attach(shellSession);
                            final Session cmdShellSession = new Session(shellSession, cmdProcessor);
                            emitter.onSuccess(cmdShellSession);
                        }
                        @Override
                        public void onError(Throwable e) {
                            Timber.tag(TAG).w("Failed to open RxShell session!");
                            synchronized (RxCmdShell.this) {
                                session = null;
                            }
                            emitter.tryOnError(e);
                        }
                    }))
                    .subscribeOn(Schedulers.io())
                    .doOnSuccess(s -> {
                        if (RXSDebug.isDebug()) Timber.tag(TAG).v("open():doOnSuccess %s", s);
                        s.waitFor().subscribe(integer -> {
                            synchronized (RxCmdShell.this) {
                                session = null;
                            }
                        }, e -> Timber.tag(TAG).w(e, "Error resetting session."));
                    })
                    .doOnError(t -> {if (RXSDebug.isDebug()) Timber.tag(TAG).v(t, "open():doOnError");})
                    .cache();
        }
        return session;
    }
public synchronized Single < Session > open ( ) { if ( RXSDebug . isDebug ( ) ) Timber . tag ( TAG ) . v ( "open()" ) ; if ( session == null ) { session = Single . create ( ( SingleOnSubscribe < Session > ) emitter -> rxShell . open ( ) . subscribe ( new SingleObserver < RxShell . Session > ( ) { @ Override public void onSubscribe ( Disposable d ) { } @ Override public void onSuccess ( RxShell . Session shellSession ) { try { final Iterator < Map . Entry < String , String > > envIterator = environment . entrySet ( ) . iterator ( ) ; while ( envIterator . hasNext ( ) ) { final Map . Entry < String , String > entry = envIterator . next ( ) ; shellSession . writeLine ( entry . getKey ( ) + "=" + entry . getValue ( ) , ! envIterator . hasNext ( ) ) ; } } catch ( IOException e ) { emitter . tryOnError ( e ) ; return ; } CmdProcessor cmdProcessor = processorFactory . create ( ) ; cmdProcessor . attach ( shellSession ) ; final Session cmdShellSession = new Session ( shellSession , cmdProcessor ) ; emitter . onSuccess ( cmdShellSession ) ; } @ Override public void onError ( Throwable e ) { Timber . tag ( TAG ) . w ( "Failed to open RxShell session!" ) ; synchronized ( RxCmdShell . this ) { session = null ; } emitter . tryOnError ( e ) ; } } ) ) . subscribeOn ( Schedulers . io ( ) ) . doOnSuccess ( s -> { if ( RXSDebug . isDebug ( ) ) Timber . tag ( TAG ) . v ( "open():doOnSuccess %s" , s ) ; s . waitFor ( ) . subscribe ( integer -> { synchronized ( RxCmdShell . this ) { session = null ; } } , e -> Timber . tag ( TAG ) . w ( e , "Error resetting session." ) ) ; } ) . doOnError ( t -> { if ( RXSDebug . isDebug ( ) ) Timber . tag ( TAG ) . v ( t , "open():doOnError" ) ; } ) . cache ( ) ; } return session ; }
Calling this repeatedly will keep returning the same {@link Session} while it is alive.
Calling this repeatedly will keep returning the same { @link Session } while it is alive .