Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: mindbright/ssh/SSHChannel.java


1   /******************************************************************************
2    *
3    * Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
4    *                 www.mindbright.se, info@mindbright.se
5    *
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   *****************************************************************************
17   * $Author: nallen $
18   * $Date: 2001/11/12 16:31:16 $
19   * $Name:  $
20   *****************************************************************************/
21  
22  /* Copyright (c) 1999-2001 AppGate AB. All Rights Reserved.
23  
24     This file contains Original Code and/or Modifications of Original Code as defined
25     in and that are subject to the MindTerm Public Source License, Version 1.1, (the 'License').
26     You may not use this file except in compliance with the License.
27     Please obtain a copy of the License at http://www.appgate.com and read it before using this file.
28  
29     This file was modified by Nicholas Allen <nallen@freenet.co.uk> on 01/08/2001 */
30  
31  package mindbright.ssh;
32  
33  public abstract class SSHChannel extends Thread {
34  
35    protected int                channelId;
36    protected SSHChannelListener listener;
37  
38    public SSHChannel(int channelId) {
39      super();
40      this.channelId = channelId;
41      this.listener  = null;
42    }
43  
44    public void setSSHChannelListener(SSHChannelListener listener) {
45      this.listener = listener;
46    }
47  
48    public int getId() {
49      return channelId;
50    }
51  
52    public abstract void serviceLoop() throws Exception;
53  
54    public void close() {
55    }
56  
57    public void run() {
58  
59      /*if(SSH.NETSCAPE_SECURITY_MODEL) {
60        try {
61    netscape.security.PrivilegeManager.enablePrivilege("TerminalEmulator");
62        } catch (netscape.security.ForbiddenTargetException e) {
63    // !!! A pity, we could have done so much fun... :-)
64        }
65       }*/
66  
67      try {
68        serviceLoop();
69      } catch (Exception e) {
70  
71        if(SSH.DEBUGMORE) {
72    System.out.println("--- channel exit (exception is not an error):");
73    e.printStackTrace();
74    System.out.println("---");
75        }
76  
77        close();
78        if(listener != null)
79    listener.close(this);
80  
81      } catch (ThreadDeath death) {
82        SSH.logExtra("Channel killed " + channelId);
83        throw death;
84      }
85    }
86  
87  }