summaryrefslogtreecommitdiff
path: root/test/files/detach-run/basic/Client.scala
blob: f8eddb041d6355887d4a359c93cdd2f093d407e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 *  @author Stephane Micheloud
 */

import java.net._, Thread._, ClientHelper._
import scala.remoting._, Debug._

object Foo {
  def trace(s: String) { info("[Foo.trace] "+s)}
}
object Client {
  val yInstVal: Int = 10
  var yInstVar: Int = 99
  object Bar {
    def trace(s: String) { info("[Bar.trace] "+s) }
  }
  def main(args: Array[String]) {
    init(args)
    val server = new Channel(host, port)
    val zLocVal: Int = 1000
    var zLocVar: Int = 9998
    server ! detach(
      (x: Int) => {
        println("yInstVal = "+yInstVal)
        this.trace("yInstVar = "+yInstVar)
        Bar.trace("zLocVal = "+zLocVal)
        Foo.trace("zLocVar = "+zLocVar)
        zLocVar += 2
        System.out.println("zLocVal = "+zLocVal)
        Debug.info("zLocVar = "+zLocVar)
        x + yInstVal + yInstVar + zLocVal + zLocVar
      })
    val result = server.receiveInt
    println("result received: " + result)
  }
  private def trace(s: String) { info("[Client.trace] "+s) }
}

object ClientHelper {
  private var _host = "127.0.0.1"
  private var _port = 8888
  def host = _host
  def port = _port
  def init(args: Array[String]) {
    try { _host = args(0) } catch { case _ => }
    try { _port = args(1).toInt } catch { case _ => }
  }
}