public class Connection extends Object implements ConnectionBase
| Modifier and Type | Field and Description |
|---|---|
protected com.google.gson.Gson |
mGson |
protected com.google.gson.JsonParser |
mJsonParser |
protected ConnectionState |
mState |
static Version |
PROTOCOL_VERSION |
| Constructor and Description |
|---|
Connection(String url)
Initializes the connection with an URL
|
Connection(String url,
Logger logger)
Initializes the connection with an URL and a logger
|
Connection(String url,
String queryString)
Initializes the connection with an URL and a query string
|
Connection(String url,
String queryString,
Logger logger)
Initializes the connection with an URL, a query string and a Logger
|
| Modifier and Type | Method and Description |
|---|---|
void |
closed(Runnable handler)
Sets the handler for the "Closed" event
|
void |
connected(Runnable handler)
Sets the handler for the "Connected" event
|
void |
connectionSlow(Runnable handler)
Sets the handler for the "ConnectionSlow" event
|
void |
disconnect()
Closes the connection
|
void |
error(ErrorCallback handler)
Sets the handler for the "Error" event
|
String |
getConnectionData()
Returns the data used by the connection
|
String |
getConnectionId()
Returns the connection Id
|
String |
getConnectionToken()
Returns the connection token
|
Credentials |
getCredentials()
Returns the credentials used by the connection
|
String |
getGroupsToken()
Returns the connection groups token
|
com.google.gson.Gson |
getGson()
Returns the Gson instance used by the connection
|
Map<String,String> |
getHeaders()
Returns the connection headers
|
com.google.gson.JsonParser |
getJsonParser()
Returns the JsonParser used by the connection
|
Logger |
getLogger()
Returns the Logger used by the connection
|
String |
getMessageId()
Returns the current message Id
|
String |
getQueryString()
Returns the query string used by the connection
|
protected String |
getSourceNameForLog() |
ConnectionState |
getState()
Returns the connection state
|
String |
getUrl()
Returns the URL used by the connection
|
protected void |
log(String message,
LogLevel level) |
protected void |
log(Throwable error) |
protected void |
onClosed()
Triggers the Closed event
|
protected void |
onConnected()
Triggers the Connected event
|
void |
onError(Throwable error,
boolean mustCleanCurrentConnection)
Triggers the Error event
|
void |
onReceived(com.google.gson.JsonElement message) |
protected void |
onReconnected()
Triggers the Reconnected event
|
protected void |
onReconnecting()
Triggers the Reconnecting event
|
void |
prepareRequest(Request request)
Prepares a request that is going to be sent to the server
|
protected com.google.gson.JsonElement |
processMessage(com.google.gson.JsonElement message)
Processes a received message
|
void |
received(MessageReceivedHandler handler)
Sets the handler for the "Received" event
|
void |
reconnected(Runnable handler)
Sets the handler for the "Reconnected" event
|
void |
reconnecting(Runnable handler)
Sets the handler for the "Reconnecting" event
|
SignalRFuture<Void> |
send(Object object)
Sends a serialized object
|
SignalRFuture<Void> |
send(String data)
Sends data using the connection
|
void |
setClientCertificate(String clientCertificatePath,
char[] clientCertificatePassword,
String clientCertificateAlias)
Set the client certificate information
|
void |
setCredentials(Credentials credentials)
Sets the credentials the connection should use
|
void |
setGroupsToken(String groupsToken)
Sets the groups token the connection should use
|
void |
setGson(com.google.gson.Gson gson)
Sets the Gson instance used by the connection
|
void |
setMessageId(String messageId)
Sets the message id the connection should use
|
SignalRFuture<Void> |
start(boolean ignoreSsl)
Starts the connection using the best available transport
|
SignalRFuture<Void> |
start(ClientTransport transport)
Starts the connection
|
void |
stateChanged(StateChangedCallback handler)
Sets the handler for the "StateChanged" event
|
void |
stop()
Aborts the connection and closes it
|
public static final Version PROTOCOL_VERSION
protected ConnectionState mState
protected com.google.gson.JsonParser mJsonParser
protected com.google.gson.Gson mGson
public Connection(String url)
url - The connection URLpublic Connection(String url, String queryString)
url - The connection URLqueryString - The connection query stringpublic Connection(String url, Logger logger)
url - The connection URLlogger - The connection loggerpublic Logger getLogger()
ConnectionBasegetLogger in interface ConnectionBasepublic ConnectionState getState()
ConnectionBasegetState in interface ConnectionBasepublic String getUrl()
ConnectionBasegetUrl in interface ConnectionBasepublic String getConnectionToken()
ConnectionBasegetConnectionToken in interface ConnectionBasepublic String getConnectionId()
ConnectionBasegetConnectionId in interface ConnectionBasepublic String getQueryString()
ConnectionBasegetQueryString in interface ConnectionBasepublic String getMessageId()
ConnectionBasegetMessageId in interface ConnectionBasepublic void setMessageId(String messageId)
ConnectionBasesetMessageId in interface ConnectionBasemessageId - Message Idpublic String getGroupsToken()
ConnectionBasegetGroupsToken in interface ConnectionBasepublic void setGroupsToken(String groupsToken)
ConnectionBasesetGroupsToken in interface ConnectionBasegroupsToken - Group Tokenpublic Map<String,String> getHeaders()
ConnectionBasegetHeaders in interface ConnectionBasepublic void reconnecting(Runnable handler)
ConnectionBasereconnecting in interface ConnectionBasehandler - Handlerpublic void reconnected(Runnable handler)
ConnectionBasereconnected in interface ConnectionBasehandler - Handlerpublic void connected(Runnable handler)
ConnectionBaseconnected in interface ConnectionBasehandler - Handlerpublic void error(ErrorCallback handler)
ConnectionBaseerror in interface ConnectionBasehandler - Error Handlerpublic void received(MessageReceivedHandler handler)
ConnectionBasereceived in interface ConnectionBasehandler - Message received handlerpublic void connectionSlow(Runnable handler)
ConnectionBaseconnectionSlow in interface ConnectionBasehandler - Handlerpublic void closed(Runnable handler)
ConnectionBaseclosed in interface ConnectionBasehandler - Handlerpublic void stateChanged(StateChangedCallback handler)
ConnectionBasestateChanged in interface ConnectionBasehandler - State change handlerpublic void setClientCertificate(String clientCertificatePath, char[] clientCertificatePassword, String clientCertificateAlias)
ConnectionBasesetClientCertificate in interface ConnectionBaseclientCertificatePath - client certificate pathclientCertificatePassword - client certificate passwordclientCertificateAlias - client certificate aliaspublic SignalRFuture<Void> start(boolean ignoreSsl)
ignoreSsl - Ignore SSL certificate verificationpublic SignalRFuture<Void> send(Object object)
object - The object to send. If the object is a JsonElement, its string
representation is sent. Otherwise, the object is serialized to
Json.public SignalRFuture<Void> send(String data)
ConnectionBasesend in interface ConnectionBasedata - Data to sendpublic SignalRFuture<Void> start(ClientTransport transport)
ConnectionBasestart in interface ConnectionBasetransport - Transport to be used by the connectionpublic Credentials getCredentials()
ConnectionBasegetCredentials in interface ConnectionBasepublic void setCredentials(Credentials credentials)
ConnectionBasesetCredentials in interface ConnectionBasecredentials - Credentialspublic void prepareRequest(Request request)
ConnectionBaseprepareRequest in interface ConnectionBaserequest - The request to preparepublic String getConnectionData()
ConnectionBasegetConnectionData in interface ConnectionBasepublic void stop()
ConnectionBasestop in interface ConnectionBasepublic void disconnect()
ConnectionBasedisconnect in interface ConnectionBasepublic com.google.gson.Gson getGson()
ConnectionBasegetGson in interface ConnectionBasepublic void setGson(com.google.gson.Gson gson)
ConnectionBasesetGson in interface ConnectionBasegson - Gson instancepublic com.google.gson.JsonParser getJsonParser()
ConnectionBasegetJsonParser in interface ConnectionBaseprotected void onReconnecting()
protected void onReconnected()
protected void onConnected()
protected com.google.gson.JsonElement processMessage(com.google.gson.JsonElement message)
throws Exception
message - The message to processException - An exception could be thrown if there an error while
processing the messagepublic void onError(Throwable error, boolean mustCleanCurrentConnection)
ConnectionBaseonError in interface ConnectionBaseerror - The error that triggered the eventmustCleanCurrentConnection - True if the connection must be cleanedprotected void onClosed()
protected void log(Throwable error)
protected String getSourceNameForLog()
public void onReceived(com.google.gson.JsonElement message)
onReceived in interface ConnectionBaseCopyright © 2019. All rights reserved.