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.Encoding -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CopyOnWriteArraySet<IBasicScope>Set of basic scopes.protected IClientClient bound to connectionprivate booleanIs the connection closed?protected CopyOnWriteArrayList<IConnectionListener>Listenersprotected AtomicLongNumber of dropped messagesprotected StringConnection hostprivate static final org.slf4j.LoggerConnection 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 identifierprivate ThreadLocal<Number>protected final StringConnection typeprivate final SemaphoreUsed to protect mulit-threaded operations on writeprotected AtomicLongNumber of written messagesFields inherited from class org.red5.server.AttributeStore
attributesFields inherited from interface org.red5.server.api.IConnection
PERSISTENT, POLLING, TRANSIENT -
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 parametersvoiddispatchEvent(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.getHost()Get the hostname that the client is connected to.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) Initializes clientbooleanisClosed()Returns whether or not a connection is closed.booleanCheck whether connection is alivebooleanReturns whether or not the reader is idle.booleanReturns whether or not the writer is idle.voidnotifyEvent(IEvent event) Notified on eventvoidregisterBasicScope(IBroadcastScope basicScope) Registers basic scopevoidremoveListener(IConnectionListener listener) Removes the listener from this objectvoidSets the Client.voidsetStreamId(Number id) Sets the current stream id.voidunregisterBasicScope(IBasicScope basicScope) Unregister basic scopeMethods 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, 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, getAttributeNames, getAttributes, hasAttribute, removeAttribute, removeAttributes, 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
-
log
private static final org.slf4j.Logger log -
type
Connection 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. -
closed
private volatile boolean closedIs the connection closed? -
connectionListeners
Listeners -
writeLock
Used to protect mulit-threaded operations on write -
streamLocal
-
-
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
-
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
-
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
-
getLock
- Returns:
- lock for changing state operations
-
initialize
Initializes client- Specified by:
initializein interfaceIConnection- Parameters:
client- Client bound to connection
-
getType
Description copied from interface:IConnectionGet the connection type.- Specified by:
getTypein interfaceIConnection- Returns:
- type
-
getHost
Description copied from interface:IConnectionGet 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:
- host
-
getRemoteAddress
Description copied from interface:IConnectionGet the IP address the client is connected from.- Specified by:
getRemoteAddressin interfaceIConnection- Returns:
- remote address
-
getRemoteAddresses
Description copied from interface:IConnectionGet 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:
- remote address
-
getRemotePort
public int getRemotePort()Description copied from interface:IConnectionGet the port the client is connected from.- Specified by:
getRemotePortin interfaceIConnection- Returns:
- remote port
-
getPath
Description copied from interface:IConnectionGet the path for this connection. This is not updated if you switch scope.- Specified by:
getPathin interfaceIConnection- Returns:
- path
-
getSessionId
Description copied from interface:IConnectionGet 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
-
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
-
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
-
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
-