This is an automated email from the ASF dual-hosted git repository. zhaoyunxing pushed a commit to branch config-enhance in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
commit 9cf47225f6a03123e9f371174d47ee544f0e2be8 Author: sunrui1225 <[email protected]> AuthorDate: Sat Sep 4 14:14:35 2021 +0800 Config enhance rpc dubbo (#213) * Config enhance: rpc samples dubbo * Config enhance rpc dubbo:add README.md * Config enhance: rpc samples dubbo,reimport ,update logger, update java file * Config enhance rpc dubbo: add run.sh, update README.md * Config enhance rpc dubbo: update user provider interface specification Co-authored-by: ruishansun <[email protected]> --- .../rpc/dubbo}/docker/docker-compose.yml | 0 .../rpc/dubbo}/docker/docker-health-check.sh | 0 .../rpc/dubbo}/tests/integration/main_test.go | 0 .../dubbo}/tests/integration/userprovider_test.go | 0 rpc/dubbo/README.md | 23 ++ rpc/dubbo/README_zh.md | 22 + rpc/dubbo/go-client/cmd/client.go | 71 ++-- rpc/dubbo/go-client/conf/client.yml | 56 --- rpc/dubbo/go-client/conf/dubbogo.yml | 15 + rpc/dubbo/go-client/pkg/user.go | 24 +- rpc/dubbo/go-server/cmd/server.go | 12 +- rpc/dubbo/go-server/conf/client.yml | 58 --- rpc/dubbo/go-server/conf/dubbogo.yml | 26 ++ rpc/dubbo/go-server/conf/server.yml | 55 --- rpc/dubbo/go-server/pkg/user_provider.go | 18 +- rpc/dubbo/java-client/2.6/run.sh | 2 + .../src/main/java/org/apache/dubbo/Consumer.java | 454 ++++++++++----------- rpc/dubbo/java-client/2.7/run.sh | 2 + .../src/main/java/org/apache/dubbo/Consumer.java | 454 ++++++++++----------- rpc/dubbo/java-server/2.6/run.sh | 2 + .../main/java/org/apache/dubbo/UserProvider.java | 102 ++--- .../org/apache/dubbo/UserProviderAnotherImpl.java | 290 ++++++------- .../java/org/apache/dubbo/UserProviderImpl.java | 234 +++++------ rpc/dubbo/java-server/2.7/run.sh | 2 + .../main/java/org/apache/dubbo/UserProvider.java | 102 ++--- .../org/apache/dubbo/UserProviderAnotherImpl.java | 290 ++++++------- .../java/org/apache/dubbo/UserProviderImpl.java | 234 +++++------ 27 files changed, 1235 insertions(+), 1313 deletions(-) diff --git a/rpc/dubbo/go-server/docker/docker-compose.yml b/integrate_test/rpc/dubbo/docker/docker-compose.yml similarity index 100% rename from rpc/dubbo/go-server/docker/docker-compose.yml rename to integrate_test/rpc/dubbo/docker/docker-compose.yml diff --git a/rpc/dubbo/go-server/docker/docker-health-check.sh b/integrate_test/rpc/dubbo/docker/docker-health-check.sh similarity index 100% rename from rpc/dubbo/go-server/docker/docker-health-check.sh rename to integrate_test/rpc/dubbo/docker/docker-health-check.sh diff --git a/rpc/dubbo/go-server/tests/integration/main_test.go b/integrate_test/rpc/dubbo/tests/integration/main_test.go similarity index 100% rename from rpc/dubbo/go-server/tests/integration/main_test.go rename to integrate_test/rpc/dubbo/tests/integration/main_test.go diff --git a/rpc/dubbo/go-server/tests/integration/userprovider_test.go b/integrate_test/rpc/dubbo/tests/integration/userprovider_test.go similarity index 100% rename from rpc/dubbo/go-server/tests/integration/userprovider_test.go rename to integrate_test/rpc/dubbo/tests/integration/userprovider_test.go diff --git a/rpc/dubbo/README.md b/rpc/dubbo/README.md new file mode 100644 index 0000000..c2c7fdc --- /dev/null +++ b/rpc/dubbo/README.md @@ -0,0 +1,23 @@ +# RPC Dubbo for Dubbo-go 3.0 + +For api definition and go client and server startup, please refer to [dubbo-go 3.0 quickstart](https://dubbogo.github.io/zh-cn/docs/user/quickstart/3.0/quickstart.html) + +## Instructions +1. Start zookeeper + +2. Start the server + +Use goland to start rpc-dubbo-go-server + +or + +Execute `sh run.sh` in the java-server folder to start the java server + +3. Start the client + +Use goland to start rpc-dubbo-go-client + +or + +Execute `sh run.sh` under the java-client folder to start the java client + diff --git a/rpc/dubbo/README_zh.md b/rpc/dubbo/README_zh.md new file mode 100644 index 0000000..56490bd --- /dev/null +++ b/rpc/dubbo/README_zh.md @@ -0,0 +1,22 @@ +# RPC Dubbo for Dubbo-go 3.0 + +api 定义以及 go 客户端、服务端启动,可以参考 [dubbo-go 3.0 快速开始](https://dubbogo.github.io/zh-cn/docs/user/quickstart/3.0/quickstart.html) + +## 使用方法 +1. 启动 zookeeper + +2. 启动服务端 + +使用 goland 启动 rpc-dubbo-go-server + +或者 + +在 java-server 文件夹下执行 `sh run.sh` 启动 java server + +3. 启动客户端 + +使用 goland 启动 rpc-dubbo-go-client + +或者 + +在 java-client 文件夹下执行 `sh run.sh` 启动 java client diff --git a/rpc/dubbo/go-client/cmd/client.go b/rpc/dubbo/go-client/cmd/client.go index dcd1939..03a78fd 100644 --- a/rpc/dubbo/go-client/cmd/client.go +++ b/rpc/dubbo/go-client/cmd/client.go @@ -23,18 +23,10 @@ import ( ) import ( - _ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl" - _ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance" - _ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory" + "dubbo.apache.org/dubbo-go/v3/common/logger" "dubbo.apache.org/dubbo-go/v3/config" - _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl" - _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo" - _ "dubbo.apache.org/dubbo-go/v3/registry/protocol" - _ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper" - + _ "dubbo.apache.org/dubbo-go/v3/imports" hessian "github.com/apache/dubbo-go-hessian2" - - "github.com/dubbogo/gost/log" ) import ( @@ -45,7 +37,7 @@ var ( userProvider = new(pkg.UserProvider) ) -// need to setup environment variable "CONF_CONSUMER_FILE_PATH" to "conf/client.yml" before run +// need to setup environment variable "DUBBO_GO_CONFIG_PATH" to "conf/dubbogo.yml" before run func main() { hessian.RegisterJavaEnum(pkg.Gender(pkg.MAN)) hessian.RegisterJavaEnum(pkg.Gender(pkg.WOMAN)) @@ -57,84 +49,77 @@ func main() { time.Sleep(6 * time.Second) - gxlog.CInfo("\n\ntest") + logger.Info("\n\ntest") test() } func test() { - gxlog.CInfo("\n\n\necho") + logger.Info("\n\n\necho") res, err := userProvider.Echo(context.TODO(), "OK") if err != nil { panic(err) } - gxlog.CInfo("res: %v\n", res) + logger.Info("res: %v\n", res) - gxlog.CInfo("\n\n\nstart to test dubbo") + logger.Info("\n\n\nstart to test dubbo") user := &pkg.User{} - err = userProvider.GetUser(context.TODO(), []interface{}{"A003"}, user) + user, err = userProvider.GetUser(context.TODO(), []interface{}{"A003"}) if err != nil { panic(err) } - gxlog.CInfo("response result: %v", user) + logger.Info("response result: %v", user) - gxlog.CInfo("\n\n\nstart to test dubbo - enum") + logger.Info("\n\n\nstart to test dubbo - enum") gender, err := userProvider.GetGender(1) if err != nil { - gxlog.CInfo("error: %v", err) + logger.Info("error: %v", err) } else { - gxlog.CInfo("response result: %v", gender) + logger.Info("response result: %v", gender) } - gxlog.CInfo("\n\n\nstart to test dubbo - GetUser0") + logger.Info("\n\n\nstart to test dubbo - GetUser0") ret, err := userProvider.GetUser0("A003", "Moorse") if err != nil { panic(err) } - gxlog.CInfo("response result: %v", ret) + logger.Info("response result: %v", ret) - gxlog.CInfo("\n\n\nstart to test dubbo - GetUsers") + logger.Info("\n\n\nstart to test dubbo - GetUsers") ret1, err := userProvider.GetUsers([]interface{}{[]interface{}{"A002", "A003"}}) if err != nil { panic(err) } - gxlog.CInfo("response result: %v", ret1) + logger.Info("response result: %v", ret1) - gxlog.CInfo("\n\n\nstart to test dubbo - getUser") + logger.Info("\n\n\nstart to test dubbo - getUser") user = &pkg.User{} var i int32 = 1 - err = userProvider.GetUser2(context.TODO(), []interface{}{i}, user) + user, err = userProvider.GetUser2(context.TODO(), []interface{}{i}) if err != nil { panic(err) } - gxlog.CInfo("response result: %v", user) + logger.Info("response result: %v", user) - gxlog.CInfo("\n\n\nstart to test dubbo - getUser - overload") + logger.Info("\n\n\nstart to test dubbo - getUser - overload") user = &pkg.User{} - err = userProvider.GetUser2(context.TODO(), []interface{}{i, "overload"}, user) - if err != nil { - panic(err) - } - gxlog.CInfo("response result: %v", user) - - gxlog.CInfo("\n\n\nstart to test dubbo - GetUser3") - err = userProvider.GetUser3() + user, err = userProvider.GetUser2(context.TODO(), []interface{}{i, "overload"}) if err != nil { panic(err) } - gxlog.CInfo("succ!") + logger.Info("response result: %v", user) - gxlog.CInfo("\n\n\nstart to test dubbo - getErr") + logger.Info("\n\n\nstart to test dubbo - getErr") user = &pkg.User{} - err = userProvider.GetErr(context.TODO(), []interface{}{"A003"}, user) + user, err = userProvider.GetErr(context.TODO(), []interface{}{"A003"}) if err == nil { panic("err is nil") } - gxlog.CInfo("getErr - error: %v", err) + logger.Info("getErr - error: %v", err) - gxlog.CInfo("\n\n\nstart to test dubbo illegal method") - err = userProvider.GetUser1(context.TODO(), []interface{}{"A003"}, user) + logger.Info("\n\n\nstart to test dubbo illegal method") + user, err = userProvider.GetUser1(context.TODO(), []interface{}{"A003"}) if err == nil { panic("err is nil") } - gxlog.CInfo("error: %v", err) + logger.Info("error: %v", err) } diff --git a/rpc/dubbo/go-client/conf/client.yml b/rpc/dubbo/go-client/conf/client.yml deleted file mode 100644 index d744d39..0000000 --- a/rpc/dubbo/go-client/conf/client.yml +++ /dev/null @@ -1,56 +0,0 @@ -# dubbo client yaml configure file - -check: true -# client -request_timeout: "3s" -# connect timeout -connect_timeout: "3s" - -# application config -application: - organization: "dubbo.io" - name: "UserInfoConsumer" - module: "dubbo-go user-info client" - version: "0.0.1" - environment: "dev" - -# registry config -registries: - "demoZk": - protocol: "zookeeper" - timeout: "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - -# reference config -references: - "UserProvider": - registry: "demoZk" - protocol: "dubbo" - interface: "org.apache.dubbo.UserProvider" - cluster: "failover" - -# protocol config -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 1 - heartbeat_period: "5s" - session_timeout: "180s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_rq_size: 1024 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024000 - session_name: "client" diff --git a/rpc/dubbo/go-client/conf/dubbogo.yml b/rpc/dubbo/go-client/conf/dubbogo.yml new file mode 100644 index 0000000..e1e64cd --- /dev/null +++ b/rpc/dubbo/go-client/conf/dubbogo.yml @@ -0,0 +1,15 @@ +# dubbo client yaml configure file + +dubbo: + registries: + "demoZK": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + consumer: + registry: + - demoZK + references: + "UserProvider": + protocol: "dubbo" + interface: "org.apache.dubbo.UserProvider" \ No newline at end of file diff --git a/rpc/dubbo/go-client/pkg/user.go b/rpc/dubbo/go-client/pkg/user.go index 14ef525..12624ac 100644 --- a/rpc/dubbo/go-client/pkg/user.go +++ b/rpc/dubbo/go-client/pkg/user.go @@ -89,15 +89,15 @@ func (User) JavaClassName() string { type UserProvider struct { GetUsers func(req []interface{}) ([]interface{}, error) - GetErr func(ctx context.Context, req []interface{}, rsp *User) error + GetErr func(ctx context.Context, req []interface{}) (*User, error) - GetUserOld func(ctx context.Context, req []interface{}, rsp *User) error + GetUser func(ctx context.Context, req []interface{}) (*User, error) GetUserNew func(ctx context.Context, req1, req2 *User) (*User, error) GetUser0 func(id string, name string) (User, error) - GetUser1 func(ctx context.Context, req []interface{}, rsp *User) error - GetUser2 func(ctx context.Context, req []interface{}, rsp *User) error `dubbo:"getUser"` + GetUser1 func(ctx context.Context, req []interface{}) (*User, error) + GetUser2 func(ctx context.Context, req []interface{}) (*User, error) `dubbo:"getUser"` GetUser3 func() error GetGender func(i int32) (Gender, error) Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used @@ -109,11 +109,11 @@ func (u *UserProvider) Reference() string { type UserProvider1 struct { GetUsers func(req []interface{}) ([]interface{}, error) - GetErr func(ctx context.Context, req []interface{}, rsp *User) error - GetUser func(ctx context.Context, req []interface{}, rsp *User) error + GetErr func(ctx context.Context, req []interface{}) (*User, error) + GetUser func(ctx context.Context, req []interface{}) (*User, error) GetUser0 func(id string, name string) (User, error) - GetUser1 func(ctx context.Context, req []interface{}, rsp *User) error - GetUser2 func(ctx context.Context, req []interface{}, rsp *User) error `dubbo:"getUser"` + GetUser1 func(ctx context.Context, req []interface{}) (*User, error) + GetUser2 func(ctx context.Context, req []interface{}) (*User, error) `dubbo:"getUser"` GetUser3 func() error Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used } @@ -124,11 +124,11 @@ func (u *UserProvider1) Reference() string { type UserProvider2 struct { GetUsers func(req []interface{}) ([]interface{}, error) - GetErr func(ctx context.Context, req []interface{}, rsp *User) error - GetUser func(ctx context.Context, req []interface{}, rsp *User) error + GetErr func(ctx context.Context, req []interface{}) (*User, error) + GetUser func(ctx context.Context, req []interface{}) (*User, error) GetUser0 func(id string, name string) (User, error) - GetUser1 func(ctx context.Context, req []interface{}, rsp *User) error - GetUser2 func(ctx context.Context, req []interface{}, rsp *User) error `dubbo:"getUser"` + GetUser1 func(ctx context.Context, req []interface{}) (*User, error) + GetUser2 func(ctx context.Context, req []interface{}) (*User, error) `dubbo:"getUser"` GetUser3 func() error Echo func(ctx context.Context, req interface{}) (interface{}, error) // Echo represent EchoFilter will be used } diff --git a/rpc/dubbo/go-server/cmd/server.go b/rpc/dubbo/go-server/cmd/server.go index fc74d81..4ec1bbb 100644 --- a/rpc/dubbo/go-server/cmd/server.go +++ b/rpc/dubbo/go-server/cmd/server.go @@ -26,17 +26,9 @@ import ( ) import ( - _ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl" - _ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance" "dubbo.apache.org/dubbo-go/v3/common/logger" - _ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory" "dubbo.apache.org/dubbo-go/v3/config" - _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl" - _ "dubbo.apache.org/dubbo-go/v3/metadata/service/local" - _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo" - _ "dubbo.apache.org/dubbo-go/v3/registry/protocol" - _ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper" - + _ "dubbo.apache.org/dubbo-go/v3/imports" hessian "github.com/apache/dubbo-go-hessian2" ) @@ -48,7 +40,7 @@ var ( survivalTimeout = int(3e9) ) -// need to setup environment variable "CONF_PROVIDER_FILE_PATH" to "conf/server.yml" before run +// need to setup environment variable "DUBBO_GO_CONFIG_PATH" to "conf/dubbogo.yml" before run func main() { // ------for hessian2------ diff --git a/rpc/dubbo/go-server/conf/client.yml b/rpc/dubbo/go-server/conf/client.yml deleted file mode 100644 index f8c56cb..0000000 --- a/rpc/dubbo/go-server/conf/client.yml +++ /dev/null @@ -1,58 +0,0 @@ -# dubbo client yaml configure file - -check: true -# client -request_timeout: "3s" -# connect timeout -connect_timeout: "3s" - -# application config -application: - organization: "dubbo.io" - name: "UserInfoTest" - module: "dubbo-go user-info client" - version: "0.0.1" - environment: "dev" - -# registry config -registries: - "demoZk": - protocol: "zookeeper" - timeout: "3s" - address: "127.0.0.1:2181" - username: "" - password: "" - -# reference config -references: - "UserProvider": - registry: "demoZk" - protocol: "dubbo" - interface: "org.apache.dubbo.UserProvider" - cluster: "failover" - methods: - - name: "GetUser" - retries: 3 -# protocol config -protocol_conf: - dubbo: - reconnect_interval: 0 - connection_number: 1 - heartbeat_period: "5s" - session_timeout: "180s" - pool_size: 64 - pool_ttl: 600 - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_rq_size: 1024 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024000 - session_name: "client" diff --git a/rpc/dubbo/go-server/conf/dubbogo.yml b/rpc/dubbo/go-server/conf/dubbogo.yml new file mode 100644 index 0000000..622609d --- /dev/null +++ b/rpc/dubbo/go-server/conf/dubbogo.yml @@ -0,0 +1,26 @@ +# dubbo server yaml configure file + +dubbo: + registries: + "demoZK": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + protocols: + "dubbo": + name: "dubbo" + port: 20000 + provider: + registry: + - demoZK + services: + "UserProvider": + protocol: "dubbo" + interface: "org.apache.dubbo.UserProvider" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" diff --git a/rpc/dubbo/go-server/conf/server.yml b/rpc/dubbo/go-server/conf/server.yml deleted file mode 100644 index af90434..0000000 --- a/rpc/dubbo/go-server/conf/server.yml +++ /dev/null @@ -1,55 +0,0 @@ -# dubbo server yaml configure file - -# application config -application: - organization: "dubbo.io" - name: "UserInfoServer" - module: "dubbo-go user-info server" - version: "0.0.1" - environment: "dev" - -# registry config -registries: - "demoZk": - protocol: "zookeeper" - timeout: "3s" - address: "127.0.0.1:2181" - -# service config -services: - "UserProvider": - registry: "demoZk" - protocol: "dubbo" - interface: "org.apache.dubbo.UserProvider" - loadbalance: "random" - warmup: "100" - cluster: "failover" - methods: - - name: "GetUser" - retries: 1 - loadbalance: "random" - -# protocol config -protocols: - "dubbo": - name: "dubbo" - port: 20000 - -protocol_conf: - dubbo: - session_number: 700 - session_timeout: "180s" - getty_session_param: - compress_encoding: false - tcp_no_delay: true - tcp_keep_alive: true - keep_alive_period: "120s" - tcp_r_buf_size: 262144 - tcp_w_buf_size: 65536 - pkg_rq_size: 1024 - pkg_wq_size: 512 - tcp_read_timeout: "1s" - tcp_write_timeout: "5s" - wait_timeout: "1s" - max_msg_len: 1024000 - session_name: "server" diff --git a/rpc/dubbo/go-server/pkg/user_provider.go b/rpc/dubbo/go-server/pkg/user_provider.go index 243ddd2..f65a581 100644 --- a/rpc/dubbo/go-server/pkg/user_provider.go +++ b/rpc/dubbo/go-server/pkg/user_provider.go @@ -49,7 +49,7 @@ func (u *UserProvider) getUser(userID string) (*User, error) { return nil, fmt.Errorf("invalid user id:%s", userID) } -func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User) error { +func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) { var ( err error user *User @@ -58,10 +58,9 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User gxlog.CInfo("req:%#v", req) user, err = u.getUser(req[0].(string)) if err == nil { - *rsp = *user - gxlog.CInfo("rsp:%#v", rsp) + gxlog.CInfo("rsp:%#v", user) } - return err + return user, err } func (u *UserProvider) GetUser0(id string, name string) (User, error) { @@ -78,20 +77,21 @@ func (u *UserProvider) GetUser0(id string, name string) (User, error) { return *user, err } -func (u *UserProvider) GetUser2(ctx context.Context, req []interface{}, rsp *User) error { +func (u *UserProvider) GetUser2(ctx context.Context, req []interface{}) (*User, error) { var err error gxlog.CInfo("req:%#v", req) - rsp.ID = strconv.Itoa(int(req[0].(int32))) - return err + user := &User{} + user.ID = strconv.Itoa(int(req[0].(int32))) + return user, err } func (u *UserProvider) GetUser3() error { return nil } -func (u *UserProvider) GetErr(ctx context.Context, req []interface{}, rsp *User) error { - return java_exception.NewThrowable("exception") +func (u *UserProvider) GetErr(ctx context.Context, req []interface{}) (*User, error) { + return nil, java_exception.NewThrowable("exception") } func (u *UserProvider) GetUsers(req []interface{}) ([]interface{}, error) { diff --git a/rpc/dubbo/java-client/2.6/run.sh b/rpc/dubbo/java-client/2.6/run.sh new file mode 100644 index 0000000..df4e2f7 --- /dev/null +++ b/rpc/dubbo/java-client/2.6/run.sh @@ -0,0 +1,2 @@ +mvn install -DSkipTests +mvn exec:java -Dexec.mainClass="org.apache.dubbo.Consumer" \ No newline at end of file diff --git a/rpc/dubbo/java-client/2.6/src/main/java/org/apache/dubbo/Consumer.java b/rpc/dubbo/java-client/2.6/src/main/java/org/apache/dubbo/Consumer.java index 54e5b66..c339ad4 100644 --- a/rpc/dubbo/java-client/2.6/src/main/java/org/apache/dubbo/Consumer.java +++ b/rpc/dubbo/java-client/2.6/src/main/java/org/apache/dubbo/Consumer.java @@ -1,227 +1,227 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dubbo; - -import com.alibaba.dubbo.rpc.service.EchoService; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class Consumer { - // Define a private variable (Required in Spring) - private static UserProvider userProvider; - private static UserProvider userProvider1; - private static UserProvider userProvider2; - - public static void main(String[] args) throws Exception { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo.consumer.xml"}); - userProvider = (UserProvider)context.getBean("userProvider"); - userProvider1 = (UserProvider)context.getBean("userProvider1"); - userProvider2 = (UserProvider)context.getBean("userProvider2"); - - start(); - } - - // Start the entry function for consumer (Specified in the configuration file) - public static void start() throws Exception { - System.out.println("\n\ntest"); - testGetUser(); - testGetUsers(); - System.out.println("\n\ntest1"); - testGetUser1(); - testGetUsers1(); - System.out.println("\n\ntest2"); - testGetUser2(); - testGetUsers2(); - Thread.sleep(2000); - } - - private static void testGetUser() throws Exception { - try { - EchoService echoService = (EchoService)userProvider; - Object status = echoService.$echo("OK"); - System.out.println("echo: "+status); - User user1 = userProvider.GetUser("A003"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user1.getID() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() - + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); - User user2 = userProvider.GetUser0("A003","Moorse"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user2.getID() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() - + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); - User user3 = userProvider.getUser(1); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user3.getID() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() - + ", age:" + user3.getAge() + ", time:" + user3.getTime()); - User user4 = userProvider.getUser(1, "name"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user4.getID() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() - + ", age:" + user4.getAge() + ", time:" + user4.getTime()); - userProvider.GetUser3(); - System.out.println("GetUser3 succ"); - - User user9 = userProvider.GetUser1("A003"); - } catch (Throwable e) { - System.out.println("*************exception***********"); - e.printStackTrace(); - } - try { - userProvider.GetErr("A003"); - } catch (Throwable t) { - System.out.println("*************exception***********"); - t.printStackTrace(); - } - } - - private static void testGetUsers() throws Exception { - try { - List<String> userIDList = new ArrayList<String>(); - userIDList.add("A001"); - userIDList.add("A002"); - userIDList.add("A003"); - - List<User> userList = userProvider.GetUsers(userIDList); - - for (int i = 0; i < userList.size(); i++) { - User user = userList.get(i); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user.getID() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() - + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static void testGetUser1() throws Exception { - try { - EchoService echoService = (EchoService)userProvider1; - Object status = echoService.$echo("OK"); - System.out.println("echo: "+status); - User user1 = userProvider1.GetUser("A003"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user1.getID() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() - + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); - User user2 = userProvider1.GetUser0("A003","Moorse"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user2.getID() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() - + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); - User user3 = userProvider1.getUser(1); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user3.getID() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() - + ", age:" + user3.getAge() + ", time:" + user3.getTime()); - User user4 = userProvider1.getUser(1, "name"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user4.getID() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() - + ", age:" + user4.getAge() + ", time:" + user4.getTime()); - userProvider1.GetUser3(); - System.out.println("GetUser3 succ"); - - User user9 = userProvider1.GetUser1("A003"); - } catch (Throwable e) { - System.out.println("*************exception***********"); - e.printStackTrace(); - } - try { - userProvider1.GetErr("A003"); - } catch (Throwable t) { - System.out.println("*************exception***********"); - t.printStackTrace(); - } - } - - private static void testGetUsers1() throws Exception { - try { - List<String> userIDList = new ArrayList<String>(); - userIDList.add("A001"); - userIDList.add("A002"); - userIDList.add("A003"); - - List<User> userList = userProvider1.GetUsers(userIDList); - - for (int i = 0; i < userList.size(); i++) { - User user = userList.get(i); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user.getID() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() - + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static void testGetUser2() throws Exception { - try { - EchoService echoService = (EchoService)userProvider2; - Object status = echoService.$echo("OK"); - System.out.println("echo: "+status); - User user1 = userProvider2.GetUser("A003"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user1.getID() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() - + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); - User user2 = userProvider2.GetUser0("A003","Moorse"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user2.getID() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() - + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); - User user3 = userProvider2.getUser(1); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user3.getID() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() - + ", age:" + user3.getAge() + ", time:" + user3.getTime()); - User user4 = userProvider2.getUser(1, "name"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user4.getID() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() - + ", age:" + user4.getAge() + ", time:" + user4.getTime()); - userProvider2.GetUser3(); - System.out.println("GetUser3 succ"); - - User user9 = userProvider2.GetUser1("A003"); - } catch (Throwable e) { - System.out.println("*************exception***********"); - e.printStackTrace(); - } - try { - userProvider2.GetErr("A003"); - } catch (Throwable t) { - System.out.println("*************exception***********"); - t.printStackTrace(); - } - } - - private static void testGetUsers2() throws Exception { - try { - List<String> userIDList = new ArrayList<String>(); - userIDList.add("A001"); - userIDList.add("A002"); - userIDList.add("A003"); - - List<User> userList = userProvider2.GetUsers(userIDList); - - for (int i = 0; i < userList.size(); i++) { - User user = userList.get(i); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user.getID() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() - + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dubbo; + +import com.alibaba.dubbo.rpc.service.EchoService; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Consumer { + // Define a private variable (Required in Spring) + private static UserProvider userProvider; + private static UserProvider userProvider1; + private static UserProvider userProvider2; + + public static void main(String[] args) throws Exception { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo.consumer.xml"}); + userProvider = (UserProvider)context.getBean("userProvider"); + userProvider1 = (UserProvider)context.getBean("userProvider1"); + userProvider2 = (UserProvider)context.getBean("userProvider2"); + + start(); + } + + // Start the entry function for consumer (Specified in the configuration file) + public static void start() throws Exception { + System.out.println("\n\ntest"); + testGetUser(); + testGetUsers(); + System.out.println("\n\ntest1"); + testGetUser1(); + testGetUsers1(); + System.out.println("\n\ntest2"); + testGetUser2(); + testGetUsers2(); + Thread.sleep(2000); + } + + private static void testGetUser() throws Exception { + try { + EchoService echoService = (EchoService)userProvider; + Object status = echoService.$echo("OK"); + System.out.println("echo: "+status); + User user1 = userProvider.GetUser("A003"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user1.getId() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() + + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); + User user2 = userProvider.GetUser0("A003","Moorse"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() + + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); + User user3 = userProvider.getUser(1); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user3.getId() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() + + ", age:" + user3.getAge() + ", time:" + user3.getTime()); + User user4 = userProvider.getUser(1, "name"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user4.getId() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() + + ", age:" + user4.getAge() + ", time:" + user4.getTime()); + userProvider.GetUser3(); + System.out.println("GetUser3 succ"); + + User user9 = userProvider.GetUser1("A003"); + } catch (Throwable e) { + System.out.println("*************exception***********"); + e.printStackTrace(); + } + try { + userProvider.GetErr("A003"); + } catch (Throwable t) { + System.out.println("*************exception***********"); + t.printStackTrace(); + } + } + + private static void testGetUsers() throws Exception { + try { + List<String> userIDList = new ArrayList<String>(); + userIDList.add("A001"); + userIDList.add("A002"); + userIDList.add("A003"); + + List<User> userList = userProvider.GetUsers(userIDList); + + for (int i = 0; i < userList.size(); i++) { + User user = userList.get(i); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user.getId() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() + + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void testGetUser1() throws Exception { + try { + EchoService echoService = (EchoService)userProvider1; + Object status = echoService.$echo("OK"); + System.out.println("echo: "+status); + User user1 = userProvider1.GetUser("A003"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user1.getId() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() + + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); + User user2 = userProvider1.GetUser0("A003","Moorse"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() + + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); + User user3 = userProvider1.getUser(1); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user3.getId() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() + + ", age:" + user3.getAge() + ", time:" + user3.getTime()); + User user4 = userProvider1.getUser(1, "name"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user4.getId() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() + + ", age:" + user4.getAge() + ", time:" + user4.getTime()); + userProvider1.GetUser3(); + System.out.println("GetUser3 succ"); + + User user9 = userProvider1.GetUser1("A003"); + } catch (Throwable e) { + System.out.println("*************exception***********"); + e.printStackTrace(); + } + try { + userProvider1.GetErr("A003"); + } catch (Throwable t) { + System.out.println("*************exception***********"); + t.printStackTrace(); + } + } + + private static void testGetUsers1() throws Exception { + try { + List<String> userIDList = new ArrayList<String>(); + userIDList.add("A001"); + userIDList.add("A002"); + userIDList.add("A003"); + + List<User> userList = userProvider1.GetUsers(userIDList); + + for (int i = 0; i < userList.size(); i++) { + User user = userList.get(i); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user.getId() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() + + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void testGetUser2() throws Exception { + try { + EchoService echoService = (EchoService)userProvider2; + Object status = echoService.$echo("OK"); + System.out.println("echo: "+status); + User user1 = userProvider2.GetUser("A003"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user1.getId() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() + + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); + User user2 = userProvider2.GetUser0("A003","Moorse"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() + + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); + User user3 = userProvider2.getUser(1); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user3.getId() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() + + ", age:" + user3.getAge() + ", time:" + user3.getTime()); + User user4 = userProvider2.getUser(1, "name"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user4.getId() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() + + ", age:" + user4.getAge() + ", time:" + user4.getTime()); + userProvider2.GetUser3(); + System.out.println("GetUser3 succ"); + + User user9 = userProvider2.GetUser1("A003"); + } catch (Throwable e) { + System.out.println("*************exception***********"); + e.printStackTrace(); + } + try { + userProvider2.GetErr("A003"); + } catch (Throwable t) { + System.out.println("*************exception***********"); + t.printStackTrace(); + } + } + + private static void testGetUsers2() throws Exception { + try { + List<String> userIDList = new ArrayList<String>(); + userIDList.add("A001"); + userIDList.add("A002"); + userIDList.add("A003"); + + List<User> userList = userProvider2.GetUsers(userIDList); + + for (int i = 0; i < userList.size(); i++) { + User user = userList.get(i); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user.getId() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() + + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/rpc/dubbo/java-client/2.7/run.sh b/rpc/dubbo/java-client/2.7/run.sh new file mode 100644 index 0000000..df4e2f7 --- /dev/null +++ b/rpc/dubbo/java-client/2.7/run.sh @@ -0,0 +1,2 @@ +mvn install -DSkipTests +mvn exec:java -Dexec.mainClass="org.apache.dubbo.Consumer" \ No newline at end of file diff --git a/rpc/dubbo/java-client/2.7/src/main/java/org/apache/dubbo/Consumer.java b/rpc/dubbo/java-client/2.7/src/main/java/org/apache/dubbo/Consumer.java index 54e5b66..c339ad4 100644 --- a/rpc/dubbo/java-client/2.7/src/main/java/org/apache/dubbo/Consumer.java +++ b/rpc/dubbo/java-client/2.7/src/main/java/org/apache/dubbo/Consumer.java @@ -1,227 +1,227 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dubbo; - -import com.alibaba.dubbo.rpc.service.EchoService; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class Consumer { - // Define a private variable (Required in Spring) - private static UserProvider userProvider; - private static UserProvider userProvider1; - private static UserProvider userProvider2; - - public static void main(String[] args) throws Exception { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo.consumer.xml"}); - userProvider = (UserProvider)context.getBean("userProvider"); - userProvider1 = (UserProvider)context.getBean("userProvider1"); - userProvider2 = (UserProvider)context.getBean("userProvider2"); - - start(); - } - - // Start the entry function for consumer (Specified in the configuration file) - public static void start() throws Exception { - System.out.println("\n\ntest"); - testGetUser(); - testGetUsers(); - System.out.println("\n\ntest1"); - testGetUser1(); - testGetUsers1(); - System.out.println("\n\ntest2"); - testGetUser2(); - testGetUsers2(); - Thread.sleep(2000); - } - - private static void testGetUser() throws Exception { - try { - EchoService echoService = (EchoService)userProvider; - Object status = echoService.$echo("OK"); - System.out.println("echo: "+status); - User user1 = userProvider.GetUser("A003"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user1.getID() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() - + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); - User user2 = userProvider.GetUser0("A003","Moorse"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user2.getID() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() - + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); - User user3 = userProvider.getUser(1); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user3.getID() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() - + ", age:" + user3.getAge() + ", time:" + user3.getTime()); - User user4 = userProvider.getUser(1, "name"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user4.getID() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() - + ", age:" + user4.getAge() + ", time:" + user4.getTime()); - userProvider.GetUser3(); - System.out.println("GetUser3 succ"); - - User user9 = userProvider.GetUser1("A003"); - } catch (Throwable e) { - System.out.println("*************exception***********"); - e.printStackTrace(); - } - try { - userProvider.GetErr("A003"); - } catch (Throwable t) { - System.out.println("*************exception***********"); - t.printStackTrace(); - } - } - - private static void testGetUsers() throws Exception { - try { - List<String> userIDList = new ArrayList<String>(); - userIDList.add("A001"); - userIDList.add("A002"); - userIDList.add("A003"); - - List<User> userList = userProvider.GetUsers(userIDList); - - for (int i = 0; i < userList.size(); i++) { - User user = userList.get(i); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user.getID() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() - + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static void testGetUser1() throws Exception { - try { - EchoService echoService = (EchoService)userProvider1; - Object status = echoService.$echo("OK"); - System.out.println("echo: "+status); - User user1 = userProvider1.GetUser("A003"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user1.getID() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() - + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); - User user2 = userProvider1.GetUser0("A003","Moorse"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user2.getID() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() - + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); - User user3 = userProvider1.getUser(1); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user3.getID() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() - + ", age:" + user3.getAge() + ", time:" + user3.getTime()); - User user4 = userProvider1.getUser(1, "name"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user4.getID() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() - + ", age:" + user4.getAge() + ", time:" + user4.getTime()); - userProvider1.GetUser3(); - System.out.println("GetUser3 succ"); - - User user9 = userProvider1.GetUser1("A003"); - } catch (Throwable e) { - System.out.println("*************exception***********"); - e.printStackTrace(); - } - try { - userProvider1.GetErr("A003"); - } catch (Throwable t) { - System.out.println("*************exception***********"); - t.printStackTrace(); - } - } - - private static void testGetUsers1() throws Exception { - try { - List<String> userIDList = new ArrayList<String>(); - userIDList.add("A001"); - userIDList.add("A002"); - userIDList.add("A003"); - - List<User> userList = userProvider1.GetUsers(userIDList); - - for (int i = 0; i < userList.size(); i++) { - User user = userList.get(i); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user.getID() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() - + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static void testGetUser2() throws Exception { - try { - EchoService echoService = (EchoService)userProvider2; - Object status = echoService.$echo("OK"); - System.out.println("echo: "+status); - User user1 = userProvider2.GetUser("A003"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user1.getID() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() - + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); - User user2 = userProvider2.GetUser0("A003","Moorse"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user2.getID() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() - + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); - User user3 = userProvider2.getUser(1); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user3.getID() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() - + ", age:" + user3.getAge() + ", time:" + user3.getTime()); - User user4 = userProvider2.getUser(1, "name"); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user4.getID() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() - + ", age:" + user4.getAge() + ", time:" + user4.getTime()); - userProvider2.GetUser3(); - System.out.println("GetUser3 succ"); - - User user9 = userProvider2.GetUser1("A003"); - } catch (Throwable e) { - System.out.println("*************exception***********"); - e.printStackTrace(); - } - try { - userProvider2.GetErr("A003"); - } catch (Throwable t) { - System.out.println("*************exception***********"); - t.printStackTrace(); - } - } - - private static void testGetUsers2() throws Exception { - try { - List<String> userIDList = new ArrayList<String>(); - userIDList.add("A001"); - userIDList.add("A002"); - userIDList.add("A003"); - - List<User> userList = userProvider2.GetUsers(userIDList); - - for (int i = 0; i < userList.size(); i++) { - User user = userList.get(i); - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + - " UserInfo, ID:" + user.getID() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() - + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dubbo; + +import com.alibaba.dubbo.rpc.service.EchoService; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Consumer { + // Define a private variable (Required in Spring) + private static UserProvider userProvider; + private static UserProvider userProvider1; + private static UserProvider userProvider2; + + public static void main(String[] args) throws Exception { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo.consumer.xml"}); + userProvider = (UserProvider)context.getBean("userProvider"); + userProvider1 = (UserProvider)context.getBean("userProvider1"); + userProvider2 = (UserProvider)context.getBean("userProvider2"); + + start(); + } + + // Start the entry function for consumer (Specified in the configuration file) + public static void start() throws Exception { + System.out.println("\n\ntest"); + testGetUser(); + testGetUsers(); + System.out.println("\n\ntest1"); + testGetUser1(); + testGetUsers1(); + System.out.println("\n\ntest2"); + testGetUser2(); + testGetUsers2(); + Thread.sleep(2000); + } + + private static void testGetUser() throws Exception { + try { + EchoService echoService = (EchoService)userProvider; + Object status = echoService.$echo("OK"); + System.out.println("echo: "+status); + User user1 = userProvider.GetUser("A003"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user1.getId() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() + + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); + User user2 = userProvider.GetUser0("A003","Moorse"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() + + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); + User user3 = userProvider.getUser(1); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user3.getId() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() + + ", age:" + user3.getAge() + ", time:" + user3.getTime()); + User user4 = userProvider.getUser(1, "name"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user4.getId() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() + + ", age:" + user4.getAge() + ", time:" + user4.getTime()); + userProvider.GetUser3(); + System.out.println("GetUser3 succ"); + + User user9 = userProvider.GetUser1("A003"); + } catch (Throwable e) { + System.out.println("*************exception***********"); + e.printStackTrace(); + } + try { + userProvider.GetErr("A003"); + } catch (Throwable t) { + System.out.println("*************exception***********"); + t.printStackTrace(); + } + } + + private static void testGetUsers() throws Exception { + try { + List<String> userIDList = new ArrayList<String>(); + userIDList.add("A001"); + userIDList.add("A002"); + userIDList.add("A003"); + + List<User> userList = userProvider.GetUsers(userIDList); + + for (int i = 0; i < userList.size(); i++) { + User user = userList.get(i); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user.getId() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() + + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void testGetUser1() throws Exception { + try { + EchoService echoService = (EchoService)userProvider1; + Object status = echoService.$echo("OK"); + System.out.println("echo: "+status); + User user1 = userProvider1.GetUser("A003"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user1.getId() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() + + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); + User user2 = userProvider1.GetUser0("A003","Moorse"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() + + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); + User user3 = userProvider1.getUser(1); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user3.getId() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() + + ", age:" + user3.getAge() + ", time:" + user3.getTime()); + User user4 = userProvider1.getUser(1, "name"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user4.getId() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() + + ", age:" + user4.getAge() + ", time:" + user4.getTime()); + userProvider1.GetUser3(); + System.out.println("GetUser3 succ"); + + User user9 = userProvider1.GetUser1("A003"); + } catch (Throwable e) { + System.out.println("*************exception***********"); + e.printStackTrace(); + } + try { + userProvider1.GetErr("A003"); + } catch (Throwable t) { + System.out.println("*************exception***********"); + t.printStackTrace(); + } + } + + private static void testGetUsers1() throws Exception { + try { + List<String> userIDList = new ArrayList<String>(); + userIDList.add("A001"); + userIDList.add("A002"); + userIDList.add("A003"); + + List<User> userList = userProvider1.GetUsers(userIDList); + + for (int i = 0; i < userList.size(); i++) { + User user = userList.get(i); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user.getId() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() + + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void testGetUser2() throws Exception { + try { + EchoService echoService = (EchoService)userProvider2; + Object status = echoService.$echo("OK"); + System.out.println("echo: "+status); + User user1 = userProvider2.GetUser("A003"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user1.getId() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString() + + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString()); + User user2 = userProvider2.GetUser0("A003","Moorse"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString() + + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString()); + User user3 = userProvider2.getUser(1); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user3.getId() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString() + + ", age:" + user3.getAge() + ", time:" + user3.getTime()); + User user4 = userProvider2.getUser(1, "name"); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user4.getId() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString() + + ", age:" + user4.getAge() + ", time:" + user4.getTime()); + userProvider2.GetUser3(); + System.out.println("GetUser3 succ"); + + User user9 = userProvider2.GetUser1("A003"); + } catch (Throwable e) { + System.out.println("*************exception***********"); + e.printStackTrace(); + } + try { + userProvider2.GetErr("A003"); + } catch (Throwable t) { + System.out.println("*************exception***********"); + t.printStackTrace(); + } + } + + private static void testGetUsers2() throws Exception { + try { + List<String> userIDList = new ArrayList<String>(); + userIDList.add("A001"); + userIDList.add("A002"); + userIDList.add("A003"); + + List<User> userList = userProvider2.GetUsers(userIDList); + + for (int i = 0; i < userList.size(); i++) { + User user = userList.get(i); + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " + + " UserInfo, ID:" + user.getId() + ", name:" + user.getName() + ", sex:" + user.getSex().toString() + + ", age:" + user.getAge() + ", time:" + user.getTime().toString()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/rpc/dubbo/java-server/2.6/run.sh b/rpc/dubbo/java-server/2.6/run.sh new file mode 100644 index 0000000..9416b14 --- /dev/null +++ b/rpc/dubbo/java-server/2.6/run.sh @@ -0,0 +1,2 @@ +mvn install -DSkipTests +mvn exec:java -Dexec.mainClass="java.org.apache.dubbo.Provider" \ No newline at end of file diff --git a/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProvider.java b/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProvider.java index 1c13f05..0e62224 100644 --- a/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProvider.java +++ b/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProvider.java @@ -1,50 +1,52 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dubbo; - -import java.util.List; -import java.util.Map; - -public interface UserProvider { - - boolean isLimit(Gender gender, String name); - - User GetUser(String userId); // the first alpha is Upper case to compatible with golang. - - List<User> GetUsers(List<String> userIdList); - - void GetUser3(); - - User GetUser0(String userId, String name); - - User GetErr(String userId) throws Exception; - - Map<String, User> GetUserMap(List<String> userIdList); - - User getUser(int usercode); - - User getUser(int usercode, String name); - - User queryUser(User user); - - Map<String, User> queryAll(); - - int Calc(int a, int b); - - Response<Integer> Sum(int a, int b); -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dubbo; + +import java.util.List; +import java.util.Map; + +public interface UserProvider { + + boolean isLimit(Gender gender, String name); + + User GetUser(String userId); // the first alpha is Upper case to compatible with golang. + + List<User> GetUsers(List<String> userIdList); + + Integer GetGender(Integer gender); + + void GetUser3(); + + User GetUser0(String userId, String name); + + User GetErr(String userId) throws Exception; + + Map<String, User> GetUserMap(List<String> userIdList); + + User getUser(int usercode); + + User getUser(int usercode, String name); + + User queryUser(User user); + + Map<String, User> queryAll(); + + int Calc(int a, int b); + + Response<Integer> Sum(int a, int b); +} diff --git a/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProviderAnotherImpl.java b/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProviderAnotherImpl.java index cc6170e..9d41811 100644 --- a/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProviderAnotherImpl.java +++ b/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProviderAnotherImpl.java @@ -1,143 +1,147 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dubbo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -public class UserProviderAnotherImpl implements UserProvider { - // private static final Logger logger = LoggerFactory.getLogger(getClass()); // Only output to dubbo's log(logs/server.log) - private static final Logger logger = LoggerFactory.getLogger("userLogger"); // Output to com.dubbogo.user-server.log - - private Map<String, User> userMap = new HashMap<String, User>(); - - public UserProviderAnotherImpl() { - // userMap.put("001", new User("001", "other-zhangsan", 18, new Date(1998-1900, 1, 2, 3, 4, 5), Gender.MAN)); - userMap.put("001", new User("001", "other-zhangsan", 18, new Date(0x12345678), Gender.MAN)); - userMap.put("002", new User("002", "other-lisi", 20, new Date(1996-1900, 1, 2, 3, 4, 5), Gender.MAN)); - userMap.put("003", new User("003", "other-lily", 23, new Date(1993-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); - userMap.put("004", new User("004", "other-lisa", 32, new Date(1985-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); - } - - public boolean isLimit(Gender gender, String name) { - logger.info(String.format("input gender=%sand name=%s", gender, name)); - return Gender.MAN == gender; - } - - public User GetUser(String userId) { - logger.info("input userId = " + userId); - return new User(userId, "Joe", 48); - } - - public User GetUser0(String userId, String name) { - return new User(userId, name, 48); - } - - public void GetUser3() { - logger.info("this is GetUser3 of another"); - } - - public User GetErr(String userId) throws Exception { - throw new Exception("exception"); - } - - public List<User> GetUsers(ArrayList<String> userIdList) { - Iterator it = userIdList.iterator(); - List<User> userList = new ArrayList<User>(); - logger.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - logger.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - userList.add(userMap.get(id)); - logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return userList; - } - - public Map<String, User> GetUserMap(List<String> userIdList) { - Iterator it = userIdList.iterator(); - Map<String, User> map = new HashMap<String, User>(); - logger.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - logger.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - map.put(id, userMap.get(id)); - logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return map; - } - - public List<User> GetUsers(List<String> userIdList) { - Iterator it = userIdList.iterator(); - List<User> userList = new ArrayList<User>(); - logger.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - logger.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - userList.add(userMap.get(id)); - logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return userList; - } - - // @Override - public User getUser(int userCode) { - logger.info("input userCode = " + userCode); - return new User(String.valueOf(userCode), "userCode get", 48); - } - - public User getUser(int usercode, String name) { - return new User(String.valueOf(usercode), name, 18); - } - - public User queryUser(User user) { - logger.info("input com.dubbogo.user = " + user); - return new User(user.getId(), "get:" + user.getName(), user.getAge() + 18); - } - - public Map<String, User> queryAll() { - logger.info("input"); - Map<String, User> map = new HashMap<String, User>(); - map.put("001", new User("001", "Joe", 18)); - map.put("002", new User("002", "Wen", 20)); - - return map; - } - - public int Calc(int a,int b) { - return a + b + 100; - } - - public Response<Integer> Sum(int a,int b) { - return Response.ok(a+b); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dubbo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + +public class UserProviderAnotherImpl implements UserProvider { + // private static final Logger logger = LoggerFactory.getLogger(getClass()); // Only output to dubbo's log(logs/server.log) + private static final Logger logger = LoggerFactory.getLogger("userLogger"); // Output to com.dubbogo.user-server.log + + private Map<String, User> userMap = new HashMap<String, User>(); + + public UserProviderAnotherImpl() { + // userMap.put("001", new User("001", "other-zhangsan", 18, new Date(1998-1900, 1, 2, 3, 4, 5), Gender.MAN)); + userMap.put("001", new User("001", "other-zhangsan", 18, new Date(0x12345678), Gender.MAN)); + userMap.put("002", new User("002", "other-lisi", 20, new Date(1996-1900, 1, 2, 3, 4, 5), Gender.MAN)); + userMap.put("003", new User("003", "other-lily", 23, new Date(1993-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); + userMap.put("004", new User("004", "other-lisa", 32, new Date(1985-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); + } + + public boolean isLimit(Gender gender, String name) { + logger.info(String.format("input gender=%sand name=%s", gender, name)); + return Gender.MAN == gender; + } + + public User GetUser(String userId) { + logger.info("input userId = " + userId); + return new User(userId, "Joe", 48); + } + + public User GetUser0(String userId, String name) { + return new User(userId, name, 48); + } + + public void GetUser3() { + logger.info("this is GetUser3 of another"); + } + + public User GetErr(String userId) throws Exception { + throw new Exception("exception"); + } + + public List<User> GetUsers(ArrayList<String> userIdList) { + Iterator it = userIdList.iterator(); + List<User> userList = new ArrayList<User>(); + logger.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + logger.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + userList.add(userMap.get(id)); + logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return userList; + } + + public Map<String, User> GetUserMap(List<String> userIdList) { + Iterator it = userIdList.iterator(); + Map<String, User> map = new HashMap<String, User>(); + logger.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + logger.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + map.put(id, userMap.get(id)); + logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return map; + } + + public List<User> GetUsers(List<String> userIdList) { + Iterator it = userIdList.iterator(); + List<User> userList = new ArrayList<User>(); + logger.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + logger.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + userList.add(userMap.get(id)); + logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return userList; + } + + public Integer GetGender(Integer gender) { + return gender != null && gender == 1 ? 1 : 0; + } + + // @Override + public User getUser(int userCode) { + logger.info("input userCode = " + userCode); + return new User(String.valueOf(userCode), "userCode get", 48); + } + + public User getUser(int usercode, String name) { + return new User(String.valueOf(usercode), name, 18); + } + + public User queryUser(User user) { + logger.info("input com.dubbogo.user = " + user); + return new User(user.getId(), "get:" + user.getName(), user.getAge() + 18); + } + + public Map<String, User> queryAll() { + logger.info("input"); + Map<String, User> map = new HashMap<String, User>(); + map.put("001", new User("001", "Joe", 18)); + map.put("002", new User("002", "Wen", 20)); + + return map; + } + + public int Calc(int a,int b) { + return a + b + 100; + } + + public Response<Integer> Sum(int a,int b) { + return Response.ok(a+b); + } +} diff --git a/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProviderImpl.java b/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProviderImpl.java index bdb9651..73747eb 100644 --- a/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProviderImpl.java +++ b/rpc/dubbo/java-server/2.6/src/main/java/org/apache/dubbo/UserProviderImpl.java @@ -1,115 +1,119 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dubbo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -public class UserProviderImpl implements UserProvider { - // private static final Logger logger = LoggerFactory.getLogger(getClass()); // Only output to dubbo's log(logs/server.log) - private static final Logger LOG = LoggerFactory.getLogger("UserLogger"); // Output to com.dubbogo.user-server.log - Map<String, User> userMap = new HashMap<String, User>(); - - public UserProviderImpl() { - userMap.put("A001", new User("A001", "demo-zhangsan", 18)); - userMap.put("A002", new User("A002", "demo-lisi", 20)); - userMap.put("A003", new User("A003", "demo-lily", 23)); - userMap.put("A004", new User("A004", "demo-lisa", 32)); - } - - public boolean isLimit(Gender gender, String name) { - return Gender.WOMAN == gender; - } - - public User GetUser(String userId) { - return new User(userId, "zhangsan", 18); - } - - public User GetErr(String userId) throws Exception { - throw new Exception("exception"); - } - - public User GetUser0(String userId, String name) { - return new User(userId, name, 18); - } - - public List<User> GetUsers(List<String> userIdList) { - Iterator it = userIdList.iterator(); - List<User> userList = new ArrayList<User>(); - LOG.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - LOG.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - userList.add(userMap.get(id)); - LOG.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return userList; - } - - public void GetUser3() { - LOG.info("this is GetUser3 of impl"); - } - - public Map<String, User> GetUserMap(List<String> userIdList) { - Iterator it = userIdList.iterator(); - Map<String, User> map = new HashMap<String, User>(); - LOG.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - LOG.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - map.put(id, userMap.get(id)); - LOG.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return map; - } - - public User queryUser(User user) { - return new User(user.getId(), "hello:" +user.getName(), user.getAge() + 18); - } - - public Map<String, User> queryAll() { - return userMap; - } - - - public User getUser(int userCode) { - return new User(String.valueOf(userCode), "userCode get", 48); - } - - public User getUser(int usercode, String name) { - return new User(String.valueOf(usercode), name, 38); - } - - public int Calc(int a,int b) { - return a + b; - } - - public Response<Integer> Sum(int a,int b) { - return Response.ok(a+b); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dubbo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + +public class UserProviderImpl implements UserProvider { + // private static final Logger logger = LoggerFactory.getLogger(getClass()); // Only output to dubbo's log(logs/server.log) + private static final Logger LOG = LoggerFactory.getLogger("UserLogger"); // Output to com.dubbogo.user-server.log + Map<String, User> userMap = new HashMap<String, User>(); + + public UserProviderImpl() { + userMap.put("A001", new User("A001", "demo-zhangsan", 18)); + userMap.put("A002", new User("A002", "demo-lisi", 20)); + userMap.put("A003", new User("A003", "demo-lily", 23)); + userMap.put("A004", new User("A004", "demo-lisa", 32)); + } + + public boolean isLimit(Gender gender, String name) { + return Gender.WOMAN == gender; + } + + public User GetUser(String userId) { + return new User(userId, "zhangsan", 18); + } + + public User GetErr(String userId) throws Exception { + throw new Exception("exception"); + } + + public User GetUser0(String userId, String name) { + return new User(userId, name, 18); + } + + public List<User> GetUsers(List<String> userIdList) { + Iterator it = userIdList.iterator(); + List<User> userList = new ArrayList<User>(); + LOG.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + LOG.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + userList.add(userMap.get(id)); + LOG.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return userList; + } + + public Integer GetGender(Integer gender) { + return gender != null && gender == 1 ? 1 : 0; + } + + public void GetUser3() { + LOG.info("this is GetUser3 of impl"); + } + + public Map<String, User> GetUserMap(List<String> userIdList) { + Iterator it = userIdList.iterator(); + Map<String, User> map = new HashMap<String, User>(); + LOG.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + LOG.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + map.put(id, userMap.get(id)); + LOG.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return map; + } + + public User queryUser(User user) { + return new User(user.getId(), "hello:" +user.getName(), user.getAge() + 18); + } + + public Map<String, User> queryAll() { + return userMap; + } + + + public User getUser(int userCode) { + return new User(String.valueOf(userCode), "userCode get", 48); + } + + public User getUser(int usercode, String name) { + return new User(String.valueOf(usercode), name, 38); + } + + public int Calc(int a,int b) { + return a + b; + } + + public Response<Integer> Sum(int a,int b) { + return Response.ok(a+b); + } +} diff --git a/rpc/dubbo/java-server/2.7/run.sh b/rpc/dubbo/java-server/2.7/run.sh new file mode 100644 index 0000000..9416b14 --- /dev/null +++ b/rpc/dubbo/java-server/2.7/run.sh @@ -0,0 +1,2 @@ +mvn install -DSkipTests +mvn exec:java -Dexec.mainClass="java.org.apache.dubbo.Provider" \ No newline at end of file diff --git a/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProvider.java b/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProvider.java index 1c13f05..d6f7268 100644 --- a/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProvider.java +++ b/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProvider.java @@ -1,50 +1,52 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dubbo; - -import java.util.List; -import java.util.Map; - -public interface UserProvider { - - boolean isLimit(Gender gender, String name); - - User GetUser(String userId); // the first alpha is Upper case to compatible with golang. - - List<User> GetUsers(List<String> userIdList); - - void GetUser3(); - - User GetUser0(String userId, String name); - - User GetErr(String userId) throws Exception; - - Map<String, User> GetUserMap(List<String> userIdList); - - User getUser(int usercode); - - User getUser(int usercode, String name); - - User queryUser(User user); - - Map<String, User> queryAll(); - - int Calc(int a, int b); - - Response<Integer> Sum(int a, int b); -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dubbo; + +import java.util.List; +import java.util.Map; + +public interface UserProvider { + + boolean isLimit(Gender gender, String name); + + User GetUser(String userId); // the first alpha is Upper case to compatible with golang. + + List<User> GetUsers(List<String> userIdList); + + void GetUser3(); + + User GetUser0(String userId, String name); + + User GetErr(String userId) throws Exception; + + Map<String, User> GetUserMap(List<String> userIdList); + + User getUser(int usercode); + + User getUser(int usercode, String name); + + Integer GetGender(Integer gender); + + User queryUser(User user); + + Map<String, User> queryAll(); + + int Calc(int a, int b); + + Response<Integer> Sum(int a, int b); +} diff --git a/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProviderAnotherImpl.java b/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProviderAnotherImpl.java index cc6170e..3c84a9f 100644 --- a/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProviderAnotherImpl.java +++ b/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProviderAnotherImpl.java @@ -1,143 +1,147 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dubbo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -public class UserProviderAnotherImpl implements UserProvider { - // private static final Logger logger = LoggerFactory.getLogger(getClass()); // Only output to dubbo's log(logs/server.log) - private static final Logger logger = LoggerFactory.getLogger("userLogger"); // Output to com.dubbogo.user-server.log - - private Map<String, User> userMap = new HashMap<String, User>(); - - public UserProviderAnotherImpl() { - // userMap.put("001", new User("001", "other-zhangsan", 18, new Date(1998-1900, 1, 2, 3, 4, 5), Gender.MAN)); - userMap.put("001", new User("001", "other-zhangsan", 18, new Date(0x12345678), Gender.MAN)); - userMap.put("002", new User("002", "other-lisi", 20, new Date(1996-1900, 1, 2, 3, 4, 5), Gender.MAN)); - userMap.put("003", new User("003", "other-lily", 23, new Date(1993-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); - userMap.put("004", new User("004", "other-lisa", 32, new Date(1985-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); - } - - public boolean isLimit(Gender gender, String name) { - logger.info(String.format("input gender=%sand name=%s", gender, name)); - return Gender.MAN == gender; - } - - public User GetUser(String userId) { - logger.info("input userId = " + userId); - return new User(userId, "Joe", 48); - } - - public User GetUser0(String userId, String name) { - return new User(userId, name, 48); - } - - public void GetUser3() { - logger.info("this is GetUser3 of another"); - } - - public User GetErr(String userId) throws Exception { - throw new Exception("exception"); - } - - public List<User> GetUsers(ArrayList<String> userIdList) { - Iterator it = userIdList.iterator(); - List<User> userList = new ArrayList<User>(); - logger.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - logger.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - userList.add(userMap.get(id)); - logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return userList; - } - - public Map<String, User> GetUserMap(List<String> userIdList) { - Iterator it = userIdList.iterator(); - Map<String, User> map = new HashMap<String, User>(); - logger.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - logger.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - map.put(id, userMap.get(id)); - logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return map; - } - - public List<User> GetUsers(List<String> userIdList) { - Iterator it = userIdList.iterator(); - List<User> userList = new ArrayList<User>(); - logger.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - logger.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - userList.add(userMap.get(id)); - logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return userList; - } - - // @Override - public User getUser(int userCode) { - logger.info("input userCode = " + userCode); - return new User(String.valueOf(userCode), "userCode get", 48); - } - - public User getUser(int usercode, String name) { - return new User(String.valueOf(usercode), name, 18); - } - - public User queryUser(User user) { - logger.info("input com.dubbogo.user = " + user); - return new User(user.getId(), "get:" + user.getName(), user.getAge() + 18); - } - - public Map<String, User> queryAll() { - logger.info("input"); - Map<String, User> map = new HashMap<String, User>(); - map.put("001", new User("001", "Joe", 18)); - map.put("002", new User("002", "Wen", 20)); - - return map; - } - - public int Calc(int a,int b) { - return a + b + 100; - } - - public Response<Integer> Sum(int a,int b) { - return Response.ok(a+b); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dubbo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + +public class UserProviderAnotherImpl implements UserProvider { + // private static final Logger logger = LoggerFactory.getLogger(getClass()); // Only output to dubbo's log(logs/server.log) + private static final Logger logger = LoggerFactory.getLogger("userLogger"); // Output to com.dubbogo.user-server.log + + private Map<String, User> userMap = new HashMap<String, User>(); + + public UserProviderAnotherImpl() { + // userMap.put("001", new User("001", "other-zhangsan", 18, new Date(1998-1900, 1, 2, 3, 4, 5), Gender.MAN)); + userMap.put("001", new User("001", "other-zhangsan", 18, new Date(0x12345678), Gender.MAN)); + userMap.put("002", new User("002", "other-lisi", 20, new Date(1996-1900, 1, 2, 3, 4, 5), Gender.MAN)); + userMap.put("003", new User("003", "other-lily", 23, new Date(1993-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); + userMap.put("004", new User("004", "other-lisa", 32, new Date(1985-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); + } + + public boolean isLimit(Gender gender, String name) { + logger.info(String.format("input gender=%sand name=%s", gender, name)); + return Gender.MAN == gender; + } + + public User GetUser(String userId) { + logger.info("input userId = " + userId); + return new User(userId, "Joe", 48); + } + + public User GetUser0(String userId, String name) { + return new User(userId, name, 48); + } + + public void GetUser3() { + logger.info("this is GetUser3 of another"); + } + + public User GetErr(String userId) throws Exception { + throw new Exception("exception"); + } + + public List<User> GetUsers(ArrayList<String> userIdList) { + Iterator it = userIdList.iterator(); + List<User> userList = new ArrayList<User>(); + logger.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + logger.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + userList.add(userMap.get(id)); + logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return userList; + } + + public Map<String, User> GetUserMap(List<String> userIdList) { + Iterator it = userIdList.iterator(); + Map<String, User> map = new HashMap<String, User>(); + logger.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + logger.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + map.put(id, userMap.get(id)); + logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return map; + } + + public List<User> GetUsers(List<String> userIdList) { + Iterator it = userIdList.iterator(); + List<User> userList = new ArrayList<User>(); + logger.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + logger.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + userList.add(userMap.get(id)); + logger.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return userList; + } + + // @Override + public User getUser(int userCode) { + logger.info("input userCode = " + userCode); + return new User(String.valueOf(userCode), "userCode get", 48); + } + + public User getUser(int usercode, String name) { + return new User(String.valueOf(usercode), name, 18); + } + + public User queryUser(User user) { + logger.info("input com.dubbogo.user = " + user); + return new User(user.getId(), "get:" + user.getName(), user.getAge() + 18); + } + + public Map<String, User> queryAll() { + logger.info("input"); + Map<String, User> map = new HashMap<String, User>(); + map.put("001", new User("001", "Joe", 18)); + map.put("002", new User("002", "Wen", 20)); + + return map; + } + + public int Calc(int a,int b) { + return a + b + 100; + } + + public Response<Integer> Sum(int a,int b) { + return Response.ok(a+b); + } + + public Integer GetGender(Integer gender) { + return gender != null && gender == 1 ? 1 : 0; + } +} diff --git a/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProviderImpl.java b/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProviderImpl.java index bdb9651..b711ae9 100644 --- a/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProviderImpl.java +++ b/rpc/dubbo/java-server/2.7/src/main/java/org/apache/dubbo/UserProviderImpl.java @@ -1,115 +1,119 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.dubbo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -public class UserProviderImpl implements UserProvider { - // private static final Logger logger = LoggerFactory.getLogger(getClass()); // Only output to dubbo's log(logs/server.log) - private static final Logger LOG = LoggerFactory.getLogger("UserLogger"); // Output to com.dubbogo.user-server.log - Map<String, User> userMap = new HashMap<String, User>(); - - public UserProviderImpl() { - userMap.put("A001", new User("A001", "demo-zhangsan", 18)); - userMap.put("A002", new User("A002", "demo-lisi", 20)); - userMap.put("A003", new User("A003", "demo-lily", 23)); - userMap.put("A004", new User("A004", "demo-lisa", 32)); - } - - public boolean isLimit(Gender gender, String name) { - return Gender.WOMAN == gender; - } - - public User GetUser(String userId) { - return new User(userId, "zhangsan", 18); - } - - public User GetErr(String userId) throws Exception { - throw new Exception("exception"); - } - - public User GetUser0(String userId, String name) { - return new User(userId, name, 18); - } - - public List<User> GetUsers(List<String> userIdList) { - Iterator it = userIdList.iterator(); - List<User> userList = new ArrayList<User>(); - LOG.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - LOG.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - userList.add(userMap.get(id)); - LOG.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return userList; - } - - public void GetUser3() { - LOG.info("this is GetUser3 of impl"); - } - - public Map<String, User> GetUserMap(List<String> userIdList) { - Iterator it = userIdList.iterator(); - Map<String, User> map = new HashMap<String, User>(); - LOG.warn("@userIdList size:" + userIdList.size()); - - while(it.hasNext()) { - String id = (String)(it.next()); - LOG.info("GetUsers(@uid:" + id + ")"); - if (userMap.containsKey(id)) { - map.put(id, userMap.get(id)); - LOG.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); - } - } - - return map; - } - - public User queryUser(User user) { - return new User(user.getId(), "hello:" +user.getName(), user.getAge() + 18); - } - - public Map<String, User> queryAll() { - return userMap; - } - - - public User getUser(int userCode) { - return new User(String.valueOf(userCode), "userCode get", 48); - } - - public User getUser(int usercode, String name) { - return new User(String.valueOf(usercode), name, 38); - } - - public int Calc(int a,int b) { - return a + b; - } - - public Response<Integer> Sum(int a,int b) { - return Response.ok(a+b); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dubbo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + +public class UserProviderImpl implements UserProvider { + // private static final Logger logger = LoggerFactory.getLogger(getClass()); // Only output to dubbo's log(logs/server.log) + private static final Logger LOG = LoggerFactory.getLogger("UserLogger"); // Output to com.dubbogo.user-server.log + Map<String, User> userMap = new HashMap<String, User>(); + + public UserProviderImpl() { + userMap.put("A001", new User("A001", "demo-zhangsan", 18)); + userMap.put("A002", new User("A002", "demo-lisi", 20)); + userMap.put("A003", new User("A003", "demo-lily", 23)); + userMap.put("A004", new User("A004", "demo-lisa", 32)); + } + + public boolean isLimit(Gender gender, String name) { + return Gender.WOMAN == gender; + } + + public User GetUser(String userId) { + return new User(userId, "zhangsan", 18); + } + + public User GetErr(String userId) throws Exception { + throw new Exception("exception"); + } + + public User GetUser0(String userId, String name) { + return new User(userId, name, 18); + } + + public List<User> GetUsers(List<String> userIdList) { + Iterator it = userIdList.iterator(); + List<User> userList = new ArrayList<User>(); + LOG.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + LOG.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + userList.add(userMap.get(id)); + LOG.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return userList; + } + + public void GetUser3() { + LOG.info("this is GetUser3 of impl"); + } + + public Map<String, User> GetUserMap(List<String> userIdList) { + Iterator it = userIdList.iterator(); + Map<String, User> map = new HashMap<String, User>(); + LOG.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + LOG.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + map.put(id, userMap.get(id)); + LOG.info("id:" + id + ", com.dubbogo.user:" + userMap.get(id)); + } + } + + return map; + } + + public User queryUser(User user) { + return new User(user.getId(), "hello:" +user.getName(), user.getAge() + 18); + } + + public Map<String, User> queryAll() { + return userMap; + } + + + public User getUser(int userCode) { + return new User(String.valueOf(userCode), "userCode get", 48); + } + + public User getUser(int usercode, String name) { + return new User(String.valueOf(usercode), name, 38); + } + + public int Calc(int a,int b) { + return a + b; + } + + public Response<Integer> Sum(int a,int b) { + return Response.ok(a+b); + } + + public Integer GetGender(Integer gender) { + return gender != null && gender == 1 ? 1 : 0; + } +}
