Skip to content

Commit

Permalink
Revert "drop compat code for java 8"
Browse files Browse the repository at this point in the history
This reverts commit e8404ef.
  • Loading branch information
pm47 committed Jan 27, 2022
1 parent c848cfe commit bb10ef7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import fr.acinq.eclair.crypto.ChaCha20Poly1305.ChaCha20Poly1305Error
import fr.acinq.eclair.crypto.Noise._
import fr.acinq.eclair.remote.EclairInternalsSerializer.RemoteTypes
import fr.acinq.eclair.wire.protocol.{AnnouncementSignatures, RoutingMessage}
import fr.acinq.eclair.{Diagnostics, FSMDiagnosticActorLogging, Logs}
import fr.acinq.eclair.{Diagnostics, FSMDiagnosticActorLogging, Logs, getSimpleClassName}
import scodec.bits.ByteVector
import scodec.{Attempt, Codec, DecodeResult}

Expand Down Expand Up @@ -277,7 +277,7 @@ class TransportHandler[T: ClassTag](keyPair: KeyPair, rs: Option[ByteVector], co
stateData match {
case normal: NormalData[_] =>
// NB: we deduplicate on the class name: each class will appear once but there may be many instances (less verbose and gives debug hints)
log.info("stopping (unackedReceived={} unackedSent={})", normal.unackedReceived.keys.map(_.getClass.getSimpleName).toSet.mkString(","), normal.unackedSent.map(_.getClass.getSimpleName))
log.info("stopping (unackedReceived={} unackedSent={})", normal.unackedReceived.keys.map(getSimpleClassName).toSet.mkString(","), normal.unackedSent.map(getSimpleClassName))
case _ =>
log.info("stopping")
}
Expand Down
5 changes: 5 additions & 0 deletions eclair-core/src/main/scala/fr/acinq/eclair/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,9 @@ package object eclair {
// @formatter:on
}

/**
* Apparently .getClass.getSimpleName can crash java 8 with a "Malformed class name" error
*/
def getSimpleClassName(o: Any): String = o.getClass.getName.split("\\$").last

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ScodecSerializer[T <: AnyRef](override val identifier: Int, codec: Codec[T
}

/** we don't rely on the manifest to provide backward compatibility, we will use dedicated codecs instead */
override def manifest(o: AnyRef): String = o.getClass.getSimpleName
override def manifest(o: AnyRef): String = fr.acinq.eclair.getSimpleClassName(o)

override def toBinary(o: AnyRef): Array[Byte] = codec.encode(o.asInstanceOf[T]).require.toByteArray

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package fr.acinq.eclair.router

import fr.acinq.bitcoin.{BtcDouble, MilliBtcDouble, SatoshiLong}
import fr.acinq.eclair.MilliSatoshi
import fr.acinq.eclair.router.Router.GossipDecision
import fr.acinq.eclair.wire.protocol.ChannelUpdate
import fr.acinq.eclair.{MilliSatoshi, getSimpleClassName}
import kamon.Kamon
import kamon.metric.{Counter, MeasurementUnit}

Expand Down Expand Up @@ -64,7 +64,7 @@ object Monitoring {

def gossipResult(decision: GossipDecision): Counter = decision match {
case _: GossipDecision.Accepted => GossipResult.withTag("result", "accepted")
case rejected: GossipDecision.Rejected => GossipResult.withTag("result", "rejected").withTag("reason", rejected.getClass.getSimpleName)
case rejected: GossipDecision.Rejected => GossipResult.withTag("result", "rejected").withTag("reason", getSimpleClassName(rejected))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import fr.acinq.eclair.crypto.TransportHandler
import fr.acinq.eclair.io.Peer.PeerRoutingMessage
import fr.acinq.eclair.router.Router._
import fr.acinq.eclair.wire.protocol._
import fr.acinq.eclair.{FSMDiagnosticActorLogging, Logs, ShortChannelId}
import fr.acinq.eclair.{FSMDiagnosticActorLogging, Logs, ShortChannelId, getSimpleClassName}
import kamon.Kamon
import kamon.metric.Counter

Expand Down Expand Up @@ -224,15 +224,15 @@ object FrontRouter {
private val RouterEvent = Kamon.counter("front.router.event")

// @formatter:off
def gossipDropped(ann: AnnouncementMessage): Counter = Gossip.withTag("status", "dropped").withTag("type", ann.getClass.getSimpleName)
def gossipStashed(ann: AnnouncementMessage): Counter = Gossip.withTag("status", "stashed").withTag("type", ann.getClass.getSimpleName)
def gossipStashedRebroadcast(ann: AnnouncementMessage): Counter = Gossip.withTag("status", "stashed-rebroadcast").withTag("type", ann.getClass.getSimpleName)
def gossipForwarded(ann: AnnouncementMessage): Counter = Gossip.withTag("status", "forwarded").withTag("type", ann.getClass.getSimpleName)
def gossipDropped(ann: AnnouncementMessage): Counter = Gossip.withTag("status", "dropped").withTag("type", getSimpleClassName(ann))
def gossipStashed(ann: AnnouncementMessage): Counter = Gossip.withTag("status", "stashed").withTag("type", getSimpleClassName(ann))
def gossipStashedRebroadcast(ann: AnnouncementMessage): Counter = Gossip.withTag("status", "stashed-rebroadcast").withTag("type", getSimpleClassName(ann))
def gossipForwarded(ann: AnnouncementMessage): Counter = Gossip.withTag("status", "forwarded").withTag("type", getSimpleClassName(ann))

def gossipAccepted(ann: AnnouncementMessage): Counter = GossipResult.withTag("result", "accepted").withTag("type", ann.getClass.getSimpleName)
def gossipRejected(ann: AnnouncementMessage, reason: GossipDecision.Rejected): Counter = GossipResult.withTag("result", "rejected").withTag("reason", reason.getClass.getSimpleName).withTag("type", ann.getClass.getSimpleName)
def gossipAccepted(ann: AnnouncementMessage): Counter = GossipResult.withTag("result", "accepted").withTag("type", getSimpleClassName(ann))
def gossipRejected(ann: AnnouncementMessage, reason: GossipDecision.Rejected): Counter = GossipResult.withTag("result", "rejected").withTag("reason", getSimpleClassName(reason)).withTag("type", getSimpleClassName(ann))

def routerEvent(event: NetworkEvent): Counter = RouterEvent.withTag("type", event.getClass.getSimpleName)
def routerEvent(event: NetworkEvent): Counter = RouterEvent.withTag("type", getSimpleClassName(event))
// @formatter:on
}

Expand Down

0 comments on commit bb10ef7

Please sign in to comment.