org.red5.server

## Class BaseConnection

- java.lang.Object
- - org.red5.server.AttributeStore
  - - org.red5.server.BaseConnection

All Implemented Interfaces:
  IEventDispatcher, IEventHandler, IEventListener, IAttributeStore, ICastingAttributeStore, IConnection, ICoreObject, AttributeStoreMXBean

Direct Known Subclasses:
  RTMPConnection

    public abstract class BaseConnection
    extends AttributeStore
    implements IConnection

Base abstract class for connections. Adds connection specific functionality like work with clients to AttributeStore.

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.red5.server.api.IConnection

`IConnection.Encoding`

### Field Summary

Fields
`protected Set<IBasicScope>` `basicScopes` Set of basic scopes.
`protected IClient` `client` Client bound to connection
`protected boolean` `closed` Is the connection closed?
`protected AtomicLong` `droppedMessages` Number of dropped messages
`protected String` `host` Connection host
`protected Map<String,Object>` `params` Connection params passed from client with NetConnection.connect call
`protected String` `path` Path of scope client connected to
`protected AtomicLong` `readMessages` Number of read messages
`protected String` `remoteAddress` Connection remote address
`protected List<String>` `remoteAddresses` Connection remote addresses
`protected int` `remotePort` Remote port
`protected Scope` `scope` Scope that connection belongs to
`protected String` `sessionId` Connection session identifier
`protected String` `type` Connection type
`protected AtomicLong` `writtenMessages` Number of written messages

### Fields inherited from class org.red5.server.AttributeStore

`attributes`

### Fields inherited from interface org.red5.server.api.IConnection

`PERSISTENT, POLLING, TRANSIENT`

### Constructor Summary

Constructors
Constructor and Description
`BaseConnection()` Creates a new persistent base connection
`BaseConnection(String type)` Creates a new base connection with the given type.
`BaseConnection(String type, String host, String remoteAddress, int remotePort, String path, String sessionId, Map<String,Object> params)` Creates a new base connection with the given parameters.

### Method Summary

Methods
`void` `close()` Closes connection
`boolean` `connect(IScope newScope)` Connect to another scope on server
`boolean` `connect(IScope newScope, Object[] params)` Connect to another scope on server with given parameters
`void` `dispatchEvent(IEvent event)` Dispatches event
`boolean` `equals(Object obj)`
`Iterator<IBasicScope>` `getBasicScopes()` Get the basic scopes this connection has subscribed.
`IClient` `getClient()` Get the client object associated with this connection.
`long` `getClientBytesRead()` Return number of written bytes the client reports to have received.
`Map<String,Object>` `getConnectParams()` Return connection parameters
`long` `getDroppedMessages()` Total number of messages that have been dropped.
`String` `getHost()` Get the hostname that the client is connected to.
`Semaphore` `getLock()`
`static int` `getNextClientId()` Returns the next available client id.
`String` `getPath()` Get the path for this connection.
`long` `getPendingMessages()` Total number of messages that are pending to be sent to the connection.
`long` `getPendingVideoMessages(int streamId)`
`abstract long` `getReadBytes()` Total number of bytes read from the connection.
`long` `getReadMessages()` Total number of messages read from the connection.
`String` `getRemoteAddress()` Get the IP address the client is connected from.
`List<String>` `getRemoteAddresses()` Get the IP addresses the client is connected from.
`int` `getRemotePort()` Get the port the client is connected from.
`IScope` `getScope()` Get the scope this is connected to.
`String` `getSessionId()` Get the session id, this may be `null`.
`String` `getType()` Get the connection type.
`abstract long` `getWrittenBytes()` Total number of bytes written to the connection.
`long` `getWrittenMessages()` Total number of messages written to the connection.
`boolean` `handleEvent(IEvent event)` Handles event
`int` `hashCode()`
`void` `initialize(IClient client)` Initializes client
`boolean` `isConnected()` Check whether connection is alive
`void` `notifyEvent(IEvent event)` Notified on event
`void` `registerBasicScope(IBasicScope basicScope)` Registers basic scope
`void` `unregisterBasicScope(IBasicScope basicScope)` Unregister basic scope

### Methods inherited from class org.red5.server.AttributeStore

`filterNull, from, getAttribute, getAttribute, getAttributeNames, getAttributes, getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttribute, hasAttribute, removeAttribute, removeAttributes, setAttribute, setAttributes, setAttributes`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.red5.server.api.IConnection

`getEncoding, getLastPingTime, ping, setBandwidth`

### Methods inherited from interface org.red5.server.api.ICastingAttributeStore

`getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttribute`

### Methods inherited from interface org.red5.server.api.IAttributeStore

`getAttribute, getAttribute, getAttributeNames, getAttributes, hasAttribute, removeAttribute, removeAttributes, setAttribute, setAttributes, setAttributes`

### Field Detail

#### type

    protected final String type

Connection type

#### host

    protected volatile String host

Connection host

#### remoteAddress

    protected volatile String remoteAddress

Connection remote address

#### remoteAddresses

    protected volatile List<String> remoteAddresses

Connection remote addresses

#### remotePort

    protected volatile int remotePort

Remote port

#### path

    protected volatile String path

Path of scope client connected to

#### sessionId

    protected volatile String sessionId

Connection session identifier

#### readMessages

    protected AtomicLong readMessages

Number of read messages

#### writtenMessages

    protected AtomicLong writtenMessages

Number of written messages

#### droppedMessages

    protected AtomicLong droppedMessages

Number of dropped messages

#### params

    protected volatile Map<String,Object> params

Connection params passed from client with NetConnection.connect call

See Also:
  NetConnection in Flash Media Server docs (external)

#### client

    protected volatile IClient client

Client bound to connection

#### scope

    protected volatile Scope scope

Scope that connection belongs to

#### basicScopes

    protected Set<IBasicScope> basicScopes

Set of basic scopes.

#### closed

    protected volatile boolean closed

Is the connection closed?

### Constructor Detail

#### BaseConnection

    @ConstructorProperties(value="persistent")
    public BaseConnection()

Creates a new persistent base connection

#### BaseConnection

    @ConstructorProperties(value="type")
    public BaseConnection(String type)

Creates a new base connection with the given type.

Parameters:
  `type` - Connection type

#### BaseConnection

    @ConstructorProperties(value={"type","host","remoteAddress","remotePort","path","sessionId"})
    public BaseConnection(String type,
                                             String host,
                                             String remoteAddress,
                                             int remotePort,
                                             String path,
                                             String sessionId,
                                             Map<String,Object> params)

Creates a new base connection with the given parameters.

Parameters:
  `type` - Connection type
  `host` - Host
  `remoteAddress` - Remote address
  `remotePort` - Remote port
  `path` - Scope path on server
  `sessionId` - Session id
  `params` - Params passed from client

### Method Detail

#### getNextClientId

    public static int getNextClientId()

Returns the next available client id.

Returns:
  new client id

#### getLock

    public Semaphore getLock()

Returns:
  lock for changing state operations

#### initialize

    public void initialize(IClient client)

Initializes client

Specified by:
  `initialize` in interface `IConnection`
Parameters:
  `client` - Client bound to connection

#### getType

    public String getType()

Description copied from interface: `IConnection`
Get the connection type.

Specified by:
  `getType` in interface `IConnection`
Returns:
  type

#### getHost

    public String getHost()

Description copied from interface: `IConnection`
Get the hostname that the client is connected to. If they are connected to an IP, the IP address will be returned as a String.

Specified by:
  `getHost` in interface `IConnection`
Returns:
  host

#### getRemoteAddress

    public String getRemoteAddress()

Description copied from interface: `IConnection`
Get the IP address the client is connected from.

Specified by:
  `getRemoteAddress` in interface `IConnection`
Returns:
  remote address

#### getRemoteAddresses

    public List<String> getRemoteAddresses()

Description copied from interface: `IConnection`
Get the IP addresses the client is connected from. If a client is connected through RTMPT and uses a proxy to connect, this will contain all hosts the client used to connect to the server.

Specified by:
  `getRemoteAddresses` in interface `IConnection`
Returns:
  remote address

#### getRemotePort

    public int getRemotePort()

Description copied from interface: `IConnection`
Get the port the client is connected from.

Specified by:
  `getRemotePort` in interface `IConnection`
Returns:
  remote port

#### getPath

    public String getPath()

Description copied from interface: `IConnection`
Get the path for this connection. This is not updated if you switch scope.

Specified by:
  `getPath` in interface `IConnection`
Returns:
  path

#### getSessionId

    public String getSessionId()

Description copied from interface: `IConnection`
Get the session id, this may be `null`.

Specified by:
  `getSessionId` in interface `IConnection`
Returns:
  session id

#### getConnectParams

    public Map<String,Object> getConnectParams()

Return connection parameters

Specified by:
  `getConnectParams` in interface `IConnection`
Returns:
  connection parameters

#### getClient

    public IClient getClient()

Description copied from interface: `IConnection`
Get the client object associated with this connection.

Specified by:
  `getClient` in interface `IConnection`
Returns:
  client

#### isConnected

    public boolean isConnected()

Check whether connection is alive

Specified by:
  `isConnected` in interface `IConnection`
Returns:
  true if connection is bound to scope, false otherwise

#### connect

    public boolean connect(IScope newScope)

Connect to another scope on server

Specified by:
  `connect` in interface `IConnection`
Parameters:
  `newScope` - New scope
Returns:
  true on success, false otherwise

#### connect

    public boolean connect(IScope newScope,
                  Object[] params)

Connect to another scope on server with given parameters

Specified by:
  `connect` in interface `IConnection`
Parameters:
  `newScope` - New scope
  `params` - Parameters to connect with
Returns:
  true on success, false otherwise

#### getScope

    public IScope getScope()

Description copied from interface: `IConnection`
Get the scope this is connected to.

Specified by:
  `getScope` in interface `IConnection`
Returns:
  scope

#### close

    public void close()

Closes connection

Specified by:
  `close` in interface `IConnection`

#### notifyEvent

    public void notifyEvent(IEvent event)

Notified on event

Specified by:
  `notifyEvent` in interface `IEventListener`
Parameters:
  `event` - Event

#### dispatchEvent

    public void dispatchEvent(IEvent event)

Dispatches event

Specified by:
  `dispatchEvent` in interface `IEventDispatcher`
Parameters:
  `event` - Event

#### handleEvent

    public boolean handleEvent(IEvent event)

Handles event

Specified by:
  `handleEvent` in interface `IEventHandler`
Parameters:
  `event` - Event
Returns:
  true if associated scope was able to handle event, false otherwise

#### getBasicScopes

    public Iterator<IBasicScope> getBasicScopes()

Description copied from interface: `IConnection`
Get the basic scopes this connection has subscribed. This list will contain the shared objects and broadcast streams the connection connected to.

Specified by:
  `getBasicScopes` in interface `IConnection`
Returns:
  basic scopes

#### registerBasicScope

    public void registerBasicScope(IBasicScope basicScope)

Registers basic scope

Parameters:
  `basicScope` - Basic scope to register

#### unregisterBasicScope

    public void unregisterBasicScope(IBasicScope basicScope)

Unregister basic scope

Parameters:
  `basicScope` - Unregister basic scope

#### getReadBytes

    public abstract long getReadBytes()

Description copied from interface: `IConnection`
Total number of bytes read from the connection.

Specified by:
  `getReadBytes` in interface `IConnection`
Returns:
  bytes read

#### getWrittenBytes

    public abstract long getWrittenBytes()

Description copied from interface: `IConnection`
Total number of bytes written to the connection.

Specified by:
  `getWrittenBytes` in interface `IConnection`
Returns:
  bytes written

#### getReadMessages

    public long getReadMessages()

Description copied from interface: `IConnection`
Total number of messages read from the connection.

Specified by:
  `getReadMessages` in interface `IConnection`
Returns:
  messages read

#### getWrittenMessages

    public long getWrittenMessages()

Description copied from interface: `IConnection`
Total number of messages written to the connection.

Specified by:
  `getWrittenMessages` in interface `IConnection`
Returns:
  messages written

#### getDroppedMessages

    public long getDroppedMessages()

Description copied from interface: `IConnection`
Total number of messages that have been dropped.

Specified by:
  `getDroppedMessages` in interface `IConnection`
Returns:
  dropped messages

#### getPendingMessages

    public long getPendingMessages()

Description copied from interface: `IConnection`
Total number of messages that are pending to be sent to the connection.

Specified by:
  `getPendingMessages` in interface `IConnection`
Returns:
  pending messages

#### getPendingVideoMessages

    public long getPendingVideoMessages(int streamId)

Parameters:
  `streamId` - the id you want to know about
Returns:
  pending messages for this streamId

#### getClientBytesRead

    public long getClientBytesRead()

Return number of written bytes the client reports to have received. This is the last value of the BytesRead message received from a client.

Specified by:
  `getClientBytesRead` in interface `IConnection`
Returns:
  number of written bytes received by the client
See Also:
  `BytesRead`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### equals

    public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`