Skip to content

Updated netty to 4.0.x, Enabled socks proxy, etc. #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.3</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

Expand Down Expand Up @@ -91,27 +91,18 @@
</plugins>
</reporting>

<repositories>
<repository>
<id>repository.jboss.org</id>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack</artifactId>
<version>0.6.6</version>
<version>0.6.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>3.2.1.Final</version>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.28.Final</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/org/msgpack/rpc/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,32 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
/*
* Copyright (C) 2014-2015 Information Analysis Laboratory, NICT
*
* RaSC is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at
* your option) any later version.
*
* RaSC is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.msgpack.rpc;

import org.msgpack.type.Value;
import org.msgpack.rpc.message.ResponseMessage;
import org.msgpack.rpc.transport.MessageSendable;
import org.msgpack.type.Value;

public class Request implements Callback<Object> {
private MessageSendable channel; // TODO #SF synchronized?
private int msgid;
protected MessageSendable channel; // TODO #SF synchronized?
protected int msgid;
private String method;
private Value args;

Expand Down
34 changes: 24 additions & 10 deletions src/main/java/org/msgpack/rpc/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,49 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
/*
* Copyright (C) 2014-2015 Information Analysis Laboratory, NICT
*
* RaSC is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at
* your option) any later version.
*
* RaSC is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.msgpack.rpc;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

import org.msgpack.rpc.address.IPAddress;
import org.msgpack.rpc.builder.DefaultDispatcherBuilder;
import org.msgpack.rpc.builder.DispatcherBuilder;
import org.msgpack.rpc.reflect.Reflect;
import org.msgpack.type.NilValue;
import org.msgpack.type.Value;
import org.msgpack.rpc.address.IPAddress;
import org.msgpack.rpc.dispatcher.Dispatcher;
import org.msgpack.rpc.dispatcher.MethodDispatcher;
import org.msgpack.rpc.config.ClientConfig;
import org.msgpack.rpc.config.ServerConfig;
import org.msgpack.rpc.config.TcpServerConfig;
import org.msgpack.rpc.transport.ServerTransport;
import org.msgpack.rpc.transport.MessageSendable;
import org.msgpack.rpc.loop.EventLoop;
import org.msgpack.rpc.dispatcher.Dispatcher;
import org.msgpack.rpc.error.RPCError;
import org.msgpack.rpc.loop.EventLoop;
import org.msgpack.rpc.transport.MessageSendable;
import org.msgpack.rpc.transport.ServerTransport;
import org.msgpack.type.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Server extends SessionPool {

private final static Logger logger = LoggerFactory.getLogger(Server.class);

private Dispatcher dp;
protected Dispatcher dp;
private ServerTransport stran;
private DispatcherBuilder dispatcherBuilder = new DefaultDispatcherBuilder();

Expand Down
49 changes: 38 additions & 11 deletions src/main/java/org/msgpack/rpc/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,53 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
/*
* Copyright (C) 2014-2015 Information Analysis Laboratory, NICT
*
* RaSC is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at
* your option) any later version.
*
* RaSC is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.msgpack.rpc;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;

import org.msgpack.rpc.address.Address;
import org.msgpack.rpc.message.RequestMessage;
import org.msgpack.rpc.config.ClientConfig;
import org.msgpack.rpc.loop.EventLoop;
import org.msgpack.rpc.message.NotifyMessage;
import org.msgpack.rpc.message.RequestMessage;
import org.msgpack.rpc.reflect.Reflect;
import org.msgpack.rpc.transport.ClientTransport;
import org.msgpack.rpc.config.ClientConfig;
import org.msgpack.rpc.loop.EventLoop;
import org.msgpack.type.Value;
import org.msgpack.type.ValueFactory;

public class Session {
protected Address address;
protected EventLoop loop;
private ClientTransport transport;
protected ClientTransport transport;
private Reflect reflect;

private int requestTimeout;
private AtomicInteger seqid = new AtomicInteger(0); // FIXME rand()?
private Map<Integer, FutureImpl> reqtable = new HashMap<Integer, FutureImpl>();
protected AtomicInteger seqid = new AtomicInteger(0); // FIXME rand()?
protected Map<Integer, FutureImpl> reqtable = new HashMap<Integer, FutureImpl>();

Session(Address address, ClientConfig config, EventLoop loop) {
this(address,config,loop,new Reflect(loop.getMessagePack()));
Expand Down Expand Up @@ -141,16 +159,14 @@ void closeSession() {
}

public void transportConnectFailed() { // FIXME error rseult
/*
synchronized(reqtable) {
for(Map.Entry<Integer,FutureImpl> pair : reqtable.entrySet()) {
// FIXME
FutureImpl f = pair.getValue();
f.setResult(null,null);
f.setResult(null,ValueFactory.createRawValue("Fail to connect"));
}
reqtable.clear();
}
*/
}

public void onResponse(int msgid, Value result, Value error) {
Expand Down Expand Up @@ -183,4 +199,15 @@ void stepTimeout() {
f.setResult(null, ValueFactory.createRawValue("timedout"));
}
}

public void transportError(String msg){
synchronized(reqtable) {
for(Map.Entry<Integer,FutureImpl> pair : reqtable.entrySet()) {
// FIXME
FutureImpl f = pair.getValue();
f.setResult(null,ValueFactory.createRawValue(msg));
}
reqtable.clear();
}
}
}
32 changes: 26 additions & 6 deletions src/main/java/org/msgpack/rpc/config/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,32 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
/*
* Copyright (C) 2014-2015 Information Analysis Laboratory, NICT
*
* RaSC is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at
* your option) any later version.
*
* RaSC is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.msgpack.rpc.config;

import java.util.HashMap;
import io.netty.channel.ChannelOption;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class ClientConfig {
private Map<String, Object> options = new HashMap<String, Object>();
private Map<ChannelOption<?>,Object> options = new ConcurrentHashMap<>();
protected int requestTimeout = 30; // FIXME default timeout time

public void setRequestTimeout(int sec) {
Expand All @@ -32,15 +51,16 @@ public int getRequestTimeout() {
return this.requestTimeout;
}

public Object getOption(String key) {
return options.get(key);
@SuppressWarnings("unchecked")
public<T> T getOption(ChannelOption<T> key) {
return (T)options.get(key);
}

public Map<String, Object> getOptions() {
public Map<ChannelOption<?>,Object> getOptions() {
return options;
}

public void setOption(String key, Object value) {
public<T> void setOption(ChannelOption<T> key, T value) {
options.put(key, value);
}
}
Loading