Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running TcpServer example #159

Closed
klangner opened this issue Jan 24, 2020 · 1 comment · Fixed by #191
Closed

Error when running TcpServer example #159

klangner opened this issue Jan 24, 2020 · 1 comment · Fixed by #191
Labels
bug Something isn't working

Comments

@klangner
Copy link
Contributor

When I try to run TcpServer example with the command:

sbt "examples/runMain zio.keeper.example.TcpServer"

I got an error:

Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
	at zio.logging.slf4j.Slf4jLogger.$anonfun$logger$1(Slf4jLogger.scala:18)
	at zio.internal.FiberContext.evaluateNow(FiberContext.scala:333)
	at zio.internal.FiberContext.$anonfun$fork$2(FiberContext.scala:655)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.joran.spi.JoranException
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at sbt.internal.ManagedClassLoader.findClass(ManagedClassLoader.java:98)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 10 more

Looks like logger lib is missing, but on the pther hand I can start Node1 without any problems and it logs.

@mijicd mijicd added the bug Something isn't working label Jan 24, 2020
@pshemass
Copy link
Contributor

pshemass commented Feb 4, 2020

if you add fork : =true to settings of example module in build.sbt this will go away. However this particular example doesn't work because our strict scalac option that detect dead code. Should look like below.

object TcpServer extends zio.App {
  import zio._
  import zio.duration._
  import zio.keeper.transport._

  val localEnvironment = ZIO.environment[zio.ZEnv] @@ enrichWith[Logging[String]](
    new Slf4jLogger.Live {

      override def formatMessage(msg: String): ZIO[Any, Nothing, String] =
        ZIO.succeed(msg)
    }
  )

  override def run(args: List[String]) =
    localEnvironment >>> (for {
      tcp       <- tcp.tcpTransport(10.seconds, 10.seconds)
      localHost <- InetAddress.localHost.orDie
      publicAddress <- SocketAddress
                        .inetSocketAddress(localHost, 8010)
                        .orDie
      console <- ZIO.environment[Console]
      handler = (channel: ChannelOut) => {
        for {
          data <- channel.read
          _    <- putStrLn(new String(data.toArray))
          _    <- channel.send(data)
        } yield ()
      }.forever
        .catchAll(ex => putStrLn("error: " + ex.msg))
        .provide(console)

      _ <- putStrLn("public address: " + publicAddress.toString())
      _ <- bind(publicAddress)(handler)
            .provide(tcp)
            .use(ch => ZIO.never.ensuring(ch.close.ignore))
    } yield ()).ignore.as(0)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants