pcp-rpc


License

License

GroupId

GroupId

io.github.lock-free
ArtifactId

ArtifactId

pcp-rpc_2.12
Last Version

Last Version

0.0.10
Release Date

Release Date

Type

Type

jar
Description

Description

pcp-rpc
pcp-rpc
Project URL

Project URL

https://github.com/lock-free/pcp-rpc
Project Organization

Project Organization

io.github.lock-free
Source Code Management

Source Code Management

https://github.com/lock-free/pcp-rpc

Download pcp-rpc_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.lock-free/pcp-rpc_2.12/ -->
<dependency>
    <groupId>io.github.lock-free</groupId>
    <artifactId>pcp-rpc_2.12</artifactId>
    <version>0.0.10</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.lock-free/pcp-rpc_2.12/
implementation 'io.github.lock-free:pcp-rpc_2.12:0.0.10'
// https://jarcasting.com/artifacts/io.github.lock-free/pcp-rpc_2.12/
implementation ("io.github.lock-free:pcp-rpc_2.12:0.0.10")
'io.github.lock-free:pcp-rpc_2.12:jar:0.0.10'
<dependency org="io.github.lock-free" name="pcp-rpc_2.12" rev="0.0.10">
  <artifact name="pcp-rpc_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.lock-free', module='pcp-rpc_2.12', version='0.0.10')
)
libraryDependencies += "io.github.lock-free" % "pcp-rpc_2.12" % "0.0.10"
[io.github.lock-free/pcp-rpc_2.12 "0.0.10"]

Dependencies

compile (8)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.4
io.github.lock-free : klog_2.12 jar 0.1.0
io.github.lock-free : sjson_2.12 jar 0.2.0
io.github.lock-free : pcp_2.12 jar 0.1.1
io.github.lock-free : pcp-stream_2.12 jar 0.0.2
io.github.lock-free : saio_2.12 jar 0.0.2
io.netty : netty jar 3.7.0.Final
io.github.lock-free : spool_2.12 jar 0.0.1

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.1

Project Modules

There are no modules declared in this project.

pcp-rpc

A scala RPC based on pcp protocol

Quick Example

import io.github.free.lock.pcp.{ BoxFun, PcpClient, PcpServer, Sandbox }
import io.github.free.lock.pcprpc.PcpRpc
import scala.concurrent.ExecutionContext.Implicits.global

val sandbox = new Sandbox(
  Map[String, BoxFun](
    // define add function
    "add" -> Sandbox.toSanboxFun((params: List[Any], pcs: PcpServer) => {
      val a = params(0).asInstanceOf[Int]
      val b = params(1).asInstanceOf[Int]
      a + b
    }),
    "testFuture" -> Sandbox.toSanboxFun((params: List[Any], pcs: PcpServer) => {
      Future { 123 }
    }),
    "textException" -> Sandbox.toSanboxFun((params: List[Any], pcs: PcpServer) => {
      Future { throw new Exception("test rpc exception.") }
    })
  )
)

val server = PcpRpc.getPCServer(port = 5878, sandbox = sandbox)

PcpRpc.getPCClient(port = 5878) map { client =>
  val p = new PcpClient()
  client.call(p.call("add", 1, 2)) // Future {3}
}

Pool client example

import io.github.free.lock.pcp.{ BoxFun, PcpClient, PcpServer, Sandbox }
import io.github.free.lock.pcprpc.PcpRpc
import scala.concurrent.ExecutionContext.Implicits.global

val sandbox = new Sandbox(
  Map[String, BoxFun](
    // define add function
    "add" -> Sandbox.toSanboxFun((params: List[Any], pcs: PcpServer) => {
      val a = params(0).asInstanceOf[Int]
      val b = params(1).asInstanceOf[Int]
      a + b
    }),
    "testFuture" -> Sandbox.toSanboxFun((params: List[Any], pcs: PcpServer) => {
      Future { 123 }
    }),
    "textException" -> Sandbox.toSanboxFun((params: List[Any], pcs: PcpServer) => {
      Future { throw new Exception("test rpc exception.") }
    })
  )
)

val server = PcpRpc.getPCServer(port = 5878, sandbox = sandbox)

val pool = PcpRpc.getPCClientPool(
  getServerAddress = () => Future { PcpRpc.ServerAddress(port = 5878) }
)
pool.call(p.call("add", 1, 2)) // Future {3}
io.github.lock-free

LockFree

Versions

Version
0.0.10