# ConnectionImpl (sshj 0.4.0 API)
Date: 2011-06-06

## net.schmizz.sshj.connection
Class ConnectionImpl

    java.lang.Object
      net.schmizz.sshj.AbstractService
          net.schmizz.sshj.connection.ConnectionImpl

All Implemented Interfaces:
  ErrorNotifiable, SSHPacketHandler, Connection, Service

    public class ConnectionImpl

extends AbstractService
implements Connection

`Connection` implementation.

Nested Class Summary

Nested classes/interfaces inherited from interface net.schmizz.sshj.common.ErrorNotifiable
`ErrorNotifiable.Util`

Field Summary

Fields inherited from class net.schmizz.sshj.AbstractService
`log, name, timeout, trans`

Constructor Summary
`ConnectionImpl(Transport trans)` Create with an associated `Transport`.

Method Summary
`void` `attach(Channel chan)` Attach a `Channel` to this connection.
`void` `attach(ForwardedChannelOpener opener)` Attach a `ForwardedChannelOpener` to this connection, which will be delegated opening of any `CHANNEL_OPEN` packets `for which it is responsible`.
`void` `forget(Channel chan)` Forget an attached `Channel`.
`void` `forget(ForwardedChannelOpener opener)` Forget an attached `ForwardedChannelOpener`.
`Channel` `get(int id)`
`ForwardedChannelOpener` `get(String chanType)`
`int` `getMaxPacketSize()`
`Transport` `getTransport()`
`int` `getWindowSize()`
`void` `handle(Message msg, SSHPacket buf)` Delegate handling of some SSH packet to this object.
`void` `join()` Wait for the situation that no channels are attached (e.g., got closed).
`int` `nextID()`
`void` `notifyError(SSHException error)` Notifies this object of an `error`.
`Promise<SSHPacket,ConnectionException>` `sendGlobalRequest(String name, boolean wantReply, byte[] specifics)` Send an SSH global request.
`void` `sendOpenFailure(int recipient, OpenFailException.Reason reason, String message)` Send a `SSH_MSG_OPEN_FAILURE` for specified `Reason` and `message`.
`void` `setMaxPacketSize(int maxPacketSize)` Set the maximum packet size for the local window this connection recommends to any `Channel`'s that ask for it.
`void` `setWindowSize(int windowSize)` Set the size for the local window this connection recommends to any `Channel`'s that ask for it.

Methods inherited from class net.schmizz.sshj.AbstractService
`getName, getTimeout, notifyUnimplemented, request, setTimeout`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface net.schmizz.sshj.connection.Connection
`getTimeout, setTimeout`

Constructor Detail

### ConnectionImpl

    public ConnectionImpl(Transport trans)

  Create with an associated `Transport`.

  Parameters:
    `trans` - transport layer

Method Detail

### attach

    public void attach(Channel chan)

  Description copied from interface: `Connection`
  Attach a `Channel` to this connection. A channel must be attached to the connection if it is to receive any channel-specific data that is received.

  Specified by:
    `attach` in interface `Connection`
  Parameters:
    `chan` - the channel

### get

    public Channel get(int id)

  Specified by:
    `get` in interface `Connection`
  Parameters:
    `id` - number of the channel to retrieve
  Returns:
    an attached `Channel` of specified channel number, or `null` if no such channel was attached

### get

    public ForwardedChannelOpener get(String chanType)

  Specified by:
    `get` in interface `Connection`
  Parameters:
    `chanType` - channel type
  Returns:
    an attached `ForwardedChannelOpener` of specified channel-type, or `null` if no such channel was attached

### forget

    public void forget(Channel chan)

  Description copied from interface: `Connection`
  Forget an attached `Channel`.

  Specified by:
    `forget` in interface `Connection`
  Parameters:
    `chan` - the channel

### forget

    public void forget(ForwardedChannelOpener opener)

  Description copied from interface: `Connection`
  Forget an attached `ForwardedChannelOpener`.

  Specified by:
    `forget` in interface `Connection`
  Parameters:
    `opener` - the opener to forget

### attach

    public void attach(ForwardedChannelOpener opener)

  Description copied from interface: `Connection`
  Attach a `ForwardedChannelOpener` to this connection, which will be delegated opening of any `CHANNEL_OPEN` packets `for which it is responsible`.

  Specified by:
    `attach` in interface `Connection`
  Parameters:
    `opener` - an opener for forwarded channels

### handle

    public void handle(Message msg,
                       SSHPacket buf)
                throws SSHException

  Description copied from interface: `SSHPacketHandler`
  Delegate handling of some SSH packet to this object.

  Specified by:
    `handle` in interface `SSHPacketHandler`
  Overrides:
    `handle` in class `AbstractService`
  Parameters:
    `msg` - the SSH `message identifier`
    `buf` - `SSHPacket` containing rest of the request
  Throws:
    `SSHException` - if there is a non-recoverable error

### getMaxPacketSize

    public int getMaxPacketSize()

  Specified by:
    `getMaxPacketSize` in interface `Connection`
  Returns:
    the maximum packet size for the local window this connection recommends to any `Channel`'s that ask for it.

### getTransport

    public Transport getTransport()

  Specified by:
    `getTransport` in interface `Connection`
  Returns:
    the associated `Transport`.

### setMaxPacketSize

    public void setMaxPacketSize(int maxPacketSize)

  Description copied from interface: `Connection`
  Set the maximum packet size for the local window this connection recommends to any `Channel`'s that ask for it.

  Specified by:
    `setMaxPacketSize` in interface `Connection`
  Parameters:
    `maxPacketSize` - maximum packet size in bytes

### getWindowSize

    public int getWindowSize()

  Specified by:
    `getWindowSize` in interface `Connection`
  Returns:
    the size for the local window this connection recommends to any `Channel`'s that ask for it.

### setWindowSize

    public void setWindowSize(int windowSize)

  Description copied from interface: `Connection`
  Set the size for the local window this connection recommends to any `Channel`'s that ask for it.

  Specified by:
    `setWindowSize` in interface `Connection`
  Parameters:
    `windowSize` - window size in bytes

### join

    public void join()
              throws InterruptedException

  Description copied from interface: `Connection`
  Wait for the situation that no channels are attached (e.g., got closed).

  Specified by:
    `join` in interface `Connection`
  Throws:
    `InterruptedException` - if the thread is interrupted

### nextID

    public int nextID()

  Specified by:
    `nextID` in interface `Connection`
  Returns:
    an available ID a `Channel` can rightfully claim.

### sendGlobalRequest

    public Promise<SSHPacket,ConnectionException> sendGlobalRequest(String name,
                                                                    boolean wantReply,
                                                                    byte[] specifics)
                                                             throws TransportException

  Description copied from interface: `Connection`
  Send an SSH global request.

  Specified by:
    `sendGlobalRequest` in interface `Connection`
  Parameters:
    `name` - request name
    `wantReply` - whether a reply is requested
    `specifics` - `SSHPacket` containing fields specific to the request
  Returns:
    a `Promise` for the reply data (in case `wantReply` is true) which allows waiting on the reply, or `null` if a reply is not requested.
  Throws:
    `TransportException` - if there is an error sending the request

### sendOpenFailure

    public void sendOpenFailure(int recipient,
                                OpenFailException.Reason reason,
                                String message)
                         throws TransportException

  Description copied from interface: `Connection`
  Send a `SSH_MSG_OPEN_FAILURE` for specified `Reason` and `message`.

  Specified by:
    `sendOpenFailure` in interface `Connection`
  Parameters:
    `recipient` - number of the recipient channel
    `reason` - a reason for the failure
    `message` - an explanatory message
  Throws:
    `TransportException` - if there is a transport-layer error

### notifyError

    public void notifyError(SSHException error)

  Description copied from interface: `ErrorNotifiable`
  Notifies this object of an `error`.

  Specified by:
    `notifyError` in interface `ErrorNotifiable`
  Overrides:
    `notifyError` in class `AbstractService`

Copyright © 2009-2011. All Rights Reserved.