Skip to content

Commit

Permalink
first submit
Browse files Browse the repository at this point in the history
first submit
  • Loading branch information
stefzhlg committed Nov 20, 2014
1 parent 6585cb5 commit c018166
Show file tree
Hide file tree
Showing 118 changed files with 3,861 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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 kind="src" path="src/test/resources"/>
<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 kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<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="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>snrpc</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>
4 changes: 4 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
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
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
SNRPC

--------------------
-- a simple netty RPC framework
use protostuff-1.07 for serializer,use netty-3.2.1 for nio.

##How to use

e.g.

1, interface and implementor
// define an interface:
public interface SnRpcInterface {
public String getMessage(String param);
}

// implement interface
public class SnRpcImpl implements SnRpcInterface {
public String getMessage(String param) {
return "hi,it is message from server...param+" + param;
}
}

2, start server

SnRpcInterface inter = new SnRpcImpl();
SnRpcServer server = new SnNettyRpcServer(new Object[] { inter });
try {
server.start();
} catch (Throwable e) {
e.printStackTrace();
}

3, client invoker

SnRpcConnectionFactory factory = new SnNettyRpcConnectionFactory(
"localhost", 8080);
factory = new PoolableRpcConnectionFactory(factory);
SnRpcClient client = new CommonSnRpcClient(factory);
try {
SnRpcInterface clazz = client.proxy(SnRpcInterface.class);
String message = clazz.getMessage("come on");
System.out.println("client receive message .... : " + message);
} catch (Throwable e) {
e.printStackTrace();
}
## Pre-requirement

* JDK6+
* Maven 2



# Dependency

* reflectasm-1.07.jar
* asm-4.0.jar
* log4j-1.2.16.jar
* dom4j-1.6.1.jar
* xml-apis-1.0.b2.jar
* slf4j-api-1.6.6.jar
* netty-3.2.1.Final.jar
* jaxen-1.1.6.jar
* protostuff-core-1.0.7.jar
* protostuff-api-1.0.7.jar
* protostuff-runtime-1.0.7.jar
* protostuff-collectionschema-1.0.7.jar
* commons-pool-1.6.jar

91 changes: 91 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<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>org.stefan</groupId>
<artifactId>snrpc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>faraway</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.esotericsoftware.reflectasm</groupId>
<artifactId>reflectasm</artifactId>
<version>1.07</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>3.2.1.Final</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.0.7</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.dyuproject.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.0.7</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
9 changes: 9 additions & 0 deletions src/main/java/org/stefan/snrpc/SnRpcClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.stefan.snrpc;

/**
* @author zhaoliangang 2014-11-13
*/
public interface SnRpcClient {

public <T> T proxy(Class<T> interfaceClass) throws Throwable;
}
20 changes: 20 additions & 0 deletions src/main/java/org/stefan/snrpc/SnRpcConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.stefan.snrpc;

import org.stefan.snrpc.serializer.SnRpcRequest;
import org.stefan.snrpc.serializer.SnRpcResponse;

/**
* @author zhaoliangang 2014-11-13
*/
public interface SnRpcConnection {

SnRpcResponse sendRequest(SnRpcRequest request) throws Throwable;

void connection() throws Throwable;

void close() throws Throwable;

boolean isConnected();

boolean isClosed();
}
11 changes: 11 additions & 0 deletions src/main/java/org/stefan/snrpc/SnRpcConnectionFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.stefan.snrpc;

/**
* @author zhaoliangang 2014-11-13
*/
public interface SnRpcConnectionFactory {

SnRpcConnection getConnection() throws Throwable;

void recycle(SnRpcConnection connection) throws Throwable;
}
11 changes: 11 additions & 0 deletions src/main/java/org/stefan/snrpc/SnRpcServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.stefan.snrpc;

/**
* @author zhaoliangang 2014-11-13
*/
public interface SnRpcServer {

void start() throws Throwable;

void stop() throws Throwable;
}
Loading

0 comments on commit c018166

Please sign in to comment.