use of org.apache.felix.gogo.jline.Shell in project felix by apache.
the class Telnet method start.
private void start(CommandSession session) throws IOException {
ConnectionManager connectionManager = new ConnectionManager(1000, 5 * 60 * 1000, 5 * 60 * 1000, 60 * 1000, null, null, false) {
@Override
protected Connection createConnection(ThreadGroup threadGroup, ConnectionData newCD) {
return new Connection(threadGroup, newCD) {
TelnetIO telnetIO;
@Override
protected void doRun() throws Exception {
telnetIO = new TelnetIO();
telnetIO.setConnection(this);
telnetIO.initIO();
InputStream in = new InputStream() {
@Override
public int read() throws IOException {
return telnetIO.read();
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
int r = read();
if (r >= 0) {
b[off] = (byte) r;
return 1;
} else {
return -1;
}
}
};
PrintStream out = new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
telnetIO.write(b);
}
@Override
public void flush() throws IOException {
telnetIO.flush();
}
});
Terminal terminal = TerminalBuilder.builder().type(getConnectionData().getNegotiatedTerminalType().toLowerCase()).streams(in, out).system(false).name("telnet").build();
terminal.setSize(new Size(getConnectionData().getTerminalColumns(), getConnectionData().getTerminalRows()));
terminal.setAttributes(Shell.getTerminal(session).getAttributes());
addConnectionListener(new ConnectionListener() {
@Override
public void connectionIdle(ConnectionEvent ce) {
}
@Override
public void connectionTimedOut(ConnectionEvent ce) {
}
@Override
public void connectionLogoutRequest(ConnectionEvent ce) {
}
@Override
public void connectionSentBreak(ConnectionEvent ce) {
}
@Override
public void connectionTerminalGeometryChanged(ConnectionEvent ce) {
terminal.setSize(new Size(getConnectionData().getTerminalColumns(), getConnectionData().getTerminalRows()));
terminal.raise(Signal.WINCH);
}
});
PrintStream pout = new PrintStream(terminal.output());
CommandSession session = processor.createSession(terminal.input(), pout, pout);
session.put(Shell.VAR_TERMINAL, terminal);
Context context = new Context() {
@Override
public String getProperty(String name) {
return System.getProperty(name);
}
@Override
public void exit() throws Exception {
close();
}
};
new Shell(context, processor).gosh(session, new String[] { "--login" });
}
@Override
protected void doClose() throws Exception {
telnetIO.closeOutput();
telnetIO.closeInput();
}
};
}
};
portListener = new PortListener("gogo", port, 10);
portListener.setConnectionManager(connectionManager);
portListener.start();
}
Aggregations