public int getHeight() { if (!closed) { ensureSize(); return client.getHeight(); } else { return -1; } }
public int getWidth() { if (!closed) { ensureSize(); return client.getWidth(); } else { return -1; } }
@Override protected void handle(InputStream in, OutputStream out) throws IOException { this.automaton = new ServerAutomaton(in, out).addCloseListener(this); }
public synchronized void end(ShellResponse response) { // It may have been cancelled concurrently if (client.current == this) { // Flush what we have in buffer first flush(); // Send end message try { client.current = null; client.out.writeObject(new ServerMessage.End(response)); client.out.flush(); } catch (IOException ignore) { // } finally { closed = true; if (response instanceof ShellResponse.Close) { client.close(); } } } } }
public void testPrompt() throws Exception { ClientProcessor t = new ClientProcessor(clientOIS, clientOOS, new BaseShell() { @Override public String getPrompt() { return "foo"; } }); t.start(); // ServerAutomaton server = new ServerAutomaton(serverOOS, serverOIS); assertEquals("foo", server.getPrompt()); // t.interrupt(); assertJoin(t); }
public void testWelcome() throws Exception { ClientProcessor t = new ClientProcessor(clientOIS, clientOOS, new BaseShell() { @Override public String getWelcome() { return "bar"; } }); t.start(); // ServerAutomaton server = new ServerAutomaton(serverOOS, serverOIS); assertEquals("bar", server.getWelcome()); // t.interrupt(); assertJoin(t); }
@Override protected void handle(InputStream in, OutputStream out) throws IOException { this.automaton = new ClientAutomaton(in, out, shell).addCloseListener(this);; }
@Override public void run() { ClientAutomaton client = new ClientAutomaton(out, in, shell); client.run(); } }
public ShellProcess createProcess(String request) throws IllegalStateException { return new ServerProcess(this, request); }
public void cancel() { switch (status) { case 0: throw new IllegalStateException(); case 1: server.cancel(this); break; } } }
public void execute(ShellProcessContext processContext) throws IllegalStateException { if (status != 0) { throw new IllegalStateException(); } status = 1; try { server.execute(this, processContext); } finally { status = 2; } }
void cancel(ServerProcess process) throws IllegalStateException { if (process == this.process) { this.process = null; try { out.writeObject(new ClientMessage.Cancel()); out.flush(); } catch (IOException ignore) { } } } }
public boolean takeAlternateBuffer() { if (!closed) { try { client.out.writeObject(new ServerMessage.UseAlternateBuffer()); client.out.flush(); } catch (Exception e) { // } } // For now we suppose any impl return true; return true; }
public boolean releaseAlternateBuffer() { if (!closed) { try { client.out.writeObject(new ServerMessage.UseMainBuffer()); client.out.flush(); } catch (Exception e) { // } } // For now we suppose any impl return true; return true; }
@Override protected void run() throws Throwable { // If it's not executing then we attempt to end it end(ShellResponse.error(ErrorKind.INTERNAL, "Unexpected process execution error", t)); } }.all();
@Override public Screenable append(char c) throws IOException { return append(Character.toString(c)); }
@Override public Screenable cls() throws IOException { if (!closed) { buffer.add(new ServerMessage.Chunk.Cls()); } return this; }
@Override public Screenable append(CharSequence s) throws IOException { if (!closed) { buffer.add(new ServerMessage.Chunk.Text(s)); } return this; }
@Override public Screenable append(Style style) throws IOException { if (!closed) { buffer.add(new ServerMessage.Chunk.Style(style)); } return this; }
@Override public Screenable append(CharSequence csq, int start, int end) throws IOException { return append(csq.subSequence(start, end)); }