Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010, 2011 SAP AG and others All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Lazar Kirchev, SAP AG - initial API and implementation IBM Corporation - ongoing development /
 
 package org.eclipse.equinox.console.telnet;
 
 
This class manages a telnet connection. It is responsible for wrapping the original io streams from the socket, and starting a CommandSession to execute commands from the telnet.
 
 public class TelnetConnection extends Thread implements Closeable {
 	
 	private Socket socket;
 	private BundleContext context;
 	protected boolean isTelnetNegotiationFinished = false;
     private Callback callback;
     private static final long TIMEOUT = 1000;
     private static final long NEGOTIATION_TIMEOUT = 60000;
     private static final String PROMPT = "prompt";
     private static final String OSGI_PROMPT = "osgi> ";
     private static final String SCOPE = "SCOPE";
     private static final String EQUINOX_SCOPE = "equinox:*";
     private static final String CLOSEABLE = "CLOSEABLE";
 	
 	public TelnetConnection (Socket socketCommandProcessor processorBundleContext context) {
 		this. = socket;
 		this. = processor;
 		this. = context;
 	}
 	
 	public void run() {
 		try {
 			out.autoSend();
 			TelnetInputHandler telnetInputHandler = new TelnetInputHandler(.getInputStream(), inout);
 			telnetInputHandler.start();
 			
 			long start = System.currentTimeMillis();
 			
 			synchronized (this) {
 				while ( == false && System.currentTimeMillis() - start < ) {
 					try {
 					} catch (InterruptedException e) {
 						// do nothing
 					}
 				}
 			}
 			final CommandSession session;
 			PrintStream output = new PrintStream(out);
 			
 			
 	        ConsoleInputHandler consoleInputHandler = new ConsoleInputHandler(ininpout);
 	        consoleInputHandler.getScanner().setBackspace(telnetInputHandler.getScanner().getBackspace());
 	        consoleInputHandler.getScanner().setDel(telnetInputHandler.getScanner().getDel());
 	        consoleInputHandler.getScanner().setCurrentEscapesToKey(telnetInputHandler.getScanner().getCurrentEscapesToKey());
 	        consoleInputHandler.getScanner().setEscapes(telnetInputHandler.getScanner().getEscapes());
 	        ((ConsoleInputScanner)consoleInputHandler.getScanner()).setContext();
 	        
 	        consoleInputHandler.start();
 	        
 	        session = .createSession(inpoutputoutput);
 	        session.put();
 	        session.put();
 	        // Store this closeable object in the session, so that the disconnect command can close it
 	        session.put(this);
 	        ((ConsoleInputScanner)consoleInputHandler.getScanner()).setSession(session);
 	        
 			try {
 	            session.execute("gosh --login --noshutdown");
 	        } catch (Exception e) {
 	            e.printStackTrace();
 	        } finally {
 	            session.close();
 	            try {
	                .close();
	            }
	            catch (IOException e) {
	            	// do nothing
	            }
	        }
catch (IOException e) {
		}
	}
	public void close() {
		try {
			this.interrupt();
catch (IOException e) {
		}
	}
	public synchronized void telnetNegotiationFinished() {
	}
New to GrepCode? Check out our FAQ X