json made optional for all rpc encodings

This commit is contained in:
Radu Ioan Fericean
2012-07-08 15:19:35 +03:00
parent ef42b662ad
commit b4f64c8662
5 changed files with 40 additions and 12 deletions

View File

@@ -36,6 +36,7 @@ var (
httpApiAddress = flag.String("httpapiaddr", "127.0.0.1:8000", "Http API server address (localhost:2002)")
freeswitchsrv = flag.String("freeswitchsrv", "localhost:8021", "freeswitch address host:port")
freeswitchpass = flag.String("freeswitchpass", "ClueCon", "freeswitch address host:port")
js = flag.Bool("json", false, "use JSON for RPC encoding")
bal *balancer.Balancer
balancerRWMutex sync.RWMutex
)
@@ -92,7 +93,7 @@ func main() {
go StopSingnalHandler()
go listenToRPCRaterRequests()
go listenToJsonRPCRequests()
go listenToRPCRequests()
sm := &sessionmanager.FSSessionManager{}
sm.Connect(sessionmanager.NewRPCBalancerSessionDelegate(bal), *freeswitchsrv, *freeswitchpass)

View File

@@ -97,7 +97,7 @@ func (r *Responder) Status(arg timespans.CallDescriptor, replay *string) (err er
/*
Creates the json rpc server.
*/
func listenToJsonRPCRequests() {
func listenToRPCRequests() {
l, err := net.Listen("tcp", *jsonRpcAddress)
defer l.Close()
@@ -111,13 +111,19 @@ func listenToJsonRPCRequests() {
rpc.Register(responder)
for {
c, err := l.Accept()
conn, err := l.Accept()
if err != nil {
log.Printf("accept error: %s", c)
log.Printf("accept error: %s", conn)
continue
}
log.Printf("connection started: %v", c.RemoteAddr())
go jsonrpc.ServeConn(c)
log.Printf("connection started: %v", conn.RemoteAddr())
if *js {
// log.Print("json encoding")
go jsonrpc.ServeConn(conn)
} else {
// log.Print("gob encoding")
go rpc.ServeConn(conn)
}
}
}

View File

@@ -38,7 +38,9 @@ var (
redissrv = flag.String("redissrv", "127.0.0.1:6379", "redis address host:port")
redisdb = flag.Int("redisdb", 10, "redis database number")
listen = flag.String("listen", "127.0.0.1:1234", "listening address host:port")
standalone = flag.Bool("standalone", false, "start standalone server (no balancer), and use JSON for RPC encoding")
standalone = flag.Bool("standalone", false, "start standalone server (no balancer)")
freeswitch = flag.Bool("freeswitch", false, "connect to freeswitch server")
json = flag.Bool("json", false, "use JSON for RPC encoding")
storage Responder
)
@@ -122,10 +124,11 @@ func main() {
if err != nil {
log.Fatalf("Cannot open storage: %v", err)
}
if *standalone {
if *freeswitch {
sm := &sessionmanager.FSSessionManager{}
sm.Connect(sessionmanager.NewDirectSessionDelegate(getter), *freeswitchsrv, *freeswitchpass)
} else {
}
if !*standalone {
go RegisterToServer(balancer, listen)
go StopSingnalHandler(balancer, listen, getter)
}
@@ -155,7 +158,7 @@ func main() {
continue
}
log.Printf("connection started: %v", conn.RemoteAddr())
if *standalone {
if *json {
// log.Print("json encoding")
go jsonrpc.ServeConn(conn)
} else {

View File

@@ -23,11 +23,13 @@ import (
"github.com/cgrates/cgrates/sessionmanager"
"github.com/cgrates/cgrates/timespans"
"log"
"net/rpc"
"net/rpc/jsonrpc"
)
var (
standalone = flag.Bool("standalone", false, "run standalone (run as a rater)")
json = flag.Bool("json", false, "use JSON for RPC encoding")
balancer = flag.String("balancer", "127.0.0.1:2000", "balancer address host:port")
freeswitchsrv = flag.String("freeswitchsrv", "localhost:8021", "freeswitch address host:port")
freeswitchpass = flag.String("freeswitchpass", "ClueCon", "freeswitch address host:port")
@@ -46,7 +48,12 @@ func main() {
if *standalone {
sm.Connect(sessionmanager.NewDirectSessionDelegate(getter), *freeswitchsrv, *freeswitchpass)
} else {
client, err := jsonrpc.Dial("tcp", *balancer)
var client *rpc.Client
if *json {
client, err = jsonrpc.Dial("tcp", *balancer)
} else {
client, err = rpc.Dial("tcp", *balancer)
}
if err != nil {
log.Fatalf("could not connect to balancer: %v", err)
}

View File

@@ -21,6 +21,7 @@ package main
import (
"github.com/cgrates/cgrates/timespans"
"log"
"net/rpc"
"net/rpc/jsonrpc"
"time"
"flag"
@@ -28,6 +29,7 @@ import (
var (
runs = flag.Int("runs", 10000, "stress cycle number")
json = flag.Bool("json", false, "use JSON for RPC encoding")
)
func main() {
@@ -36,7 +38,16 @@ func main() {
t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC)
cd := timespans.CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
result := timespans.CallCost{}
client, _ := jsonrpc.Dial("tcp", "localhost:1234")
var client *rpc.Client
var err error
if *json {
client, err = jsonrpc.Dial("tcp", "localhost:1234")
} else {
client, err = rpc.Dial("tcp", "localhost:1234")
}
if err != nil {
log.Panic("Could not connect to rater: ", err)
}
i := 0
start := time.Now()
for j := 0; j < *runs; j++ {