-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
405 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>RPCFrameWork</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | ||
org.eclipse.jdt.core.compiler.compliance=1.5 | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>RPCFrameWork</groupId> | ||
<artifactId>RPCFrameWork</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<!-- SLF4J --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<version>1.7.7</version> | ||
</dependency> | ||
|
||
<!-- Spring --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>3.2.12.RELEASE</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>3.2.12.RELEASE</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.dyuproject.protostuff</groupId> | ||
<artifactId>protostuff-core</artifactId> | ||
<version>1.0.7</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.dyuproject.protostuff</groupId> | ||
<artifactId>protostuff-runtime</artifactId> | ||
<version>1.0.7</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package client; | ||
|
||
|
||
public interface HelloWorldService { | ||
|
||
public String hello(String hello); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package core; | ||
|
||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
public class RPCBootstrap { | ||
|
||
public static void main(String[] args){ | ||
System.out.println("调用"); | ||
new ClassPathXmlApplicationContext("spring.xml"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package core; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.omg.CORBA.Request; | ||
|
||
import com.dyuproject.protostuff.LinkedBuffer; | ||
import com.dyuproject.protostuff.ProtostuffIOUtil; | ||
import com.dyuproject.protostuff.Schema; | ||
import com.dyuproject.protostuff.runtime.RuntimeSchema; | ||
|
||
public class RPCRequest { | ||
|
||
private long requestId; | ||
|
||
private String message; | ||
|
||
private ArrayList<Object> params = new ArrayList<Object>(20); | ||
|
||
public long getRequestId() { | ||
return requestId; | ||
} | ||
|
||
public void setRequestId(long requestId) { | ||
this.requestId = requestId; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public ArrayList<Object> getParams() { | ||
return params; | ||
} | ||
|
||
public void setParams(ArrayList<Object> params) { | ||
this.params = params; | ||
} | ||
|
||
|
||
public byte[] encode(){ | ||
Schema<RPCRequest> schema = RuntimeSchema.getSchema(RPCRequest.class); | ||
LinkedBuffer buffer = LinkedBuffer.allocate(4096); | ||
byte[] protostuff = null; | ||
try { | ||
protostuff = ProtostuffIOUtil.toByteArray(this, schema, buffer); | ||
|
||
} finally { | ||
buffer.clear(); | ||
} | ||
|
||
return protostuff; | ||
} | ||
|
||
public RPCRequest decode(byte[] request){ | ||
if(request == null || request.length <= 0) { | ||
return null; | ||
} | ||
RPCRequest result = new RPCRequest(); | ||
Schema<RPCRequest> schema = RuntimeSchema.getSchema(RPCRequest.class); | ||
ProtostuffIOUtil.mergeFrom(request, result, schema); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package core; | ||
|
||
import com.dyuproject.protostuff.LinkedBuffer; | ||
import com.dyuproject.protostuff.ProtostuffIOUtil; | ||
import com.dyuproject.protostuff.Schema; | ||
import com.dyuproject.protostuff.runtime.RuntimeSchema; | ||
|
||
public class RPCResponse { | ||
|
||
private long responseId; | ||
|
||
private Object values; | ||
|
||
public long getResponseId() { | ||
return responseId; | ||
} | ||
|
||
public void setResponseId(long responseId) { | ||
this.responseId = responseId; | ||
} | ||
|
||
public Object getValues() { | ||
return values; | ||
} | ||
|
||
public void setValues(Object values) { | ||
this.values = values; | ||
} | ||
|
||
public byte[] encode(){ | ||
Schema<RPCResponse> schema = RuntimeSchema.getSchema(RPCResponse.class); | ||
LinkedBuffer buffer = LinkedBuffer.allocate(4096); | ||
byte[] protostuff = null; | ||
try { | ||
protostuff = ProtostuffIOUtil.toByteArray(this, schema, buffer); | ||
|
||
} finally { | ||
buffer.clear(); | ||
} | ||
|
||
return protostuff; | ||
} | ||
|
||
public RPCResponse decode(byte[] response){ | ||
if(response == null || response.length <= 0) { | ||
return null; | ||
} | ||
RPCResponse result = new RPCResponse(); | ||
Schema<RPCResponse> schema = RuntimeSchema.getSchema(RPCResponse.class); | ||
ProtostuffIOUtil.mergeFrom(response, result, schema); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package core; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.RetentionPolicy; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Component | ||
public @interface RPCService { | ||
|
||
Class<?> value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package core; | ||
|
||
public class ServiceRegister { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package server; | ||
|
||
import core.RPCService; | ||
|
||
@RPCService(HelloWorldService.class) | ||
public interface HelloWorldService { | ||
|
||
public String hello(String hello); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package server; | ||
|
||
|
||
public class HelloWorldServiceImpl implements HelloWorldService { | ||
|
||
public String hello(String hello) { | ||
// TODO Auto-generated method stub | ||
if("hello".equals(hello)) | ||
return "hello"; | ||
else | ||
return "wrongInput"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package server; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
|
||
import core.ServiceRegister; | ||
|
||
public class RPCServer implements ApplicationContextAware,InitializingBean { | ||
|
||
|
||
private String serverAddress ; | ||
private ServiceRegister serviceRegister; | ||
private Map<String, Object> handlerMap = new HashMap<String,Object>(); | ||
|
||
public RPCServer(String serverAddress ,ServiceRegister serviceRegister){ | ||
this.serverAddress = serverAddress; | ||
this.serviceRegister = serviceRegister; | ||
} | ||
|
||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
public void afterPropertiesSet() throws Exception { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
public String getServerAddress() { | ||
return serverAddress; | ||
} | ||
|
||
public void setServerAddress(String serverAddress) { | ||
this.serverAddress = serverAddress; | ||
} | ||
|
||
public ServiceRegister getServiceRegister() { | ||
return serviceRegister; | ||
} | ||
|
||
public void setServiceRegister(ServiceRegister serviceRegister) { | ||
this.serviceRegister = serviceRegister; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans> | ||
|
||
<context:component-scan base-package="com.xxx.rpc.sample.server"/> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Manifest-Version: 1.0 | ||
Built-By: apple | ||
Build-Jdk: 1.8.0_25 | ||
Created-By: Maven Integration for Eclipse | ||
|
7 changes: 7 additions & 0 deletions
7
target/classes/META-INF/maven/RPCFrameWork/RPCFrameWork/pom.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#Generated by Maven Integration for Eclipse | ||
#Thu May 26 19:29:55 CST 2016 | ||
version=0.0.1-SNAPSHOT | ||
groupId=RPCFrameWork | ||
m2e.projectName=RPCFrameWork | ||
m2e.projectLocation=C\:\\Users\\apple\\Desktop\\MyRPCFrameWork | ||
artifactId=RPCFrameWork |
Oops, something went wrong.