├── .gitignore ├── LICENSE ├── README.md ├── jprotobuf-rpc-core-spring-base ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── baidu │ │ └── jprotobuf │ │ └── pbrpc │ │ ├── client │ │ └── ha │ │ │ ├── HaProtobufRpcProxy.java │ │ │ ├── NamingService.java │ │ │ ├── NamingServiceChangeListener.java │ │ │ └── lb │ │ │ ├── LoadBalanceProxyFactoryBean.java │ │ │ ├── ServiceInterfaceAccessor.java │ │ │ ├── ServiceMultiInterfaceAccessor.java │ │ │ ├── failover │ │ │ ├── DummySocketFailOverInterceptor.java │ │ │ ├── FailOverEvent.java │ │ │ ├── FailOverInterceptor.java │ │ │ ├── RecoverHeartbeat.java │ │ │ ├── SocketFailOverInterceptor.java │ │ │ ├── TimeoutIgnoredSocketFailOverInterceptor.java │ │ │ ├── TimeoutIngoredSocketFailOverInterceptor.java │ │ │ └── package.html │ │ │ ├── package.html │ │ │ └── strategy │ │ │ ├── LoadBalanceStrategy.java │ │ │ ├── NamingServiceLoadBalanceStrategy.java │ │ │ ├── NamingServiceLoadBalanceStrategyFactory.java │ │ │ ├── RRNamingServiceLoadBalanceStrategyFactory.java │ │ │ ├── RoundRobinLoadBalanceStrategy.java │ │ │ ├── StrategyInterceptor.java │ │ │ └── package.html │ │ └── spring │ │ ├── HaProtobufRpcProxyBean.java │ │ ├── HaRpcProxyFactoryBean.java │ │ ├── PlaceholderResolved.java │ │ ├── PlaceholderResolver.java │ │ ├── PropertyPlaceholderConfigurerTool.java │ │ ├── ProtobufRpcProxyBean.java │ │ ├── RpcProxyFactoryBean.java │ │ ├── RpcServiceExporter.java │ │ ├── RpcServiceRegistryBean.java │ │ ├── UrlBasedNamingService.java │ │ ├── annotation │ │ ├── AbstractAnnotationParserCallback.java │ │ ├── AnnotationParserCallback.java │ │ ├── HaRpcProxy.java │ │ ├── ProtobufRpcAnnotationResolver.java │ │ ├── ProtobufRpcAnnotationRessolverListener.java │ │ ├── RpcExporter.java │ │ └── RpcProxy.java │ │ └── meta │ │ └── RpcMetaExporter.java │ └── test │ ├── java │ └── com │ │ └── baidu │ │ └── jprotobuf │ │ └── pbrpc │ │ └── client │ │ ├── ha │ │ └── lb │ │ │ └── LoadBalanceProxyFactoryBeanTest.java │ │ └── test │ │ ├── Greet.java │ │ └── SimpleGreet.java │ └── resources │ └── com │ └── baidu │ └── jprotobuf │ └── pbrpc │ └── spring │ ├── AnnotationRpcXmlConfigurationTest.xml │ ├── HaRpcXmlConfigurationTest.xml │ ├── RpcXmlConfigurationTest.xml │ ├── client │ └── AnnotationRpcXmlConfigurationTest.xml │ └── server │ └── AnnotationRpcXmlConfigurationTest.xml ├── jprotobuf-rpc-core-spring ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── baidu │ │ └── jprotobuf │ │ └── pbrpc │ │ └── spring │ │ └── annotation │ │ └── CommonAnnotationBeanPostProcessor.java │ └── test │ ├── java │ └── com │ │ └── baidu │ │ └── jprotobuf │ │ └── pbrpc │ │ ├── client │ │ └── ha │ │ │ ├── DummyNamingService.java │ │ │ ├── HaEchoServiceTest.java │ │ │ └── HaEchoServiceTestBase.java │ │ └── spring │ │ ├── AnnotationEchoServiceClient.java │ │ ├── AnnotationEchoServiceImpl.java │ │ ├── AnnotationEchoServiceImpl2.java │ │ ├── AnnotationEchoServiceImpl3.java │ │ ├── AnnotationEchoServiceImpl4.java │ │ ├── AnnotationRpcXmlConfigurationTest.java │ │ ├── ClientRPCInvokerInterceptor.java │ │ ├── HaRpcXmlConfigurationTest.java │ │ ├── MyInterceptor.java │ │ ├── RpcProxyTest.java │ │ ├── RpcXmlConfigurationTest.java │ │ ├── RpcXmlConfigurationTestBase.java │ │ ├── ServerRPCInvokerInterceptor.java │ │ ├── SimpleAopClass.java │ │ └── SimpleBean.java │ └── resources │ └── com │ └── baidu │ └── jprotobuf │ └── pbrpc │ └── spring │ ├── AnnotationRpcXmlConfigurationTest.xml │ ├── HaRpcXmlConfigurationTest.xml │ └── RpcXmlConfigurationTest.xml ├── jprotobuf-rpc-core-spring2 ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── baidu │ │ └── jprotobuf │ │ └── pbrpc │ │ └── spring │ │ └── annotation │ │ └── CommonAnnotationBeanPostProcessor.java │ └── test │ ├── java │ └── com │ │ └── baidu │ │ └── jprotobuf │ │ └── pbrpc │ │ ├── client │ │ └── ha │ │ │ ├── DummyNamingService.java │ │ │ ├── HaEchoServiceTest.java │ │ │ └── HaEchoServiceTestBase.java │ │ └── spring │ │ ├── AnnotationEchoServiceClient.java │ │ ├── AnnotationEchoServiceImpl.java │ │ ├── AnnotationEchoServiceImpl2.java │ │ ├── AnnotationEchoServiceImpl3.java │ │ ├── AnnotationEchoServiceImpl4.java │ │ ├── AnnotationRpcXmlConfigurationTest.java │ │ ├── ClientRPCInvokerInterceptor.java │ │ ├── HaRpcXmlConfigurationTest.java │ │ ├── MyInterceptor.java │ │ ├── RpcProxyTest.java │ │ ├── RpcXmlConfigurationTest.java │ │ ├── RpcXmlConfigurationTestBase.java │ │ ├── ServerRPCInvokerInterceptor.java │ │ ├── SimpleAopClass.java │ │ └── SimpleBean.java │ └── resources │ └── com │ └── baidu │ └── jprotobuf │ └── pbrpc │ └── spring │ ├── AnnotationRpcXmlConfigurationTest.xml │ ├── HaRpcXmlConfigurationTest.xml │ ├── RpcXmlConfigurationTest.xml │ ├── client │ └── AnnotationRpcXmlConfigurationTest.xml │ └── server │ └── AnnotationRpcXmlConfigurationTest.xml ├── jprotobuf-rpc-core-test ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── baidu │ └── jprotobuf │ └── pbrpc │ ├── BaseTest.java │ ├── EchoAuthenticationDataHandler.java │ ├── EchoClientAttachmentHandler.java │ ├── EchoInfo.java │ ├── EchoLogIDGenerator.java │ ├── EchoServerAttachmentHandler.java │ ├── EchoServerAuthenticationDataHandler.java │ ├── EchoService.java │ ├── EchoServiceImpl.java │ ├── proto │ ├── EchoInfoClass.java │ ├── EchoService.java │ ├── EchoServiceImpl.java │ └── echo.proto │ └── utils │ └── SleepUtils.java ├── jprotobuf-rpc-core ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── baidu │ │ └── jprotobuf │ │ └── pbrpc │ │ ├── ErrorDataException.java │ │ ├── RpcChannelErrorException.java │ │ ├── RpcHandler.java │ │ ├── client │ │ ├── DynamicProtobufRpcProxy.java │ │ ├── GeneratedMessageRpcMethodInfo.java │ │ ├── PojoRpcMethodInfo.java │ │ ├── ProtobufRpcProxy.java │ │ ├── ProxyFactory.java │ │ ├── RpcMethodInfo.java │ │ ├── ServiceLocatorCallback.java │ │ ├── ServiceUrlAccessible.java │ │ ├── SimpleServiceLocatorCallabck.java │ │ └── package-info.java │ │ ├── compress │ │ ├── Compress.java │ │ ├── GZipCompress.java │ │ ├── SnappyCompress.java │ │ └── package-info.java │ │ ├── data │ │ ├── ChunkInfo.java │ │ ├── ProtocolConstant.java │ │ ├── Readable.java │ │ ├── RpcDataPackage.java │ │ ├── RpcHeadMeta.java │ │ ├── RpcMeta.java │ │ ├── RpcRequestMeta.java │ │ ├── RpcRequestMetaExtField.java │ │ ├── RpcResponseMeta.java │ │ ├── Trace.java │ │ ├── TraceContext.java │ │ ├── Writerable.java │ │ └── package-info.java │ │ ├── intercept │ │ ├── ChainedInvokerInterceptor.java │ │ ├── InvokerInterceptor.java │ │ ├── MethodInvocationInfo.java │ │ └── package-info.java │ │ ├── management │ │ ├── HttpConstants.java │ │ ├── HttpServer.java │ │ ├── HttpServerInboundHandler.java │ │ ├── ServerStatus.java │ │ └── package-info.java │ │ ├── meta │ │ ├── MetaExportHelper.java │ │ ├── RpcMetaAware.java │ │ ├── RpcServiceMeta.java │ │ ├── RpcServiceMetaList.java │ │ ├── RpcServiceMetaService.java │ │ └── RpcServiceMetaServiceProvider.java │ │ ├── package-info.java │ │ ├── registry │ │ ├── AsyncRegistryService.java │ │ ├── NotifyListener.java │ │ ├── RegisterInfo.java │ │ └── RegistryCenterService.java │ │ ├── server │ │ ├── AbstractAnnotationRpcHandler.java │ │ ├── AbstractServiceExporter.java │ │ ├── AnnotationRpcHandler.java │ │ ├── IDLServiceExporter.java │ │ ├── IDLServiceInvoker.java │ │ ├── IDLServiceRpcHandler.java │ │ ├── MessageGeneratedRpcHandler.java │ │ ├── RpcData.java │ │ ├── RpcServiceHandleContext.java │ │ ├── RpcServiceRegistry.java │ │ ├── ServiceExporter.java │ │ └── package-info.java │ │ ├── transport │ │ ├── AbstractChannelPoolSharableFactory.java │ │ ├── BlockingRpcCallback.java │ │ ├── ChannelPool.java │ │ ├── ChannelPoolObjectFactory.java │ │ ├── ChannelPoolSharableFactory.java │ │ ├── Connection.java │ │ ├── ExceptionCatcher.java │ │ ├── ExceptionHandler.java │ │ ├── GlobalChannelPoolSharableFactory.java │ │ ├── RpcChannel.java │ │ ├── RpcChannelFutureListener.java │ │ ├── RpcClient.java │ │ ├── RpcClientCallState.java │ │ ├── RpcClientOptions.java │ │ ├── RpcClientPipelineinitializer.java │ │ ├── RpcErrorMessage.java │ │ ├── RpcServer.java │ │ ├── RpcServerOptions.java │ │ ├── RpcServerPipelineInitializer.java │ │ ├── RpcTimerTask.java │ │ ├── SimpleChannelPoolSharableFactory.java │ │ ├── handler │ │ │ ├── ErrorCodes.java │ │ │ ├── RpcClientServiceHandler.java │ │ │ ├── RpcDataPackageCompressHandler.java │ │ │ ├── RpcDataPackageDecoder.java │ │ │ ├── RpcDataPackageEncoder.java │ │ │ ├── RpcDataPackageUnCompressHandler.java │ │ │ ├── RpcServerChannelIdleHandler.java │ │ │ ├── RpcServiceHandler.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ └── utils │ │ ├── ArrayUtils.java │ │ ├── Constants.java │ │ ├── LogIdThreadLocalHolder.java │ │ ├── MapUtils.java │ │ ├── NetUtils.java │ │ ├── Pool.java │ │ ├── ReflectionUtils.java │ │ ├── ServiceSignatureUtils.java │ │ ├── StringUtils.java │ │ ├── TalkTimeoutController.java │ │ └── package-info.java │ └── test │ └── java │ └── com │ └── baidu │ └── jprotobuf │ └── pbrpc │ ├── BaseEchoServiceTest.java │ ├── BasePerformaceTest.java │ ├── BusinessExceptionTest.java │ ├── ClientMain.java │ ├── DynamiceEchoServiceTest.java │ ├── EchoServicePerformanceMain.java │ ├── EchoServicePerformanceTest.java │ ├── EchoServiceTest.java │ ├── PingDemo.java │ ├── RpcServiceMetaServiceTest.java │ ├── ServerMain.java │ ├── TrunkEchoServiceTest.java │ ├── compress │ ├── BaseCompressTest.java │ ├── GZipCompressTest.java │ └── SnappyCompressTest.java │ ├── data │ ├── ChunkInfoTest.java │ ├── RpcDataPackageTest.java │ ├── RpcHeadMetaTest.java │ ├── RpcMetaTest.java │ ├── RpcRequestMetaTest.java │ ├── RpcResponseMetaTest.java │ └── TraceTest.java │ └── proto │ ├── BaseEchoServiceTest.java │ ├── EchoServicePerformanceTest.java │ └── EchoServiceTest.java ├── jprotobuf-rpc-ext-validator ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── baidu │ │ └── jprotobuf │ │ └── pbrpc │ │ └── ext │ │ └── validator │ │ ├── BeanValidatorInvokerInterceptor.java │ │ ├── ConstraintViolationsFormatter.java │ │ ├── DefaultConstraintViolationsFormatter.java │ │ └── package-info.java │ └── test │ └── java │ └── com │ └── baidu │ └── jprotobuf │ └── pbrpc │ └── ext │ └── validator │ ├── BeanValidatorInvokerInterceptorTest.java │ └── PojoBean.java ├── jprotobuf-rpc-registry-bns ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── baidu │ │ └── pbrpc │ │ └── register │ │ └── bns │ │ ├── BNSNamingService.java │ │ ├── BNSNamingServiceOld.java │ │ └── package-info.java │ └── test │ └── java │ └── com │ └── baidu │ └── pbrpc │ └── register │ └── bns │ ├── BNSNamingServiceMock.java │ └── BnsNamingServiceXmlConfigurationTest.xml ├── jprotobuf-rpc-registry-redis ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── baidu │ │ └── pbrpc │ │ ├── register │ │ └── redis │ │ │ ├── JedisPool.java │ │ │ ├── RedisClient.java │ │ │ └── RedisRegistryService.java │ │ └── utils │ │ ├── RedisCacheableJdkCompiler.java │ │ └── package-info.java │ └── test │ └── resources │ └── com │ └── baidu │ └── pbrpc │ └── register │ └── redis │ └── RedisRegisterRpcXmlConfigurationTest.xml ├── jprotobuf-rpc-spring-starter ├── .factorypath ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── baidu │ │ └── pbrpc │ │ └── spring │ │ ├── conf │ │ └── PbRPCConfiguration.java │ │ └── package-info.java │ └── resources │ └── META-INF │ └── spring.factories ├── pom.xml └── user_guide.md /.gitignore: -------------------------------------------------------------------------------- 1 | ### NetBeans template 2 | nbproject/private/ 3 | build/ 4 | nbbuild/ 5 | dist/ 6 | nbdist/ 7 | nbactions.xml 8 | nb-configuration.xml 9 | 10 | 11 | ### Eclipse template 12 | *.pydevproject 13 | .metadata 14 | .gradle 15 | bin/ 16 | tmp/ 17 | *.tmp 18 | *.bak 19 | *.swp 20 | *~.nib 21 | local.properties 22 | .settings/ 23 | .loadpath 24 | 25 | # External tool builders 26 | .externalToolBuilders/ 27 | 28 | # Locally stored "Eclipse launch configurations" 29 | *.launch 30 | 31 | # CDT-specific 32 | .cproject 33 | 34 | # PDT-specific 35 | .buildpath 36 | 37 | # sbteclipse plugin 38 | .target 39 | 40 | # TeXlipse plugin 41 | .texlipse 42 | 43 | 44 | ### SVN template 45 | .svn/ 46 | 47 | 48 | ### JetBrains template 49 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 50 | 51 | *.iml 52 | 53 | ## Directory-based project format: 54 | .idea/ 55 | # if you remove the above rule, at least ignore the following: 56 | 57 | # User-specific stuff: 58 | # .idea/workspace.xml 59 | # .idea/tasks.xml 60 | # .idea/dictionaries 61 | 62 | # Sensitive or high-churn files: 63 | # .idea/dataSources.ids 64 | # .idea/dataSources.xml 65 | # .idea/sqlDataSources.xml 66 | # .idea/dynamic.xml 67 | # .idea/uiDesigner.xml 68 | 69 | # Gradle: 70 | # .idea/gradle.xml 71 | # .idea/libraries 72 | 73 | # Mongo Explorer plugin: 74 | # .idea/mongoSettings.xml 75 | 76 | ## File-based project format: 77 | *.ipr 78 | *.iws 79 | 80 | ## Plugin-specific files: 81 | 82 | # IntelliJ 83 | out/ 84 | 85 | # mpeltonen/sbt-idea plugin 86 | .idea_modules/ 87 | 88 | # JIRA plugin 89 | atlassian-ide-plugin.xml 90 | 91 | # Crashlytics plugin (for Android Studio and IntelliJ) 92 | com_crashlytics_export_strings.xml 93 | crashlytics.properties 94 | crashlytics-build.properties 95 | 96 | 97 | ### Java template 98 | *.class 99 | 100 | # Mobile Tools for Java (J2ME) 101 | .mtj.tmp/ 102 | 103 | # Package Files # 104 | *.jar 105 | *.war 106 | *.ear 107 | 108 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 109 | hs_err_pid* 110 | 111 | 112 | 113 | ### Maven template 114 | target/ 115 | pom.xml.tag 116 | pom.xml.releaseBackup 117 | pom.xml.versionsBackup 118 | pom.xml.next 119 | release.properties 120 | 121 | 122 | /dependency/ 123 | /log/ 124 | 125 | .checkstyle 126 | *.classpath 127 | .project 128 | /jprotobuf-rpc-ext-dtc/ 129 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.baidu 6 | jprotobuf-rpc-socket 7 | 4.2.2 8 | 9 | jprotobuf-rpc-core-spring-base 10 | jar 11 | ${project.artifactId} 12 | The module for Spring extendsion 13 | 14 | 15 | UTF-8 16 | 17 | 3.2.11.RELEASE 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | com.baidu 27 | jprotobuf-rpc-core 28 | ${project.parent.version} 29 | 30 | 31 | org.springframework 32 | spring-web 33 | ${spring-web.version} 34 | 35 | 36 | org.springframework 37 | spring-aop 38 | ${spring-web.version} 39 | 40 | 41 | cglib 42 | cglib 43 | 3.2.0 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/NamingService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | import java.util.Set; 21 | 22 | import com.baidu.jprotobuf.pbrpc.registry.RegisterInfo; 23 | 24 | /** 25 | * Naming service interface. 26 | * 27 | * @author xiemalin 28 | * @since 2.15 29 | */ 30 | public interface NamingService { 31 | 32 | /** 33 | * get server list from naming service. 34 | * 35 | * @param serviceSignatures service signatures 36 | * @return server list mapped by service signature. 37 | * @throws Exception in case of any exception 38 | */ 39 | Map> list(Set serviceSignatures) throws Exception; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/ServiceInterfaceAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb; 17 | 18 | /** 19 | * Service Interface Accessor. 20 | * 21 | * @author xiemalin 22 | * @since 1.0.0.0 23 | */ 24 | public abstract class ServiceInterfaceAccessor { 25 | 26 | /** The service interface. */ 27 | private Class serviceInterface; 28 | 29 | /** 30 | * Sets the service interface. 31 | * 32 | * @param serviceInterface the new service interface 33 | */ 34 | public void setServiceInterface(Class serviceInterface) { 35 | if (serviceInterface != null && !serviceInterface.isInterface()) { 36 | throw new IllegalArgumentException("'serviceInterface' must be an interface"); 37 | } 38 | this.serviceInterface = serviceInterface; 39 | } 40 | 41 | /** 42 | * Gets the service interface. 43 | * 44 | * @return the service interface 45 | */ 46 | public Class getServiceInterface() { 47 | return this.serviceInterface; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/failover/DummySocketFailOverInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.failover; 17 | 18 | /** 19 | * Dummy {@link FailOverInterceptor} instance to close fail over feature. 20 | * 21 | * @author xiemalin 22 | * @since 3.1.3 23 | */ 24 | public class DummySocketFailOverInterceptor extends SocketFailOverInterceptor { 25 | 26 | /* 27 | * (non-Javadoc) 28 | * 29 | * @see com.baidu.jprotobuf.pbrpc.client.ha.lb.failover.FailOverInterceptor#isDoFailover(java.lang.Throwable, 30 | * java.lang.String) 31 | */ 32 | @Override 33 | public boolean isDoFailover(Throwable t, String beanKey) { 34 | return false; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/failover/FailOverEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.failover; 17 | 18 | import org.aopalliance.intercept.MethodInvocation; 19 | 20 | /** 21 | * Load balance fail over event interface. 22 | * 23 | * @author xiemalin 24 | * @since 2.16 25 | */ 26 | public interface FailOverEvent { 27 | 28 | /** 29 | * if detect target is recovered. 30 | * 31 | * @param targetName the target name 32 | */ 33 | void onTargetRecover(String targetName); 34 | 35 | /** 36 | * if detect target is fail on specified invoke action. 37 | * 38 | * @param targetName the target name 39 | * @param bean the bean 40 | * @param invocation the invocation 41 | */ 42 | void onTargetFailed(String targetName, Object bean, 43 | MethodInvocation invocation); 44 | } 45 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/failover/FailOverInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.failover; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | /** 21 | * Load balance fail over intercepter interface.
22 | * 23 | * @author xiemalin 24 | * @see LoadBalanceProxyFactoryBean 25 | * @since 2.16 26 | */ 27 | public interface FailOverInterceptor { 28 | 29 | /** 30 | * return if target is available. 31 | * 32 | * @param o the o 33 | * @param m the m 34 | * @param beanKey the bean key 35 | * @return true if available 36 | */ 37 | boolean isAvailable(Object o, Method m, String beanKey); 38 | 39 | /** 40 | * return if failed target is recovered. 41 | * 42 | * @param o the o 43 | * @param m the m 44 | * @param beanKey the bean key 45 | * @return true if recovered 46 | */ 47 | boolean isRecover(Object o, Method m, String beanKey); 48 | 49 | /** 50 | * return is catch exception need do fail over action. 51 | * 52 | * @param t the t 53 | * @param beanKey the bean key 54 | * @return true if do fail over action 55 | */ 56 | boolean isDoFailover(Throwable t, String beanKey); 57 | } 58 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/failover/TimeoutIgnoredSocketFailOverInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.failover; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import com.baidu.jprotobuf.pbrpc.ErrorDataException; 22 | import com.baidu.jprotobuf.pbrpc.transport.handler.ErrorCodes; 23 | 24 | /** 25 | * Dummy all failover action of timeout exception. 26 | * 27 | * @author xiemalin 28 | * @since 3.1.9 29 | */ 30 | public class TimeoutIgnoredSocketFailOverInterceptor extends SocketFailOverInterceptor { 31 | 32 | /** log this class. */ 33 | protected static final Logger LOGGER = LoggerFactory.getLogger(TimeoutIgnoredSocketFailOverInterceptor.class); 34 | 35 | /* 36 | * (non-Javadoc) 37 | * 38 | * @see com.baidu.jprotobuf.pbrpc.client.ha.lb.failover.SocketFailOverInterceptor#isDoFailover(java.lang.Throwable, 39 | * java.lang.String) 40 | */ 41 | @Override 42 | public boolean isDoFailover(Throwable t, String beanKey) { 43 | if (t instanceof ErrorDataException) { 44 | ErrorDataException errorDataException = (ErrorDataException) t; 45 | int errorCode = errorDataException.getErrorCode(); 46 | // only not read time out error should do fail over action 47 | boolean doFailover = ErrorCodes.ST_READ_TIMEOUT != errorCode; 48 | if (!doFailover && LOGGER.isInfoEnabled()) { 49 | LOGGER.info("Found timeout exception of ErrorDataException in failoverinterceptor, " 50 | + "will not do failover now."); 51 | } 52 | return doFailover; 53 | } 54 | 55 | return super.isDoFailover(t, beanKey); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/failover/TimeoutIngoredSocketFailOverInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.failover; 17 | 18 | /** 19 | * Dummy all failover action of timeout exception. 20 | * 21 | * @author xiemalin 22 | * @since 3.1.5 23 | * @deprecated Due to error spell pls using {@link TimeoutIgnoredSocketFailOverInterceptor} instead 24 | */ 25 | @Deprecated 26 | public class TimeoutIngoredSocketFailOverInterceptor extends TimeoutIgnoredSocketFailOverInterceptor { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/failover/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Load balance fail over interface implementation. 5 | 6 |
7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Common load balance support base on spring. 5 | 6 |
7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/strategy/LoadBalanceStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.strategy; 17 | 18 | import java.util.Set; 19 | 20 | import com.baidu.jprotobuf.pbrpc.client.ha.lb.LoadBalanceProxyFactoryBean; 21 | 22 | /** 23 | * load balance strategy interface. 24 | * 25 | * @author xiemalin 26 | * @see LoadBalanceProxyFactoryBean 27 | * @since 2.16 28 | */ 29 | public interface LoadBalanceStrategy { 30 | 31 | /** 32 | * do load balance and get target. 33 | * 34 | * @return the string 35 | */ 36 | String elect(); 37 | 38 | /** 39 | * remove target from load balance target list. 40 | * 41 | * @param t the t 42 | */ 43 | void removeTarget(String t); 44 | 45 | /** 46 | * add target to load balance target list. 47 | * 48 | * @param t the t 49 | */ 50 | void recoverTarget(String t); 51 | 52 | /** 53 | * Gets the targets. 54 | * 55 | * @return the targets 56 | */ 57 | Set getTargets(); 58 | 59 | /** 60 | * Checks for targets. 61 | * 62 | * @return true if availabled load balance target list is not empty 63 | */ 64 | boolean hasTargets(); 65 | 66 | /** 67 | * Gets the failed targets. 68 | * 69 | * @return the failed targets 70 | */ 71 | Set getFailedTargets(); 72 | 73 | } 74 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/strategy/NamingServiceLoadBalanceStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.strategy; 17 | 18 | import com.baidu.jprotobuf.pbrpc.client.ha.NamingService; 19 | 20 | /** 21 | * {@link NamingService} support load balance strategy. 22 | * 23 | * @author xiemalin 24 | * @since 2.17 25 | */ 26 | public interface NamingServiceLoadBalanceStrategy extends LoadBalanceStrategy { 27 | 28 | /** 29 | * do reinit once by the naming service. 30 | * 31 | * @param serviceSignature the service signature 32 | * @param namingService {@link NamingService} 33 | */ 34 | void doReInit(String serviceSignature, NamingService namingService); 35 | } 36 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/strategy/NamingServiceLoadBalanceStrategyFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.strategy; 17 | 18 | import com.baidu.jprotobuf.pbrpc.client.ha.NamingService; 19 | 20 | /** 21 | * Factory pattern for {@link NamingServiceLoadBalanceStrategy}. 22 | * 23 | * @author xiemalin 24 | * @since 2.19 25 | */ 26 | public interface NamingServiceLoadBalanceStrategyFactory { 27 | 28 | /** 29 | * create a new {@link NamingServiceLoadBalanceStrategy}. 30 | * 31 | * @param serviceSignature service signature 32 | * @param namingService naming service 33 | * @return {@link NamingServiceLoadBalanceStrategy} 34 | */ 35 | NamingServiceLoadBalanceStrategy create(String serviceSignature, NamingService namingService); 36 | } 37 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/strategy/RRNamingServiceLoadBalanceStrategyFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.strategy; 17 | 18 | import com.baidu.jprotobuf.pbrpc.client.ha.NamingService; 19 | 20 | /** 21 | * Factory bean for {@link RoundRobinLoadBalanceStrategy}. 22 | * 23 | * @author xiemalin 24 | * @since 2.19 25 | */ 26 | public class RRNamingServiceLoadBalanceStrategyFactory implements NamingServiceLoadBalanceStrategyFactory { 27 | 28 | /* 29 | * (non-Javadoc) 30 | * 31 | * @see 32 | * com.baidu.jprotobuf.pbrpc.client.ha.lb.strategy.NamingServiceLoadBalanceStrategyFactory#create(java.lang.String, 33 | * com.baidu.jprotobuf.pbrpc.client.ha.NamingService) 34 | */ 35 | @Override 36 | public NamingServiceLoadBalanceStrategy create(String serviceSignature, NamingService namingService) { 37 | return new RoundRobinLoadBalanceStrategy(serviceSignature, namingService); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/strategy/StrategyInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha.lb.strategy; 17 | 18 | import org.aopalliance.intercept.MethodInvocation; 19 | 20 | import com.baidu.jprotobuf.pbrpc.client.ha.lb.failover.FailOverEvent; 21 | 22 | /** 23 | * load balance strategy intercepter.
24 | * it implements from {@link FailOverEvent} 25 | * 26 | * @author xiemalin 27 | * @see FailOverEvent 28 | * @since 2.16 29 | */ 30 | public interface StrategyInterceptor extends FailOverEvent { 31 | 32 | /** 33 | * before strategy elect method invoke. 34 | * 35 | * @param lbStratety {@link LoadBalanceStrategy} 36 | * @param invocation {@link MethodInvocation} 37 | */ 38 | void beforeElection(LoadBalanceStrategy lbStratety, 39 | MethodInvocation invocation); 40 | 41 | /** 42 | * after strategy elect method invoke. 43 | * 44 | * @param electKey elect returned target name 45 | * @param invocation {@link MethodInvocation} 46 | */ 47 | void afterElection(String electKey, MethodInvocation invocation); 48 | 49 | /** 50 | * return if need to do elect method. 51 | * 52 | * @param invocation {@link MethodInvocation} 53 | * @return true if need to do elect method 54 | */ 55 | boolean isDoElection(MethodInvocation invocation); 56 | 57 | /** 58 | * do elect action. 59 | * 60 | * @param invocation {@link MethodInvocation} 61 | * @return the string 62 | */ 63 | String elect(MethodInvocation invocation); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/client/ha/lb/strategy/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Load balance strategy interface implementation. 5 | 6 |
7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/spring/PlaceholderResolved.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | /** 19 | * Placehoader resolved call back . 20 | * 21 | * @author xiemalin 22 | * @since 2.17 23 | */ 24 | public interface PlaceholderResolved { 25 | 26 | /** 27 | * parsed placeholder value returned. 28 | * 29 | * @param placeholder the placeholder 30 | * @return parsed string 31 | */ 32 | String doResolved(String placeholder); 33 | } 34 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/spring/RpcServiceRegistryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import com.baidu.jprotobuf.pbrpc.ProtobufRPCService; 21 | import com.baidu.jprotobuf.pbrpc.RpcHandler; 22 | import com.baidu.jprotobuf.pbrpc.server.RpcServiceRegistry; 23 | 24 | /** 25 | * Supports {@link RemoteInvocationExecutor} parse. 26 | * 27 | * @author xiemalin 28 | * @since 2.17 29 | */ 30 | public class RpcServiceRegistryBean extends RpcServiceRegistry { 31 | 32 | /** 33 | * Instantiates a new rpc service registry bean. 34 | */ 35 | public RpcServiceRegistryBean() { 36 | } 37 | 38 | /* 39 | * (non-Javadoc) 40 | * 41 | * @see 42 | * com.baidu.jprotobuf.pbrpc.server.RpcServiceRegistry#doCreateRpcHandler 43 | * (java.lang.reflect.Method, java.lang.Object, 44 | * com.baidu.jprotobuf.pbrpc.ProtobufPRCService) 45 | */ 46 | @Override 47 | protected RpcHandler doCreateRpcHandler(Method method, 48 | Object service, ProtobufRPCService protobufPRCService) { 49 | 50 | RpcHandler handler = super.doCreateRpcHandler(method, service, protobufPRCService); 51 | return handler; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/spring/annotation/AbstractAnnotationParserCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring.annotation; 17 | 18 | import com.baidu.jprotobuf.pbrpc.spring.PlaceholderResolver; 19 | import com.baidu.jprotobuf.pbrpc.utils.StringUtils; 20 | 21 | 22 | /** 23 | * Base annotation parser call back class. 24 | * 25 | * @author xiemalin 26 | * @since 2.17 27 | */ 28 | public abstract class AbstractAnnotationParserCallback implements 29 | AnnotationParserCallback { 30 | 31 | 32 | /** configuration resource placeholder resolver. */ 33 | private PlaceholderResolver resolver; 34 | 35 | /** 36 | * do parser action. 37 | * 38 | * @param value to parser 39 | * @return value parser by {@link PlaceholderResolver} 40 | */ 41 | public String parsePlaceholder(String value) { 42 | if (resolver != null) { 43 | return resolver.doParse(value); 44 | } 45 | return value; 46 | } 47 | 48 | /** 49 | * test if value contains placeholder marked string. 50 | * 51 | * @param value to test 52 | * @return true if string is null or contains placeholder marked string 53 | */ 54 | public boolean hasPlaceholder(String value) { 55 | if (StringUtils.isBlank(value)) { 56 | return false; 57 | } 58 | if (resolver != null) { 59 | return resolver.hasPlaceHolder(value); 60 | } 61 | return false; 62 | } 63 | 64 | /* (non-Javadoc) 65 | * @see com.baidu.jprotobuf.pbrpc.spring.annotation.AnnotationParserCallback#setPlaceholderResolver(com.baidu.jprotobuf.pbrpc.spring.PlaceholderResolver) 66 | */ 67 | public void setPlaceholderResolver(PlaceholderResolver resolver) { 68 | this.resolver = resolver; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/spring/annotation/ProtobufRpcAnnotationRessolverListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring.annotation; 17 | 18 | import java.util.List; 19 | 20 | import com.baidu.jprotobuf.pbrpc.spring.RpcProxyFactoryBean; 21 | 22 | /** 23 | * Listener class for {@link ProtobufRpcAnnotationResolver} while doing annotation parser action. 24 | * 25 | * @author xiemalin 26 | * @since 3.4.1 27 | */ 28 | public interface ProtobufRpcAnnotationRessolverListener { 29 | 30 | /** 31 | * This method will called after {@link RpcExporter} annotation parsed. 32 | * 33 | * @param rpcExporter {@link RpcExporter} annotation 34 | * @param port real port 35 | * @param bean target bean 36 | * @param registerServices registered service list 37 | */ 38 | void onRpcExporterAnnotationParsered(RpcExporter rpcExporter, int port, Object bean, List registerServices); 39 | 40 | 41 | /** 42 | * Destroy. 43 | */ 44 | void destroy(); 45 | 46 | 47 | /** 48 | * This method will called after {@link RpcProxy} annotation parsed. 49 | * 50 | * @param rpcProxy {@link RpcProxy} annotation 51 | * @param newRpcProxyFactoryBean a new created {@link RpcProxyFactoryBean} 52 | * @param object target PROXY bean for this {@link RpcProxy} annotation delegated 53 | */ 54 | void onRpcProxyAnnotationParsed(RpcProxy rpcProxy, RpcProxyFactoryBean newRpcProxyFactoryBean, Object object); 55 | 56 | 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/main/java/com/baidu/jprotobuf/pbrpc/spring/annotation/RpcExporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring.annotation; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Inherited; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor; 26 | import com.baidu.jprotobuf.pbrpc.spring.RpcServiceExporter; 27 | import com.baidu.jprotobuf.pbrpc.transport.RpcServerOptions; 28 | 29 | /** 30 | * Annotation publish for {@link RpcServiceExporter}. 31 | * 32 | * @author xiemalin 33 | * @since 2.17 34 | */ 35 | @Target({ElementType.TYPE}) 36 | @Retention(RetentionPolicy.RUNTIME) 37 | @Inherited 38 | @Documented 39 | public @interface RpcExporter { 40 | 41 | /** 42 | * RPC server port to publish. 43 | * 44 | * @return the string 45 | */ 46 | String port(); 47 | 48 | /** 49 | * Host. 50 | * 51 | * @return the string 52 | */ 53 | String host() default ""; 54 | 55 | /** 56 | * bean name of RPC server options bean type must be {@link RpcServerOptions}. 57 | * 58 | * @return the string 59 | */ 60 | String rpcServerOptionsBeanName() default ""; 61 | 62 | /** 63 | * bean name of RPC intercepter bean type must be {@link InvokerInterceptor}. 64 | * 65 | * @return the string 66 | */ 67 | String invokerIntercepterBeanName() default ""; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/test/java/com/baidu/jprotobuf/pbrpc/client/test/Greet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.client.test; 5 | 6 | /** 7 | * The Interface ITestInterface. 8 | * 9 | * @author xiemalin 10 | * @since 3.5.22 11 | */ 12 | public interface Greet { 13 | 14 | /** 15 | * Dummy call. 16 | * 17 | * @param name the arg 18 | * @return the string 19 | */ 20 | String greet(String name); 21 | } 22 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/test/java/com/baidu/jprotobuf/pbrpc/client/test/SimpleGreet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.client.test; 5 | 6 | /** 7 | * The Class SimpleGreet. 8 | * 9 | * @author xiemalin 10 | * @since 3.5.22 11 | */ 12 | public class SimpleGreet implements Greet { 13 | 14 | /** 15 | * Dummy call. 16 | * 17 | * @param name the arg 18 | * @return the string 19 | */ 20 | @Override 21 | public String greet(String name) { 22 | return "Hello " + name; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/HaRpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | localhost:1031;localhost:1032;localhost:1033 46 | 47 | 48 | 49 | 50 | 51 | 52 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/RpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/client/AnnotationRpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | localhost:1031 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring-base/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/server/AnnotationRpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.baidu 7 | jprotobuf-rpc-socket 8 | 4.2.2 9 | 10 | jprotobuf-rpc-core-spring 11 | jar 12 | ${project.artifactId} 13 | The module for Spring extendsion 14 | 15 | 16 | UTF-8 17 | 18 | 5.1.19.RELEASE 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | com.baidu 27 | jprotobuf-rpc-core 28 | ${project.parent.version} 29 | 30 | 31 | com.baidu 32 | jprotobuf-rpc-core-spring-base 33 | ${project.parent.version} 34 | 35 | 36 | org.springframework 37 | spring-context 38 | ${spring-web.version} 39 | 40 | 41 | org.springframework 42 | spring-aop 43 | ${spring-web.version} 44 | 45 | 46 | cglib 47 | cglib 48 | 3.1 49 | 50 | 51 | org.ow2.asm 52 | asm 53 | 5.0.4 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/client/ha/DummyNamingService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha; 17 | 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Set; 22 | 23 | import com.baidu.jprotobuf.pbrpc.registry.RegisterInfo; 24 | 25 | /** 26 | * A dummy {@link NamingService} implements support default server list. 27 | * 28 | * @author xiemalin 29 | * @since 2.15 30 | */ 31 | public class DummyNamingService implements NamingService { 32 | 33 | private List list; 34 | 35 | /** 36 | * @param list 37 | */ 38 | public DummyNamingService(List list) { 39 | super(); 40 | this.list = list; 41 | } 42 | 43 | /* (non-Javadoc) 44 | * @see com.baidu.jprotobuf.pbrpc.client.ha.NamingService#list() 45 | */ 46 | public List list() throws Exception { 47 | return list; 48 | } 49 | 50 | /* (non-Javadoc) 51 | * @see com.baidu.jprotobuf.pbrpc.client.ha.NamingService#list(java.util.Set) 52 | */ 53 | @Override 54 | public Map> list(Set serviceSignatures) throws Exception { 55 | Map> ret = new HashMap>(); 56 | 57 | if (serviceSignatures == null || serviceSignatures.isEmpty()) { 58 | return ret; 59 | } 60 | for (String string : serviceSignatures) { 61 | ret.put(string, list); 62 | } 63 | 64 | return ret; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/spring/AnnotationEchoServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.spring; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoServiceImpl; 22 | import com.baidu.jprotobuf.pbrpc.spring.annotation.RpcExporter; 23 | 24 | /** 25 | * Echo service for annotation exporter 26 | * 27 | * @author xiemalin 28 | * @since 2.17 29 | */ 30 | @Service("echoServiceAOP") 31 | @RpcExporter(port = "1031", rpcServerOptionsBeanName = "rpcServerOptions", invokerIntercepterBeanName = "annoServerInterceptor") 32 | public class AnnotationEchoServiceImpl extends EchoServiceImpl { 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/spring/AnnotationEchoServiceImpl2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.spring; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoServiceImpl; 22 | import com.baidu.jprotobuf.pbrpc.spring.annotation.RpcExporter; 23 | 24 | /** 25 | * Echo service for annotation exporter 26 | * 27 | * @author xiemalin 28 | * @since 2.17 29 | */ 30 | @Component 31 | @RpcExporter(port = "1032", rpcServerOptionsBeanName = "rpcServerOptions") 32 | public class AnnotationEchoServiceImpl2 extends EchoServiceImpl { 33 | 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/spring/AnnotationEchoServiceImpl3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.spring; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoServiceImpl; 22 | import com.baidu.jprotobuf.pbrpc.spring.annotation.RpcExporter; 23 | 24 | /** 25 | * Echo service for annotation exporter 26 | * 27 | * @author xiemalin 28 | * @since 2.17 29 | */ 30 | @Component 31 | @RpcExporter(port = "1033" , rpcServerOptionsBeanName = "rpcServerOptions") 32 | public class AnnotationEchoServiceImpl3 extends EchoServiceImpl { 33 | 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/spring/AnnotationEchoServiceImpl4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.spring; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoInfo; 22 | import com.baidu.jprotobuf.pbrpc.EchoServiceImpl; 23 | import com.baidu.jprotobuf.pbrpc.ProtobufRPCService; 24 | import com.baidu.jprotobuf.pbrpc.spring.annotation.RpcExporter; 25 | 26 | /** 27 | * Echo service for annotation exporter 28 | * 29 | * @author xiemalin 30 | * @since 2.17 31 | */ 32 | @Service 33 | @RpcExporter(port = "1034", rpcServerOptionsBeanName = "rpcServerOptions", invokerIntercepterBeanName = "failedAnnoServerInterceptor") 34 | public class AnnotationEchoServiceImpl4 extends EchoServiceImpl { 35 | 36 | @ProtobufRPCService(serviceName = "echoService", methodName = "serverFailed", description ="echo测试服务") 37 | public EchoInfo serverfailed(EchoInfo info) { 38 | EchoInfo ret = new EchoInfo(); 39 | return ret; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/spring/ClientRPCInvokerInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.springframework.util.Assert; 19 | 20 | import com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor; 21 | import com.baidu.jprotobuf.pbrpc.intercept.MethodInvocationInfo; 22 | 23 | /** 24 | * A {@link InvokerInterceptor} implements to print intercepter message for client 25 | * 26 | * @author xiemalin 27 | * @since 3.4.0 28 | */ 29 | public class ClientRPCInvokerInterceptor implements InvokerInterceptor { 30 | 31 | private String from; 32 | 33 | private boolean failed = false; 34 | 35 | /** 36 | * set failed value to failed 37 | * @param failed the failed to set 38 | */ 39 | public void setFailed(boolean failed) { 40 | this.failed = failed; 41 | } 42 | 43 | /** 44 | * set from value to from 45 | * @param from the from to set 46 | */ 47 | public void setFrom(String from) { 48 | this.from = from; 49 | } 50 | 51 | /* (non-Javadoc) 52 | * @see com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor#beforeInvoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) 53 | */ 54 | @Override 55 | public void beforeInvoke(MethodInvocationInfo methodInvocation) { 56 | System.out.println("ClientRPCInvokerInterceptor--> method=" + methodInvocation.getMethod().getName() + " this is from " + from); 57 | 58 | } 59 | 60 | /* (non-Javadoc) 61 | * @see com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor#process(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) 62 | */ 63 | @Override 64 | public Object process(MethodInvocationInfo methodInvocation) { 65 | Assert.notNull(methodInvocation.getMethod()); 66 | return null; 67 | } 68 | 69 | /* (non-Javadoc) 70 | * @see com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor#afterProcess() 71 | */ 72 | @Override 73 | public void afterProcess() { 74 | 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/spring/MyInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.aopalliance.intercept.MethodInterceptor; 19 | import org.aopalliance.intercept.MethodInvocation; 20 | 21 | /** 22 | * 23 | * @author xiemalin 24 | * 25 | */ 26 | public class MyInterceptor implements MethodInterceptor { 27 | 28 | /* (non-Javadoc) 29 | * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) 30 | */ 31 | @Override 32 | public Object invoke(MethodInvocation arg0) throws Throwable { 33 | 34 | System.out.println("inteceptor'" + MyInterceptor.class.getName() + "' =>" + arg0.getMethod().getName()); 35 | return arg0.proceed(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/spring/RpcXmlConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.junit.Ignore; 19 | import org.junit.Test; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoService; 22 | 23 | 24 | /** 25 | * Test class for {@link RpcServiceExporter} and {@link RpcProxyFactoryBean} by XML configuration. 26 | * 27 | * @author xiemalin 28 | * @since 2.17 29 | */ 30 | 31 | public class RpcXmlConfigurationTest extends RpcXmlConfigurationTestBase { 32 | 33 | 34 | /* 35 | * (non-Javadoc) 36 | * 37 | * @see com.baidu.jprotobuf.pbrpc.spring.RpcXmlConfigurationTestBase#getConfigurationPath() 38 | */ 39 | @Override 40 | protected String getConfigurationPath() { 41 | return "classpath:" + RpcXmlConfigurationTest.class.getName().replace('.', '/') + ".xml"; 42 | } 43 | 44 | 45 | @Test 46 | public void testRpcRequestAndResponse() { 47 | EchoService echoService = (EchoService) context.getBean("echoServiceProxy", EchoService.class); 48 | super.internalRpcRequestAndResponse(echoService); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/spring/RpcXmlConfigurationTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.junit.After; 19 | import org.junit.Assert; 20 | import org.junit.Before; 21 | import org.springframework.context.support.AbstractApplicationContext; 22 | import org.springframework.context.support.ClassPathXmlApplicationContext; 23 | 24 | import com.baidu.jprotobuf.pbrpc.EchoInfo; 25 | import com.baidu.jprotobuf.pbrpc.EchoService; 26 | 27 | /** 28 | * Base RPC XML configuration test class. 29 | * 30 | * @author xiemalin 31 | * @since 2.17 32 | */ 33 | public abstract class RpcXmlConfigurationTestBase { 34 | 35 | /** 36 | * context of {@link AbstractApplicationContext} 37 | */ 38 | protected AbstractApplicationContext context; 39 | 40 | 41 | 42 | @Before 43 | public void setUp() { 44 | context = 45 | new ClassPathXmlApplicationContext(getConfigurationPath()); 46 | } 47 | 48 | protected abstract String getConfigurationPath(); 49 | 50 | @After 51 | public void tearDown() { 52 | if (context != null) { 53 | context.close(); 54 | } 55 | } 56 | 57 | protected void internalRpcRequestAndResponse(EchoService echoService) { 58 | EchoInfo echo = new EchoInfo(); 59 | echo.setMessage("world"); 60 | 61 | EchoInfo response = echoService.echo(echo); 62 | Assert.assertEquals("hello:world", response.getMessage()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/java/com/baidu/jprotobuf/pbrpc/spring/SimpleAopClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.springframework.stereotype.Service; 19 | 20 | /** 21 | * 22 | * @author xiemalin 23 | * 24 | */ 25 | @Service("simpleAOP") 26 | public class SimpleAopClass { 27 | 28 | public void doHello() { 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/HaRpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | localhost:1031;localhost:1032;localhost:1033 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/RpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.baidu 6 | jprotobuf-rpc-socket 7 | 4.2.2 8 | 9 | jprotobuf-rpc-core-spring2 10 | jar 11 | ${project.artifactId} 12 | The module for Spring extendsion 13 | 14 | 15 | UTF-8 16 | 17 | 2.5.6.SEC03 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | com.baidu 27 | jprotobuf-rpc-core 28 | ${project.parent.version} 29 | 30 | 31 | com.baidu 32 | jprotobuf-rpc-core-spring-base 33 | ${project.parent.version} 34 | 35 | 36 | org.springframework 37 | spring-web 38 | ${spring-web.version} 39 | 40 | 41 | org.springframework 42 | spring-aop 43 | ${spring-web.version} 44 | 45 | 46 | redis.clients 47 | jedis 48 | ${jedis.version} 49 | jar 50 | compile 51 | 52 | 53 | cglib 54 | cglib 55 | 3.2.0 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/client/ha/DummyNamingService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client.ha; 17 | 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Set; 22 | 23 | import com.baidu.jprotobuf.pbrpc.registry.RegisterInfo; 24 | 25 | /** 26 | * A dummy {@link NamingService} implements support default server list. 27 | * 28 | * @author xiemalin 29 | * @since 2.15 30 | */ 31 | public class DummyNamingService implements NamingService { 32 | 33 | private List list; 34 | 35 | /** 36 | * @param list 37 | */ 38 | public DummyNamingService(List list) { 39 | super(); 40 | this.list = list; 41 | } 42 | 43 | /* (non-Javadoc) 44 | * @see com.baidu.jprotobuf.pbrpc.client.ha.NamingService#list() 45 | */ 46 | public List list() throws Exception { 47 | return list; 48 | } 49 | 50 | /* (non-Javadoc) 51 | * @see com.baidu.jprotobuf.pbrpc.client.ha.NamingService#list(java.util.Set) 52 | */ 53 | @Override 54 | public Map> list(Set serviceSignatures) throws Exception { 55 | Map> ret = new HashMap>(); 56 | 57 | if (serviceSignatures == null || serviceSignatures.isEmpty()) { 58 | return ret; 59 | } 60 | for (String string : serviceSignatures) { 61 | ret.put(string, list); 62 | } 63 | 64 | return ret; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/spring/AnnotationEchoServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.spring; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoServiceImpl; 22 | import com.baidu.jprotobuf.pbrpc.spring.annotation.RpcExporter; 23 | 24 | /** 25 | * Echo service for annotation exporter 26 | * 27 | * @author xiemalin 28 | * @since 2.17 29 | */ 30 | @Service("echoServiceAOP") 31 | @RpcExporter(port = "1031", rpcServerOptionsBeanName = "rpcServerOptions", invokerIntercepterBeanName = "annoServerInterceptor") 32 | public class AnnotationEchoServiceImpl extends EchoServiceImpl { 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/spring/AnnotationEchoServiceImpl2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.spring; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoServiceImpl; 22 | import com.baidu.jprotobuf.pbrpc.spring.annotation.RpcExporter; 23 | 24 | /** 25 | * Echo service for annotation exporter 26 | * 27 | * @author xiemalin 28 | * @since 2.17 29 | */ 30 | @Component 31 | @RpcExporter(port = "1032", rpcServerOptionsBeanName = "rpcServerOptions") 32 | public class AnnotationEchoServiceImpl2 extends EchoServiceImpl { 33 | 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/spring/AnnotationEchoServiceImpl3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.spring; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoServiceImpl; 22 | import com.baidu.jprotobuf.pbrpc.spring.annotation.RpcExporter; 23 | 24 | /** 25 | * Echo service for annotation exporter 26 | * 27 | * @author xiemalin 28 | * @since 2.17 29 | */ 30 | @Component 31 | @RpcExporter(port = "1033" , rpcServerOptionsBeanName = "rpcServerOptions") 32 | public class AnnotationEchoServiceImpl3 extends EchoServiceImpl { 33 | 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/spring/AnnotationEchoServiceImpl4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.spring; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoInfo; 22 | import com.baidu.jprotobuf.pbrpc.EchoServiceImpl; 23 | import com.baidu.jprotobuf.pbrpc.ProtobufRPCService; 24 | import com.baidu.jprotobuf.pbrpc.spring.annotation.RpcExporter; 25 | 26 | /** 27 | * Echo service for annotation exporter 28 | * 29 | * @author xiemalin 30 | * @since 2.17 31 | */ 32 | @Service 33 | @RpcExporter(port = "1034", rpcServerOptionsBeanName = "rpcServerOptions", invokerIntercepterBeanName = "failedAnnoServerInterceptor") 34 | public class AnnotationEchoServiceImpl4 extends EchoServiceImpl { 35 | 36 | @ProtobufRPCService(serviceName = "echoService", methodName = "serverFailed", description ="echo测试服务") 37 | public EchoInfo serverfailed(EchoInfo info) { 38 | EchoInfo ret = new EchoInfo(); 39 | return ret; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/spring/ClientRPCInvokerInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.springframework.util.Assert; 19 | 20 | import com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor; 21 | import com.baidu.jprotobuf.pbrpc.intercept.MethodInvocationInfo; 22 | 23 | /** 24 | * A {@link InvokerInterceptor} implements to print intercepter message for client 25 | * 26 | * @author xiemalin 27 | * @since 3.4.0 28 | */ 29 | public class ClientRPCInvokerInterceptor implements InvokerInterceptor { 30 | 31 | private String from; 32 | 33 | private boolean failed = false; 34 | 35 | /** 36 | * set failed value to failed 37 | * @param failed the failed to set 38 | */ 39 | public void setFailed(boolean failed) { 40 | this.failed = failed; 41 | } 42 | 43 | /** 44 | * set from value to from 45 | * @param from the from to set 46 | */ 47 | public void setFrom(String from) { 48 | this.from = from; 49 | } 50 | 51 | /* (non-Javadoc) 52 | * @see com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor#beforeInvoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) 53 | */ 54 | @Override 55 | public void beforeInvoke(MethodInvocationInfo methodInvocation) { 56 | System.out.println("ClientRPCInvokerInterceptor--> method=" + methodInvocation.getMethod().getName() + " this is from " + from); 57 | 58 | } 59 | 60 | /* (non-Javadoc) 61 | * @see com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor#process(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) 62 | */ 63 | @Override 64 | public Object process(MethodInvocationInfo methodInvocation) { 65 | Assert.notNull(methodInvocation.getMethod()); 66 | return null; 67 | } 68 | 69 | /* (non-Javadoc) 70 | * @see com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor#afterProcess() 71 | */ 72 | @Override 73 | public void afterProcess() { 74 | 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/spring/MyInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.aopalliance.intercept.MethodInterceptor; 19 | import org.aopalliance.intercept.MethodInvocation; 20 | 21 | /** 22 | * 23 | * @author xiemalin 24 | * 25 | */ 26 | public class MyInterceptor implements MethodInterceptor { 27 | 28 | /* (non-Javadoc) 29 | * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) 30 | */ 31 | @Override 32 | public Object invoke(MethodInvocation arg0) throws Throwable { 33 | 34 | System.out.println("inteceptor'" + MyInterceptor.class.getName() + "' =>" + arg0.getMethod().getName()); 35 | return arg0.proceed(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/spring/RpcXmlConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.junit.Ignore; 19 | import org.junit.Test; 20 | 21 | import com.baidu.jprotobuf.pbrpc.EchoService; 22 | 23 | 24 | /** 25 | * Test class for {@link RpcServiceExporter} and {@link RpcProxyFactoryBean} by XML configuration. 26 | * 27 | * @author xiemalin 28 | * @since 2.17 29 | */ 30 | 31 | public class RpcXmlConfigurationTest extends RpcXmlConfigurationTestBase { 32 | 33 | 34 | /* 35 | * (non-Javadoc) 36 | * 37 | * @see com.baidu.jprotobuf.pbrpc.spring.RpcXmlConfigurationTestBase#getConfigurationPath() 38 | */ 39 | @Override 40 | protected String getConfigurationPath() { 41 | return "classpath:" + RpcXmlConfigurationTest.class.getName().replace('.', '/') + ".xml"; 42 | } 43 | 44 | 45 | @Test 46 | public void testRpcRequestAndResponse() { 47 | EchoService echoService = (EchoService) context.getBean("echoServiceProxy", EchoService.class); 48 | super.internalRpcRequestAndResponse(echoService); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/spring/RpcXmlConfigurationTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.junit.After; 19 | import org.junit.Assert; 20 | import org.junit.Before; 21 | import org.springframework.context.support.AbstractApplicationContext; 22 | import org.springframework.context.support.ClassPathXmlApplicationContext; 23 | 24 | import com.baidu.jprotobuf.pbrpc.EchoInfo; 25 | import com.baidu.jprotobuf.pbrpc.EchoService; 26 | 27 | /** 28 | * Base RPC XML configuration test class. 29 | * 30 | * @author xiemalin 31 | * @since 2.17 32 | */ 33 | public abstract class RpcXmlConfigurationTestBase { 34 | 35 | /** 36 | * context of {@link AbstractApplicationContext} 37 | */ 38 | protected AbstractApplicationContext context; 39 | 40 | 41 | 42 | @Before 43 | public void setUp() { 44 | context = 45 | new ClassPathXmlApplicationContext(getConfigurationPath()); 46 | } 47 | 48 | protected abstract String getConfigurationPath(); 49 | 50 | @After 51 | public void tearDown() { 52 | if (context != null) { 53 | context.close(); 54 | } 55 | } 56 | 57 | protected void internalRpcRequestAndResponse(EchoService echoService) { 58 | EchoInfo echo = new EchoInfo(); 59 | echo.setMessage("world"); 60 | 61 | EchoInfo response = echoService.echo(echo); 62 | Assert.assertEquals("hello:world", response.getMessage()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/java/com/baidu/jprotobuf/pbrpc/spring/SimpleAopClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.spring; 17 | 18 | import org.springframework.stereotype.Service; 19 | 20 | /** 21 | * 22 | * @author xiemalin 23 | * 24 | */ 25 | @Service("simpleAOP") 26 | public class SimpleAopClass { 27 | 28 | public void doHello() { 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/HaRpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | localhost:1031;localhost:1032;localhost:1033 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/RpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/client/AnnotationRpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | localhost:1031 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-spring2/src/test/resources/com/baidu/jprotobuf/pbrpc/spring/server/AnnotationRpcXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.baidu 6 | jprotobuf-rpc-socket 7 | 4.2.2 8 | 9 | jprotobuf-rpc-core-test 10 | jar 11 | ${project.artifactId} 12 | The base test module 13 | 14 | 15 | 16 | javax.servlet 17 | servlet-api 18 | ${servlet-api.version} 19 | jar 20 | compile 21 | 22 | 23 | junit 24 | junit 25 | ${junit.version} 26 | compile 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/BaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc; 18 | 19 | /** 20 | * Base test class 21 | * 22 | * @author xiemalin 23 | * @since 1.0 24 | */ 25 | public abstract class BaseTest { 26 | protected static final String HOST = System.getProperty("host", "127.0.0.1"); 27 | protected static final int PORT = Integer.parseInt(System.getProperty("port", "1031")); 28 | } 29 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/EchoAuthenticationDataHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc; 17 | 18 | /** 19 | * Echo test {@link AuthenticationDataHandler} 20 | * 21 | * @author xiemalin 22 | * @since 3.5.2 23 | */ 24 | public class EchoAuthenticationDataHandler implements AuthenticationDataHandler { 25 | 26 | private static byte[] bytes = EchoAuthenticationDataHandler.class.getName().getBytes(); 27 | 28 | /* (non-Javadoc) 29 | * @see com.baidu.jprotobuf.pbrpc.AuthenticationDataHandler#create(java.lang.String, java.lang.String, java.lang.Object[]) 30 | */ 31 | @Override 32 | public byte[] create(String serviceName, String methodName, Object...params) { 33 | return bytes; 34 | } 35 | 36 | public static byte[] getBytes() { 37 | return bytes; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/EchoClientAttachmentHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc; 18 | 19 | import org.junit.Assert; 20 | 21 | /** 22 | * Echo test {@link ClientAttachmentHandler} 23 | * 24 | * @author xiemalin 25 | * @since 1.0 26 | */ 27 | public class EchoClientAttachmentHandler implements ClientAttachmentHandler { 28 | 29 | private byte[] attachment = EchoClientAttachmentHandler.class.getName().getBytes(); 30 | 31 | /* 32 | * (non-Javadoc) 33 | * 34 | * @see 35 | * com.baidu.jprotobuf.pbrpc.AttachmentHandler#handleRequest(java.lang.String 36 | * , java.lang.String, java.lang.Object[]) 37 | */ 38 | public byte[] handleRequest(String serviceName, String methodName, Object... params) { 39 | return attachment; 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * 45 | * @see 46 | * com.baidu.jprotobuf.pbrpc.ClientAttachmentHandler#handleResponse(byte[], 47 | * java.lang.String, java.lang.String, java.lang.Object[]) 48 | */ 49 | public void handleResponse(byte[] response, String serviceName, String methodName, Object... params) { 50 | Assert.assertEquals(EchoServerAttachmentHandler.class.getName(), new String(response)); 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/EchoInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc; 18 | 19 | import com.baidu.bjf.remoting.protobuf.annotation.Protobuf; 20 | 21 | /** 22 | * Echo info class by using Jprotobuf annotation. 23 | * more information visit: https://github.com/jhunters/jprotobuf 24 | * 25 | * @author xiemalin 26 | * @since 1.0 27 | * @see EchoService 28 | */ 29 | public class EchoInfo { 30 | 31 | @Protobuf(description = "Echo消息内容") 32 | private String message; 33 | 34 | /** 35 | * 36 | */ 37 | public EchoInfo() { 38 | } 39 | 40 | /** 41 | * @param message 42 | */ 43 | public EchoInfo(String message) { 44 | this.message = message; 45 | } 46 | 47 | /** 48 | * get the message 49 | * @return the message 50 | */ 51 | public String getMessage() { 52 | return message; 53 | } 54 | 55 | /** 56 | * set message value to message 57 | * @param message the message to set 58 | */ 59 | public void setMessage(String message) { 60 | this.message = message; 61 | } 62 | 63 | /* (non-Javadoc) 64 | * @see java.lang.Object#toString() 65 | */ 66 | @Override 67 | public String toString() { 68 | StringBuilder builder = new StringBuilder(); 69 | builder.append("EchoInfo [message="); 70 | builder.append(message); 71 | builder.append("]"); 72 | return builder.toString(); 73 | } 74 | 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/EchoLogIDGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc; 18 | 19 | import java.util.concurrent.atomic.AtomicLong; 20 | 21 | import com.baidu.jprotobuf.pbrpc.LogIDGenerator; 22 | 23 | /** 24 | * Echo test {@link LogIDGenerator} instance. 25 | * 26 | * @author xiemalin 27 | * @since 1.0 28 | */ 29 | public class EchoLogIDGenerator implements LogIDGenerator { 30 | 31 | private static final AtomicLong SEQENCE = new AtomicLong(1); 32 | 33 | /* 34 | * (non-Javadoc) 35 | * 36 | * @see com.baidu.jprotobuf.pbrpc.LogIDGenerator#generate(java.lang.String, 37 | * java.lang.String, java.lang.Object[]) 38 | */ 39 | public long generate(String serviceName, String methodName, Object... params) { 40 | return SEQENCE.incrementAndGet(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/EchoServerAttachmentHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc; 18 | 19 | 20 | import org.junit.Assert; 21 | 22 | /** 23 | * Echo test {@link ServerAttachmentHandler} 24 | * 25 | * @author xiemalin 26 | * @since 1.1 27 | */ 28 | public class EchoServerAttachmentHandler implements ServerAttachmentHandler { 29 | 30 | /* 31 | * (non-Javadoc) 32 | * 33 | * @see 34 | * com.baidu.jprotobuf.pbrpc.ServerAttachmentHandler#handleAttachement(byte 35 | * [], java.lang.String, java.lang.String, java.lang.Object[]) 36 | */ 37 | public byte[] handleAttachement(byte[] response, String serviceName, String methodName, Object... params) { 38 | Assert.assertEquals(EchoClientAttachmentHandler.class.getName(), new String(response)); 39 | return EchoServerAttachmentHandler.class.getName().getBytes(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/EchoServerAuthenticationDataHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc; 17 | 18 | import org.junit.Assert; 19 | 20 | /** 21 | * Echo test {@link ServerAuthenticationDataHandler} 22 | * @author xiemalin 23 | * @since 3.5.2 24 | */ 25 | public class EchoServerAuthenticationDataHandler implements ServerAuthenticationDataHandler { 26 | 27 | /* (non-Javadoc) 28 | * @see com.baidu.jprotobuf.pbrpc.ServerAuthenticationDataHandler#handle(byte[], java.lang.String, java.lang.String, java.lang.Object[]) 29 | */ 30 | @Override 31 | public void handle(byte[] authenticationData, String serviceName, String methodName, Object...params) { 32 | Assert.assertNotNull(authenticationData); 33 | Assert.assertArrayEquals(EchoAuthenticationDataHandler.getBytes(), authenticationData); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/proto/EchoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.proto; 18 | 19 | import com.baidu.jprotobuf.pbrpc.EchoClientAttachmentHandler; 20 | import com.baidu.jprotobuf.pbrpc.EchoLogIDGenerator; 21 | import com.baidu.jprotobuf.pbrpc.ProtobufRPC; 22 | import com.baidu.jprotobuf.pbrpc.proto.EchoInfoClass.EchoInfo; 23 | 24 | /** 25 | * Simple echo service interface 26 | * 27 | * @author xiemalin 28 | * @since 1.0 29 | */ 30 | public interface EchoService { 31 | 32 | /** 33 | * To define a RPC client method.
34 | * serviceName is "echoService" 35 | * methodName is use default method name "echo" 36 | * onceTalkTimeout is 200 milliseconds 37 | * 38 | * @param info 39 | * @return 40 | */ 41 | @ProtobufRPC(serviceName = "echoService", onceTalkTimeout = 1111112500) 42 | EchoInfo echo(EchoInfo info); 43 | 44 | @ProtobufRPC(serviceName = "echoService", onceTalkTimeout = 150000000, 45 | attachmentHandler = EchoClientAttachmentHandler.class, logIDGenerator = EchoLogIDGenerator.class) 46 | EchoInfo echoWithAttachement(EchoInfo info); 47 | } 48 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/proto/EchoServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.proto; 18 | 19 | import com.baidu.jprotobuf.pbrpc.EchoServerAttachmentHandler; 20 | import com.baidu.jprotobuf.pbrpc.ProtobufRPCService; 21 | import com.baidu.jprotobuf.pbrpc.proto.EchoInfoClass.EchoInfo; 22 | 23 | /** 24 | * Echo service 25 | * 26 | * @author xiemalin 27 | * @since 1.0 28 | */ 29 | public class EchoServiceImpl { 30 | 31 | 32 | @ProtobufRPCService(serviceName = "echoService", methodName = "echo") 33 | public EchoInfo doEcho(EchoInfo info) { 34 | EchoInfo ret = EchoInfo.newBuilder().setMessage("hello:" + info.getMessage()).build(); 35 | return ret; 36 | } 37 | 38 | @ProtobufRPCService(serviceName = "echoService", methodName = "echoWithAttachement", 39 | attachmentHandler = EchoServerAttachmentHandler.class) 40 | public EchoInfo dealWithAttachement(EchoInfo info) { 41 | return doEcho(info); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/proto/echo.proto: -------------------------------------------------------------------------------- 1 | package pkg; 2 | 3 | option java_package = "com.baidu.jprotobuf.pbrpc.proto"; 4 | 5 | //这里声明输出的java的类名 6 | option java_outer_classname = "EchoInfoClass"; 7 | 8 | message EchoInfo { 9 | required string message = 1; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core-test/src/main/java/com/baidu/jprotobuf/pbrpc/utils/SleepUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Baidu company (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 7 | */ 8 | package com.baidu.jprotobuf.pbrpc.utils; 9 | 10 | import java.util.logging.Level; 11 | import java.util.logging.Logger; 12 | 13 | /** 14 | * Utility tool for test usage. 15 | * 16 | * @author xiemalin 17 | * @since 2.19 18 | */ 19 | public class SleepUtils { 20 | 21 | private static final Logger LOG = Logger.getLogger(SleepUtils.class.getName()); 22 | 23 | /** 24 | * time sleep for current thread. 25 | * 26 | * @param sleepTimeInMilliseconds 27 | */ 28 | public static void dummySleep(int sleepTimeInMilliseconds) { 29 | try { 30 | Thread.sleep(sleepTimeInMilliseconds); 31 | } catch (Exception e) { 32 | LOG.log(Level.SEVERE, e.getMessage(), e.getCause()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.baidu 7 | jprotobuf-rpc-socket 8 | 4.2.2 9 | 10 | jprotobuf-rpc-core 11 | jar 12 | ${project.artifactId} 13 | The core module of jprotobuf rpc socket implementation 14 | 15 | 16 | 17 | com.baidu 18 | jprotobuf-rpc-core-test 19 | ${project.parent.version} 20 | 21 | 22 | io.netty 23 | netty-all 24 | ${netty-all.version} 25 | compile 26 | 27 | 28 | javax.servlet 29 | servlet-api 30 | ${servlet-api.version} 31 | jar 32 | provided 33 | 34 | 35 | org.slf4j 36 | slf4j-api 37 | 1.7.2 38 | 39 | 40 | org.apache.logging.log4j 41 | log4j-api 42 | 2.17.0 43 | test 44 | 45 | 46 | org.apache.logging.log4j 47 | log4j-core 48 | 2.17.0 49 | test 50 | 51 | 52 | org.apache.logging.log4j 53 | log4j-slf4j-impl 54 | 2.17.0 55 | test 56 | 57 | 58 | 59 | org.apache.logging.log4j 60 | log4j-jcl 61 | 2.17.0 62 | test 63 | 64 | 65 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/RpcHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc; 18 | 19 | import com.baidu.jprotobuf.pbrpc.server.RpcData; 20 | 21 | /** 22 | * RPC handle for each request and response. 23 | * 24 | * @author xiemalin 25 | * @since 1.0 26 | */ 27 | public interface RpcHandler { 28 | 29 | /** 30 | * send data to server. 31 | * 32 | * @param data the data 33 | * @return the rpc data 34 | * @exception Exception in case of any exception in handle 35 | */ 36 | RpcData doHandle(RpcData data) throws Exception; 37 | 38 | /** 39 | * Gets the service name. 40 | * 41 | * @return the service name 42 | */ 43 | String getServiceName(); 44 | 45 | /** 46 | * Gets the method name. 47 | * 48 | * @return the method name 49 | */ 50 | String getMethodName(); 51 | 52 | /** 53 | * Gets the service. 54 | * 55 | * @return the service 56 | */ 57 | Object getService(); 58 | 59 | /** 60 | * Gets the input class. 61 | * 62 | * @return the input class 63 | */ 64 | Class getInputClass(); 65 | 66 | /** 67 | * Gets the output class. 68 | * 69 | * @return the output class 70 | */ 71 | Class getOutputClass(); 72 | 73 | 74 | /** 75 | * Gets the description. 76 | * 77 | * @return the description 78 | */ 79 | String getDescription(); 80 | 81 | /** 82 | * Gets the method signature. 83 | * 84 | * @return the method signature 85 | */ 86 | String getMethodSignature(); 87 | 88 | } 89 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/client/ProxyFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.client; 18 | 19 | import java.lang.reflect.InvocationHandler; 20 | import java.lang.reflect.Proxy; 21 | 22 | /** 23 | * Proxy factory by JDK default implements. 24 | * 25 | * @author xiemalin 26 | * @since 1.0 27 | */ 28 | @SuppressWarnings({"unchecked","rawtypes"}) 29 | public class ProxyFactory { 30 | 31 | /** 32 | * To create proxy object. 33 | * 34 | * @param the generic type 35 | * @param clazz the clazz 36 | * @param classLoader the class loader 37 | * @param handler invocation handler 38 | * @return proxied object. 39 | */ 40 | public static T createProxy(Class[] clazz, ClassLoader classLoader, InvocationHandler handler) { 41 | return (T) Proxy.newProxyInstance(classLoader, clazz, handler); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/client/ServiceLocatorCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client; 17 | 18 | import java.net.InetSocketAddress; 19 | 20 | /** 21 | * This interface is used to call back on {@link ProtobufRpcProxy} on create connection for each serviceSignature.
22 | * serviceSignature should be unique to each service for same business. 23 | * 24 | * @author xiemalin 25 | * @since 2.19 26 | */ 27 | public interface ServiceLocatorCallback { 28 | 29 | /** 30 | * Fetch address. 31 | * 32 | * @param serviceSignature the service signature 33 | * @return the inet socket address 34 | */ 35 | InetSocketAddress fetchAddress(String serviceSignature); 36 | } 37 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/client/ServiceUrlAccessible.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client; 17 | 18 | /** 19 | * Service URL accessible interface. 20 | * 21 | * 22 | * @author xiemalin 23 | * @since 3.2.5 24 | */ 25 | public interface ServiceUrlAccessible { 26 | 27 | /** 28 | * Gets the service url. 29 | * 30 | * @return the service url 31 | */ 32 | String getServiceUrl(); 33 | } 34 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/client/SimpleServiceLocatorCallabck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.client; 17 | 18 | import java.net.InetSocketAddress; 19 | 20 | /** 21 | * Simple {@link InetSocketAddress} call back implements {@link ServiceLocatorCallback}. 22 | * 23 | * @author xiemalin 24 | * @since 2.19 25 | */ 26 | public class SimpleServiceLocatorCallabck implements ServiceLocatorCallback { 27 | 28 | /** The address. */ 29 | private InetSocketAddress address; 30 | 31 | /** The serivce si string. */ 32 | private String serivceSiString; 33 | 34 | /** 35 | * Instantiates a new simple service locator callabck. 36 | * 37 | * @param address the address 38 | * @param serivceSiString the serivce si string 39 | */ 40 | public SimpleServiceLocatorCallabck(InetSocketAddress address, String serivceSiString) { 41 | super(); 42 | this.address = address; 43 | this.serivceSiString = serivceSiString; 44 | } 45 | 46 | /* 47 | * (non-Javadoc) 48 | * 49 | * @see com.baidu.jprotobuf.pbrpc.client.ServiceLocatorCallback#fetchAddress(java.lang.String) 50 | */ 51 | @Override 52 | public InetSocketAddress fetchAddress(String serviceSignature) { 53 | if (this.serivceSiString == null) { 54 | return null; 55 | } 56 | if (this.serivceSiString.equals(serviceSignature)) { 57 | return address; 58 | } 59 | return null; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/client/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * RPC client supports. 3 | * 4 | * @since 1.0 5 | */ 6 | package com.baidu.jprotobuf.pbrpc.client; 7 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/compress/Compress.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.compress; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Compress interface. 22 | * 23 | * @author xiemalin 24 | * @since 1.4 25 | */ 26 | public interface Compress { 27 | 28 | /** 29 | * Compress. 30 | * 31 | * @param array the array 32 | * @return the byte[] 33 | * @throws IOException Signals that an I/O exception has occurred. 34 | */ 35 | byte[] compress(byte[] array) throws IOException; 36 | 37 | 38 | /** 39 | * Un compress. 40 | * 41 | * @param array the array 42 | * @return the byte[] 43 | * @throws IOException Signals that an I/O exception has occurred. 44 | */ 45 | byte[] unCompress(byte[] array) throws IOException; 46 | } 47 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/compress/SnappyCompress.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.compress; 17 | 18 | import java.io.IOException; 19 | 20 | import org.xerial.snappy.Snappy; 21 | 22 | /** 23 | * Compress support by Snappy by snappy-java client. 24 | * more information pls visit: https://github.com/xerial/snappy-java 25 | * 26 | * @author xiemalin 27 | * @since 2.12 28 | */ 29 | public class SnappyCompress implements Compress { 30 | 31 | /* (non-Javadoc) 32 | * @see com.baidu.jprotobuf.pbrpc.compress.Compress#compress(byte[]) 33 | */ 34 | public byte[] compress(byte[] array) throws IOException { 35 | if (array == null) { 36 | return null; 37 | } 38 | return Snappy.compress(array); 39 | } 40 | 41 | /* (non-Javadoc) 42 | * @see com.baidu.jprotobuf.pbrpc.compress.Compress#unCompress(byte[]) 43 | */ 44 | public byte[] unCompress(byte[] array) throws IOException { 45 | if (array == null) { 46 | return null; 47 | } 48 | return Snappy.uncompress(array); 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/compress/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides Compress supports. It provides messes of implementation of Compress interface. 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.compress; -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/data/ProtocolConstant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.data; 18 | 19 | import java.nio.charset.Charset; 20 | 21 | /** 22 | * Protocol constant definition. 23 | * 24 | * @author xiemalin 25 | * @since 1.0 26 | */ 27 | public class ProtocolConstant { 28 | 29 | /** default magic code. */ 30 | public static final String MAGIC_CODE = "PRPC"; 31 | 32 | /** default charset. */ 33 | public static Charset CHARSET = Charset.forName("utf-8"); 34 | 35 | /** 36 | * Gets the char set. 37 | * 38 | * @return the char set 39 | */ 40 | public static Charset getCharSet() { 41 | return CHARSET; 42 | } 43 | 44 | /** 45 | * Sets the charset. 46 | * 47 | * @param charSet the new charset 48 | */ 49 | public static void setCharset(Charset charSet) { 50 | CHARSET = charSet; 51 | } 52 | 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/data/Readable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.data; 18 | 19 | /** 20 | * Byte array serializable interface. 21 | * 22 | * @author xiemalin 23 | * @since 1.0 24 | */ 25 | public interface Readable { 26 | 27 | /** 28 | * Do deserializable action. 29 | * 30 | * @param bytes the bytes 31 | */ 32 | void read(byte[] bytes); 33 | } 34 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/data/TraceContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.data; 17 | 18 | /** 19 | * Hold the Trace object in the current thread. 20 | * 21 | * @author xiemalin 22 | * @since 4.0.0 23 | */ 24 | public class TraceContext { 25 | 26 | /** The Constant TRACE. */ 27 | private static final ThreadLocal TRACE = new ThreadLocal(); 28 | 29 | 30 | /** 31 | * Sets the trace. 32 | * 33 | * @param trace the new trace 34 | */ 35 | public static void setTrace(Trace trace) { 36 | if (trace != null) { 37 | TRACE.set(trace);; 38 | } 39 | } 40 | 41 | /** 42 | * Gets the trace. 43 | * 44 | * @return the trace 45 | */ 46 | public static Trace getTrace() { 47 | return TRACE.get(); 48 | } 49 | 50 | 51 | /** 52 | * Clear trace. 53 | */ 54 | public static void clearTrace() { 55 | TRACE.remove(); 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/data/Writerable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.data; 18 | 19 | 20 | /** 21 | * A byte deserializable interface. 22 | * 23 | * @author xiemalin 24 | * @since 1.0 25 | */ 26 | public interface Writerable { 27 | 28 | /** 29 | * Write. 30 | * 31 | * @return all content as byte array 32 | */ 33 | byte[] write(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/data/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * RPC protocol implements. 3 | * 4 | * @since 1.0 5 | */ 6 | package com.baidu.jprotobuf.pbrpc.data; 7 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/intercept/InvokerInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.intercept; 17 | 18 | /** 19 | * RPC method invoker intercepter. 20 | * 21 | * @author xiemalin 22 | * @since 3.4.0 23 | */ 24 | public interface InvokerInterceptor { 25 | 26 | Object NULL = new Object(); 27 | 28 | /** 29 | * This method will call before RPC method invoke. 30 | * 31 | * @param methodInvocation the method invocation 32 | */ 33 | void beforeInvoke(MethodInvocationInfo methodInvocation); 34 | 35 | /** 36 | * to do intercept action. 37 | * 38 | * @param methodInvocation the method invocation 39 | * @return if not null, this intercepter will active and this result will replace to real RPC return.
40 | * if return null will continue to another intercepter. 41 | * if method with void return type. please return NULL to stop next chain invocation. 42 | */ 43 | Object process(MethodInvocationInfo methodInvocation); 44 | 45 | 46 | /** 47 | * to call after process called. here need to clear some garbage here 48 | */ 49 | void afterProcess(); 50 | } 51 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/intercept/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * 拦截器模块 18 | * 19 | * @author xiemalin 20 | * @since 3.4.0 21 | */ 22 | package com.baidu.jprotobuf.pbrpc.intercept; -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/management/HttpConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.management; 17 | 18 | /** 19 | * Http constant class. 20 | * 21 | * @author xiemalin 22 | * @since 3.1.0 23 | */ 24 | public class HttpConstants { 25 | 26 | /** The Constant LINE_BREAK. */ 27 | public static final String LINE_BREAK = "
"; 28 | 29 | /** The Constant PRE_STARTS. */ 30 | public static final String PRE_STARTS = "
";
31 |     
32 |     /** The Constant PRE_ENDS. */
33 |     public static final String PRE_ENDS = "
"; 34 | 35 | /** The Constant HTML_HEAD. */ 36 | public static final String HTML_HEAD = ""; 38 | 39 | /** The Constant HTML_TAIL. */ 40 | public static final String HTML_TAIL = ""; 41 | 42 | /** The Constant BOLD_FONT. */ 43 | public static final String BOLD_FONT = ""; 44 | 45 | /** The Constant BOLD_FONT_END. */ 46 | public static final String BOLD_FONT_END = ""; 47 | } 48 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/management/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Management module for protobuf RPC. 18 | * 19 | * @author xiemalin 20 | * @since 3.1.0 21 | */ 22 | package com.baidu.jprotobuf.pbrpc.management; -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/meta/RpcMetaAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.meta; 18 | 19 | /** 20 | * To get Rpc service method description. 21 | * 22 | * @author xiemalin 23 | * @since 2.1 24 | */ 25 | public interface RpcMetaAware { 26 | 27 | /** 28 | * Gets the input meta proto. 29 | * 30 | * @return the input meta proto 31 | */ 32 | String getInputMetaProto(); 33 | 34 | /** 35 | * Gets the output meta proto. 36 | * 37 | * @return the output meta proto 38 | */ 39 | String getOutputMetaProto(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/meta/RpcServiceMetaService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.meta; 18 | 19 | import com.baidu.jprotobuf.pbrpc.ProtobufRPC; 20 | 21 | /** 22 | * {@link RpcServiceMetaService}. 23 | * 24 | * @author xiemalin 25 | * @since 2.1 26 | */ 27 | public interface RpcServiceMetaService { 28 | 29 | /** 30 | * Gets the rpc service meta info. 31 | * 32 | * @return the rpc service meta info 33 | */ 34 | @ProtobufRPC(serviceName = RpcServiceMetaServiceProvider.RPC_META_SERVICENAME, onceTalkTimeout = 100000) 35 | RpcServiceMetaList getRpcServiceMetaInfo(); 36 | 37 | /** 38 | * Ping. 39 | */ 40 | @ProtobufRPC(serviceName = RpcServiceMetaServiceProvider.RPC_META_SERVICENAME) 41 | void ping(); 42 | } 43 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Protobuf RPC implements. 3 | * 4 | * @since 1.0 5 | */ 6 | package com.baidu.jprotobuf.pbrpc; 7 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/registry/NotifyListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.registry; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * NotifyListener. (API, Prototype, ThreadSafe) 22 | * 23 | * @author xiemalin 24 | * @since 2.27 25 | */ 26 | public interface NotifyListener { 27 | 28 | /** 29 | * 当收到服务变更通知时触发。. 30 | * 31 | * @param urls 已注册信息列表,总不为空, 32 | */ 33 | void notify(List urls); 34 | 35 | } -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/registry/RegistryCenterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.registry; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * RegistryService. (SPI, Prototype, ThreadSafe) 22 | * 23 | * @author xiemalin 24 | * @since 2.27 25 | */ 26 | public interface RegistryCenterService { 27 | 28 | /** 29 | * 注册数据,比如:提供者地址,消费者地址,路由规则,覆盖规则,等数据。. 30 | * 31 | * @param url 注册信息,不允许为空 32 | */ 33 | void register(RegisterInfo url); 34 | 35 | /** 36 | * 取消注册. 37 | * 38 | * @param url 注册信息,不允许为空 39 | */ 40 | void unregister(RegisterInfo url); 41 | 42 | /** 43 | * 订阅符合条件的已注册数据,当有注册数据变更时自动推送. 44 | * 45 | * @param url 订阅条件,不允许为空, 46 | * @param listener 变更事件监听器,不允许为空 47 | */ 48 | void subscribe(RegisterInfo url, NotifyListener listener); 49 | 50 | /** 51 | * 取消订阅. 52 | * 53 | * @param url 订阅条件,不允许为空 54 | * @param listener 变更事件监听器,不允许为空 55 | */ 56 | void unsubscribe(RegisterInfo url, NotifyListener listener); 57 | 58 | /** 59 | * 查询符合条件的已注册数据,与订阅的推模式相对应,这里为拉模式,只返回一次结果。. 60 | * 61 | * @param url 查询条件,不允许为空, 62 | * @return 已注册信息列表,可能为空, 63 | * @see com.alibaba.dubbo.registry.NotifyListener#notify(List) 64 | */ 65 | List lookup(RegisterInfo url); 66 | 67 | } -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/server/AbstractServiceExporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.server; 18 | 19 | /** 20 | * Abstract service exporter class. 21 | * 22 | * @author xiemalin 23 | * @param the generic type 24 | * @param the generic type 25 | * @since 1.0 26 | */ 27 | public abstract class AbstractServiceExporter implements ServiceExporter { 28 | 29 | /** The service invoker. */ 30 | private IDLServiceInvoker serviceInvoker; 31 | 32 | /** 33 | * Gets the service invoker. 34 | * 35 | * @return the service invoker 36 | */ 37 | public IDLServiceInvoker getServiceInvoker() { 38 | return serviceInvoker; 39 | } 40 | 41 | /** 42 | * Sets the service invoker. 43 | * 44 | * @param serviceInvoker the new service invoker 45 | */ 46 | public void setServiceInvoker(IDLServiceInvoker serviceInvoker) { 47 | this.serviceInvoker = serviceInvoker; 48 | } 49 | 50 | 51 | /** service name. */ 52 | private String serviceName; 53 | 54 | /** method name. */ 55 | private String methodName; 56 | 57 | /* (non-Javadoc) 58 | * @see com.baidu.jprotobuf.pbrpc.server.ServiceExporter#getServiceName() 59 | */ 60 | public String getServiceName() { 61 | return serviceName; 62 | } 63 | 64 | /* (non-Javadoc) 65 | * @see com.baidu.jprotobuf.pbrpc.server.ServiceExporter#getMethodName() 66 | */ 67 | public String getMethodName() { 68 | return methodName; 69 | } 70 | 71 | /** 72 | * Sets the service name. 73 | * 74 | * @param serviceName the new service name 75 | */ 76 | public void setServiceName(String serviceName) { 77 | this.serviceName = serviceName; 78 | } 79 | 80 | /** 81 | * Sets the method name. 82 | * 83 | * @param methodName the new method name 84 | */ 85 | public void setMethodName(String methodName) { 86 | this.methodName = methodName; 87 | } 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/server/IDLServiceInvoker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.server; 18 | 19 | import com.baidu.bjf.remoting.protobuf.IDLProxyObject; 20 | 21 | /** 22 | * IDL service invoker. 23 | * 24 | * @author xiemalin 25 | * @since 1.0 26 | */ 27 | public interface IDLServiceInvoker { 28 | 29 | /** 30 | * RPC service call back method. 31 | * 32 | * @param input 33 | * request IDL proxy object by protobuf deserialized 34 | * @param output 35 | * return back IDL proxy object to serialized 36 | * @throws Exception 37 | * in case of any exception 38 | */ 39 | void invoke(IDLProxyObject input, IDLProxyObject output) throws Exception; 40 | 41 | 42 | /** 43 | * Gets the input. 44 | * 45 | * @return the input 46 | */ 47 | IDLProxyObject getInput(); 48 | 49 | /** 50 | * Gets the output. 51 | * 52 | * @return the output 53 | */ 54 | IDLProxyObject getOutput(); 55 | } 56 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/server/RpcServiceHandleContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.server; 17 | 18 | import io.netty.channel.ChannelHandlerContext; 19 | 20 | /** 21 | * The context class around RPC service method handle scope to get ChannelHandlerContext. 22 | * 23 | * @author xiemalin 24 | * @since 4.1.3 25 | */ 26 | public class RpcServiceHandleContext { 27 | 28 | /** The Constant CHANNEL_CONTEXT. */ 29 | private static final ThreadLocal CHANNEL_CONTEXT = new ThreadLocal(); 30 | 31 | 32 | /** 33 | * Sets the channel handler context. 34 | * 35 | * @param chc the new channel handler context 36 | */ 37 | public static void setChannelHandlerContext(ChannelHandlerContext chc) { 38 | CHANNEL_CONTEXT.set(chc); 39 | } 40 | 41 | 42 | /** 43 | * Gets the channel handler context. 44 | * 45 | * @return the channel handler context 46 | */ 47 | public static ChannelHandlerContext getChannelHandlerContext() { 48 | return CHANNEL_CONTEXT.get(); 49 | } 50 | 51 | /** 52 | * Clear channel handler context. 53 | */ 54 | public static void clearChannelHandlerContext() { 55 | CHANNEL_CONTEXT.remove(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/server/ServiceExporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.server; 18 | 19 | 20 | /** 21 | * RPC service exporter interface. 22 | * 23 | * @author xiemalin 24 | * @param input parameter 25 | * @param response result 26 | */ 27 | public interface ServiceExporter { 28 | 29 | /** 30 | * Gets the service name. 31 | * 32 | * @return the service name 33 | */ 34 | String getServiceName(); 35 | 36 | /** 37 | * Gets the method name. 38 | * 39 | * @return the method name 40 | */ 41 | String getMethodName(); 42 | 43 | /** 44 | * execute service action. 45 | * 46 | * @param input the input 47 | * @return the o 48 | * @throws Exception the exception 49 | */ 50 | O execute(I input) throws Exception; 51 | } 52 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/server/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * RPC server supports. 3 | * 4 | * @since 1.0 5 | */ 6 | package com.baidu.jprotobuf.pbrpc.server; 7 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/AbstractChannelPoolSharableFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.transport; 5 | 6 | import java.net.InetSocketAddress; 7 | import java.util.Map; 8 | 9 | /** 10 | * A factory for creating GlobalChannelPoolSharable objects. 11 | * 12 | * @author xiemalin 13 | * @since 3.5.20 14 | */ 15 | public abstract class AbstractChannelPoolSharableFactory implements ChannelPoolSharableFactory { 16 | 17 | protected abstract Map getRpcChannelMap(); 18 | 19 | /** 20 | * Gets the host address. 21 | * 22 | * @param host the host 23 | * @param port the port 24 | * @return the host address 25 | */ 26 | protected String getHostAddress(String host, int port) { 27 | InetSocketAddress address; 28 | if (host == null) { 29 | address = new InetSocketAddress(port); 30 | } else { 31 | address = new InetSocketAddress(host, port); 32 | } 33 | return address.toString(); 34 | } 35 | 36 | /* 37 | * (non-Javadoc) 38 | * 39 | * @see com.baidu.jprotobuf.pbrpc.transport.ChannelPoolSharableFactory#getOrCreateChannelPool(java.lang.String, int) 40 | */ 41 | @Override 42 | public RpcChannel getOrCreateChannelPool(RpcClient rpcClient, String host, int port) { 43 | 44 | String hostAddress = getHostAddress(host, port); 45 | if (!getRpcChannelMap().containsKey(hostAddress)) { 46 | RpcChannel rpcChannel = new RpcChannel(rpcClient, host, port); 47 | getRpcChannelMap().put(hostAddress, rpcChannel); 48 | return rpcChannel; 49 | } 50 | 51 | return getRpcChannelMap().get(hostAddress); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/ChannelPoolSharableFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.transport; 5 | 6 | /** 7 | * A factory for creating ChannelSharable objects. 8 | * 9 | * @author xiemalin 10 | * @since 3.5.20 11 | */ 12 | public interface ChannelPoolSharableFactory { 13 | 14 | /** 15 | * Gets the or create channel pool. 16 | * 17 | * @param rpcClient the rpc client 18 | * @param host the host 19 | * @param port the port 20 | * @return the or create channel pool 21 | */ 22 | RpcChannel getOrCreateChannelPool(RpcClient rpcClient, String host, int port); 23 | } 24 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/ExceptionCatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.transport; 17 | 18 | /** 19 | * The Interface ExceptionCatcher. 20 | * 21 | * @author xiemalin 22 | * @since 3.5.13 23 | */ 24 | public interface ExceptionCatcher { 25 | 26 | /** 27 | * On exception. 28 | * 29 | * @param e the e 30 | * @return the rpc error message 31 | */ 32 | RpcErrorMessage onException(Exception e); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/ExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.transport; 17 | 18 | /** 19 | * The Interface ExceptionHandler. 20 | * 21 | * @author xiemalin 22 | * @since 3.5.13 23 | */ 24 | public interface ExceptionHandler { 25 | 26 | /** 27 | * Handle exception. if return null ignore the exception. 28 | * 29 | * @param error the error 30 | * @return the exception 31 | */ 32 | Exception handleException(RpcErrorMessage error); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/GlobalChannelPoolSharableFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.transport; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * A factory for creating GlobalChannelPoolSharable objects. 11 | * 12 | * @author xiemalin 13 | * @since 3.5.20 14 | */ 15 | public class GlobalChannelPoolSharableFactory extends AbstractChannelPoolSharableFactory { 16 | 17 | /** The rpc channel map. */ 18 | private static Map rpcChannelMap = new HashMap(); 19 | 20 | protected Map getRpcChannelMap() { 21 | return rpcChannelMap; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/RpcErrorMessage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.transport; 5 | 6 | /** 7 | * The Class RpcErrorMessage. 8 | * 9 | * @author xiemalin 10 | * @since 3.5.13 11 | */ 12 | public class RpcErrorMessage { 13 | 14 | /** The error code. */ 15 | private int errorCode; 16 | 17 | /** The error message. */ 18 | private String errorMessage; 19 | 20 | /** 21 | * Gets the error code. 22 | * 23 | * @return the error code 24 | */ 25 | public int getErrorCode() { 26 | return errorCode; 27 | } 28 | 29 | /** 30 | * Sets the error code. 31 | * 32 | * @param errorCode the new error code 33 | */ 34 | public void setErrorCode(int errorCode) { 35 | this.errorCode = errorCode; 36 | } 37 | 38 | /** 39 | * Gets the error message. 40 | * 41 | * @return the error message 42 | */ 43 | public String getErrorMessage() { 44 | return errorMessage; 45 | } 46 | 47 | /** 48 | * Sets the error message. 49 | * 50 | * @param errorMessage the new error message 51 | */ 52 | public void setErrorMessage(String errorMessage) { 53 | this.errorMessage = errorMessage; 54 | } 55 | 56 | /** 57 | * Instantiates a new rpc error. 58 | * 59 | * @param errorCode the error code 60 | * @param errorMessage the error message 61 | */ 62 | public RpcErrorMessage(int errorCode, String errorMessage) { 63 | super(); 64 | this.errorCode = errorCode; 65 | this.errorMessage = errorMessage; 66 | } 67 | 68 | /* (non-Javadoc) 69 | * @see java.lang.Object#hashCode() 70 | */ 71 | @Override 72 | public int hashCode() { 73 | final int prime = 31; 74 | int result = 1; 75 | result = prime * result + errorCode; 76 | return result; 77 | } 78 | 79 | /* (non-Javadoc) 80 | * @see java.lang.Object#equals(java.lang.Object) 81 | */ 82 | @Override 83 | public boolean equals(Object obj) { 84 | if (this == obj) 85 | return true; 86 | if (obj == null) 87 | return false; 88 | if (getClass() != obj.getClass()) 89 | return false; 90 | RpcErrorMessage other = (RpcErrorMessage) obj; 91 | if (errorCode != other.errorCode) 92 | return false; 93 | return true; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/SimpleChannelPoolSharableFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.transport; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * A factory for creating GlobalChannelPoolSharable objects. 11 | * 12 | * @author xiemalin 13 | * @since 3.5.20 14 | */ 15 | public class SimpleChannelPoolSharableFactory extends AbstractChannelPoolSharableFactory { 16 | 17 | /** The rpc channel map. */ 18 | private Map rpcChannelMap = new HashMap(); 19 | 20 | protected Map getRpcChannelMap() { 21 | return rpcChannelMap; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/handler/RpcDataPackageCompressHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.transport.handler; 18 | 19 | import java.util.List; 20 | 21 | import com.baidu.jprotobuf.pbrpc.compress.Compress; 22 | import com.baidu.jprotobuf.pbrpc.compress.GZipCompress; 23 | import com.baidu.jprotobuf.pbrpc.compress.SnappyCompress; 24 | import com.baidu.jprotobuf.pbrpc.data.RpcDataPackage; 25 | import com.baidu.jprotobuf.pbrpc.data.RpcMeta; 26 | 27 | import io.netty.channel.ChannelHandler.Sharable; 28 | import io.netty.channel.ChannelHandlerContext; 29 | import io.netty.handler.codec.MessageToMessageEncoder; 30 | 31 | /** 32 | * Do data compress handler. 33 | * 34 | * @author xiemalin 35 | * @since 1.4 36 | */ 37 | @Sharable 38 | public class RpcDataPackageCompressHandler extends 39 | MessageToMessageEncoder { 40 | 41 | /* (non-Javadoc) 42 | * @see io.netty.handler.codec.MessageToMessageEncoder#encode(io.netty.channel.ChannelHandlerContext, java.lang.Object, java.util.List) 43 | */ 44 | @Override 45 | protected void encode(ChannelHandlerContext ctx, RpcDataPackage msg, 46 | List out) throws Exception { 47 | RpcDataPackage dataPackage = msg; 48 | 49 | // check if do compress 50 | Integer compressType = dataPackage.getRpcMeta().getCompressType(); 51 | Compress compress = null; 52 | if (compressType == RpcMeta.COMPERESS_GZIP) { 53 | compress = new GZipCompress(); 54 | } else if (compressType == RpcMeta.COMPRESS_SNAPPY) { 55 | compress = new SnappyCompress(); 56 | } 57 | 58 | if (compress != null) { 59 | byte[] data = dataPackage.getData(); 60 | data = compress.compress(data); 61 | dataPackage.data(data); 62 | } 63 | out.add(dataPackage); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/handler/RpcServerChannelIdleHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.transport.handler; 17 | 18 | import java.util.logging.Level; 19 | import java.util.logging.Logger; 20 | 21 | import io.netty.channel.ChannelDuplexHandler; 22 | import io.netty.channel.ChannelHandler.Sharable; 23 | import io.netty.channel.ChannelHandlerContext; 24 | import io.netty.handler.timeout.IdleState; 25 | import io.netty.handler.timeout.IdleStateEvent; 26 | 27 | /** 28 | * Idle 连接检测处理类。. 29 | * 30 | * @author xiemalin 31 | */ 32 | @Sharable 33 | public class RpcServerChannelIdleHandler extends ChannelDuplexHandler { 34 | 35 | /** The log. */ 36 | private static Logger LOG = Logger 37 | .getLogger(RpcServerChannelIdleHandler.class.getName()); 38 | private int idleTimeout; 39 | 40 | public RpcServerChannelIdleHandler(int idleTimeout) { 41 | this.idleTimeout = idleTimeout; 42 | } 43 | 44 | /* (non-Javadoc) 45 | * @see io.netty.channel.ChannelInboundHandlerAdapter#userEventTriggered(io.netty.channel.ChannelHandlerContext, java.lang.Object) 46 | */ 47 | @Override 48 | public void userEventTriggered(ChannelHandlerContext ctx, Object evt) 49 | throws Exception { 50 | if (evt instanceof IdleStateEvent) { 51 | IdleStateEvent e = (IdleStateEvent) evt; 52 | if (e.state() == IdleState.ALL_IDLE) { 53 | // if no read and write for period time, close current channel 54 | LOG.log(Level.WARNING, "channel:" + ctx.channel() 55 | + " ip=" + ctx.channel().remoteAddress() + " is idle for period time [" + idleTimeout + "]. close now."); 56 | ctx.close(); 57 | } else { 58 | LOG.log(Level.WARNING, "idle on channel[" + e.state() + "]:" + ctx.channel()); 59 | } 60 | } 61 | } 62 | 63 | /** 64 | * Instantiates a new rpc server channel idle handler. 65 | */ 66 | public RpcServerChannelIdleHandler() { 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/handler/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * RPC TCP protocol transport encode and decode supports. 3 | * 4 | * @since 1.0 5 | */ 6 | package com.baidu.jprotobuf.pbrpc.transport.handler; 7 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/transport/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * RPC TCP protocol transport implements. 3 | * 4 | * @since 1.0 5 | */ 6 | package com.baidu.jprotobuf.pbrpc.transport; 7 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/utils/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.utils; 17 | 18 | /** 19 | * Constant class. 20 | * 21 | * @author xiemalin 22 | * @since 2.27 23 | */ 24 | public class Constants { 25 | 26 | /** pbrpc scheme. */ 27 | public static final String PBRPC_SCHEME = "pbrpc"; 28 | 29 | /** The Constant SERVICE_KEY_PREIFX. */ 30 | public static final String SERVICE_KEY_PREIFX = "baidu-rpc:"; 31 | 32 | 33 | /** The Constant DYNAMIC_SERVICE_NAME. */ 34 | public static final String DYNAMIC_SERVICE_NAME = "__DYANMICE_SERVICE__"; 35 | } 36 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/utils/LogIdThreadLocalHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.utils; 17 | 18 | /** 19 | * Hold log id message info under current thread local . 20 | * 21 | * @author xiemalin 22 | * @since 3.2.8 23 | */ 24 | public class LogIdThreadLocalHolder { 25 | 26 | /** log id holder. */ 27 | private static final ThreadLocal LOG_ID_HOLDER = new ThreadLocal(); 28 | 29 | /** 30 | * Sets the log id. 31 | * 32 | * @param logId the new log id 33 | */ 34 | public static void setLogId(Long logId) { 35 | if (logId != null) { 36 | LOG_ID_HOLDER.set(logId); 37 | } 38 | } 39 | 40 | /** 41 | * Gets the log id. 42 | * 43 | * @return the log id 44 | */ 45 | public static Long getLogId() { 46 | return LOG_ID_HOLDER.get(); 47 | } 48 | 49 | /** 50 | * clear current log id under current thread scope. 51 | */ 52 | public static void clearLogId() { 53 | LOG_ID_HOLDER.remove(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/utils/ServiceSignatureUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.utils; 17 | 18 | /** 19 | * Utility class for service signature string wrap. 20 | * 21 | * @author xiemalin 22 | * @since 2.3.1 23 | */ 24 | public class ServiceSignatureUtils { 25 | 26 | /** 27 | * make service signature. 28 | * 29 | * @param serviceName name of service 30 | * @param methodName name of method 31 | * @return service signature 32 | */ 33 | public static String makeSignature(String serviceName, String methodName) { 34 | return serviceName + '!' + methodName; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/utils/TalkTimeoutController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.utils; 17 | 18 | /** 19 | * to change once talk time out setting dynamically. 20 | * 21 | * @author xiemalin 22 | * @since 3.5.22 23 | */ 24 | public class TalkTimeoutController { 25 | 26 | /** The Constant TALK_TIMEOUT. */ 27 | private static final ThreadLocal TALK_TIMEOUT = new ThreadLocal(); 28 | 29 | /** The enable once. */ 30 | private static boolean enableOnce = true; 31 | 32 | /** 33 | * Sets the enable once. 34 | * 35 | * @param enableOnce the new enable once 36 | */ 37 | public static void setEnableOnce(boolean enableOnce) { 38 | TalkTimeoutController.enableOnce = enableOnce; 39 | } 40 | 41 | /** 42 | * Checks if is enable once. 43 | * 44 | * @return true, if is enable once 45 | */ 46 | public static boolean isEnableOnce() { 47 | return enableOnce; 48 | } 49 | 50 | /** 51 | * Sets the talk timeout. 52 | * 53 | * @param talkTimeout the new talk timeout 54 | */ 55 | public static void setTalkTimeout(long talkTimeout) { 56 | if (talkTimeout > 0) { 57 | TALK_TIMEOUT.set(talkTimeout); 58 | } else { 59 | clearTalkTimeout(); 60 | } 61 | } 62 | 63 | /** 64 | * Gets the talk timeout. 65 | * 66 | * @return the talk timeout 67 | */ 68 | public static long getTalkTimeout() { 69 | Long talkTimeout = TALK_TIMEOUT.get(); 70 | if (talkTimeout != null) { 71 | return talkTimeout; 72 | } 73 | 74 | return 0; 75 | } 76 | 77 | /** 78 | * Clear talk timeout. 79 | */ 80 | public static void clearTalkTimeout() { 81 | TALK_TIMEOUT.remove(); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/main/java/com/baidu/jprotobuf/pbrpc/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Utility classes. 3 | * 4 | * @since 1.0 5 | */ 6 | package com.baidu.jprotobuf.pbrpc.utils; 7 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/BasePerformaceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc; 18 | 19 | import com.baidu.jprotobuf.pbrpc.data.ProtocolConstant; 20 | import com.baidu.jprotobuf.pbrpc.data.RpcDataPackage; 21 | 22 | /** 23 | * Base performace test case. 24 | * 25 | * @author xiemalin 26 | * @since 1.0 27 | */ 28 | public abstract class BasePerformaceTest extends BaseTest { 29 | 30 | String formatString = "|%20s|%20s|%22s|%20s|%20s|"; 31 | 32 | String formatString2 = "|%10d|%10d|%12d|%10d|%10d|"; 33 | 34 | protected void printResult(RpcDataPackage in, RpcDataPackage out, int totalCount, long totaltime, int threadCount) { 35 | System.out.println("---------------------Performance Result-------------------------"); 36 | System.out.println("send byte size: " + in.write().length + ";receive byte size: " + out.write().length); 37 | System.out 38 | .println(String.format(formatString, "total count", "time took(ms)", "average(ms)", "QPS", "threads")); 39 | double avg = (totaltime * 1.0 / totalCount); 40 | double qps = totalCount * 1000.0 / totaltime; 41 | System.out.println(String.format(formatString, totalCount, totaltime, new Double(avg).longValue(), new Double(qps).longValue(), threadCount)); 42 | System.out.println("---------------------Performance Result-------------------------"); 43 | } 44 | 45 | protected RpcDataPackage buildPackage(byte[] data, byte[] attachment, byte[] authenticationData, 46 | String serivceName, String methodName) { 47 | RpcDataPackage dataPackage = new RpcDataPackage(); 48 | dataPackage.magicCode(ProtocolConstant.MAGIC_CODE).data(data).attachment(attachment) 49 | .authenticationData(authenticationData); 50 | dataPackage.serviceName(serivceName).methodName(methodName); 51 | return dataPackage; 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/ClientMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc; 17 | 18 | import com.baidu.jprotobuf.pbrpc.client.ProtobufRpcProxy; 19 | import com.baidu.jprotobuf.pbrpc.transport.RpcClient; 20 | import com.baidu.jprotobuf.pbrpc.transport.RpcClientOptions; 21 | 22 | /** 23 | * @author xiemalin 24 | * 25 | */ 26 | public class ClientMain { 27 | 28 | public static void main(String[] args) { 29 | 30 | RpcClientOptions options = new RpcClientOptions(); 31 | options.setThreadPoolSize(5); 32 | options.setMaxIdleSize(10); 33 | options.setMaxWait(1000); 34 | // options.setInnerResuePool(true); 35 | 36 | RpcClient rpcClient = new RpcClient(options); 37 | ProtobufRpcProxy pbrpcProxy = new ProtobufRpcProxy(rpcClient, EchoService.class); 38 | pbrpcProxy.setPort(8122); 39 | pbrpcProxy.setHost("localhost"); 40 | EchoService echoService = pbrpcProxy.proxy(); 41 | 42 | EchoInfo echoInfo = new EchoInfo(); 43 | echoInfo.setMessage("hello"); 44 | 45 | for (int i = 0; i < 1000; i++) { 46 | EchoInfo ret = echoService.echo(echoInfo); 47 | System.out.println(ret); 48 | } 49 | 50 | pbrpcProxy.close(); 51 | rpcClient.shutdown(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/PingDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2007 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc; 17 | 18 | import com.baidu.jprotobuf.pbrpc.client.ProtobufRpcProxy; 19 | import com.baidu.jprotobuf.pbrpc.meta.RpcServiceMetaServiceProvider; 20 | import com.baidu.jprotobuf.pbrpc.transport.RpcClient; 21 | 22 | /** 23 | * The Class PingDemo. 24 | * 25 | * @author xiemalin 26 | */ 27 | public class PingDemo { 28 | 29 | /** 30 | * The main method. 31 | * 32 | * @param args the arguments 33 | */ 34 | public static void main(String[] args) { 35 | RpcClient rpcClient = new RpcClient(); 36 | 37 | ProtobufRpcProxy pbrpcProxy = new ProtobufRpcProxy(rpcClient, PingService.class); 38 | pbrpcProxy.setPort(808); // to change port 39 | 40 | PingService pingService = pbrpcProxy.proxy(); 41 | 42 | // test success if 43 | pingService.ping(); 44 | } 45 | 46 | /** 47 | * The Interface PingService. 48 | */ 49 | public static interface PingService { 50 | 51 | /** 52 | * Ping. 53 | */ 54 | @ProtobufRPC(serviceName = RpcServiceMetaServiceProvider.RPC_META_SERVICENAME, 55 | onceTalkTimeout = 3000, 56 | compressType = CompressType.NO) 57 | void ping(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/ServerMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc; 17 | 18 | import com.baidu.jprotobuf.pbrpc.transport.RpcServer; 19 | import com.baidu.jprotobuf.pbrpc.transport.RpcServerOptions; 20 | 21 | /** 22 | * 23 | * @author xiemalin 24 | * 25 | */ 26 | public class ServerMain { 27 | 28 | public static void main(String[] args) { 29 | 30 | if (args.length == 0) { 31 | args = new String[]{"8122"}; 32 | } 33 | 34 | RpcServerOptions rpcServerOptions = new RpcServerOptions(); 35 | rpcServerOptions.setHttpServerPort(8866); 36 | rpcServerOptions.setWorkThreads(50); 37 | 38 | RpcServer rpcServer = new RpcServer(rpcServerOptions); 39 | EchoServiceImpl echoServiceImpl = new EchoServiceImpl(); 40 | rpcServer.registerService(echoServiceImpl); 41 | rpcServer.startSync(Integer.valueOf(args[0])); 42 | 43 | System.out.println("ok"); 44 | 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/TrunkEchoServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc; 17 | 18 | import com.baidu.jprotobuf.pbrpc.transport.RpcClientOptions; 19 | import com.baidu.jprotobuf.pbrpc.transport.RpcServerOptions; 20 | 21 | /** 22 | * Test case for trunk data test 23 | * 24 | * @author xiemalin 25 | * @since 2.10 26 | */ 27 | 28 | public class TrunkEchoServiceTest extends EchoServiceTest { 29 | 30 | /* (non-Javadoc) 31 | * @see com.baidu.jprotobuf.pbrpc.BaseEchoServiceTest#getRpcClientOptions() 32 | */ 33 | @Override 34 | protected RpcClientOptions getRpcClientOptions() { 35 | RpcClientOptions rpcClientOptions = new RpcClientOptions(); 36 | rpcClientOptions.setChunkSize(5); 37 | rpcClientOptions.setShareThreadPoolUnderEachProxy(true); 38 | return rpcClientOptions; 39 | } 40 | 41 | /* (non-Javadoc) 42 | * @see com.baidu.jprotobuf.pbrpc.BaseEchoServiceTest#getRpcServerOptions() 43 | */ 44 | @Override 45 | protected RpcServerOptions getRpcServerOptions() { 46 | RpcServerOptions rpcServerOptions = new RpcServerOptions(); 47 | rpcServerOptions.setChunkSize(3); 48 | return rpcServerOptions; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/compress/BaseCompressTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.compress; 17 | 18 | import java.io.IOException; 19 | import java.io.UnsupportedEncodingException; 20 | 21 | import org.junit.Assert; 22 | import org.junit.Test; 23 | 24 | /** 25 | * Base test class for compress uitilty class. 26 | * 27 | * @author xiemalin 28 | * @since 2.13 29 | */ 30 | public abstract class BaseCompressTest { 31 | 32 | protected abstract Compress createCompress(); 33 | 34 | @Test 35 | public void testSimpleChineseCompress() throws UnsupportedEncodingException, IOException { 36 | 37 | String simpleCHNString = "中国欢迎你!"; 38 | 39 | assertResult(simpleCHNString); 40 | } 41 | 42 | private void assertResult(String string) throws UnsupportedEncodingException, IOException { 43 | Compress compress = createCompress(); 44 | byte[] compressedByteArray = compress.compress(string.getBytes("utf-8")); 45 | 46 | byte[] unCompressString = compress.unCompress(compressedByteArray); 47 | Assert.assertEquals(string, new String(unCompressString, "utf-8")); 48 | } 49 | 50 | @Test 51 | public void testMixString() throws UnsupportedEncodingException, IOException { 52 | 53 | String simpleCHNString = "中国欢迎你! hello world to china 中国. 123 !@#$%^&*()"; 54 | 55 | assertResult(simpleCHNString); 56 | } 57 | 58 | @Test 59 | public void testLongMixString() throws UnsupportedEncodingException, IOException { 60 | 61 | String simpleCHNString = "中国欢迎你! hello world to china 中国. 123 !@#$%^&*()"; 62 | 63 | int repeat = 1000; 64 | StringBuilder longText = new StringBuilder(simpleCHNString.length() * repeat); 65 | for (int i = 0; i < repeat; i++) { 66 | longText.append(simpleCHNString); 67 | } 68 | 69 | assertResult(longText.toString()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/compress/GZipCompressTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.compress; 17 | 18 | /** 19 | * Test class for {@link GZipCompress} 20 | * 21 | * @author xiemalin 22 | * @since 2.13 23 | */ 24 | public class GZipCompressTest extends BaseCompressTest { 25 | 26 | /* (non-Javadoc) 27 | * @see com.baidu.jprotobuf.pbrpc.compress.BaseCompressTest#createCompress() 28 | */ 29 | @Override 30 | protected Compress createCompress() { 31 | return new GZipCompress(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/compress/SnappyCompressTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.jprotobuf.pbrpc.compress; 17 | 18 | /** 19 | * Test class for {@link SnappyCompress} 20 | * 21 | * @author xiemalin 22 | * @since 2.13 23 | */ 24 | public class SnappyCompressTest extends BaseCompressTest { 25 | 26 | /* (non-Javadoc) 27 | * @see com.baidu.jprotobuf.pbrpc.compress.BaseCompressTest#createCompress() 28 | */ 29 | @Override 30 | protected Compress createCompress() { 31 | return new SnappyCompress(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/data/ChunkInfoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.data; 18 | 19 | import junit.framework.Assert; 20 | 21 | import org.junit.Test; 22 | 23 | 24 | /** 25 | * Test class for ChunkInfo 26 | * 27 | * @author xiemalin 28 | * @since 1.0 29 | */ 30 | public class ChunkInfoTest { 31 | 32 | @Test 33 | public void testReadWrite() { 34 | ChunkInfo info = new ChunkInfo(); 35 | info.setChunkId(100L); 36 | info.setStreamId(-1L); 37 | 38 | byte[] bytes = info.write(); 39 | 40 | ChunkInfo info2 = new ChunkInfo(); 41 | info2.read(bytes); 42 | 43 | Assert.assertEquals(info.getChunkId(), info2.getChunkId()); 44 | Assert.assertEquals(info.getStreamId(), info2.getStreamId()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/data/RpcHeadMetaTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.data; 18 | 19 | 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | 24 | /** 25 | * Test class for RpcHeadMeta 26 | * 27 | * @author xiemalin 28 | * @since 1.0 29 | */ 30 | public class RpcHeadMetaTest { 31 | 32 | @Test 33 | public void testReadWrite() { 34 | RpcHeadMeta meta = new RpcHeadMeta(); 35 | meta.setMagicCode("HULU"); 36 | meta.setMetaSize(0); 37 | meta.setMessageSize(12); 38 | 39 | byte[] bytes = meta.write(); 40 | Assert.assertEquals(RpcHeadMeta.SIZE, bytes.length); 41 | 42 | RpcHeadMeta meta2 = new RpcHeadMeta(); 43 | meta2.read(bytes); 44 | 45 | Assert.assertArrayEquals(meta.getMagicCode(), meta2.getMagicCode()); 46 | Assert.assertEquals(meta.getMetaSize(), meta2.getMetaSize()); 47 | Assert.assertEquals(meta.getMessageSize(), meta2.getMessageSize()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jprotobuf-rpc-core/src/test/java/com/baidu/jprotobuf/pbrpc/data/RpcResponseMetaTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.baidu.jprotobuf.pbrpc.data; 18 | 19 | import junit.framework.Assert; 20 | 21 | import org.junit.Test; 22 | 23 | 24 | /** 25 | * Test class for RpcResponseMeta 26 | * 27 | * @author xiemalin 28 | * @since 1.0 29 | */ 30 | public class RpcResponseMetaTest { 31 | 32 | @Test 33 | public void testReadWrite() { 34 | RpcResponseMeta meta = new RpcResponseMeta(); 35 | 36 | meta.setErrorCode(10); 37 | byte[] bytes = meta.write(); 38 | 39 | RpcResponseMeta meta2 = new RpcResponseMeta(); 40 | meta2.read(bytes); 41 | 42 | Assert.assertEquals(meta.getErrorCode(), meta2.getErrorCode()); 43 | Assert.assertNull(meta2.getErrorText()); 44 | } 45 | 46 | @Test 47 | public void testReadWriteAll() { 48 | RpcResponseMeta meta = new RpcResponseMeta(); 49 | 50 | meta.setErrorCode(10); 51 | meta.setErrorText("this is error text"); 52 | byte[] bytes = meta.write(); 53 | 54 | RpcResponseMeta meta2 = new RpcResponseMeta(); 55 | meta2.read(bytes); 56 | 57 | Assert.assertEquals(meta.getErrorCode(), meta2.getErrorCode()); 58 | Assert.assertEquals(meta.getErrorText(), meta2.getErrorText()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /jprotobuf-rpc-ext-validator/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.baidu 6 | jprotobuf-rpc-socket 7 | 4.2.1 8 | 9 | ${project.artifactId} 10 | jprotobuf-rpc-ext-validator 11 | supportsbean validation by jsr 303 12 | 13 | 14 | UTF-8 15 | 1.7 16 | 17 | 18 | 19 | 20 | org.jboss.forge.addon 21 | bean-validation 22 | 2.16.1.Final 23 | 24 | 25 | com.baidu 26 | jprotobuf-rpc-core 27 | ${project.parent.version} 28 | 29 | 30 | -------------------------------------------------------------------------------- /jprotobuf-rpc-ext-validator/src/main/java/com/baidu/jprotobuf/pbrpc/ext/validator/BeanValidatorInvokerInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.ext.validator; 5 | 6 | import java.lang.reflect.Method; 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | import javax.validation.ConstraintViolation; 11 | import javax.validation.Validation; 12 | import javax.validation.Validator; 13 | import javax.validation.ValidatorFactory; 14 | 15 | import com.baidu.jprotobuf.pbrpc.intercept.InvokerInterceptor; 16 | import com.baidu.jprotobuf.pbrpc.intercept.MethodInvocationInfo; 17 | 18 | /** 19 | * This class is to implements {@link InvokerInterceptor} interface for validating target bean argument before invoke method process 20 | * 21 | * @author xiemalin 22 | * @since 3.4.0 23 | */ 24 | public class BeanValidatorInvokerInterceptor implements InvokerInterceptor { 25 | 26 | private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); 27 | private Validator validator = validatorFactory.getValidator(); 28 | 29 | private ConstraintViolationsFormatter formatter = new DefaultConstraintViolationsFormatter(); 30 | 31 | public void setFormatter(ConstraintViolationsFormatter formatter) { 32 | this.formatter = formatter; 33 | } 34 | 35 | /** 36 | * To validate bean by Bean-Validation tool. if validate failed will throws RuntimeException 37 | * 38 | * @param methodInvocationInfo method invocation info 39 | */ 40 | @Override 41 | public void beforeInvoke(MethodInvocationInfo methodInvocationInfo) { 42 | if (formatter == null) { 43 | throw new IllegalArgumentException("'property' formatter is null"); 44 | } 45 | Object[] args = methodInvocationInfo.getArgs(); 46 | if (args == null || args.length == 0) { 47 | return; 48 | } 49 | 50 | boolean voilationFound = false; 51 | Set> results = new HashSet>(); 52 | for (Object o : args) { 53 | Set> result = validator.validate(o); 54 | if (result == null || result.isEmpty()) { 55 | continue; 56 | } 57 | 58 | voilationFound = true; 59 | results.addAll(result); 60 | 61 | } 62 | 63 | if (voilationFound) { 64 | String message = formatter.format(results); 65 | throw new RuntimeException(message); 66 | } 67 | 68 | 69 | } 70 | 71 | @Override 72 | public Object process(MethodInvocationInfo methodInvocationInfo) { 73 | return null; 74 | } 75 | 76 | public void afterProcess() { 77 | 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /jprotobuf-rpc-ext-validator/src/main/java/com/baidu/jprotobuf/pbrpc/ext/validator/ConstraintViolationsFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.ext.validator; 5 | 6 | import java.util.Set; 7 | 8 | import javax.validation.ConstraintViolation; 9 | 10 | /** 11 | * A format tool to print out validate constraint violation result as a {@link String} object 12 | * 13 | * @author xiemalin 14 | * @since 3.4.0 15 | */ 16 | public interface ConstraintViolationsFormatter { 17 | 18 | 19 | /** 20 | * format validate constraint violation result as a {@link String} object 21 | * @param result validate constraint violation result 22 | * @return formatter string 23 | */ 24 | String format(Set> result); 25 | } 26 | -------------------------------------------------------------------------------- /jprotobuf-rpc-ext-validator/src/main/java/com/baidu/jprotobuf/pbrpc/ext/validator/DefaultConstraintViolationsFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.ext.validator; 5 | 6 | import java.util.Set; 7 | 8 | import javax.validation.ConstraintViolation; 9 | import javax.validation.Path; 10 | 11 | /** 12 | * Default formatter implements for {@link ConstraintViolationsFormatter} 13 | * 14 | * @author xiemalin 15 | * @since 3.4.0 16 | */ 17 | public class DefaultConstraintViolationsFormatter implements ConstraintViolationsFormatter { 18 | 19 | private static final String EMPTY_STRING = ""; 20 | 21 | private String formatter = "Validate violdation: property '%s' validate failed with message '%s' current value is '%s'\n"; 22 | 23 | @Override 24 | public String format(Set> result) { 25 | if (result == null || result.isEmpty()) { 26 | return EMPTY_STRING; 27 | } 28 | 29 | StringBuilder builder = new StringBuilder(); 30 | for (ConstraintViolation constraintViolation : result) { 31 | String message = constraintViolation.getMessage(); 32 | Object invalidValue = constraintViolation.getInvalidValue(); 33 | Path propertyPath = constraintViolation.getPropertyPath(); 34 | 35 | builder.append(String.format(formatter, propertyPath, message, String.valueOf(invalidValue))); 36 | } 37 | 38 | return builder.toString(); 39 | } 40 | 41 | public void setFormatter(String formatter) { 42 | this.formatter = formatter; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /jprotobuf-rpc-ext-validator/src/main/java/com/baidu/jprotobuf/pbrpc/ext/validator/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Extension module package for Bean Validation(JSR303) supports 3 | * 4 | * @author xiemalin 5 | * @since 3.4.0 6 | */ 7 | package com.baidu.jprotobuf.pbrpc.ext.validator; -------------------------------------------------------------------------------- /jprotobuf-rpc-ext-validator/src/test/java/com/baidu/jprotobuf/pbrpc/ext/validator/BeanValidatorInvokerInterceptorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.baidu.jprotobuf.pbrpc.ext.validator; 5 | 6 | import org.junit.Test; 7 | 8 | import com.baidu.jprotobuf.pbrpc.intercept.MethodInvocationInfo; 9 | 10 | import junit.framework.Assert; 11 | 12 | /** 13 | * Test class for {@link BeanValidatorInvokerInterceptor} 14 | * 15 | * @author xiemalin 16 | * @since 3.4.0 17 | */ 18 | public class BeanValidatorInvokerInterceptorTest { 19 | 20 | private BeanValidatorInvokerInterceptor beanValidatorInvokerInterceptor = new BeanValidatorInvokerInterceptor(); 21 | 22 | 23 | @Test 24 | public void testValidateSuccess() { 25 | PojoBean bean = PojoBean.makeValidate(); 26 | 27 | MethodInvocationInfo methodInvocationInfo = new MethodInvocationInfo(null, new Object[] {bean}, null, null, null); 28 | 29 | try { 30 | beanValidatorInvokerInterceptor.beforeInvoke(methodInvocationInfo); 31 | } catch (Exception e) { 32 | System.out.println(e.getMessage()); 33 | Assert.fail(e.getMessage()); 34 | } 35 | } 36 | 37 | @Test 38 | public void testValidateFailed() { 39 | PojoBean bean = PojoBean.makeInValidate(); 40 | MethodInvocationInfo methodInvocationInfo = new MethodInvocationInfo(null, new Object[] {bean}, null, null, null); 41 | 42 | try { 43 | beanValidatorInvokerInterceptor.beforeInvoke(methodInvocationInfo); 44 | Assert.fail("should throw exception here."); 45 | } catch (Exception e) { 46 | System.out.println(e.getMessage()); 47 | Assert.assertNotNull(e.getMessage()); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /jprotobuf-rpc-registry-bns/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.baidu 6 | jprotobuf-rpc-socket 7 | 4.2.1 8 | 9 | jprotobuf-rpc-registry-bns 10 | jar 11 | ${project.artifactId} 12 | The module for Spring extendsion 13 | 14 | 15 | 16 | com.baidu 17 | jprotobuf-rpc-core 18 | ${project.parent.version} 19 | 20 | 21 | com.baidu.noah.naming 22 | naming-sdk-java 23 | 1.0.7.2 24 | 25 | 26 | com.baidu 27 | jprotobuf-rpc-core-spring 28 | ${project.parent.version} 29 | 30 | 31 | com.baidu 32 | bns-client-spring 33 | 1.4.9-SNAPSHOT 34 | 35 | 36 | com.google.protobuf 37 | protobuf-java 38 | 39 | 40 | org.springframework 41 | spring-web 42 | 43 | 44 | org.slf4j 45 | slf4j-nop 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /jprotobuf-rpc-registry-bns/src/main/java/com/baidu/pbrpc/register/bns/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Regitser supports by Baidu Naming Service 18 | * 19 | * @author xiemalin 20 | * @since 3.0.2 21 | */ 22 | package com.baidu.pbrpc.register.bns; -------------------------------------------------------------------------------- /jprotobuf-rpc-registry-bns/src/test/java/com/baidu/pbrpc/register/bns/BNSNamingServiceMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.baidu.pbrpc.register.bns; 17 | 18 | import java.net.InetAddress; 19 | import java.net.UnknownHostException; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import com.baidu.driver4j.bns.Instance; 24 | 25 | /** 26 | * Mock class for {@link BNSNamingService} 27 | * 28 | * @author xiemalin 29 | * @since 3.0.2 30 | */ 31 | public class BNSNamingServiceMock extends BNSNamingService { 32 | 33 | /* 34 | * (non-Javadoc) 35 | * 36 | * @see com.baidu.pbrpc.register.bns.BNSNamingService#doGetInstanceList() 37 | */ 38 | @Override 39 | protected List doGetInstanceList() { 40 | 41 | List ret = new ArrayList(); 42 | 43 | Instance instance = new Instance(); 44 | 45 | instance.setPort("{rpc=1031}"); 46 | try { 47 | instance.setIp(lookupHost(InetAddress.getLocalHost().getHostName())); 48 | } catch (UnknownHostException e) { 49 | e.printStackTrace(); 50 | } 51 | ret.add(instance); 52 | 53 | return ret; 54 | } 55 | 56 | public static int lookupHost(String hostname) { 57 | InetAddress inetAddress; 58 | try { 59 | inetAddress = InetAddress.getByName(hostname); 60 | } catch (UnknownHostException e) { 61 | return -1; 62 | } 63 | byte[] addrBytes; 64 | int addr; 65 | addrBytes = inetAddress.getAddress(); 66 | addr = ((addrBytes[3] & 0xff) << 24) | ((addrBytes[2] & 0xff) << 16) | ((addrBytes[1] & 0xff) << 8) 67 | | (addrBytes[0] & 0xff); 68 | return addr; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /jprotobuf-rpc-registry-bns/src/test/java/com/baidu/pbrpc/register/bns/BnsNamingServiceXmlConfigurationTest.xml: -------------------------------------------------------------------------------- 1 |  2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /jprotobuf-rpc-registry-redis/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.baidu 6 | jprotobuf-rpc-socket 7 | 4.2.2 8 | 9 | jprotobuf-rpc-registry-redis 10 | jar 11 | ${project.artifactId} 12 | The registry service implements for redis 13 | 14 | 15 | 16 | com.baidu 17 | jprotobuf-rpc-core-spring 18 | ${project.parent.version} 19 | 20 | 21 | redis.clients 22 | jedis 23 | ${jedis.version} 24 | jar 25 | compile 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /jprotobuf-rpc-registry-redis/src/main/java/com/baidu/pbrpc/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Utility for redis usage. 18 | * 19 | * @author xiemalin 20 | * @since 3.2.3 21 | */ 22 | package com.baidu.pbrpc.utils; -------------------------------------------------------------------------------- /jprotobuf-rpc-spring-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.baidu 7 | jprotobuf-rpc-socket 8 | 4.2.1 9 | 10 | jprotobuf-rpc-spring-starter 11 | 12 | 13 | UTF-8 14 | UTF-8 15 | 1.8 16 | 1.8 17 | 1.4.0.BUILD-SNAPSHOT 18 | 1.5.14.RELEASE 19 | 3.5.21 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-configuration-processor 26 | ${spring-boot.version} 27 | true 28 | 29 | 30 | com.baidu 31 | jprotobuf-rpc-core-spring 32 | ${project.parent.version} 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | ${spring-boot.version} 38 | test 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter 43 | ${spring-boot.version} 44 | test 45 | 46 | 47 | junit 48 | junit 49 | 4.9 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /jprotobuf-rpc-spring-starter/src/main/java/com/baidu/pbrpc/spring/conf/PbRPCConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. 3 | */ 4 | package com.baidu.pbrpc.spring.conf; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import com.baidu.jprotobuf.pbrpc.spring.annotation.CommonAnnotationBeanPostProcessor; 10 | import com.baidu.jprotobuf.pbrpc.spring.annotation.ProtobufRpcAnnotationResolver; 11 | 12 | /** 13 | * spring boot configuration class 14 | * 15 | * @author xiemalin 16 | * @since 3.5.25 17 | */ 18 | @Configuration 19 | public class PbRPCConfiguration { 20 | 21 | 22 | /** 23 | * Gets the common annotation bean post processor. 24 | * 25 | * @return the common annotation bean post processor 26 | */ 27 | @Bean 28 | public CommonAnnotationBeanPostProcessor getCommonAnnotationBeanPostProcessor() { 29 | CommonAnnotationBeanPostProcessor cabp = new CommonAnnotationBeanPostProcessor(); 30 | 31 | ProtobufRpcAnnotationResolver resolver = new ProtobufRpcAnnotationResolver(); 32 | cabp.setCallback(resolver); 33 | 34 | return cabp; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /jprotobuf-rpc-spring-starter/src/main/java/com/baidu/pbrpc/spring/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * spring boot package 3 | */ 4 | package com.baidu.pbrpc.spring; 5 | -------------------------------------------------------------------------------- /jprotobuf-rpc-spring-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.baidu.pbrpc.spring.conf.PbRPCConfiguration --------------------------------------------------------------------------------