diff --git a/.travis.yml b/.travis.yml index d307bf10ca..c564f59dde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ matrix: script: - ./sbt ++$SCALA_VERSION "; coverage; ${PROJECT}/test; coverageReport" - "./sbt coverageAggregate && bash <(curl -s https://codecov.io/bash)" - - env: SCALA_VERSION=2.13.0-M3 PROJECT=projectJVM + - env: SCALA_VERSION=2.13.0-M4 PROJECT=projectJVM services: postgresql before_script: psql -c 'create database travis_ci_test;' -U postgres jdk: oraclejdk8 diff --git a/airframe-codec/src/main/scala/wvlet/airframe/codec/CollectionCodec.scala b/airframe-codec/src/main/scala/wvlet/airframe/codec/CollectionCodec.scala index 3e53b98d87..9457dddbf9 100644 --- a/airframe-codec/src/main/scala/wvlet/airframe/codec/CollectionCodec.scala +++ b/airframe-codec/src/main/scala/wvlet/airframe/codec/CollectionCodec.scala @@ -21,9 +21,6 @@ import wvlet.surface.{Surface, Zero} import scala.collection.JavaConverters._ import scala.collection.mutable -/** - * - */ object CollectionCodec { object BaseSeqCodec { @@ -59,7 +56,7 @@ object CollectionCodec { } } - case class SeqCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[Seq[A]] { + class SeqCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[Seq[A]] { override def pack(p: MessagePacker, v: Seq[A]): Unit = { BaseSeqCodec.pack(p, v, elementCodec) } @@ -69,7 +66,7 @@ object CollectionCodec { } } - case class IndexedSeqCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[IndexedSeq[A]] { + class IndexedSeqCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[IndexedSeq[A]] { override def pack(p: MessagePacker, v: IndexedSeq[A]): Unit = { BaseSeqCodec.pack(p, v, elementCodec) } @@ -88,7 +85,7 @@ object CollectionCodec { [error] at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:172) */ - case class ListCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[Seq[A]] { + class ListCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[Seq[A]] { override def pack(p: MessagePacker, v: Seq[A]): Unit = { BaseSeqCodec.pack(p, v, elementCodec) } @@ -123,7 +120,7 @@ object CollectionCodec { case class MapCodec[A, B](keyCodec: MessageCodec[A], valueCodec: MessageCodec[B]) extends MessageCodec[Map[A, B]] { override def pack(p: MessagePacker, m: Map[A, B]): Unit = { p.packMapHeader(m.size) - for ((k, v) <- m.seq) { + for ((k, v) <- m) { keyCodec.pack(p, k) valueCodec.pack(p, v) } @@ -148,7 +145,7 @@ object CollectionCodec { extends MessageCodec[java.util.Map[A, B]] { override def pack(p: MessagePacker, m: java.util.Map[A, B]): Unit = { p.packMapHeader(m.size) - for ((k, v) <- m.asScala.seq) { + for ((k, v) <- m.asScala) { keyCodec.pack(p, k) valueCodec.pack(p, v) } diff --git a/airframe-codec/src/main/scala/wvlet/airframe/codec/JDBCCodec.scala b/airframe-codec/src/main/scala/wvlet/airframe/codec/JDBCCodec.scala index 2c1a7446fb..48f8948048 100644 --- a/airframe-codec/src/main/scala/wvlet/airframe/codec/JDBCCodec.scala +++ b/airframe-codec/src/main/scala/wvlet/airframe/codec/JDBCCodec.scala @@ -58,7 +58,7 @@ object JDBCCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val size = u.unpackArrayHeader() for (i <- 0 until size) { u.unpackValue() diff --git a/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageCodec.scala b/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageCodec.scala index 8cab0ab280..f38223b864 100644 --- a/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageCodec.scala +++ b/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageCodec.scala @@ -21,9 +21,9 @@ import wvlet.log.LogSupport import scala.reflect.runtime.{universe => ru} import scala.util.{Failure, Success, Try} -trait MessageCodec[A] extends LogSupport { - def pack(p: MessagePacker, v: A) - def unpack(u: MessageUnpacker, v: MessageHolder) +trait MessageCodec[A] { + def pack(p: MessagePacker, v: A): Unit + def unpack(u: MessageUnpacker, v: MessageHolder): Unit // TODO add specialized methods for primitive values // def unpackInt(u:MessageUnpacker) : Int @@ -51,11 +51,11 @@ trait MessageValueCodec[A] extends MessageCodec[A] { def pack(v: A): Value def unpack(v: Value): A - override def pack(p: MessagePacker, v: A) { + override def pack(p: MessagePacker, v: A): Unit = { p.packValue(pack(v)) } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val vl = u.unpackValue() Try(unpack(vl)) match { case Success(x) => diff --git a/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageCodecFactory.scala b/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageCodecFactory.scala index c50cb114f5..a6f101521f 100644 --- a/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageCodecFactory.scala +++ b/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageCodecFactory.scala @@ -13,7 +13,7 @@ */ package wvlet.airframe.codec -import wvlet.airframe.codec.CollectionCodec._ +import CollectionCodec._ import wvlet.airframe.codec.ScalaStandardCodec.{OptionCodec, TupleCodec} import wvlet.airframe.codec.StandardCodec.EnumCodec import wvlet.log.LogSupport @@ -26,7 +26,7 @@ import scala.reflect.runtime.{universe => ru} /** * */ -class MessageCodecFactory(knownCodecs: Map[Surface, MessageCodec[_]]) extends LogSupport { +class MessageCodecFactory(knownCodecs: Map[Surface, MessageCodec[_]]) { def withCodecs(additionalCodecs: Map[Surface, MessageCodec[_]]): MessageCodecFactory = { new MessageCodecFactory(knownCodecs ++ additionalCodecs) @@ -45,7 +45,8 @@ class MessageCodecFactory(knownCodecs: Map[Surface, MessageCodec[_]]) extends Lo throw new IllegalArgumentException(s"Codec for recursive types is not supported: ${surface}") } else { val seenSet = seen + surface - trace(s"Finding MessageCodec of ${surface.dealias}") + //trace(s"Finding MessageCodec of ${surface.dealias}") + val codec = surface.dealias match { case s if s.isOption => @@ -58,22 +59,22 @@ class MessageCodecFactory(knownCodecs: Map[Surface, MessageCodec[_]]) extends Lo EnumCodec(cl) case g: GenericSurface if ReflectTypeUtil.isSeq(g.rawType) => // Seq[A] - val elementSurface = ofSurface(g.typeArgs(0), seenSet) + val elementSurface = this.ofSurface(g.typeArgs(0), seenSet) if (ReflectTypeUtil.isIndexedSeq(g.rawType)) { - IndexedSeqCodec(g.typeArgs(0), elementSurface) + new IndexedSeqCodec(g.typeArgs(0), elementSurface) } else if (ReflectTypeUtil.isList(g.rawType)) { - ListCodec(g.typeArgs(0), elementSurface) + new ListCodec(g.typeArgs(0), elementSurface) } else { - SeqCodec(g.typeArgs(0), elementSurface) + new SeqCodec(g.typeArgs(0), elementSurface) } case g: GenericSurface if ReflectTypeUtil.isJavaColleciton(g.rawType) => - JavaListCodec(ofSurface(g.typeArgs(0), seenSet)) + CollectionCodec.JavaListCodec(ofSurface(g.typeArgs(0), seenSet)) case g: GenericSurface if ReflectTypeUtil.isMap(g.rawType) => // Map[A,B] - MapCodec(ofSurface(g.typeArgs(0), seen), ofSurface(g.typeArgs(1), seenSet)) + CollectionCodec.MapCodec(ofSurface(g.typeArgs(0), seen), ofSurface(g.typeArgs(1), seenSet)) case g: GenericSurface if ReflectTypeUtil.isJavaMap(g.rawType) => // Map[A,B] - JavaMapCodec(ofSurface(g.typeArgs(0), seen), ofSurface(g.typeArgs(1), seenSet)) + CollectionCodec.JavaMapCodec(ofSurface(g.typeArgs(0), seen), ofSurface(g.typeArgs(1), seenSet)) case s if ReflectTypeUtil.isTuple(s.rawType) => // Tuple TupleCodec(surface.typeArgs.map(x => ofSurface(x, seenSet))) diff --git a/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageHolder.scala b/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageHolder.scala index 65f9a7a7b5..106fb569a1 100644 --- a/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageHolder.scala +++ b/airframe-codec/src/main/scala/wvlet/airframe/codec/MessageHolder.scala @@ -33,51 +33,51 @@ class MessageHolder { def hasError: Boolean = err.isDefined def getError: Option[Throwable] = err - def setNull { + def setNull: Unit = { dataType = NIL value = None } - def setBoolean(v: Boolean) { + def setBoolean(v: Boolean): Unit = { setValue(BOOLEAN, v) b = v } - def setByte(v: Byte) { + def setByte(v: Byte): Unit = { setValue(INTEGER, v) l = v } - def setChar(v: Char) { + def setChar(v: Char): Unit = { setValue(INTEGER, v) l = v } - def setShort(v: Short) { + def setShort(v: Short): Unit = { setValue(INTEGER, v) l = v } - def setInt(v: Int) { + def setInt(v: Int): Unit = { setValue(INTEGER, v) l = v } - def setLong(v: Long) { + def setLong(v: Long): Unit = { setValue(INTEGER, v) l = v } - def setFloat(v: Float) { + def setFloat(v: Float): Unit = { setValue(FLOAT, v) d = v } - def setDouble(v: Double) { + def setDouble(v: Double): Unit = { setValue(FLOAT, v) d = v } - def setString(v: String) { + def setString(v: String): Unit = { setValue(STRING, v) s = v } - def setObject(v: Any) { + def setObject(v: Any): Unit = { if (v == null) { setNull } else { @@ -85,7 +85,7 @@ class MessageHolder { } } - protected def setValue(dataType: DataType, v: Any) { + protected def setValue(dataType: DataType, v: Any): Unit = { this.dataType = dataType if (v != null) { value = Some(v) @@ -152,12 +152,12 @@ class MessageHolder { def getLastValue: Any = value.getOrElse(null) - def setError[A](e: Throwable) { + def setError[A](e: Throwable): Unit = { setNull err = Option(e) } - def setIncompatibleFormatException[A](codec: MessageCodec[A], message: String) { + def setIncompatibleFormatException[A](codec: MessageCodec[A], message: String): Unit = { setError(new MessageCodecException(INVALID_DATA, codec, message)) } diff --git a/airframe-codec/src/main/scala/wvlet/airframe/codec/PrimitiveCodec.scala b/airframe-codec/src/main/scala/wvlet/airframe/codec/PrimitiveCodec.scala index 1ea58b624c..8e3259e82c 100644 --- a/airframe-codec/src/main/scala/wvlet/airframe/codec/PrimitiveCodec.scala +++ b/airframe-codec/src/main/scala/wvlet/airframe/codec/PrimitiveCodec.scala @@ -68,7 +68,7 @@ object PrimitiveCodec { } override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { - def read(body: => Byte) { + def read(body: => Byte): Unit = { try { v.setByte(body) } catch { @@ -111,7 +111,7 @@ object PrimitiveCodec { } override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { - def read(body: => Char) { + def read(body: => Char): Unit = { try { v.setChar(body) } catch { @@ -154,7 +154,7 @@ object PrimitiveCodec { } override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { - def read(body: => Short) { + def read(body: => Short): Unit = { try { v.setShort(body) } catch { @@ -195,8 +195,8 @@ object PrimitiveCodec { p.packInt(v) } - override def unpack(u: MessageUnpacker, v: MessageHolder) { - def read(body: => Int) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { + def read(body: => Int): Unit = { try { v.setInt(body) } catch { @@ -238,8 +238,8 @@ object PrimitiveCodec { p.packLong(v) } - override def unpack(u: MessageUnpacker, v: MessageHolder) { - def read(body: => Long) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { + def read(body: => Long): Unit = { try { v.setLong(body) } catch { @@ -284,8 +284,8 @@ object PrimitiveCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { - def read(body: => String) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { + def read(body: => String): Unit = { try { val s = body v.setString(s) @@ -331,8 +331,8 @@ object PrimitiveCodec { p.packBoolean(v) } - override def unpack(u: MessageUnpacker, v: MessageHolder) { - def read(body: => Boolean) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { + def read(body: => Boolean): Unit = { try { val b = body v.setBoolean(b) @@ -374,8 +374,8 @@ object PrimitiveCodec { p.packFloat(v) } - override def unpack(u: MessageUnpacker, v: MessageHolder) { - def read(body: => Float) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { + def read(body: => Float): Unit = { try { v.setFloat(body) } catch { @@ -413,8 +413,8 @@ object PrimitiveCodec { p.packDouble(v) } - override def unpack(u: MessageUnpacker, v: MessageHolder) { - def read(body: => Double) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { + def read(body: => Double): Unit = { try { v.setDouble(body) } catch { @@ -453,7 +453,7 @@ object PrimitiveCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val len = u.unpackArrayHeader() val b = Array.newBuilder[Int] b.sizeHint(len) @@ -479,7 +479,7 @@ object PrimitiveCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val len = u.unpackArrayHeader() val b = Array.newBuilder[Short] b.sizeHint(len) @@ -510,7 +510,7 @@ object PrimitiveCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val len = u.unpackArrayHeader() val b = Array.newBuilder[Char] b.sizeHint(len) @@ -541,7 +541,7 @@ object PrimitiveCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val len = u.unpackArrayHeader() val b = Array.newBuilder[Long] b.sizeHint(len) @@ -567,7 +567,7 @@ object PrimitiveCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val len = u.unpackArrayHeader() val b = Array.newBuilder[Float] b.sizeHint(len) @@ -593,7 +593,7 @@ object PrimitiveCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val len = u.unpackArrayHeader() val b = Array.newBuilder[Double] b.sizeHint(len) @@ -618,7 +618,7 @@ object PrimitiveCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val len = u.unpackArrayHeader() val b = Array.newBuilder[Boolean] b.sizeHint(len) @@ -655,7 +655,7 @@ object PrimitiveCodec { } } - override def unpack(u: MessageUnpacker, v: MessageHolder) { + override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = { val len = u.unpackArrayHeader() val b = Array.newBuilder[String] b.sizeHint(len) diff --git a/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/ConnectionPool.scala b/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/ConnectionPool.scala index e2accbed1e..874f142611 100644 --- a/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/ConnectionPool.scala +++ b/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/ConnectionPool.scala @@ -51,7 +51,7 @@ trait ConnectionPool extends LogSupport { } } } - def executeUpdate(sql: String) { + def executeUpdate(sql: String): Unit = { // TODO Add update retry withConnection { conn => withResource(conn.createStatement()) { stmt => @@ -73,7 +73,7 @@ trait ConnectionPool extends LogSupport { } } - def updateWith(preparedStatement: String)(body: PreparedStatement => Unit) { + def updateWith(preparedStatement: String)(body: PreparedStatement => Unit): Unit = { withConnection { conn => withResource(conn.prepareStatement(preparedStatement)) { stmt => body(stmt) diff --git a/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/PostgreSQLConnectionPool.scala b/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/PostgreSQLConnectionPool.scala index 2d9bf16bca..5f7d8081b6 100644 --- a/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/PostgreSQLConnectionPool.scala +++ b/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/PostgreSQLConnectionPool.scala @@ -64,7 +64,7 @@ class PostgreSQLConnectionPool(val config: DbConfig, val pgConfig: PostgreSQLCon } } - def stop { + def stop: Unit = { info(s"Closing connection pool for ${config}") dataSource.close() } diff --git a/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/SQLiteConnectionPool.scala b/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/SQLiteConnectionPool.scala index dcd3069b51..e5fd0469cf 100644 --- a/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/SQLiteConnectionPool.scala +++ b/airframe-jdbc/src/main/scala/wvlet/airframe/jdbc/SQLiteConnectionPool.scala @@ -53,7 +53,7 @@ class SQLiteConnectionPool(val config: DbConfig) extends ConnectionPool with Gua } } - def stop { + def stop: Unit = { info(s"Closing connection pool for ${config}") conn.close() } diff --git a/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXMBean.scala b/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXMBean.scala index 425526e1a3..70e3641e77 100644 --- a/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXMBean.scala +++ b/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXMBean.scala @@ -171,7 +171,7 @@ object JMXMBean extends LogSupport { var seen = Set.empty[Annotation] val result = Seq.newBuilder[Annotation] - def loop(lst: Array[Annotation]) { + def loop(lst: Array[Annotation]): Unit = { for (a <- lst) { if (!seen.contains(a)) { seen += a diff --git a/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXRegistry.scala b/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXRegistry.scala index b9b4da07d0..88c120c7f0 100644 --- a/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXRegistry.scala +++ b/airframe-jmx/src/main/scala/wvlet/airframe/jmx/JMXRegistry.scala @@ -27,18 +27,18 @@ trait JMXRegistry extends JMXMBeanServerService with LogSupport { private var registeredMBean = Set.empty[ObjectName] - def register[A: ru.WeakTypeTag](obj: A) { + def register[A: ru.WeakTypeTag](obj: A): Unit = { val cl = obj.getClass val packageName = cl.getPackage.getName val name = s"${packageName}:name=${cl.getSimpleName}" register(name, obj) } - def register[A: ru.WeakTypeTag](name: String, obj: A) { + def register[A: ru.WeakTypeTag](name: String, obj: A): Unit = { register(new ObjectName(name), obj) } - def register[A: ru.WeakTypeTag](objectName: ObjectName, obj: A) { + def register[A: ru.WeakTypeTag](objectName: ObjectName, obj: A): Unit = { val mbean = JMXMBean.of(obj) mbeanServer.registerMBean(mbean, objectName) synchronized { @@ -47,11 +47,11 @@ trait JMXRegistry extends JMXMBeanServerService with LogSupport { debug(s"Registered mbean: ${mbean}") } - def unregister(name: String) { + def unregister(name: String): Unit = { mbeanServer.unregisterMBean(new ObjectName(name)) } - def unregisterAll { + def unregisterAll: Unit = { synchronized { for (name <- registeredMBean) { Try(mbeanServer.unregisterMBean(name)) match { diff --git a/airframe-log/jvm/src/main/scala/wvlet/log/LogLevelScanner.scala b/airframe-log/jvm/src/main/scala/wvlet/log/LogLevelScanner.scala index a6d15f0d13..7dcb3f19eb 100644 --- a/airframe-log/jvm/src/main/scala/wvlet/log/LogLevelScanner.scala +++ b/airframe-log/jvm/src/main/scala/wvlet/log/LogLevelScanner.scala @@ -32,7 +32,7 @@ object LogLevelScanner { * * @param file Properties file */ - def setLogLevels(file: File) { + def setLogLevels(file: File): Unit = { val logLevels = new Properties() withResource(new FileReader(file)) { in => logLevels.load(in) @@ -47,7 +47,7 @@ object LogLevelScanner { /** * Scan the default log level file only once. To periodically scan, use scheduleLogLevelScan */ - def scanLogLevels { + def scanLogLevels: Unit = { scanLogLevels(DEFAULT_LOGLEVEL_FILE_CANDIDATES) } @@ -56,14 +56,14 @@ object LogLevelScanner { * * @param loglevelFileCandidates */ - def scanLogLevels(loglevelFileCandidates: Seq[String]) { + def scanLogLevels(loglevelFileCandidates: Seq[String]): Unit = { LogLevelScanner.scan(loglevelFileCandidates, None) } /** * Run the default LogLevelScanner every 1 minute */ - def scheduleLogLevelScan { + def scheduleLogLevelScan: Unit = { scheduleLogLevelScan(LogLevelScannerConfig(DEFAULT_LOGLEVEL_FILE_CANDIDATES, Duration(1, TimeUnit.MINUTES))) } @@ -72,7 +72,7 @@ object LogLevelScanner { /** * Schedule the log level scanner with the given configuration. */ - def scheduleLogLevelScan(config: LogLevelScannerConfig) { + def scheduleLogLevelScan(config: LogLevelScannerConfig): Unit = { logLevelScanner.setConfig(config) logLevelScanner.start } @@ -80,7 +80,7 @@ object LogLevelScanner { /** * Schedule the log level scanner with the given interval */ - def scheduleLogLevelScan(duration: Duration) { + def scheduleLogLevelScan(duration: Duration): Unit = { scheduleLogLevelScan(LogLevelScannerConfig(DEFAULT_LOGLEVEL_FILE_CANDIDATES, duration)) } @@ -89,7 +89,7 @@ object LogLevelScanner { * the next log scan schedule. This is for reusing the thread if scheduleLogLevelScan is called again in a short duration, and * reduce the overhead of creating a new thread. */ - def stopScheduledLogLevelScan { + def stopScheduledLogLevelScan: Unit = { logLevelScanner.stop } @@ -154,7 +154,7 @@ private[log] class LogLevelScanner extends Guard { scanner => private[log] val scanCount = new AtomicLong(0) def getConfig: LogLevelScannerConfig = config.get() - def setConfig(config: LogLevelScannerConfig) { + def setConfig(config: LogLevelScannerConfig): Unit = { guard { val prev = this.config.get() if (prev.logLevelFileCandidates != config.logLevelFileCandidates) { @@ -167,7 +167,7 @@ private[log] class LogLevelScanner extends Guard { scanner => private val state = new AtomicReference[ScannerState](STOPPED) - def start { + def start: Unit = { guard { state.compareAndSet(STOPPING, RUNNING) if (state.compareAndSet(STOPPED, RUNNING)) { @@ -177,7 +177,7 @@ private[log] class LogLevelScanner extends Guard { scanner => } } - def stop { + def stop: Unit = { guard { state.set(STOPPING) } @@ -186,7 +186,7 @@ private[log] class LogLevelScanner extends Guard { scanner => private var lastScheduledMillis: Option[Long] = None private var lastScannedMillis: Option[Long] = None - private def run { + private def run: Unit = { // We need to exit here so that the thread can be automatically discarded after the scan interval has passed // Otherwise, the thread remains in the classloader(s) if used for running test cases while (!state.compareAndSet(STOPPING, STOPPED)) { diff --git a/airframe-log/jvm/src/main/scala/wvlet/log/LogRotationHandler.scala b/airframe-log/jvm/src/main/scala/wvlet/log/LogRotationHandler.scala index c3c6e46f80..dd2f323d08 100644 --- a/airframe-log/jvm/src/main/scala/wvlet/log/LogRotationHandler.scala +++ b/airframe-log/jvm/src/main/scala/wvlet/log/LogRotationHandler.scala @@ -134,7 +134,7 @@ class LogRotationHandler(fileName: String, } } - private def recoverTempFiles(logPath: String) { + private def recoverTempFiles(logPath: String): Unit = { // Recover orphaned temp files for { logPathFile <- Option(new File(logPath).getParentFile) diff --git a/airframe-log/jvm/src/test/scala/wvlet/log/AsyncHandlerTest.scala b/airframe-log/jvm/src/test/scala/wvlet/log/AsyncHandlerTest.scala index ca678c73f3..1f0a68f9cf 100644 --- a/airframe-log/jvm/src/test/scala/wvlet/log/AsyncHandlerTest.scala +++ b/airframe-log/jvm/src/test/scala/wvlet/log/AsyncHandlerTest.scala @@ -9,8 +9,6 @@ import wvlet.log.io.Timer */ class AsyncHandlerTest extends Spec with Timer { - import CompatParColls.Converters._ - "AsynHandler" should { "start background thread" in { val buf = new BufferedLogHandler(BareFormatter) @@ -54,22 +52,24 @@ class AsyncHandlerTest extends Spec with Timer { // sync sl.resetHandler(handler) - block("async") { - for (i <- (0 until N).par) { - al.info(s"hello world: ${i}") - } - } - - block("sync") { - for (i <- (0 until N).par) { - sl.info(s"hello world: ${i}") - } - } + // Temporarly removed to handle missing parallel collection issue of Scala 2.13.0-M4 + //import CompatParColls.Converters._ +// block("async") { +// for (i <- (0 until N).par) { +// al.info(s"hello world: ${i}") +// } +// } +// +// block("sync") { +// for (i <- (0 until N).par) { +// sl.info(s"hello world: ${i}") +// } +// } } } } val t = result(0) // heavy handler result - t("async").averageWithoutMinMax should be < t("sync").averageWithoutMinMax + //t("async").averageWithoutMinMax should be < t("sync").averageWithoutMinMax } } } diff --git a/airframe-log/shared/src/main/scala/wvlet/log/LogEnvBase.scala b/airframe-log/shared/src/main/scala/wvlet/log/LogEnvBase.scala index 6581ff108f..951621ec7e 100644 --- a/airframe-log/shared/src/main/scala/wvlet/log/LogEnvBase.scala +++ b/airframe-log/shared/src/main/scala/wvlet/log/LogEnvBase.scala @@ -24,13 +24,13 @@ private[log] trait LogEnvBase { /** * Scan the default log level file only once. To periodically scan, use scheduleLogLevelScan */ - def scanLogLevels + def scanLogLevels: Unit /** * Scan the specified log level file * * @param loglevelFileCandidates */ - def scanLogLevels(loglevelFileCandidates: Seq[String]) + def scanLogLevels(loglevelFileCandidates: Seq[String]): Unit } diff --git a/airframe-log/shared/src/main/scala/wvlet/log/LogFormat.scala b/airframe-log/shared/src/main/scala/wvlet/log/LogFormat.scala index e3d7c08119..e83dbad208 100644 --- a/airframe-log/shared/src/main/scala/wvlet/log/LogFormat.scala +++ b/airframe-log/shared/src/main/scala/wvlet/log/LogFormat.scala @@ -51,7 +51,7 @@ object LogFormatter { * * @param filter */ - def setStackTraceFilter(filter: String => Boolean) { + def setStackTraceFilter(filter: String => Boolean): Unit = { stackTraceFilter = filter } diff --git a/airframe-log/shared/src/main/scala/wvlet/log/LogMacros.scala b/airframe-log/shared/src/main/scala/wvlet/log/LogMacros.scala index 8a5a5acd87..497728811e 100644 --- a/airframe-log/shared/src/main/scala/wvlet/log/LogMacros.scala +++ b/airframe-log/shared/src/main/scala/wvlet/log/LogMacros.scala @@ -30,14 +30,14 @@ private[log] object LogMacros { import c.universe._ - val disabledLevels: Set[c.universe.Tree] = { + val disabledLevels: Set[c.Tree] = { val SettingsPrefix = "wvlet.log.disable." - val TRACE: c.universe.Tree = q"wvlet.log.LogLevel.TRACE" - val DEBUG: c.universe.Tree = q"wvlet.log.LogLevel.DEBUG" - val INFO: c.universe.Tree = q"wvlet.log.LogLevel.INFO" - val WARN: c.universe.Tree = q"wvlet.log.LogLevel.WARN" - val ERROR: c.universe.Tree = q"wvlet.log.LogLevel.ERROR" + val TRACE: c.Tree = q"wvlet.log.LogLevel.TRACE" + val DEBUG: c.Tree = q"wvlet.log.LogLevel.DEBUG" + val INFO: c.Tree = q"wvlet.log.LogLevel.INFO" + val WARN: c.Tree = q"wvlet.log.LogLevel.WARN" + val ERROR: c.Tree = q"wvlet.log.LogLevel.ERROR" c.settings .collect { case s if s startsWith SettingsPrefix => s stripPrefix SettingsPrefix } @@ -51,33 +51,31 @@ private[log] object LogMacros { .getOrElse(Set.empty) } - private def disabled(level: c.universe.Tree): Boolean = disabledLevels.exists(_.equalsStructure(level)) + private def disabled(level: c.Tree): Boolean = disabledLevels.exists(_.equalsStructure(level)) def source = { val pos = c.enclosingPosition q"wvlet.log.LogSource(${pos.source.path}, ${pos.source.file.name}, ${pos.line}, ${pos.column})" } - def log(level: c.universe.Tree, message: c.universe.Tree): c.universe.Tree = { + def log(level: c.Tree, message: c.universe.Tree): c.Tree = { val logger = q"this.logger" - if (disabled(level)) q"()" else q"if ($logger.isEnabled($level)) $logger.log(${level}, ${source}, ${message})" + if (disabled(level)) q"{}" else q"if ($logger.isEnabled($level)) $logger.log(${level}, ${source}, ${message})" } - def logWithCause(level: c.universe.Tree, message: c.universe.Tree, cause: c.universe.Tree): c.universe.Tree = { + def logWithCause(level: c.Tree, message: c.Tree, cause: c.Tree): c.Tree = { val logger = q"this.logger" - if (disabled(level)) q"()" + if (disabled(level)) q"{}" else q"if ($logger.isEnabled($level)) $logger.logWithCause(${level}, ${source}, ${message}, ${cause})" } - def logMethod(level: c.universe.Tree, message: c.universe.Tree): c.universe.Tree = { - if (disabled(level)) q"()" + def logMethod(level: c.Tree, message: c.universe.Tree): c.Tree = { + if (disabled(level)) q"{}" else q"if (${c.prefix}.isEnabled($level)) ${c.prefix}.log(${level}, ${source}, ${message})" } - def logMethodWithCause(level: c.universe.Tree, - message: c.universe.Tree, - cause: c.universe.Tree): c.universe.Tree = { - if (disabled(level)) q"()" + def logMethodWithCause(level: c.Tree, message: c.Tree, cause: c.Tree): c.Tree = { + if (disabled(level)) q"{}" else q"if (${c.prefix}.isEnabled($level)) ${c.prefix}.logWithCause(${level}, ${source}, ${message}, ${cause})" } } diff --git a/airframe-log/shared/src/main/scala/wvlet/log/Logger.scala b/airframe-log/shared/src/main/scala/wvlet/log/Logger.scala index 6dc80e3f77..970f7539c2 100644 --- a/airframe-log/shared/src/main/scala/wvlet/log/Logger.scala +++ b/airframe-log/shared/src/main/scala/wvlet/log/Logger.scala @@ -79,15 +79,15 @@ class Logger(private val name: String, getLogLevelOf(_log) } - def setLogLevel(l: LogLevel) { + def setLogLevel(l: LogLevel): Unit = { _log.setLevel(l.jlLevel) } - def setFormatter(formatter: LogFormatter) { + def setFormatter(formatter: LogFormatter): Unit = { resetHandler(new ConsoleLogHandler(formatter)) } - def resetHandler(h: Handler) { + def resetHandler(h: Handler): Unit = { clearHandlers _log.addHandler(h) setUseParentHandlers(false) @@ -97,20 +97,20 @@ class Logger(private val name: String, Option(wrapped.getParent).map(x => Logger(x.getName)) } - def addHandler(h: Handler) { + def addHandler(h: Handler): Unit = { _log.addHandler(h) } - def setUseParentHandlers(use: Boolean) { + def setUseParentHandlers(use: Boolean): Unit = { _log.setUseParentHandlers(use) } - def clear { + def clear: Unit = { clearHandlers resetLogLevel } - def clearHandlers { + def clearHandlers: Unit = { for (lst <- Option(_log.getHandlers); h <- lst) { _log.removeHandler(h) } @@ -119,7 +119,7 @@ class Logger(private val name: String, /** * Clean up all handlers including this and parent, ancestor loggers */ - def clearAllHandlers { + def clearAllHandlers: Unit = { var l: Option[Logger] = Some(this) while (l.isDefined) { l.map { x => @@ -133,7 +133,7 @@ class Logger(private val name: String, wrapped.getHandlers.toSeq } - def resetLogLevel { + def resetLogLevel: Unit = { _log.setLevel(null) } @@ -141,16 +141,16 @@ class Logger(private val name: String, _log.isLoggable(level.jlLevel) } - def log(record: LogRecord) { + def log(record: LogRecord): Unit = { record.setLoggerName(name) _log.log(record) } - def log(level: LogLevel, source: LogSource, message: Any) { + def log(level: LogLevel, source: LogSource, message: Any): Unit = { log(LogRecord(level, source, formatLog(message))) } - def logWithCause(level: LogLevel, source: LogSource, message: Any, cause: Throwable) { + def logWithCause(level: LogLevel, source: LogSource, message: Any, cause: Throwable): Unit = { log(LogRecord(level, source, formatLog(message), cause)) } @@ -217,19 +217,19 @@ object Logger { def getDefaultLogLevel: LogLevel = rootLogger.getLogLevel - def setDefaultLogLevel(level: LogLevel) { + def setDefaultLogLevel(level: LogLevel): Unit = { rootLogger.setLogLevel(level) } - def setDefaultFormatter(formatter: LogFormatter) { + def setDefaultFormatter(formatter: LogFormatter): Unit = { rootLogger.resetHandler(new ConsoleLogHandler(formatter)) } - def setDefaultHandler(handler: jl.Handler) { + def setDefaultHandler(handler: jl.Handler): Unit = { rootLogger.resetHandler(handler) } - def resetDefaultLogLevel { + def resetDefaultLogLevel: Unit = { rootLogger.resetLogLevel } @@ -242,7 +242,7 @@ object Logger { * * @param logLevels */ - def setLogLevels(logLevels: Properties) { + def setLogLevels(logLevels: Properties): Unit = { for ((loggerName, level) <- logLevels.asScala) { LogLevel.unapply(level) match { case Some(lv) => diff --git a/airframe-log/shared/src/main/scala/wvlet/log/io/StopWatch.scala b/airframe-log/shared/src/main/scala/wvlet/log/io/StopWatch.scala index b6b350f705..af674f60f6 100644 --- a/airframe-log/shared/src/main/scala/wvlet/log/io/StopWatch.scala +++ b/airframe-log/shared/src/main/scala/wvlet/log/io/StopWatch.scala @@ -303,7 +303,7 @@ class StopWatch { * getElapsedTime or getIntervalTime will measure the time interval * beginning from this method call. */ - def reset = { + def reset: Unit = { lastSystemTime = System.nanoTime() elapsedTimeAccumulated = 0L } @@ -331,7 +331,7 @@ class StopWatch { /** * Resume the timer */ - def resume { + def resume: Unit = { if (state == State.RUNNING) { return } diff --git a/airframe-log/shared/src/test/scala/wvlet/log/Spec.scala b/airframe-log/shared/src/test/scala/wvlet/log/Spec.scala index b8a4d8389d..8f9c3a856c 100644 --- a/airframe-log/shared/src/test/scala/wvlet/log/Spec.scala +++ b/airframe-log/shared/src/test/scala/wvlet/log/Spec.scala @@ -19,19 +19,19 @@ trait Spec extends WordSpec with Matchers with BeforeAndAfter with BeforeAndAfte super.afterAll() } - private[log] object CompatParColls { - val Converters = { - import Compat._ - - { - import scala.collection.parallel._ - - CollectionConverters - } - } - - object Compat { - object CollectionConverters - } - } +// private[log] object CompatParColls { +// val Converters = { +// import Compat._ +// +// { +// import scala.collection.parallel._ +// +// CollectionConverters +// } +// } +// +// object Compat { +// object CollectionConverters +// } +// } } diff --git a/airframe-metrics/shared/src/main/scala/wvlet/airframe/metrics/DataSize.scala b/airframe-metrics/shared/src/main/scala/wvlet/airframe/metrics/DataSize.scala index d18b526048..8e784d87be 100644 --- a/airframe-metrics/shared/src/main/scala/wvlet/airframe/metrics/DataSize.scala +++ b/airframe-metrics/shared/src/main/scala/wvlet/airframe/metrics/DataSize.scala @@ -78,7 +78,7 @@ case class DataSize(value: Double, unit: DataSizeUnit) extends Comparable[DataSi } object DataSize { - private[metrics] def checkState(preCondition: Boolean, errorMessage: String) { + private[metrics] def checkState(preCondition: Boolean, errorMessage: String): Unit = { if (!preCondition) { throw new IllegalStateException(errorMessage) } diff --git a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Packer.scala b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Packer.scala index 825e28df36..76c9cb1320 100644 --- a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Packer.scala +++ b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Packer.scala @@ -50,18 +50,18 @@ object Packer { elems.foreach(packValue(cursor, _)) case m @ Value.MapValue(entries) => packMapHeader(cursor, m.size) - entries.seq.foreach { x => + entries.toIndexedSeq.foreach { x => packValue(cursor, x._1) packValue(cursor, x._2) } } } - def packNil(cursor: WriteCursor) { + def packNil(cursor: WriteCursor): Unit = { cursor.writeByte(NIL) } - def packBoolean(cursor: WriteCursor, v: Boolean) { + def packBoolean(cursor: WriteCursor, v: Boolean): Unit = { cursor.writeByte(if (v) TRUE else FALSE) } @@ -99,7 +99,7 @@ object Packer { cursor.writeByteAndDouble(FLOAT64, v) } - def packByte(cursor: WriteCursor, v: Byte) { + def packByte(cursor: WriteCursor, v: Byte): Unit = { if (v < -(1 << 5)) { packINT8(cursor, v) } else { @@ -107,7 +107,7 @@ object Packer { } } - def packShort(cursor: WriteCursor, v: Short) { + def packShort(cursor: WriteCursor, v: Short): Unit = { if (v < -(1 << 5)) { if (v < -(1 << 7)) { packINT16(cursor, v) @@ -123,7 +123,7 @@ object Packer { } } - def packInt(cursor: WriteCursor, r: Int) { + def packInt(cursor: WriteCursor, r: Int): Unit = { if (r < -(1 << 5)) { if (r < -(1 << 15)) { packINT32(cursor, r) @@ -143,7 +143,7 @@ object Packer { } } - def packLong(cursor: WriteCursor, v: Long) { + def packLong(cursor: WriteCursor, v: Long): Unit = { if (v < -(1L << 5)) { if (v < -(1L << 15)) { if (v < -(1L << 31)) @@ -168,7 +168,7 @@ object Packer { packUINT64(cursor, v) } - def packBigInteger(cursor: WriteCursor, bi: BigInteger) { + def packBigInteger(cursor: WriteCursor, bi: BigInteger): Unit = { if (bi.bitLength <= 63) { packLong(cursor, bi.longValue) } else if (bi.bitLength == 64 && bi.signum == 1) { @@ -178,11 +178,11 @@ object Packer { } } - def packFloat(cursor: WriteCursor, v: Float) { + def packFloat(cursor: WriteCursor, v: Float): Unit = { packFLOAT32(cursor, v) } - def packDouble(cursor: WriteCursor, v: Double) { + def packDouble(cursor: WriteCursor, v: Double): Unit = { packFLOAT64(cursor, v) } @@ -198,7 +198,7 @@ object Packer { } private val NANOS_PER_SECOND = 1000000000L - def packTimestampEpochSecond(cursor: WriteCursor, epochSecond: Long, nanoAdjustment: Int) { + def packTimestampEpochSecond(cursor: WriteCursor, epochSecond: Long, nanoAdjustment: Int): Unit = { val sec = Math.addExact(epochSecond, Math.floorDiv(nanoAdjustment, NANOS_PER_SECOND)) val nsec = Math.floorMod(nanoAdjustment.toLong, NANOS_PER_SECOND) @@ -216,7 +216,7 @@ object Packer { } } - private[msgpack] def packTimestamp32(cursor: WriteCursor, sec: Int) { // timestamp 32 in fixext 4 + private[msgpack] def packTimestamp32(cursor: WriteCursor, sec: Int): Unit = { // timestamp 32 in fixext 4 cursor.ensureCapacity(6) cursor.writeByte(FIXEXT4) @@ -224,7 +224,7 @@ object Packer { cursor.writeInt(sec) } - private[msgpack] def packTimestamp64(cursor: WriteCursor, data64: Long) { // timestamp 64 in fixext 8 + private[msgpack] def packTimestamp64(cursor: WriteCursor, data64: Long): Unit = { // timestamp 64 in fixext 8 cursor.ensureCapacity(10) cursor.writeByte(FIXEXT8) @@ -232,7 +232,7 @@ object Packer { cursor.writeLong(data64) } - private[msgpack] def packTimestamp96(cursor: WriteCursor, sec: Long, nsec: Int) { // timestamp 96 in ext 8 + private[msgpack] def packTimestamp96(cursor: WriteCursor, sec: Long, nsec: Int): Unit = { // timestamp 96 in ext 8 cursor.ensureCapacity(15) cursor.writeByte(EXT8) @@ -242,7 +242,7 @@ object Packer { cursor.writeLong(sec) } - def packRawStringHeader(cursor: WriteCursor, len: Int) { + def packRawStringHeader(cursor: WriteCursor, len: Int): Unit = { if (len < (1 << 5)) { cursor.writeByte((FIXSTR_PREFIX | len).toByte) } else if (len < (1 << 8)) { @@ -254,7 +254,7 @@ object Packer { } } - def packArrayHeader(cursor: WriteCursor, arraySize: Int) { + def packArrayHeader(cursor: WriteCursor, arraySize: Int): Unit = { if (arraySize < 0) throw new IllegalArgumentException("array size must be >= 0") @@ -266,7 +266,7 @@ object Packer { cursor.writeByteAndInt(ARRAY32, arraySize) } - def packMapHeader(cursor: WriteCursor, mapSize: Int) { + def packMapHeader(cursor: WriteCursor, mapSize: Int): Unit = { if (mapSize < 0) throw new IllegalArgumentException("map size must be >= 0") @@ -283,7 +283,7 @@ object Packer { packExtTypeHeader(cursor, extTypeHeader.extType, extTypeHeader.byteLength) } - def packExtTypeHeader(cursor: WriteCursor, extType: Byte, payloadLen: Int) { + def packExtTypeHeader(cursor: WriteCursor, extType: Byte, payloadLen: Int): Unit = { if (payloadLen < (1 << 8)) { if (payloadLen > 0 && (payloadLen & (payloadLen - 1)) == 0) { // check whether dataLen == 2^x if (payloadLen == 1) @@ -314,7 +314,7 @@ object Packer { } } - def packBinaryHeader(cursor: WriteCursor, len: Int) { + def packBinaryHeader(cursor: WriteCursor, len: Int): Unit = { if (len < (1 << 8)) { cursor.writeByteAndByte(BIN8, len.toByte) } else if (len < (1 << 16)) { @@ -324,11 +324,11 @@ object Packer { } } - def writePayload(cursor: WriteCursor, v: Array[Byte]) { + def writePayload(cursor: WriteCursor, v: Array[Byte]): Unit = { cursor.writeBytes(v) } - def writePayload(cursor: WriteCursor, v: Array[Byte], vOffset: Int, length: Int) { + def writePayload(cursor: WriteCursor, v: Array[Byte], vOffset: Int, length: Int): Unit = { cursor.writeBytes(v, vOffset, length) } } diff --git a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/StreamUnpacker.scala b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/StreamUnpacker.scala index 3ecc3bb0f1..a9b2c55265 100644 --- a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/StreamUnpacker.scala +++ b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/StreamUnpacker.scala @@ -48,9 +48,9 @@ trait StreamUnpacker { def unpackValue: Value - def skipPayload(numBytes: Int) - def readPayload(dst: Array[Byte]) - def readPayload(dst: Array[Byte], offset: Int, length: Int) + def skipPayload(numBytes: Int): Unit + def readPayload(dst: Array[Byte]): Unit + def readPayload(dst: Array[Byte], offset: Int, length: Int): Unit def readPayload(length: Int): Array[Byte] } diff --git a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Unpacker.scala b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Unpacker.scala index 76417ab0f0..de1031b1b9 100644 --- a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Unpacker.scala +++ b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Unpacker.scala @@ -85,7 +85,7 @@ object Unpacker { } } - def unpackNil(cursor: ReadCursor) { + def unpackNil(cursor: ReadCursor): Unit = { cursor.readByte match { case Code.NIL => // OK case other => @@ -570,7 +570,7 @@ object Unpacker { private val EMPTY_STRING: String = "" - private[spi] def unexpected(expectedCode: ValueType, actual: Byte) = { + private[spi] def unexpected(expectedCode: ValueType, actual: Byte): Nothing = { val f = MessageFormat.of(actual) if (f == MessageFormat.NEVER_USED) { throw new MessageException(NEVER_USED_FORMAT, s"Expected ${expectedCode}, but found 0xC1 (NEVER_USED) byte") diff --git a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Value.scala b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Value.scala index c8a73ce188..a7c1e3d3d6 100644 --- a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Value.scala +++ b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/Value.scala @@ -233,7 +233,7 @@ object Value { override def writeTo(packer: StreamPacker): Unit = { packer.packMapHeader(entries.size) // Ensure using non-parallel collection - entries.seq.foreach { x => + entries.toIndexedSeq.foreach { x => x._1.writeTo(packer) x._2.writeTo(packer) } diff --git a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/WriteCursor.scala b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/WriteCursor.scala index fbfb7365f7..ae2bc0fe9f 100644 --- a/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/WriteCursor.scala +++ b/airframe-msgpack/src/main/scala/wvlet/airframe/msgpack/spi/WriteCursor.scala @@ -27,27 +27,27 @@ case class WriteCursor(var buf: WriteBuffer, var position: Int) { buf.ensureCapacity(position + offset, size) } - def writeByte(b: Byte) { + def writeByte(b: Byte): Unit = { offset += buf.writeByte(position + offset, b) } - def writeByteAndByte(a: Byte, b: Byte) { + def writeByteAndByte(a: Byte, b: Byte): Unit = { offset += buf.writeByteAndByte(position + offset, a, b) } - def writeByteAndShort(a: Byte, b: Short) { + def writeByteAndShort(a: Byte, b: Short): Unit = { offset += buf.writeByteAndShort(position + offset, a, b) } - def writeByteAndInt(a: Byte, b: Int) { + def writeByteAndInt(a: Byte, b: Int): Unit = { offset += buf.writeByteAndInt(position + offset, a, b) } - def writeByteAndLong(a: Byte, b: Long) { + def writeByteAndLong(a: Byte, b: Long): Unit = { offset += buf.writeByteAndLong(position + offset, a, b) } - def writeByteAndFloat(a: Byte, b: Float) { + def writeByteAndFloat(a: Byte, b: Float): Unit = { offset += buf.writeByteAndFloat(position + offset, a, b) } def writeByteAndDouble(a: Byte, b: Double): Unit = { diff --git a/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/MessageFormatTest.scala b/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/MessageFormatTest.scala index 8008a98dde..3bb8f108c7 100644 --- a/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/MessageFormatTest.scala +++ b/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/MessageFormatTest.scala @@ -23,7 +23,7 @@ import scala.util.Random class MessageFormatTest extends AirframeSpec with Timer { "MessageFormat" should { "cover all byte codes" in { - def checkV(b: Byte, tpe: ValueType) { + def checkV(b: Byte, tpe: ValueType): Unit = { try MessageFormat.of(b).valueType shouldBe tpe catch { case e: TestFailedException => @@ -32,11 +32,11 @@ class MessageFormatTest extends AirframeSpec with Timer { } } - def checkF(b: Byte, f: MessageFormat) { + def checkF(b: Byte, f: MessageFormat): Unit = { MessageFormat.of(b) shouldBe f } - def check(b: Byte, tpe: ValueType, f: MessageFormat) { + def check(b: Byte, tpe: ValueType, f: MessageFormat): Unit = { checkV(b, tpe) checkF(b, f) } diff --git a/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/ValueTest.scala b/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/ValueTest.scala index 2f23547260..52bb564359 100644 --- a/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/ValueTest.scala +++ b/airframe-msgpack/src/test/scala/wvlet/airframe/msgpack/spi/ValueTest.scala @@ -152,8 +152,19 @@ class ValueTest extends AirframeSpec with PropertyChecks { m(StringValue("name")) shouldBe StringValue("mitsu") val json = """{"id":1001,"name":"mitsu","address":["xxx-xxxx","yyy-yyyy"]}""" - // TODO check the equality as json objects instead of using direct json string comparison - check(m, ValueType.MAP, json, json) + // check the equality as json objects instead of using direct json string comparison + jsonEq(m.toJson, json) + jsonEq(m.toString, json) + } + + def jsonEq(a: String, b: String): Unit = { + // Perform rough comparison of JSON data + def sanitize(s: String): Seq[String] = { + s.replaceAll("""[\{\}\[\]\"]""", "") + .split("[,:]") + .sorted + } + sanitize(a) shouldBe sanitize(b) } "check appropriate range for integers" in { diff --git a/airframe-opts/src/main/scala/wvlet/airframe/opts/Launcher.scala b/airframe-opts/src/main/scala/wvlet/airframe/opts/Launcher.scala index e28a1b1015..998739ff3a 100755 --- a/airframe-opts/src/main/scala/wvlet/airframe/opts/Launcher.scala +++ b/airframe-opts/src/main/scala/wvlet/airframe/opts/Launcher.scala @@ -155,11 +155,11 @@ class Launcher(surface: Surface) extends LogSupport { result getOrElse mainObj } - def printHelp { + def printHelp: Unit = { printHelp(OptionParser(surface), Zero.zeroOf(surface).asInstanceOf[AnyRef]) } - def printHelp(p: OptionParser, obj: AnyRef) { + def printHelp(p: OptionParser, obj: AnyRef): Unit = { trace("print usage") p.printUsage diff --git a/airframe-opts/src/main/scala/wvlet/airframe/opts/OptionParser.scala b/airframe-opts/src/main/scala/wvlet/airframe/opts/OptionParser.scala index 65c5d9a327..ce8daed971 100755 --- a/airframe-opts/src/main/scala/wvlet/airframe/opts/OptionParser.scala +++ b/airframe-opts/src/main/scala/wvlet/airframe/opts/OptionParser.scala @@ -115,7 +115,7 @@ case class CLOption(path: Path, annot: option, override val param: Parameter) ex // validate prefixes val prefixes: Seq[String] = - for (p <- annot.prefix.split(",")) yield { + for (p <- annot.prefix.split(",").toSeq) yield { if (p.startsWith("--") || p.startsWith("-")) { p } else { @@ -241,7 +241,7 @@ object ClassOptionSchema extends LogSupport { } } - new ClassOptionSchema(surface, o.result, a.result().sortBy(x => x.argIndex)) + new ClassOptionSchema(surface, o.result.toSeq, a.result().toSeq.sortBy(x => x.argIndex)) } } diff --git a/airframe-spec/shared/src/main/scala/wvlet/airframe/AirframeSpec.scala b/airframe-spec/shared/src/main/scala/wvlet/airframe/AirframeSpec.scala index 05fe7fba45..edbde284fa 100644 --- a/airframe-spec/shared/src/main/scala/wvlet/airframe/AirframeSpec.scala +++ b/airframe-spec/shared/src/main/scala/wvlet/airframe/AirframeSpec.scala @@ -41,20 +41,22 @@ trait AirframeSpec Logger.stopScheduledLogLevelScan s } - - private[airframe] object CompatParColls { - val Converters = { - import Compat._ - - { - import scala.collection.parallel._ - - CollectionConverters - } - } - - object Compat { - object CollectionConverters - } - } +// Temporarily removed for Scala 2.13.0-M4, which doesn't have parallel collection yet. +// https://github.com/scala/scala-parallel-collections/issues/41 +// +// private[airframe] object CompatParColls { +// val Converters = { +// import Compat._ +// +// { +// import scala.collection.parallel._ +// +// CollectionConverters +// } +// } +// +// object Compat { +// object CollectionConverters +// } +// } } diff --git a/airframe-stream/src/main/scala/wvlet/airframe/stream/spi/SQLModel.scala b/airframe-stream/src/main/scala/wvlet/airframe/stream/spi/SQLModel.scala index a9e976104c..320a89791a 100644 --- a/airframe-stream/src/main/scala/wvlet/airframe/stream/spi/SQLModel.scala +++ b/airframe-stream/src/main/scala/wvlet/airframe/stream/spi/SQLModel.scala @@ -58,7 +58,7 @@ object SQLModel { object QName { def apply(s: String): QName = { // TODO handle quotation - QName(s.split("\\.")) + QName(s.split("\\.").toSeq) } } diff --git a/airframe-stream/src/main/scala/wvlet/airframe/stream/sql/parser/SQLInterpreter.scala b/airframe-stream/src/main/scala/wvlet/airframe/stream/sql/parser/SQLInterpreter.scala index 6908b2d116..3356484c58 100644 --- a/airframe-stream/src/main/scala/wvlet/airframe/stream/sql/parser/SQLInterpreter.scala +++ b/airframe-stream/src/main/scala/wvlet/airframe/stream/sql/parser/SQLInterpreter.scala @@ -68,6 +68,7 @@ class SQLInterpreter extends SqlBaseBaseVisitor[SQLModel] with LogSupport { .map { x => visitSortItem(x) } + .toSeq Sort(inputRelation, sortKeys) } @@ -131,9 +132,10 @@ class SQLInterpreter extends SqlBaseBaseVisitor[SQLModel] with LogSupport { } } - val selectItem: Seq[SelectItem] = ctx.selectItem().asScala.map { x => - visit(x).asInstanceOf[SelectItem] - } + val selectItem: Seq[SelectItem] = ctx + .selectItem().asScala.map { x => + visit(x).asInstanceOf[SelectItem] + }.toSeq val withAggregation = { if (ctx.groupBy() == null) { @@ -155,6 +157,7 @@ class SQLInterpreter extends SqlBaseBaseVisitor[SQLModel] with LogSupport { .map { expression(_) } + .toSeq val g = Aggregate(withFilter.get, selectItem, groupByKeys) @@ -173,7 +176,7 @@ class SQLInterpreter extends SqlBaseBaseVisitor[SQLModel] with LogSupport { private def fromClause(ctx: QuerySpecificationContext): Option[Relation] = { Option(ctx.relation()) .flatMap { r => - val relations = r.asScala + val relations = r.asScala.toSeq relations.size match { case 1 => relations.map(x => visit(x).asInstanceOf[Relation]).headOption @@ -204,7 +207,7 @@ class SQLInterpreter extends SqlBaseBaseVisitor[SQLModel] with LogSupport { } override def visitQualifiedName(ctx: QualifiedNameContext): QName = { - QName(ctx.identifier().asScala.map(_.getText)) + QName(ctx.identifier().asScala.map(_.getText).toSeq) } override def visitSelectAll(ctx: SelectAllContext): SelectItem = { diff --git a/airframe-surface/jvm/src/main/scala/wvlet/surface/reflect/ObjectBuilder.scala b/airframe-surface/jvm/src/main/scala/wvlet/surface/reflect/ObjectBuilder.scala index b2555496c5..12e81592a3 100644 --- a/airframe-surface/jvm/src/main/scala/wvlet/surface/reflect/ObjectBuilder.scala +++ b/airframe-surface/jvm/src/main/scala/wvlet/surface/reflect/ObjectBuilder.scala @@ -124,7 +124,7 @@ trait StandardBuilder extends GenericBuilder with LogSupport { holder.getOrElseUpdate(name, ArrayHolder(new ArrayBuffer[Any])).asInstanceOf[ArrayHolder] } - def set(path: Path, value: Any) { + def set(path: Path, value: Any): Unit = { if (path.isEmpty) { // do nothing } else { diff --git a/airframe-surface/jvm/src/test/scala/wvlet/surface/SurfaceJVMTest.scala b/airframe-surface/jvm/src/test/scala/wvlet/surface/SurfaceJVMTest.scala index 60c4b15929..3ce3e84adf 100644 --- a/airframe-surface/jvm/src/test/scala/wvlet/surface/SurfaceJVMTest.scala +++ b/airframe-surface/jvm/src/test/scala/wvlet/surface/SurfaceJVMTest.scala @@ -16,7 +16,7 @@ package wvlet.surface import java.time.temporal.ChronoUnit import java.io.File -import scala.collection.parallel.ParSeq + import wvlet.surface object SurfaceJVMTest { @@ -28,7 +28,9 @@ class SurfaceJVMTest extends SurfaceSpec { "SurfaceJVM" should { "resolve ParSeq" in { - check(surface.of[ParSeq[Int]], "ParSeq[Int]") + pending + //import scala.collection.parallel.ParSeq + //check(surface.of[ParSeq[Int]], "ParSeq[Int]") } "resolve java util type" in { diff --git a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/Tablet.scala b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/Tablet.scala index 9a5e30e71c..12a468cc17 100644 --- a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/Tablet.scala +++ b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/Tablet.scala @@ -8,7 +8,7 @@ import wvlet.airframe.tablet.text.{CSVTabletPrinter, JSONTabletPrinter, TSVTable import scala.reflect.runtime.{universe => ru} trait Record { - def pack(packer: MessagePacker) + def pack(packer: MessagePacker): Unit def unpacker: MessageUnpacker } @@ -60,7 +60,7 @@ trait TabletWriter[A] extends AutoCloseable { def write(record: Record): A - override def close() {} + override def close(): Unit = {} } object Tablet { diff --git a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/jdbc/ResultSetReader.scala b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/jdbc/ResultSetReader.scala index 42aa42a195..e226369442 100644 --- a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/jdbc/ResultSetReader.scala +++ b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/jdbc/ResultSetReader.scala @@ -26,7 +26,7 @@ class ResultSetReader(rs: ResultSet) extends TabletReader with LogSupport { val b = MessagePack.newDefaultBufferPacker() b.packArrayHeader(columns) - def pack[A, U](v: A, packBody: A => U) { + def pack[A, U](v: A, packBody: A => U): Unit = { if (rs.wasNull()) b.packNil() else { diff --git a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/jdbc/SQLObjectMapper.scala b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/jdbc/SQLObjectMapper.scala index 27dca1d14b..d059442ad5 100644 --- a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/jdbc/SQLObjectMapper.scala +++ b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/jdbc/SQLObjectMapper.scala @@ -57,10 +57,10 @@ object SQLObjectMapper extends LogSupport { def quote(s: String) = s"'${s}'" - def insertRecord[A: ru.TypeTag](conn: Connection, tableName: String, obj: A) { + def insertRecord[A: ru.TypeTag](conn: Connection, tableName: String, obj: A): Unit = { val schema = SurfaceFactory.of[A] val colSize = schema.params.size - val tuple = ("?" * colSize).mkString(", ") + val tuple = ("?" * colSize).toSeq.mkString(", ") withResource(conn.prepareStatement(s"insert into ${tableName} values(${tuple})")) { prep => for ((p, i) <- schema.params.zipWithIndex) yield { val v = p.get(obj).asInstanceOf[AnyRef] diff --git a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/msgpack/MessagePackTablet.scala b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/msgpack/MessagePackTablet.scala index c13bbbdb45..28af280e11 100644 --- a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/msgpack/MessagePackTablet.scala +++ b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/msgpack/MessagePackTablet.scala @@ -61,7 +61,7 @@ class MessagePackTabletReader(unpacker: MessageUnpacker) extends TabletReader wi * */ class MessagePackTabletWriter(packer: MessagePacker) extends TabletWriter[Unit] { - def write(r: Record) { + def write(r: Record): Unit = { r.pack(packer) } diff --git a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/JSONCodec.scala b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/JSONCodec.scala index 1c6d6ed954..b338ed73fe 100644 --- a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/JSONCodec.scala +++ b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/JSONCodec.scala @@ -28,7 +28,7 @@ object JSONCodec extends MessageCodec[String] { packJsonValue(p, j) } - private def packJsonValue(p: MessagePacker, v: JValue) { + private def packJsonValue(p: MessagePacker, v: JValue): Unit = { v match { case jo: JObject => val map = jo.obj diff --git a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/ObjectJSONCodec.scala b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/ObjectJSONCodec.scala index 3e40440ece..0fce2c62f5 100644 --- a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/ObjectJSONCodec.scala +++ b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/ObjectJSONCodec.scala @@ -32,7 +32,7 @@ case class ObjectJSONCodec[A](codec: ObjectCodec[A]) { JSONObjectPrinter.write(MessagePackRecord(bytes)) } - def fromJSON(json: String, v: MessageHolder) { + def fromJSON(json: String, v: MessageHolder): Unit = { val jsonMessage = MessagePackRecord(JSONCodec.packToBytes(json)) codec.unpack(jsonMessage.unpacker, v) } diff --git a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/PrettyPrint.scala b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/PrettyPrint.scala index 79c1309f4e..d19ef5f188 100644 --- a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/PrettyPrint.scala +++ b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/PrettyPrint.scala @@ -15,11 +15,11 @@ object PrettyPrint extends LogSupport { private val defaultPrinter = new PrettyPrint() - def show[A: ru.TypeTag](seq: Seq[A], limit: Int = 20) { + def show[A: ru.TypeTag](seq: Seq[A], limit: Int = 20): Unit = { defaultPrinter.pp(seq.take(limit)) } - def pp[A: ru.TypeTag](seq: Seq[A]) { + def pp[A: ru.TypeTag](seq: Seq[A]): Unit = { info(defaultPrinter.pf(seq).mkString("\n")) } @@ -57,19 +57,19 @@ object PrettyPrint extends LogSupport { } class PrettyPrint(codec: Map[Surface, MessageCodec[_]] = Map.empty, maxColWidth: Int = 100) extends LogSupport { - def show[A: ru.TypeTag](seq: Seq[A], limit: Int = 20) { + def show[A: ru.TypeTag](seq: Seq[A], limit: Int = 20): Unit = { showRaw(SurfaceFactory.of[A], seq, limit) } - def showRaw[A](elementSurface: Surface, seq: Seq[A], limit: Int = 20) { + def showRaw[A](elementSurface: Surface, seq: Seq[A], limit: Int = 20): Unit = { ppRaw(elementSurface, seq.take(limit)) } - def pp[A: ru.TypeTag](seq: Seq[A]) { + def pp[A: ru.TypeTag](seq: Seq[A]): Unit = { ppRaw(SurfaceFactory.of[A], seq) } - def ppRaw[A](surface: Surface, seq: Seq[A]) { + def ppRaw[A](surface: Surface, seq: Seq[A]): Unit = { println(pfRaw(surface, seq).mkString("\n")) } diff --git a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/TextTabletReader.scala b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/TextTabletReader.scala index 4db43f78ec..d843b4c7eb 100644 --- a/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/TextTabletReader.scala +++ b/airframe-tablet/src/main/scala/wvlet/airframe/tablet/text/TextTabletReader.scala @@ -21,7 +21,7 @@ import wvlet.airframe.tablet.{Record, StringArrayRecord, TabletReader} import scala.io.Source trait TextTabletReader extends TabletReader { - def close + def close: Unit } /** @@ -30,7 +30,7 @@ trait TextTabletReader extends TabletReader { class TSVTabletReader(source: Source) extends TextTabletReader { private val lines = source.getLines() - override def close { + override def close: Unit = { source.close() } @@ -41,7 +41,7 @@ class TSVTabletReader(source: Source) extends TextTabletReader { } else { val line = lines.next() val cols = line.split("\t").map(x => TSVRecordFormatter.unescape(x)) - Some(StringArrayRecord(if (cols == null) Seq.empty[String] else cols)) + Some(StringArrayRecord(if (cols == null) Seq.empty[String] else cols.toIndexedSeq)) } } } @@ -56,7 +56,7 @@ class CSVTabletReader(source: Source) extends TextTabletReader { // TODO handle CSV properly private val lines: Iterator[Seq[String]] = source.getLines().map(line => line.split(",").toSeq) - override def close { + override def close: Unit = { source.close() } diff --git a/airframe/jvm/src/main/scala/wvlet/airframe/JSR250LifeCycleExecutor.scala b/airframe/jvm/src/main/scala/wvlet/airframe/JSR250LifeCycleExecutor.scala index 1513d1db43..13e977ee16 100644 --- a/airframe/jvm/src/main/scala/wvlet/airframe/JSR250LifeCycleExecutor.scala +++ b/airframe/jvm/src/main/scala/wvlet/airframe/JSR250LifeCycleExecutor.scala @@ -23,7 +23,7 @@ import scala.reflect.ClassTag class MethodCallHook[A](val surface: Surface, obj: A, method: jl.reflect.Method) extends LifeCycleHook { override def toString: String = s"MethodCallHook for [${surface}]" - def execute { + def execute: Unit = { method.invoke(obj) } } diff --git a/airframe/shared/src/main/scala/wvlet/airframe/AirframeSession.scala b/airframe/shared/src/main/scala/wvlet/airframe/AirframeSession.scala index 1c70552a3e..060443e10a 100644 --- a/airframe/shared/src/main/scala/wvlet/airframe/AirframeSession.scala +++ b/airframe/shared/src/main/scala/wvlet/airframe/AirframeSession.scala @@ -57,7 +57,7 @@ private[airframe] class AirframeSession(sessionName: Option[String], def name: String = sessionName.getOrElse(f"session:${hashCode()}%x") // Initialize eager singleton, pre-defined instances, eager singleton providers - private[airframe] def init { + private[airframe] def init: Unit = { debug(s"[${name}] Initializing. Stage:${stage}") val production = stage == Stage.PRODUCTION if (production) { diff --git a/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleEventHandler.scala b/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleEventHandler.scala index d7a565d48a..13afbebae2 100644 --- a/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleEventHandler.scala +++ b/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleEventHandler.scala @@ -19,11 +19,11 @@ import wvlet.surface.Surface * */ trait LifeCycleEventHandler { - def onInit(lifeCycleManager: LifeCycleManager, t: Surface, injectee: AnyRef) {} - def beforeStart(lifeCycleManager: LifeCycleManager) {} - def afterStart(lifeCycleManager: LifeCycleManager) {} - def beforeShutdown(lifeCycleManager: LifeCycleManager) {} - def afterShutdown(lifeCycleManager: LifeCycleManager) {} + def onInit(lifeCycleManager: LifeCycleManager, t: Surface, injectee: AnyRef): Unit = {} + def beforeStart(lifeCycleManager: LifeCycleManager): Unit = {} + def afterStart(lifeCycleManager: LifeCycleManager): Unit = {} + def beforeShutdown(lifeCycleManager: LifeCycleManager): Unit = {} + def afterShutdown(lifeCycleManager: LifeCycleManager): Unit = {} def andThen(next: LifeCycleEventHandler): LifeCycleEventHandler = new LifeCycleEventHandlerChain(this, next) def wraps(child: LifeCycleEventHandler): LifeCycleEventHandler = new LifeCycleEventHandlerPair(this, child) diff --git a/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleHook.scala b/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleHook.scala index 405d820861..bf35ad0d58 100644 --- a/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleHook.scala +++ b/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleHook.scala @@ -23,7 +23,7 @@ trait LifeCycleHook { case class EventHookHolder[A](surface: Surface, obj: A, hook: A => Any) extends LifeCycleHook with LogSupport { override def toString: String = s"hook for [$surface]" - def execute { + def execute: Unit = { hook(obj) } } diff --git a/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleManager.scala b/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleManager.scala index 13fa06b055..07e1f3119a 100644 --- a/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleManager.scala +++ b/airframe/shared/src/main/scala/wvlet/airframe/LifeCycleManager.scala @@ -34,18 +34,18 @@ class LifeCycleManager(eventHandler: LifeCycleEventHandler) extends LogSupport { private val state = new AtomicReference[LifeCycleStage](INIT) def currentState: LifeCycleStage = state.get() - private[airframe] def onInit(t: Surface, injectee: AnyRef) { + private[airframe] def onInit(t: Surface, injectee: AnyRef): Unit = { eventHandler.onInit(this, t, injectee) } private var session: Session = _ - private[airframe] def setSession(s: Session) { + private[airframe] def setSession(s: Session): Unit = { session = s } def sessionName: String = session.name - def start { + def start: Unit = { if (!state.compareAndSet(INIT, STARTING)) { throw new IllegalStateException(s"LifeCycle is already starting") } @@ -56,7 +56,7 @@ class LifeCycleManager(eventHandler: LifeCycleEventHandler) extends LogSupport { eventHandler.afterStart(this) } - def shutdown { + def shutdown: Unit = { if (state.compareAndSet(STARTED, STOPPING) || state.compareAndSet(INIT, STOPPING) || state.compareAndSet(STARTING, STOPPING)) { eventHandler.beforeShutdown(this) @@ -79,7 +79,7 @@ class LifeCycleManager(eventHandler: LifeCycleEventHandler) extends LogSupport { session.getBindingOf(t).exists(_.forSingleton) || session.hasSingletonOf(t) } - def addInitHook(h: LifeCycleHook) { + def addInitHook(h: LifeCycleHook): Unit = { debug(s"Add init hook: ${h.surface}") val canRunHook = !(isSingletonType(h.surface) && initializedSingleton.contains(h.surface)) if (canRunHook) { @@ -88,13 +88,13 @@ class LifeCycleManager(eventHandler: LifeCycleEventHandler) extends LogSupport { } } - def addInjectHook(h: LifeCycleHook) { + def addInjectHook(h: LifeCycleHook): Unit = { debug(s"Add inject hook: ${h.surface}") // Run immediately h.execute } - def addStartHook(h: LifeCycleHook) { + def addStartHook(h: LifeCycleHook): Unit = { synchronized { val canAddHook = !(isSingletonType(h.surface) && startHook.exists(_.surface == h.surface)) if (canAddHook) { @@ -109,7 +109,7 @@ class LifeCycleManager(eventHandler: LifeCycleEventHandler) extends LogSupport { } } - def addPreShutdownHook(h: LifeCycleHook) { + def addPreShutdownHook(h: LifeCycleHook): Unit = { synchronized { val canAddHook = !(isSingletonType(h.surface) && preShutdownHook.exists(_.surface == h.surface)) if (canAddHook) { @@ -119,7 +119,7 @@ class LifeCycleManager(eventHandler: LifeCycleEventHandler) extends LogSupport { } } - def addShutdownHook(h: LifeCycleHook) { + def addShutdownHook(h: LifeCycleHook): Unit = { synchronized { val canAddHook = !(isSingletonType(h.surface) && shutdownHook.exists(_.surface == h.surface)) if (canAddHook) { @@ -141,19 +141,19 @@ object LifeCycleManager { object ShowLifeCycleLog extends LifeCycleEventHandler { private val logger = Logger.of[LifeCycleManager] - override def beforeStart(lifeCycleManager: LifeCycleManager) { + override def beforeStart(lifeCycleManager: LifeCycleManager): Unit = { logger.info(s"[${lifeCycleManager.sessionName}] Life cycle is starting ...") } - override def afterStart(lifeCycleManager: LifeCycleManager) { + override def afterStart(lifeCycleManager: LifeCycleManager): Unit = { logger.info(s"[${lifeCycleManager.sessionName}] ======= STARTED =======") } - override def beforeShutdown(lifeCycleManager: LifeCycleManager) { + override def beforeShutdown(lifeCycleManager: LifeCycleManager): Unit = { logger.info(s"[${lifeCycleManager.sessionName}] Stopping life cycle ...") } - override def afterShutdown(lifeCycleManager: LifeCycleManager) { + override def afterShutdown(lifeCycleManager: LifeCycleManager): Unit = { logger.info(s"[${lifeCycleManager.sessionName}] Life cycle has stopped.") } } diff --git a/airframe/shared/src/main/scala/wvlet/airframe/Session.scala b/airframe/shared/src/main/scala/wvlet/airframe/Session.scala index 818cae15f9..78cd2fe240 100644 --- a/airframe/shared/src/main/scala/wvlet/airframe/Session.scala +++ b/airframe/shared/src/main/scala/wvlet/airframe/Session.scala @@ -80,9 +80,9 @@ trait Session extends AutoCloseable { } } - def start { lifeCycleManager.start } - def shutdown { lifeCycleManager.shutdown } - override def close() { shutdown } + def start: Unit = { lifeCycleManager.start } + def shutdown: Unit = { lifeCycleManager.shutdown } + override def close(): Unit = { shutdown } private[airframe] def getBindingOf(t: Surface): Option[Binding] private[airframe] def hasSingletonOf(t: Surface): Boolean diff --git a/build.sbt b/build.sbt index 8ad2dca606..3a73858662 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ import sbtcrossproject.{crossProject, CrossType} -val SCALA_2_13 = "2.13.0-M3" +val SCALA_2_13 = "2.13.0-M4" val SCALA_2_12 = "2.12.6" val SCALA_2_11 = "2.11.11" @@ -11,9 +11,9 @@ val targetScalaVersions = Seq( SCALA_2_11 ) -val SCALATEST_VERSION = "3.0.5-M1" +val SCALATEST_VERSION = "3.0.6-SNAP1" val SCALACHECK_VERSION = "1.14.0" -val SCALA_PARSER_COMBINATOR_VERSION = "1.1.0" +val SCALA_PARSER_COMBINATOR_VERSION = "1.1.1" val SQLITE_JDBC_VERSION = "3.21.0.1" // For using Scala 2.12 in sbt @@ -52,7 +52,7 @@ val buildSettings = Seq[Setting[_]]( crossPaths := true, publishMavenStyle := true, logBuffered in Test := false, - scalacOptions ++= Seq("-feature", "-deprecation"), + scalacOptions ++= Seq("-feature", "-deprecation"), // ,"-Ytyper-debug"), sonatypeProfileName := "org.wvlet", licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html")), homepage := Some(url("https://github.com/wvlet/airframe")), @@ -343,7 +343,7 @@ lazy val log = libraryDependencies ++= Seq( "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided", "org.scalatest" %%% "scalatest" % SCALATEST_VERSION % "test" - ) ++ parallelCollection(scalaVersion.value) + ) ) .jvmSettings( libraryDependencies ++= Seq("ch.qos.logback" % "logback-core" % "1.2.3") @@ -382,7 +382,7 @@ lazy val airframeSpec = description := "Airframe spec test base library", libraryDependencies ++= Seq( "org.scalatest" %%% "scalatest" % SCALATEST_VERSION - ) ++ parallelCollection(scalaVersion.value) + ) ) .jsSettings(jsBuildSettings) .dependsOn(log) @@ -398,7 +398,7 @@ lazy val msgpack = .settings( name := "airframe-msgpack", description := "Pure-Scala MessagePack library", - libraryDependencies ++= parallelCollection(scalaVersion.value) ++ Seq( + libraryDependencies ++= Seq( "org.scalacheck" %%% "scalacheck" % SCALACHECK_VERSION % "test" ) ) @@ -436,7 +436,7 @@ lazy val tablet = // scala-csv doesn't support Scala 2.13 yet // "com.github.tototoshi" %% "scala-csv" % "1.3.5", // For JSON parser - "org.json4s" %% "json4s-native" % "3.5.3", + "org.json4s" %% "json4s-native" % "3.5.4", // For ColumnType parser "org.scala-lang.modules" %% "scala-parser-combinators" % SCALA_PARSER_COMBINATOR_VERSION, "org.scalacheck" %% "scalacheck" % SCALACHECK_VERSION % "test", diff --git a/project/build.properties b/project/build.properties index 4ad0d6751b..8c5a1be692 100755 --- a/project/build.properties +++ b/project/build.properties @@ -12,4 +12,4 @@ # limitations under the License. # -sbt.version=1.1.5 +sbt.version=1.2.0-RC2