Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

/**
* MemcachedProtocol
*
*
* @author william.liangf
*/
public class MemcachedProtocol extends AbstractProtocol {
Expand Down Expand Up @@ -67,7 +67,7 @@ public <T> Invoker<T> refer(final Class<T> type, final URL url) throws RpcExcept
final String get = url.getParameter("get", "get");
final String set = url.getParameter("set", Map.class.equals(type) ? "put" : "set");
final String delete = url.getParameter("delete", Map.class.equals(type) ? "remove" : "delete");
return new AbstractInvoker<T>(type, url) {
Invoker invoker = new AbstractInvoker<T>(type, url) {
protected Result doInvoke(Invocation invocation) throws Throwable {
try {
if (get.equals(invocation.getMethodName())) {
Expand Down Expand Up @@ -109,6 +109,8 @@ public void destroy() {
}
}
};
invokers.add(invoker);
return invoker;
} catch (Throwable t) {
throw new RpcException("Failed to refer memecached service. interface: " + type.getName() + ", url: " + url + ", cause: " + t.getMessage(), t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.alibaba.dubbo.rpc.protocol.redis;

import com.alibaba.dubbo.common.utils.StringUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -68,31 +69,12 @@ private Serialization getSerialization(URL url) {

public <T> Invoker<T> refer(final Class<T> type, final URL url) throws RpcException {
try {
GenericObjectPool.Config config = new GenericObjectPool.Config();
config.testOnBorrow = url.getParameter("test.on.borrow", true);
config.testOnReturn = url.getParameter("test.on.return", false);
config.testWhileIdle = url.getParameter("test.while.idle", false);
if (url.getParameter("max.idle", 0) > 0)
config.maxIdle = url.getParameter("max.idle", 0);
if (url.getParameter("min.idle", 0) > 0)
config.minIdle = url.getParameter("min.idle", 0);
if (url.getParameter("max.active", 0) > 0)
config.maxActive = url.getParameter("max.active", 0);
if (url.getParameter("max.wait", 0) > 0)
config.maxWait = url.getParameter("max.wait", 0);
if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
config.numTestsPerEvictionRun = url.getParameter("num.tests.per.eviction.run", 0);
if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
config.timeBetweenEvictionRunsMillis = url.getParameter("time.between.eviction.runs.millis", 0);
if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
config.minEvictableIdleTimeMillis = url.getParameter("min.evictable.idle.time.millis", 0);
final JedisPool jedisPool = new JedisPool(config, url.getHost(), url.getPort(DEFAULT_PORT),
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
final JedisPool jedisPool = getJedisPool(url);
final int expiry = url.getParameter("expiry", 0);
final String get = url.getParameter("get", "get");
final String set = url.getParameter("set", Map.class.equals(type) ? "put" : "set");
final String delete = url.getParameter("delete", Map.class.equals(type) ? "remove" : "delete");
return new AbstractInvoker<T>(type, url) {
Invoker invoker = new AbstractInvoker<T>(type, url) {
protected Result doInvoke(Invocation invocation) throws Throwable {
Jedis resource = null;
try {
Expand Down Expand Up @@ -163,9 +145,39 @@ public void destroy() {
}
}
};
invokers.add(invoker);
return invoker;
} catch (Throwable t) {
throw new RpcException("Failed to refer memecached service. interface: " + type.getName() + ", url: " + url + ", cause: " + t.getMessage(), t);
}
}

private JedisPool getJedisPool(URL url){
GenericObjectPool.Config config = new GenericObjectPool.Config();
config.testOnBorrow = url.getParameter("test.on.borrow", true);
config.testOnReturn = url.getParameter("test.on.return", false);
config.testWhileIdle = url.getParameter("test.while.idle", false);
if (url.getParameter("max.idle", 0) > 0)
config.maxIdle = url.getParameter("max.idle", 0);
if (url.getParameter("min.idle", 0) > 0)
config.minIdle = url.getParameter("min.idle", 0);
if (url.getParameter("max.active", 0) > 0)
config.maxActive = url.getParameter("max.active", 0);
if (url.getParameter("max.wait", 0) > 0)
config.maxWait = url.getParameter("max.wait", 0);
if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
config.numTestsPerEvictionRun = url.getParameter("num.tests.per.eviction.run", 0);
if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
config.timeBetweenEvictionRunsMillis = url.getParameter("time.between.eviction.runs.millis", 0);
if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
config.minEvictableIdleTimeMillis = url.getParameter("min.evictable.idle.time.millis", 0);
if(StringUtils.isEmpty(url.getPassword())){
return new JedisPool(config, url.getHost(), url.getPort(DEFAULT_PORT),
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
} else {
return new JedisPool(config, url.getHost(), url.getPort(DEFAULT_PORT),
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT),url.getPassword());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class RestProtocol extends AbstractProxyProtocol {

private static final int DEFAULT_PORT = 80;

private static final String HTTP_PROTOCOL = "protocol";

private static final String DEFAULT_HTTP_PROTOCOL = "http";

private final Map<String, RestServer> servers = new ConcurrentHashMap<String, RestServer>();

private final RestServerFactory serverFactory = new RestServerFactory();
Expand Down Expand Up @@ -182,8 +186,12 @@ public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
}
}

// TODO protocol
ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
ResteasyWebTarget target;
if(url.getPort() == 0){
target = client.target(url.getParameter(HTTP_PROTOCOL,DEFAULT_HTTP_PROTOCOL) + "://" + url.getHost() + "/" + getContextPath(url));
} else {
target = client.target(url.getParameter(HTTP_PROTOCOL,DEFAULT_HTTP_PROTOCOL) + "://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
}
return target.proxy(serviceType);
}

Expand Down