Package 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
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.Duty, IConnection.Encoding, IConnection.Type -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CopyOnWriteArraySet<IBasicScope> Set of basic scopes.protected IClientClient bound to connectionprotected CopyOnWriteArraySet<IConnectionListener> Listenersprotected AtomicLongNumber of dropped messagesprotected IConnection.DutyDuty typeprotected StringConnection hostConnection params passed from client with NetConnection.connect callprotected StringPath of scope client connected toprotected AtomicLongNumber of read messagesprotected StringConnection remote addressConnection remote addressesprotected intRemote portprotected ScopeScope to which this connection belongsprotected final StringConnection session identifierprotected final IConnection.TypeConnection typeprotected AtomicLongNumber of written messagesFields inherited from class org.red5.server.AttributeStore
attributes, isDebug, isTrace, log -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new persistent base connectionBaseConnection(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
Modifier and TypeMethodDescriptionvoidaddListener(IConnectionListener listener) Adds a listener to this objectvoidclose()Closes connectionbooleanConnect to another scope on serverbooleanConnect to another scope on server with given parametersvoidDisconnects connection from scopevoiddispatchEvent(IEvent event) Dispatches eventbooleanGet the basic scopes this connection has subscribed.Get the client object associated with this connection.longReturn number of written bytes the client reports to have received.Return connection parameterslongTotal number of messages that have been dropped.getDuty()Get the duty for this connection; this is not meant nor expected to remain static.getHost()Get the hostname that the client is connected to.intgetId()Returns the client id.getLock()getPath()Get the path for this connection.longCount of outgoing messages not yet written.longgetPendingVideoMessages(Number streamId) Count of outgoing video messages not yet written.abstract longTotal number of bytes read from the connection.longTotal number of messages read from the connection.Get the IP address the client is connected from.Get the IP addresses the client is connected from.intGet the port the client is connected from.getScope()Return the current scope.Get the session id, this may be null.Returns the current stream id.getType()Get the connection type.abstract longTotal number of bytes written to the connection.longTotal number of messages written to the connection.booleanhandleEvent(IEvent event) Handles eventinthashCode()voidinitialize(IClient client) Initialize the connection.booleanisClosed()Returns whether or not a connection is closed.booleanCheck whether connection is alivebooleanReturns whether or not the connection is disconnected.booleanisIdle()Returns whether or not the connection is idle.booleanReturns whether or not the reader is idle.booleanReturns whether or not the writer is idle.voidnotifyEvent(IEvent event) Notified on eventvoidNotifies listeners of a property change.voidregisterBasicScope(IBroadcastScope basicScope) Registers basic scopevoidregisterBasicScope(SharedObjectScope basicScope) Registers basic scopevoidremoveListener(IConnectionListener listener) Removes the listener from this objectvoidSets the Client.voidsetDuty(IConnection.Duty duty) voidsetId(int clientId) Deprecated.voidsetStreamId(Number id) Sets the current stream id.voidUninitializes clientvoidunregisterBasicScope(IBasicScope basicScope) Unregister basic scopeMethods inherited from class org.red5.server.AttributeStore
filterNull, from, getAttribute, getAttribute, getAttribute, getAttributeNames, getAttributes, getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttribute, hasAttribute, hasAttribute, removeAttribute, removeAttribute, removeAttributes, setAttribute, setAttribute, setAttributes, setAttributes, sizeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.red5.server.api.IAttributeStore
getAttribute, getAttribute, getAttribute, getAttributeNames, getAttributes, hasAttribute, hasAttribute, removeAttribute, removeAttribute, removeAttributes, setAttribute, setAttribute, setAttributes, setAttributes, sizeMethods inherited from interface org.red5.server.api.ICastingAttributeStore
getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttributeMethods inherited from interface org.red5.server.api.IConnection
getEncoding, getLastPingTime, getProtocol, ping, setBandwidth
-
Field Details
-
type
Connection type -
duty
Duty type -
host
Connection host -
remoteAddress
Connection remote address -
remoteAddresses
Connection remote addresses -
remotePort
protected volatile int remotePortRemote port -
path
Path of scope client connected to -
sessionId
Connection session identifier -
readMessages
Number of read messages -
writtenMessages
Number of written messages -
droppedMessages
Number of dropped messages -
params
Connection params passed from client with NetConnection.connect call -
client
Client bound to connection -
scope
Scope to which this connection belongs -
basicScopes
Set of basic scopes. The scopes may be of shared object or broadcast stream type. -
connectionListeners
Listeners
-
-
Constructor Details
-
BaseConnection
Creates a new persistent base connection -
BaseConnection
Creates a new base connection with the given type.- Parameters:
type- Connection type
-
BaseConnection
@ConstructorProperties({"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 typehost- HostremoteAddress- Remote addressremotePort- Remote portpath- Scope path on serversessionId- Session idparams- Params passed from client
-
-
Method Details
-
addListener
Adds a listener to this object- Specified by:
addListenerin interfaceIConnection- Parameters:
listener- connection listener
-
removeListener
Removes the listener from this object- Specified by:
removeListenerin interfaceIConnection- Parameters:
listener- connection listener
-
notifyPropertyChanged
Notifies listeners of a property change.- Parameters:
evt- PropertyChangeEvent containing details
-
getLock
- Returns:
- lock for changing state operations
-
getStreamId
Returns the current stream id.- Specified by:
getStreamIdin interfaceIConnection- Returns:
- stream id
-
setStreamId
Sets the current stream id.- Specified by:
setStreamIdin interfaceIConnection- Parameters:
id- stream id
-
initialize
Initialize the connection.- Specified by:
initializein interfaceIConnection- Parameters:
client- Client object associated with connection
-
uninitialize
public void uninitialize()Uninitializes client- Specified by:
uninitializein interfaceIConnection
-
getType
Get the connection type.- Specified by:
getTypein interfaceIConnection- Returns:
- string containing one of connection types
-
getDuty
Get the duty for this connection; this is not meant nor expected to remain static.- Specified by:
getDutyin interfaceIConnection- Returns:
- duty type
-
setDuty
-
getHost
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:
getHostin interfaceIConnection- Returns:
- String containing the hostname
-
getRemoteAddress
Get the IP address the client is connected from.- Specified by:
getRemoteAddressin interfaceIConnection- Returns:
- The IP address of the client
-
getRemoteAddresses
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:
getRemoteAddressesin interfaceIConnection- Returns:
- The IP addresses of the client
-
getRemotePort
public int getRemotePort()Get the port the client is connected from.- Specified by:
getRemotePortin interfaceIConnection- Returns:
- The port of the client
-
getPath
Get the path for this connection. This is not updated if you switch scope.- Specified by:
getPathin interfaceIConnection- Returns:
- path Connection path
-
getSessionId
Get the session id, this may be null.- Specified by:
getSessionIdin interfaceIConnection- Returns:
- Session id
-
getConnectParams
Return connection parameters- Specified by:
getConnectParamsin interfaceIConnection- Returns:
- connection parameters
-
setClient
Sets the Client.- Specified by:
setClientin interfaceIConnection- Parameters:
client- client
-
getClient
Get the client object associated with this connection.- Specified by:
getClientin interfaceIConnection- Returns:
- Client object
-
getId
public int getId()Returns the client id.- Returns:
- client id as an int
-
setId
Deprecated. -
isConnected
public boolean isConnected()Check whether connection is alive- Specified by:
isConnectedin interfaceIConnection- Returns:
- true if connection is bound to scope, false otherwise
-
connect
Connect to another scope on server- Specified by:
connectin interfaceIConnection- Parameters:
newScope- New scope- Returns:
- true on success, false otherwise
-
connect
Connect to another scope on server with given parameters- Specified by:
connectin interfaceIConnection- Parameters:
newScope- New scopeparams- Parameters to connect with- Returns:
- true on success, false otherwise
-
isDisconnected
public boolean isDisconnected()Returns whether or not the connection is disconnected.- Returns:
- true if connection is not bound to scope, false otherwise
-
disconnect
public void disconnect()Disconnects connection from scope -
getScope
Return the current scope.- Specified by:
getScopein interfaceIConnection- Returns:
- scope
-
close
public void close()Closes connection- Specified by:
closein interfaceIConnection
-
notifyEvent
Notified on event- Specified by:
notifyEventin interfaceIEventListener- Parameters:
event- Event
-
dispatchEvent
Dispatches event- Specified by:
dispatchEventin interfaceIEventDispatcher- Parameters:
event- Event
-
handleEvent
Handles event- Specified by:
handleEventin interfaceIEventHandler- Parameters:
event- Event- Returns:
- true if associated scope was able to handle event, false otherwise
-
getBasicScopes
Description copied from interface:IConnectionGet the basic scopes this connection has subscribed. This list will contain the shared objects and broadcast streams the connection connected to.- Specified by:
getBasicScopesin interfaceIConnection- Returns:
- basic scopes
-
registerBasicScope
Registers basic scope- Parameters:
basicScope- Basic scope to register
-
unregisterBasicScope
Unregister basic scope- Parameters:
basicScope- Unregister basic scope
-
getReadBytes
public abstract long getReadBytes()Description copied from interface:IConnectionTotal number of bytes read from the connection.- Specified by:
getReadBytesin interfaceIConnection- Returns:
- bytes read
-
getWrittenBytes
public abstract long getWrittenBytes()Description copied from interface:IConnectionTotal number of bytes written to the connection.- Specified by:
getWrittenBytesin interfaceIConnection- Returns:
- bytes written
-
getReadMessages
public long getReadMessages()Description copied from interface:IConnectionTotal number of messages read from the connection.- Specified by:
getReadMessagesin interfaceIConnection- Returns:
- messages read
-
getWrittenMessages
public long getWrittenMessages()Description copied from interface:IConnectionTotal number of messages written to the connection.- Specified by:
getWrittenMessagesin interfaceIConnection- Returns:
- messages written
-
getDroppedMessages
public long getDroppedMessages()Description copied from interface:IConnectionTotal number of messages that have been dropped.- Specified by:
getDroppedMessagesin interfaceIConnection- Returns:
- dropped messages
-
isReaderIdle
public boolean isReaderIdle()Returns whether or not the reader is idle.- Returns:
- queued messages
-
isWriterIdle
public boolean isWriterIdle()Returns whether or not the writer is idle.- Returns:
- queued messages
-
isIdle
public boolean isIdle()Returns whether or not the connection is idle.- Returns:
- true if both read and write are idle and false otherwise
-
isClosed
public boolean isClosed()Returns whether or not a connection is closed.- Returns:
- true if closed
-
getPendingMessages
public long getPendingMessages()Count of outgoing messages not yet written.- Specified by:
getPendingMessagesin interfaceIConnection- Returns:
- pending messages
-
getPendingVideoMessages
Count of outgoing video messages not yet written.- 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:
getClientBytesReadin interfaceIConnection- Returns:
- number of written bytes received by the client
- See Also:
-
hashCode
public int hashCode() -
equals
-