pcp-rpc


License

License

Categories

Categories

Data
GroupId

GroupId

io.github.idata-shopee
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/idata-shopee/pcp-rpc
Project Organization

Project Organization

io.github.idata-shopee
Source Code Management

Source Code Management

https://github.com/idata-shopee/pcp-rpc

Download pcp-rpc_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.idata-shopee/pcp-rpc_2.12/ -->
<dependency>
    <groupId>io.github.idata-shopee</groupId>
    <artifactId>pcp-rpc_2.12</artifactId>
    <version>0.0.10</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.idata-shopee/pcp-rpc_2.12/
implementation 'io.github.idata-shopee:pcp-rpc_2.12:0.0.10'
// https://jarcasting.com/artifacts/io.github.idata-shopee/pcp-rpc_2.12/
implementation ("io.github.idata-shopee:pcp-rpc_2.12:0.0.10")
'io.github.idata-shopee:pcp-rpc_2.12:jar:0.0.10'
<dependency org="io.github.idata-shopee" name="pcp-rpc_2.12" rev="0.0.10">
  <artifact name="pcp-rpc_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.idata-shopee', module='pcp-rpc_2.12', version='0.0.10')
)
libraryDependencies += "io.github.idata-shopee" % "pcp-rpc_2.12" % "0.0.10"
[io.github.idata-shopee/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.idata-shopee : klog_2.12 jar 0.1.0
io.github.idata-shopee : taskqueue_2.12 jar 0.1.0
io.github.idata-shopee : sjson_2.12 jar 0.1.5
io.github.idata-shopee : pcp_2.12 jar 0.1.1
io.github.idata-shopee : pcp-stream_2.12 jar 0.0.2
io.github.idata-shopee : saio_2.12 jar 0.0.2
io.github.idata-shopee : 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}

Versions

Version
0.0.10
0.0.9
0.0.8
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2