001    package org.crsh.shell.impl.remoting;
002    
003    import org.crsh.shell.ShellProcess;
004    import org.crsh.shell.ShellProcessContext;
005    
006    /** @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> */
007    public class ServerProcess implements ShellProcess {
008    
009      /** . */
010      final ServerAutomaton server;
011    
012      /** . */
013      final String line;
014    
015      /** . */
016      private int status;
017    
018      ServerProcess(ServerAutomaton server, String line) {
019        this.server = server;
020        this.line = line;
021        this.status = 0;
022      }
023    
024      public void execute(ShellProcessContext processContext) throws IllegalStateException {
025        if (status != 0) {
026          throw new IllegalStateException();
027        }
028        status = 1;
029        try {
030          server.execute(this, processContext);
031        }
032        finally {
033          status = 2;
034        }
035      }
036    
037      public void cancel() {
038        switch (status) {
039          case 0:
040            throw new IllegalStateException();
041          case 1:
042            server.cancel(this);
043            break;
044        }
045      }
046    }