Cleaned logging
This commit is contained in:
parent
5c4d64f3f1
commit
3a5295efe8
|
@ -42,6 +42,7 @@ import org.slf4j.LoggerFactory
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.Inet6Address
|
import java.net.Inet6Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
import java.util.*
|
||||||
import java.util.concurrent.*
|
import java.util.concurrent.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -797,11 +798,13 @@ open class Client<CONNECTION : Connection>(config: ClientConfiguration = ClientC
|
||||||
|
|
||||||
val pubSub = clientConnection.connectionInfo
|
val pubSub = clientConnection.connectionInfo
|
||||||
|
|
||||||
val connectionType = if (connectionInfo.bufferedMessages) {
|
val bufferedMessages = connectionInfo.bufferedMessages
|
||||||
|
val connectionType = if (bufferedMessages) {
|
||||||
"buffered connection"
|
"buffered connection"
|
||||||
} else {
|
} else {
|
||||||
"connection"
|
"connection"
|
||||||
}
|
}
|
||||||
|
val connectionTypeCaps = connectionType.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||||
|
|
||||||
val logInfo = pubSub.getLogInfo(logger.isDebugEnabled)
|
val logInfo = pubSub.getLogInfo(logger.isDebugEnabled)
|
||||||
if (logger.isDebugEnabled) {
|
if (logger.isDebugEnabled) {
|
||||||
|
@ -815,7 +818,7 @@ open class Client<CONNECTION : Connection>(config: ClientConfiguration = ClientC
|
||||||
endPoint = this,
|
endPoint = this,
|
||||||
connectionInfo = clientConnection.connectionInfo,
|
connectionInfo = clientConnection.connectionInfo,
|
||||||
publicKeyValidation = validateRemoteAddress,
|
publicKeyValidation = validateRemoteAddress,
|
||||||
enableBufferedMessages = connectionInfo.bufferedMessages,
|
enableBufferedMessages = bufferedMessages,
|
||||||
cryptoKey = connectionInfo.secretKey
|
cryptoKey = connectionInfo.secretKey
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -824,11 +827,11 @@ open class Client<CONNECTION : Connection>(config: ClientConfiguration = ClientC
|
||||||
if (!handshakeConnection.pubSub.isIpc) {
|
if (!handshakeConnection.pubSub.isIpc) {
|
||||||
// NOTE: Client can ALWAYS connect to the server. The server makes the decision if the client can connect or not.
|
// NOTE: Client can ALWAYS connect to the server. The server makes the decision if the client can connect or not.
|
||||||
if (logger.isTraceEnabled) {
|
if (logger.isTraceEnabled) {
|
||||||
logger.trace("[${handshakeConnection.details}] (${handshake.connectKey}) Buffered connection (${newConnection.id}) adding new signature for [$addressString -> ${connectionInfo.publicKey.toHexString()}]")
|
logger.trace("[${handshakeConnection.details}] (${handshake.connectKey}) $connectionTypeCaps (${newConnection.id}) adding new signature for [$addressString -> ${connectionInfo.publicKey.toHexString()}]")
|
||||||
} else if (logger.isDebugEnabled) {
|
} else if (logger.isDebugEnabled) {
|
||||||
logger.debug("[${handshakeConnection.details}] Buffered connection (${newConnection.id}) adding new signature for [$addressString -> ${connectionInfo.publicKey.toHexString()}]")
|
logger.debug("[${handshakeConnection.details}] $connectionTypeCaps (${newConnection.id}) adding new signature for [$addressString -> ${connectionInfo.publicKey.toHexString()}]")
|
||||||
} else if (logger.isInfoEnabled) {
|
} else if (logger.isInfoEnabled) {
|
||||||
logger.info("[${handshakeConnection.details}] Buffered connection adding new signature for [$addressString -> ${connectionInfo.publicKey.toHexString()}]")
|
logger.info("[${handshakeConnection.details}] $connectionTypeCaps adding new signature for [$addressString -> ${connectionInfo.publicKey.toHexString()}]")
|
||||||
}
|
}
|
||||||
|
|
||||||
storage.addRegisteredServerKey(address!!, connectionInfo.publicKey)
|
storage.addRegisteredServerKey(address!!, connectionInfo.publicKey)
|
||||||
|
@ -853,9 +856,9 @@ open class Client<CONNECTION : Connection>(config: ClientConfiguration = ClientC
|
||||||
handshakeConnection.close(this)
|
handshakeConnection.close(this)
|
||||||
|
|
||||||
if (logger.isTraceEnabled) {
|
if (logger.isTraceEnabled) {
|
||||||
logger.debug("[${handshakeConnection.details}] (${handshake.connectKey}) Buffered connection (${newConnection.id}) done with handshake.")
|
logger.debug("[${handshakeConnection.details}] (${handshake.connectKey}) $connectionTypeCaps (${newConnection.id}) done with handshake.")
|
||||||
} else if (logger.isDebugEnabled) {
|
} else if (logger.isDebugEnabled) {
|
||||||
logger.debug("[${handshakeConnection.details}] Buffered connection (${newConnection.id}) done with handshake.")
|
logger.debug("[${handshakeConnection.details}] $connectionTypeCaps (${newConnection.id}) done with handshake.")
|
||||||
}
|
}
|
||||||
|
|
||||||
connection0 = newConnection
|
connection0 = newConnection
|
||||||
|
@ -937,7 +940,6 @@ open class Client<CONNECTION : Connection>(config: ClientConfiguration = ClientC
|
||||||
if (autoReconnect) {
|
if (autoReconnect) {
|
||||||
// clients can reconnect automatically ONLY if there are driver errors, otherwise it's explicit!
|
// clients can reconnect automatically ONLY if there are driver errors, otherwise it's explicit!
|
||||||
eventDispatch.CLOSE.launch {
|
eventDispatch.CLOSE.launch {
|
||||||
logger.error("MUST AUTORECONNECT STARTING ON CLOSE ***********************************")
|
|
||||||
waitForEndpointShutdown()
|
waitForEndpointShutdown()
|
||||||
|
|
||||||
// also wait for everyone else to shutdown!!
|
// also wait for everyone else to shutdown!!
|
||||||
|
@ -1017,8 +1019,11 @@ open class Client<CONNECTION : Connection>(config: ClientConfiguration = ClientC
|
||||||
|
|
||||||
return if (c != null) {
|
return if (c != null) {
|
||||||
c.send(message)
|
c.send(message)
|
||||||
|
} else if (isShutdown()) {
|
||||||
|
logger.error("Cannot send a message '${message::class.java}' when there is no connection! (We are shutdown)")
|
||||||
|
false
|
||||||
} else {
|
} else {
|
||||||
val exception = TransmitException("Cannot send a message when there is no connection!")
|
val exception = TransmitException("Cannot send message '${message::class.java}' when there is no connection!")
|
||||||
listenerManager.notifyError(exception)
|
listenerManager.notifyError(exception)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -1037,8 +1042,11 @@ open class Client<CONNECTION : Connection>(config: ClientConfiguration = ClientC
|
||||||
return if (c != null) {
|
return if (c != null) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
c.send(message, onSuccessCallback as Connection.() -> Unit)
|
c.send(message, onSuccessCallback as Connection.() -> Unit)
|
||||||
|
} else if (isShutdown()) {
|
||||||
|
logger.error("Cannot send-sync message '${message::class.java}' when there is no connection! (We are shutdown)")
|
||||||
|
false
|
||||||
} else {
|
} else {
|
||||||
val exception = TransmitException("Cannot send-sync a message when there is no connection!")
|
val exception = TransmitException("Cannot send-sync message '${message::class.java}' when there is no connection!")
|
||||||
listenerManager.notifyError(exception)
|
listenerManager.notifyError(exception)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -1054,14 +1062,16 @@ open class Client<CONNECTION : Connection>(config: ClientConfiguration = ClientC
|
||||||
fun ping(function: Ping.() -> Unit): Boolean {
|
fun ping(function: Ping.() -> Unit): Boolean {
|
||||||
val c = connection0
|
val c = connection0
|
||||||
|
|
||||||
if (c != null) {
|
return if (c != null) {
|
||||||
return c.ping(function)
|
c.ping(function)
|
||||||
|
} else if (isShutdown()) {
|
||||||
|
logger.error("Cannot send a ping when there is no connection! (We are shutdown)")
|
||||||
|
false
|
||||||
} else {
|
} else {
|
||||||
val exception = TransmitException("Cannot send a ping when there is no connection!")
|
val exception = TransmitException("Cannot send a ping when there is no connection!")
|
||||||
listenerManager.notifyError(exception)
|
listenerManager.notifyError(exception)
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,17 +41,13 @@ data class PubSub(
|
||||||
fun getLogInfo(extraDetails: Boolean): String {
|
fun getLogInfo(extraDetails: Boolean): String {
|
||||||
return if (isIpc) {
|
return if (isIpc) {
|
||||||
val prefix = if (tagName.isNotEmpty()) {
|
val prefix = if (tagName.isNotEmpty()) {
|
||||||
EndPoint.IPC_NAME + " $tagName"
|
EndPoint.IPC_NAME + " ($tagName)"
|
||||||
} else {
|
} else {
|
||||||
EndPoint.IPC_NAME
|
EndPoint.IPC_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extraDetails) {
|
if (extraDetails) {
|
||||||
if (tagName.isNotEmpty()) {
|
"$prefix sessionID: p=${sessionIdPub} s=${sessionIdSub}, streamID: p=${streamIdPub} s=${streamIdSub}, reg: p=${pub.registrationId()} s=${sub.registrationId()}"
|
||||||
"$prefix sessionID: p=${sessionIdPub} s=${sessionIdSub}, streamID: p=${streamIdPub} s=${streamIdSub}, reg: p=${pub.registrationId()} s=${sub.registrationId()}"
|
|
||||||
} else {
|
|
||||||
"$prefix sessionID: p=${sessionIdPub} s=${sessionIdSub}, streamID: p=${streamIdPub} s=${streamIdSub}, reg: p=${pub.registrationId()} s=${sub.registrationId()}"
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
prefix
|
prefix
|
||||||
}
|
}
|
||||||
|
@ -63,7 +59,7 @@ data class PubSub(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tagName.isNotEmpty()) {
|
if (tagName.isNotEmpty()) {
|
||||||
prefix += " $tagName"
|
prefix += " ($tagName)"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extraDetails) {
|
if (extraDetails) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ import net.jodah.expiringmap.ExpiringMap
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
import java.util.*
|
||||||
import java.util.concurrent.*
|
import java.util.concurrent.*
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,11 +129,17 @@ internal class ServerHandshake<CONNECTION : Connection>(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val connectionType = if (newConnection.enableBufferedMessages) {
|
||||||
|
"Buffered connection"
|
||||||
|
} else {
|
||||||
|
"Connection"
|
||||||
|
}
|
||||||
|
|
||||||
// Server is the "source", client mirrors the server
|
// Server is the "source", client mirrors the server
|
||||||
if (logger.isTraceEnabled) {
|
if (logger.isTraceEnabled) {
|
||||||
logger.trace("[${newConnection}] (${message.connectKey}) Buffered connection (${newConnection.id}) done with handshake.")
|
logger.trace("[${newConnection}] (${message.connectKey}) $connectionType (${newConnection.id}) done with handshake.")
|
||||||
} else if (logger.isDebugEnabled) {
|
} else if (logger.isDebugEnabled) {
|
||||||
logger.debug("[${newConnection}] Buffered connection (${newConnection.id}) done with handshake.")
|
logger.debug("[${newConnection}] $connectionType (${newConnection.id}) done with handshake.")
|
||||||
}
|
}
|
||||||
|
|
||||||
newConnection.setImage()
|
newConnection.setImage()
|
||||||
|
@ -239,9 +246,8 @@ internal class ServerHandshake<CONNECTION : Connection>(
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val serialization = config.serialization
|
val serialization = config.serialization
|
||||||
|
|
||||||
val clientTagName = message.tag.let { if (it.isEmpty()) "" else "[$it]" }
|
val clientTagName = message.tag
|
||||||
if (clientTagName.length > 34) {
|
if (clientTagName.length > 32) {
|
||||||
// 34 to account for []
|
|
||||||
listenerManager.notifyError(ServerHandshakeException("[$logInfo] Connection not allowed! Invalid tag name."))
|
listenerManager.notifyError(ServerHandshakeException("[$logInfo] Connection not allowed! Invalid tag name."))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -361,6 +367,9 @@ internal class ServerHandshake<CONNECTION : Connection>(
|
||||||
"connection"
|
"connection"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val connectionTypeCaps = connectionType.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||||
|
|
||||||
|
|
||||||
val logInfo = newConnectionDriver.pubSub.getLogInfo(logger.isDebugEnabled)
|
val logInfo = newConnectionDriver.pubSub.getLogInfo(logger.isDebugEnabled)
|
||||||
if (logger.isDebugEnabled) {
|
if (logger.isDebugEnabled) {
|
||||||
logger.debug("Creating new $connectionType to $logInfo")
|
logger.debug("Creating new $connectionType to $logInfo")
|
||||||
|
@ -412,9 +421,9 @@ internal class ServerHandshake<CONNECTION : Connection>(
|
||||||
pendingConnections[message.connectKey] = newConnection
|
pendingConnections[message.connectKey] = newConnection
|
||||||
|
|
||||||
if (logger.isTraceEnabled) {
|
if (logger.isTraceEnabled) {
|
||||||
logger.trace("[$logInfo] (${message.connectKey}) buffered connection (${newConnection.id}) responding to handshake hello.")
|
logger.trace("[$logInfo] (${message.connectKey}) $connectionType (${newConnection.id}) responding to handshake hello.")
|
||||||
} else if (logger.isDebugEnabled) {
|
} else if (logger.isDebugEnabled) {
|
||||||
logger.debug("[$logInfo] Buffered connection (${newConnection.id}) responding to handshake hello.")
|
logger.debug("[$logInfo] $connectionTypeCaps (${newConnection.id}) responding to handshake hello.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// this tells the client all the info to connect.
|
// this tells the client all the info to connect.
|
||||||
|
@ -477,9 +486,8 @@ internal class ServerHandshake<CONNECTION : Connection>(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val clientTagName = message.tag.let { if (it.isEmpty()) "" else "[$it]" }
|
val clientTagName = message.tag
|
||||||
if (clientTagName.length > 34) {
|
if (clientTagName.length > 32) {
|
||||||
// 34 to account for []
|
|
||||||
listenerManager.notifyError(ServerHandshakeException("[$logInfo] Connection not allowed! Invalid tag name."))
|
listenerManager.notifyError(ServerHandshakeException("[$logInfo] Connection not allowed! Invalid tag name."))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -628,6 +636,7 @@ internal class ServerHandshake<CONNECTION : Connection>(
|
||||||
"connection"
|
"connection"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val connectionTypeCaps = connectionType.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||||
|
|
||||||
val logInfo = newConnectionDriver.pubSub.getLogInfo(logger.isDebugEnabled)
|
val logInfo = newConnectionDriver.pubSub.getLogInfo(logger.isDebugEnabled)
|
||||||
if (logger.isDebugEnabled) {
|
if (logger.isDebugEnabled) {
|
||||||
|
@ -676,9 +685,9 @@ internal class ServerHandshake<CONNECTION : Connection>(
|
||||||
pendingConnections[message.connectKey] = newConnection
|
pendingConnections[message.connectKey] = newConnection
|
||||||
|
|
||||||
if (logger.isTraceEnabled) {
|
if (logger.isTraceEnabled) {
|
||||||
logger.trace("[$logInfo] Buffered connection (${newConnection.id}) responding to handshake hello.")
|
logger.trace("[$logInfo] $connectionTypeCaps (${newConnection.id}) responding to handshake hello.")
|
||||||
} else if (logger.isDebugEnabled) {
|
} else if (logger.isDebugEnabled) {
|
||||||
logger.debug("[$logInfo] Buffered connection (${newConnection.id}) responding to handshake hello.")
|
logger.debug("[$logInfo] $connectionTypeCaps (${newConnection.id}) responding to handshake hello.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// this tells the client all the info to connect.
|
// this tells the client all the info to connect.
|
||||||
|
|
Loading…
Reference in New Issue