Skip to content

Commit

Permalink
NettyRPC 2.0 by tangjie
Browse files Browse the repository at this point in the history
NettyRPC 2.0 by tangjie
  • Loading branch information
tang-jie committed Oct 11, 2016
1 parent 448f0b0 commit 97ac93e
Show file tree
Hide file tree
Showing 80 changed files with 4,099 additions and 2 deletions.
16 changes: 16 additions & 0 deletions NettyRPC 2.0/NettyRPC Version 2.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
NettyRPC 2.0 Build 2016/10/7 by tangjie

## NettyRPC 2.0 中文简介:
**NettyRPC 2.0是基于NettyRPC 1.0 在Maven下构建的RPC系统,在原有1.0版本的基础上对代码进行重构升级,主要改进点如下:**
* RPC服务启动、注册、卸载支持通过Spring中的nettyrpc标签进行统一管理。
* 在原来编码解码器:JDK原生的对象序列化方式、kryo、hessian,新增了:protostuff。
* 优化了NettyRPC服务端的线程池模型,支持LinkedBlockingQueue、ArrayBlockingQueue、SynchronousQueue,并扩展了多个线程池任务处理策略。



## NettyRPC 2.0 English Introduction:
**NettyRPC 2.0 is based on NettyRPC 1.0 under the Maven to build the RPC system, based on the original 1.0 version of the code to refactoring, the main improvements are as follows:**
* RPC service startup, registration, uninstall support through the nettyrpc Spring tags for unified management.
* in the original codec: JDK native object serialization mode, kryo, hessian, added: protostuff.
* optimize the NettyRPC server's thread pool model, support LinkedBlockingQueue, ArrayBlockingQueue, SynchronousQueue, and expand the various thread pool task processing strategy.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.boot;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:RpcServerStarter.java
* @description:RpcServerStarter功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/10/7
*/
public class RpcServerStarter {
public static void main(String[] args) {
new ClassPathXmlApplicationContext("classpath:rpc-invoke-config-server.xml");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.core;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import com.newlandframework.rpc.model.MessageRequest;
import com.newlandframework.rpc.model.MessageResponse;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:MessageCallBack.java
* @description:MessageCallBack功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/10/7
*/
public class MessageCallBack {

private MessageRequest request;
private MessageResponse response;
private Lock lock = new ReentrantLock();
private Condition finish = lock.newCondition();

public MessageCallBack(MessageRequest request) {
this.request = request;
}

public Object start() throws InterruptedException {
try {
lock.lock();
finish.await(10 * 1000, TimeUnit.MILLISECONDS);
if (this.response != null) {
return this.response.getResult();
} else {
return null;
}
} finally {
lock.unlock();
}
}

public void over(MessageResponse reponse) {
try {
lock.lock();
finish.signal();
this.response = reponse;
} finally {
lock.unlock();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.core;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:RpcSystemConfig.java
* @description:RpcSystemConfig功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/10/7
*/
public class RpcSystemConfig {
public static final String SystemPropertyThreadPoolRejectedPolicyAttr = "com.newlandframework.rpc.parallel.rejected.policy";
public static final String SystemPropertyThreadPoolQueueNameAttr = "com.newlandframework.rpc.parallel.queue";
public static final int PARALLEL = Math.max(2, Runtime.getRuntime().availableProcessors());
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.event;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:ClientStopEvent.java
* @description:ClientStopEvent功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/10/7
*/
public class ClientStopEvent {
private final int message;

public ClientStopEvent(int message) {
this.message = message;
}

public int getMessage() {
return message;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.event;

import com.google.common.eventbus.Subscribe;
import com.newlandframework.rpc.netty.MessageSendExecutor;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:ClientStopEventListener.java
* @description:ClientStopEventListener功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/10/7
*/
public class ClientStopEventListener {
public int lastMessage = 0;

@Subscribe
public void listen(ClientStopEvent event) {
lastMessage = event.getMessage();
MessageSendExecutor.getInstance().stop();
}

public int getLastMessage() {
return lastMessage;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.event;

import org.springframework.context.ApplicationEvent;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:ServerStartEvent.java
* @description:ServerStartEvent功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/10/7
*/
public class ServerStartEvent extends ApplicationEvent {
public ServerStartEvent(Object source) {
super(source);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.model;

/**
* @filename:MessageKeyVal.java
* @description:MessageKeyVal功能模块
* @author tangjie<https://github.com/tang-jie>
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/10/7
*/

import java.util.Map;

public class MessageKeyVal {

private Map<String, Object> messageKeyVal;

public void setMessageKeyVal(Map<String, Object> messageKeyVal) {
this.messageKeyVal = messageKeyVal;
}

public Map<String, Object> getMessageKeyVal() {
return messageKeyVal;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright (C) 2016 Newland Group Holding Limited
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.newlandframework.rpc.model;

import java.io.Serializable;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
* @author tangjie<https://github.com/tang-jie>
* @filename:MessageRequest.java
* @description:MessageRequest功能模块
* @blogs http://www.cnblogs.com/jietang/
* @since 2016/10/7
*/
public class MessageRequest implements Serializable {

private String messageId;
private String className;
private String methodName;
private Class<?>[] typeParameters;
private Object[] parametersVal;

public String getMessageId() {
return messageId;
}

public void setMessageId(String messageId) {
this.messageId = messageId;
}

public String getClassName() {
return className;
}

public void setClassName(String className) {
this.className = className;
}

public String getMethodName() {
return methodName;
}

public void setMethodName(String methodName) {
this.methodName = methodName;
}

public Class<?>[] getTypeParameters() {
return typeParameters;
}

public void setTypeParameters(Class<?>[] typeParameters) {
this.typeParameters = typeParameters;
}

public Object[] getParameters() {
return parametersVal;
}

public void setParameters(Object[] parametersVal) {
this.parametersVal = parametersVal;
}

public String toString() {
return ReflectionToStringBuilder.toStringExclude(this, new String[]{"typeParameters", "parametersVal"});
}
}

Loading

0 comments on commit 97ac93e

Please sign in to comment.