Giter VIP home page Giter VIP logo

mod-lang-scala's People

Contributors

angeloh avatar edgarchan avatar galderz avatar mchunkytrunk avatar narigo avatar nfmelendez avatar pidster avatar purplefox avatar raniejade avatar saschaschmidt avatar swilliams-pivotal avatar vietj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mod-lang-scala's Issues

Create an ADMIN.md file

This file should provide information to administrators of the mod-lang-scala repository on how to handle Git pull requests, how do to releases...etc.

Provide testtools package for Scala

pleeeeeeeeeaaaaaaaaaaaaaaasssssssssseeeeeeeeeeee! :)

In the tests you need end up using the Java API for vertx.eventBus().send() for example.

I rewrote TestVerticle in Scala, but that doesn't help, because of the @RunWith(JavaClassRunner.class) which yields an error if the class is not extending the o.v.testtools.TestVerticle.

So please, if possible, somehow help me use all the lang-scala features in the tests, too ;)

Complete Vert.x Scala API

Reach parity with Vert.x Java testsuite in terms of API testing. This should be used to detect holes in the Scala API.

@pidster Volunteered to provide a list of APIs missing and @normanmaurer was gonna verify what's missing in the Scala API too on an earlier meeting we had on IRC.

verticle extends with org.vertx.scala.platform.Verticle failed to deploy

When testing verticle extends with org.vertx.scala.platform.Verticle, it would throw an exception.

java.lang.ClassCastException: verticles.SockJSVerticle cannot be cast to org.vertx.java.platform.Verticle

Here is my deploy code:

container.deployVerticle(
  classOf[SockJSVerticle].getName,
  (ar: AsyncResult[String]) => {

  })

Here is my verticle code

import org.vertx.scala.platform.Verticle

class SockJSVerticle extends Verticle {

   override def start(future: Future[Void]):Unit = {
    start()
   }
} 

gradle build fails on OSX

Finally got some small time to test the Scala plugin

In the small time I had to play with it I noticed that from the command line the "gradle build" will fail. After doing a "gradle eclipse", setting the project in Eclipse and after converting the project to Gradle nature, then I was able to have it working and playing with it.

The gradle version used was 1.4

Buffer implementation in scala

Implement org.vertx.java.core.buffer.Buffer in scala, so we can write more idiomatic code.
We can append to a buffer like this:

val buffer: Buffer = ...
buffer << "Hello World!"

Probably a good implementation would be using implicit conversion from Buffer to a RichBuffer.

Add DNS support

Current master of vert.x does ship a DNSClient API. We should also provide it here.

Module io.vertx~lang-scala~0.2.0 contains an empty mod.json file

Hello,

first, I appreciate what vert-x / mod-lang-scala team is doing. It is great!

Now, when I try to deploy my Scala module i get strange error (on linux, centos 6.4)

environment variables are set: VERTX_HOME and VERTX_MODS

--> my langs.properties:
scala=io.vertxlang-scala0.2.0:org.vertx.scala.platform.impl.ScalaVerticleFactory
.scala=scala

--> my mod.json:
{
// Scala verticle
"main":"scala:demo.Sender",
}

---> Error:

[root@OSOS-platform2 usr]# vertx runMod demoSender0.1 -ha
Starting clustering...
No cluster-host specified so using address 192.168.1.104
A quorum has been obtained. Any deployments waiting on a quorum will now be deployed
Downloading io.vertxlang-scala0.2.0. Please wait...
Downloading 100%
Module io.vertxlang-scala0.2.0 contains an empty mod.json file // it hangs here forever !

What I'm doing wrong ?

Best Regards,
Kresimir

Typing messages and related stuff

FWIW, instead of having a matcher over the different types for each send(), publish(), reply() methods, it would be much nicer to have type classes. I'm not sure HOW to do it, but I'm sure that it can and should be done with advanced Scala typing-fu.

Related to that: The send method restricts the reply handler to the same type as the sent message. This changed in Vert.x 2.0 and if someone comes up with a solution for the type classes, it should be easy to do without introducing even more of these pattern matching over types.

Support Vert.x compiling Scala examples for you

Vert.x Java examples can be compiled and run on the fly. The Scala modules should have a similar option that allows Scala examples to be compiled on the fly and run. This would provide parity with Vert.x Java examples.

It's unclear whether this is already supported in ScalaVerticleFactory, so the first thing to do here would be to verify whether this already works. This class already has hooks with the Scala interpreter, so it'd be good to come up with an example/test that verifies this works as expected. For example, take one of the examples and see if you can run it with similar instructions to these:

vertx run MyApp.scala

If the code in the Scala verticle is not sufficient, one of the options to achieve this is to hook an SBT based Scala compiler, just like IntelliJ IDEA currently does.

vertx timer() function should return timer id

https://github.com/vert-x/mod-lang-scala/blob/master/src/main/scala/org/vertx/scala/core/package.scala#L75

Vertx Java would return time id to caller. This behavior is disappeared in scala version. The timer id is important for caller because it can be used to track what timers are running and scheduled at user's system.

The workaround for this is just use Java version for now like this.
https://github.com/vert-x/mod-lang-scala/blob/master/src/main/scala/org/vertx/scala/core/package.scala#L75

Use traits for SSL and Common TCP Stuff

Traits can be used for the common SSL and TCP stuff that's used by NetServer/NetClient and HttpServer/HttpClient to reduce unnecessary code duplication.

See TCPSupport/SSLSupport in the Java API for the equivalent in Java.

SBT plugin for Vert.x

A separate module containing an SBT Vert.x plugin is needed. This would enable Vert.x Scala applications to be run directly from the SBT console.

Just like Spray (via their SBT Revolver plugin) or Play 2 web apps, a subtask here would be to be able to be able to detect changes in the source files and be able to recompile and restart the Vert.x app on the fly.

Exception ErasedValueType(org.vertx.scala.core.package.Vertx)

While compiling this class,

class SockJSVerticle extends Verticle {

override def start(future: Future[Void]):Unit = {
start()
val ws = "/ws"
var defaultPort = 8080
val port = Play.maybeApplication.map(_.configuration.getInt("vertx.sockjs.port").get).getOrElse(defaultPort)
val server = vertx.createHttpServer
val permitted = new JsonArray()
permitted.add(new JsonObject()) // Let everything through
val sockServer = vertx.createSockJSServer(server).bridge(new JsonObject().putString("prefix", ws), permitted, permitted).asInstanceOf[SockJSServer]
// install a test app to echo
sockServer.installApp(new JsonObject().putString("prefix", "/echoapp")) {
(sock: SockJSSocket) => {
Pump.newPump(sock, sock).start()
}
}
server.listen(port, { ar =>
if (ar.succeeded()) {
future.setResult(null)
}
else {
future.setFailure(ar.cause())
}
})
}

}

I got this exception:

[ant:scalac] error: bad symbolic reference. A signature in Configuration.class refers to term typesafe
[ant:scalac] in package com which is not available.
[ant:scalac] It may be completely missing from the current classpath, or the version on
[ant:scalac] the classpath might be incompatible with the version used when compiling Configuration.class.
[ant:scalac] error:
[ant:scalac] while compiling: /Users/macbookpro/workspaces/vertx/src/main/scala/verticles/SockJSVerticle.scala
[ant:scalac] during phase: erasure
[ant:scalac] == Expanded type of tree ==
[ant:scalac]
[ant:scalac] ErasedValueType(org.vertx.scala.core.package.Vertx)

Combine ScalaHttpTests

There are two instances of ScalaHttpTest in different packages, these should be renamed, moved or combined.

Use JsonObject instead of scala.util.parsing.JSON

Here is an example to reading out some values from the container config:

This is how it looks now:

val config = container.config().obj

connection = config.get("connection").map(_.toString().toLowerCase) match {
  case Some("postgresql") => "postgresql"
  case Some("mysql") => "mysql"
  case None => "postgresql"
  case Some(x) => throw new IllegalArgumentException("unknown connection type " + x)
}

val address = config.getOrElse("address", "campudus.asyncdb")

This is how it looks like when I'm using the Vertx JsonObject:

val config = Option(new JsonObject(container.config().toString())).getOrElse(new JsonObject)

connection = config.getString("connection", "postgresql").toLowerCase match {
  case "postgresql" => "postgresql"
  case "mysql" => "mysql"
  case x => throw new IllegalArgumentException("unknown connection type " + x)
}

val address = config.getString("address", "campudus.asyncdb")

I think it makes sense to use the JsonObject provided by Vertx. It's more user-friendly right now and it would save a lot of conversions. If you want to provide a more Scala-ish API, I'd prefer a wrapper around Vertx' JsonObject and a toMap() method which returns an immutable map.

Scala script error

Can't start scala script with newest master. I tried running this code with "vertx run Server.scala":

import org.vertx.scala.core.net.NetSocket
import org.vertx.scala.core.streams.Pump

vertx.createNetServer().connectHandler({ socket: NetSocket =>
    Pump.createPump(socket, socket).start
}).listen(1234)

and got this error:

Try running file:/D:/FH/_Campudus_Praktika/Server.scala as script
<console>:7: error: object scala is not a member of package org.vertx
       import org.vertx.scala._, org.vertx.scala.core._, org.vertx.scala.core.http._
                        ^
<console>:7: error: object scala is not a member of package org.vertx
       import org.vertx.scala._, org.vertx.scala.core._, org.vertx.scala.core.http._
                                           ^
<console>:7: error: object scala is not a member of package org.vertx
       import org.vertx.scala._, org.vertx.scala.core._, org.vertx.scala.core.http._
                                                                   ^
Not a script, try running file:/D:/FH/_Campudus_Praktika/Server.scala as class
D:\FH\_Campudus_Praktika\Server.scala:4: error: expected class or object definition
vertx.createNetServer().connectHandler({ socket: NetSocket =>
^

Instead of Java Vertx Futures, hand over Promises

This would enable us to write:

def start(p: Promise[Unit]) = {
  doSomethingAsyncReturningAFuture() map { result =>
    p.success()
  } recover { ex =>
    logger.error("problem at start up!", ex)
    p.failure()
  }
}

a) We wouldn't need the Future class at all.
b) It would be more towards the Scala-way
c) Users cannot overwrite the Futures failure handler during startup. This is safer than the Java API approach (hoping the dev doesn't do stupid things ;)).

Release 0.1.0

I don't like relying on SNAPSHOT versions, so it would be great if the current master could just be set to 0.1.0 and be released. :)

It would invite others to try out the scala mod, too. And as you can see in the mod-mysql-postgresql, it already works for a few tasks. ;)

Consider function currying

We should apply function currying, where posssible, to enable more pleasant syntax, e.g.:

vertx.setPeriodic(1000) { timerID =>
  vertx.eventBus.publish("news-feed", "News from Java!")
}

instead of:

vertx.setPeriodic(1000, { timerID =>
  vertx.eventBus.publish("news-feed", "News from Java!")
})

create module or vehicle with scala source file

In Java, you can specify .java as main and deploy .java source file directly. However, you can't use scala source directly. This following should be supported.

"main":"scala:demo/GameVerticle.scala",

vertx.eventBus.send() always registers a reply handler

IIRC this is a leak, if you don't send a reply back from the server side. It would register a handler but that would never be executed.

I guess the default value should just be null and it be disregarded by Vert.x in the Java core. Not sure whether this is the best approach, though. Probably better use an Option and then call the according Java API function.

HttpServerRequest headers names are not case insensitive

org.vertx.scala.core.http.HttpServerRequest uses Scala's collection.mutable.MultiMap which is not case insensitive, preventing headers to be correctly retrieved when the case in their names don't match.

In other vert.x langs, this works as expected, ie header names are case-insensitive.

StackOverflowError when using vertx.runOnLoop()

I believe this is because vertx.runOnLoop() calls internal.runOnLoop instead of internal.runOnContext (with adaptation of the handler).

java.lang.StackOverflowError
    at org.vertx.scala.core.package$.Vertx(package.scala:43)
    at org.vertx.scala.core.package$Vertx$.runOnLoop$extension(package.scala:71)
    at org.vertx.scala.core.package$Vertx$.runOnLoop$extension(package.scala:71)
    at org.vertx.scala.core.package$Vertx$.runOnLoop$extension(package.scala:71)
    at org.vertx.scala.core.package$Vertx$.runOnLoop$extension(package.scala:71)
    at org.vertx.scala.core.package$Vertx$.runOnLoop$extension(package.scala:71)

Use idiomatic API signatures and internalise conversions where possible.

Currently the API exposes the Handler class in various places, with an implicit conversion occurring externally. I think it would be preferable to expose a function parameter and do the conversion to a Handler internally, instead.

So replacing:

someMethod(foo: Handler[Bar]):Unit = { ... }

with:

someMethod(foo: Bar => Unit):Unit = { convertToHandler(foo) }

Provide a Scala Future/Promises based API

In our projects, we use Futures and Promises to get rid of the nested callbacks. It would be very nice to have them in the API directly instead of having to write them myself.

If you want to stay tied to the Vert.x API, this could also be done as an extra, includable module. Not sure whether this makes much sense, though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.