Skip to content

Commit

Permalink
第一次提交
Browse files Browse the repository at this point in the history
  • Loading branch information
131250105 committed May 26, 2016
1 parent 1bf668d commit 9628849
Show file tree
Hide file tree
Showing 28 changed files with 405 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .classpath
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>
23 changes: 23 additions & 0 deletions .project
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>
5 changes: 5 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
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
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
41 changes: 41 additions & 0 deletions pom.xml
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>
7 changes: 7 additions & 0 deletions src/main/java/client/HelloWorldService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package client;


public interface HelloWorldService {

public String hello(String hello);
}
11 changes: 11 additions & 0 deletions src/main/java/core/RPCBootstrap.java
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");
}
}
69 changes: 69 additions & 0 deletions src/main/java/core/RPCRequest.java
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;
}

}
54 changes: 54 additions & 0 deletions src/main/java/core/RPCResponse.java
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;
}

}
15 changes: 15 additions & 0 deletions src/main/java/core/RPCService.java
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();
}
5 changes: 5 additions & 0 deletions src/main/java/core/ServiceRegister.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package core;

public class ServiceRegister {

}
9 changes: 9 additions & 0 deletions src/main/java/server/HelloWorldService.java
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);
}
14 changes: 14 additions & 0 deletions src/main/java/server/HelloWorldServiceImpl.java
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";
}

}
51 changes: 51 additions & 0 deletions src/main/java/server/RPCServer.java
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;
}

}
6 changes: 6 additions & 0 deletions src/main/resources/spring.xml
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>
5 changes: 5 additions & 0 deletions target/classes/META-INF/MANIFEST.MF
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

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
Loading

0 comments on commit 9628849

Please sign in to comment.