Skip to content
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

Update project #3

Merged
merged 4 commits into from
May 12, 2019
Merged
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 @@ -18,6 +18,7 @@

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.cluster.Configurator;
Expand Down Expand Up @@ -104,7 +105,7 @@ private URL configureIfMatch(String host, URL url) {
|| configApplication.equals(currentApplication)) {
Set<String> conditionKeys = new HashSet<String>();
conditionKeys.add(Constants.CATEGORY_KEY);
conditionKeys.add(Constants.CHECK_KEY);
conditionKeys.add(RemotingConstants.CHECK_KEY);
conditionKeys.add(Constants.DYNAMIC_KEY);
conditionKeys.add(Constants.ENABLED_KEY);
conditionKeys.add(Constants.GROUP_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@
*/
package org.apache.dubbo.rpc.cluster.support;

import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.Cluster;
import org.apache.dubbo.rpc.cluster.Directory;
import org.apache.dubbo.rpc.cluster.LoadBalance;

import java.util.List;

/**
* AvailableCluster
Expand All @@ -36,19 +31,7 @@ public class AvailableCluster implements Cluster {

@Override
public <T> Invoker<T> join(Directory<T> directory) throws RpcException {

return new AbstractClusterInvoker<T>(directory) {
@Override
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
for (Invoker<T> invoker : invokers) {
if (invoker.isAvailable()) {
return invoker.invoke(invocation);
}
}
throw new RpcException("No provider available in " + invokers);
}
};

return new AvailableClusterInvoker<>(directory);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.utils.StringUtils;

import java.util.HashMap;
Expand Down Expand Up @@ -59,8 +60,8 @@ public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
map.remove(Constants.ALIVE_KEY);
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ALIVE_KEY);

map.remove(Constants.TRANSPORTER_KEY);
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.TRANSPORTER_KEY);
map.remove(RemotingConstants.TRANSPORTER_KEY);
map.remove(Constants.DEFAULT_KEY_PREFIX + RemotingConstants.TRANSPORTER_KEY);

map.remove(Constants.ASYNC_KEY);
map.remove(Constants.DEFAULT_KEY_PREFIX + Constants.ASYNC_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.dubbo.common;

import org.apache.dubbo.common.constants.RemotingConstants;

import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -789,7 +791,7 @@ public class Constants {

public static final String COMPATIBLE_CONFIG_KEY = "compatible_config";

public static final String[] DEFAULT_REGISTER_PROVIDER_KEYS = {APPLICATION_KEY, CODEC_KEY, EXCHANGER_KEY, SERIALIZATION_KEY, CLUSTER_KEY, CONNECTIONS_KEY, DEPRECATED_KEY,
public static final String[] DEFAULT_REGISTER_PROVIDER_KEYS = {APPLICATION_KEY, RemotingConstants.CODEC_KEY, RemotingConstants.EXCHANGER_KEY, RemotingConstants.SERIALIZATION_KEY, CLUSTER_KEY, CONNECTIONS_KEY, DEPRECATED_KEY,
GROUP_KEY, LOADBALANCE_KEY, MOCK_KEY, PATH_KEY, TIMEOUT_KEY, TOKEN_KEY, VERSION_KEY, WARMUP_KEY, WEIGHT_KEY, TIMESTAMP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY};

public static final String[] DEFAULT_REGISTER_CONSUMER_KEYS = {APPLICATION_KEY, VERSION_KEY, GROUP_KEY, DUBBO_VERSION_KEY, RELEASE_KEY};
Expand Down
5 changes: 3 additions & 2 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.config.Configuration;
import org.apache.dubbo.common.config.InmemoryConfiguration;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
Expand Down Expand Up @@ -414,7 +415,7 @@ public String getBackupAddress() {

public String getBackupAddress(int defaultPort) {
StringBuilder address = new StringBuilder(appendDefaultPort(getAddress(), defaultPort));
String[] backups = getParameter(Constants.BACKUP_KEY, new String[0]);
String[] backups = getParameter(RemotingConstants.BACKUP_KEY, new String[0]);
if (ArrayUtils.isNotEmpty(backups)) {
for (String backup : backups) {
address.append(",");
Expand All @@ -427,7 +428,7 @@ public String getBackupAddress(int defaultPort) {
public List<URL> getBackupUrls() {
List<URL> urls = new ArrayList<>();
urls.add(this);
String[] backups = getParameter(Constants.BACKUP_KEY, new String[0]);
String[] backups = getParameter(RemotingConstants.BACKUP_KEY, new String[0]);
if (backups != null && backups.length > 0) {
for (String backup : backups) {
urls.add(this.setAddress(backup));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

import static org.apache.dubbo.common.Constants.APPLICATION_KEY;
import static org.apache.dubbo.common.Constants.CLUSTER_KEY;
import static org.apache.dubbo.common.Constants.CODEC_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.CODEC_KEY;
import static org.apache.dubbo.common.Constants.CONNECTIONS_KEY;
import static org.apache.dubbo.common.Constants.DEPRECATED_KEY;
import static org.apache.dubbo.common.Constants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.Constants.EXCHANGER_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.EXCHANGER_KEY;
import static org.apache.dubbo.common.Constants.GROUP_KEY;
import static org.apache.dubbo.common.Constants.LOADBALANCE_KEY;
import static org.apache.dubbo.common.Constants.MOCK_KEY;
import static org.apache.dubbo.common.Constants.PATH_KEY;
import static org.apache.dubbo.common.Constants.RELEASE_KEY;
import static org.apache.dubbo.common.Constants.SERIALIZATION_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.SERIALIZATION_KEY;
import static org.apache.dubbo.common.Constants.TIMEOUT_KEY;
import static org.apache.dubbo.common.Constants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.Constants.TOKEN_KEY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public int read() throws IOException {
}

@Override
public int read(byte b[], int off, int len) throws IOException {
public int read(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
* UnsafeByteArrayInputStream.
*/
public class UnsafeByteArrayInputStream extends InputStream {
protected byte mData[];
protected byte[] mData;

protected int mPosition, mLimit, mMark = 0;

public UnsafeByteArrayInputStream(byte buf[]) {
public UnsafeByteArrayInputStream(byte[] buf) {
this(buf, 0, buf.length);
}

public UnsafeByteArrayInputStream(byte buf[], int offset) {
public UnsafeByteArrayInputStream(byte[] buf, int offset) {
this(buf, offset, buf.length - offset);
}

public UnsafeByteArrayInputStream(byte buf[], int offset, int length) {
public UnsafeByteArrayInputStream(byte[] buf, int offset, int length) {
mData = buf;
mPosition = mMark = offset;
mLimit = Math.min(offset + length, buf.length);
Expand All @@ -47,7 +47,7 @@ public int read() {
}

@Override
public int read(byte b[], int off, int len) {
public int read(byte[] b, int off, int len) {
if (b == null) {
throw new NullPointerException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* UnsafeByteArrayOutputStream.
*/
public class UnsafeByteArrayOutputStream extends OutputStream {
protected byte mBuffer[];
protected byte[] mBuffer;

protected int mCount;

Expand All @@ -51,7 +51,7 @@ public void write(int b) {
}

@Override
public void write(byte b[], int off, int len) {
public void write(byte[] b, int off, int len) {
if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public void writeValue(Object obj, JSONWriter jb, boolean writeClass) throws IOE
jb.objectBegin();

Wrapper w = Wrapper.getWrapper(c);
String pns[] = w.getPropertyNames();
String[] pns = w.getPropertyNames();

for (String pn : pns) {
if ((obj instanceof Throwable) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static Object toArray(Class<?> c, Stack<Object> list, int len) throws Pa
return EMPTY_STRING_ARRAY;
} else {
Object o;
String ss[] = new String[len];
String[] ss = new String[len];
for (int i = len - 1; i >= 0; i--) {
o = list.pop();
ss[i] = (o == null ? null : o.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Yylex {
* at the beginning of a line
* l is of the form l = 2*k, k a non negative integer
*/
private static final int ZZ_LEXSTATE[] = {
private static final int[] ZZ_LEXSTATE = {
0, 0, 1, 1, 2, 2
};

Expand Down Expand Up @@ -92,7 +92,7 @@ public class Yylex {
/**
* The transition table of the DFA
*/
private static final int ZZ_TRANS[] = {
private static final int[] ZZ_TRANS = {
3, 4, 5, 5, 6, 3, 5, 3, 7, 8,
3, 9, 3, 5, 10, 11, 5, 12, 5, 5,
13, 5, 5, 5, 5, 5, 14, 5, 5, 5,
Expand Down Expand Up @@ -247,7 +247,7 @@ public class Yylex {
private static final int ZZ_NO_MATCH = 1;
private static final int ZZ_PUSHBACK_2BIG = 2;
/* error messages for the codes above */
private static final String ZZ_ERROR_MSG[] = {
private static final String[] ZZ_ERROR_MSG = {
"Unkown internal scanner error",
"Error: could not match input",
"Error: pushback value was too large"
Expand Down Expand Up @@ -276,7 +276,7 @@ public class Yylex {
* this buffer contains the current text to be matched and is
* the source of the yytext() string
*/
private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
private char[] zzBuffer = new char[ZZ_BUFFERSIZE];
/**
* the textposition at the last accepting state
*/
Expand Down Expand Up @@ -447,7 +447,7 @@ private boolean zzRefill() throws java.io.IOException {
/* is the buffer big enough? */
if (zzCurrentPos >= zzBuffer.length) {
/* if not: blow it up */
char newBuffer[] = new char[zzCurrentPos * 2];
char[] newBuffer = new char[zzCurrentPos * 2];
System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
zzBuffer = newBuffer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
*/
package org.apache.dubbo.common.threadpool.support;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.JVMUtil;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ExecutorService;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.JVMUtil;

/**
* Abort Policy.
Expand All @@ -46,6 +46,16 @@ public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy {

private static volatile long lastPrintTime = 0;

private static final long TEN_MINUTES_MILLS = 10 * 60 * 1000;

private static final String OS_WIN_PREFIX = "win";

private static final String OS_NAME_KEY = "os.name";

private static final String WIN_DATETIME_FORMAT = "yyyy-MM-dd_HH-mm-ss";

private static final String DEFAULT_DATETIME_FORMAT = "yyyy-MM-dd_HH:mm:ss";

private static Semaphore guard = new Semaphore(1);

public AbortPolicyWithReport(String threadName, URL url) {
Expand All @@ -56,11 +66,13 @@ public AbortPolicyWithReport(String threadName, URL url) {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
String msg = String.format("Thread pool is EXHAUSTED!" +
" Thread Name: %s, Pool Size: %d (active: %d, core: %d, max: %d, largest: %d), Task: %d (completed: %d)," +
" Executor status:(isShutdown:%s, isTerminated:%s, isTerminating:%s), in %s://%s:%d!",
threadName, e.getPoolSize(), e.getActiveCount(), e.getCorePoolSize(), e.getMaximumPoolSize(), e.getLargestPoolSize(),
e.getTaskCount(), e.getCompletedTaskCount(), e.isShutdown(), e.isTerminated(), e.isTerminating(),
url.getProtocol(), url.getIp(), url.getPort());
" Thread Name: %s, Pool Size: %d (active: %d, core: %d, max: %d, largest: %d), Task: %d (completed: "
+ "%d)," +
" Executor status:(isShutdown:%s, isTerminated:%s, isTerminating:%s), in %s://%s:%d!",
threadName, e.getPoolSize(), e.getActiveCount(), e.getCorePoolSize(), e.getMaximumPoolSize(),
e.getLargestPoolSize(),
e.getTaskCount(), e.getCompletedTaskCount(), e.isShutdown(), e.isTerminated(), e.isTerminating(),
url.getProtocol(), url.getIp(), url.getPort());
logger.warn(msg);
dumpJStack();
throw new RejectedExecutionException(msg);
Expand All @@ -70,7 +82,7 @@ private void dumpJStack() {
long now = System.currentTimeMillis();

//dump every 10 minutes
if (now - lastPrintTime < 10 * 60 * 1000) {
if (now - lastPrintTime < TEN_MINUTES_MILLS) {
return;
}

Expand All @@ -84,18 +96,19 @@ private void dumpJStack() {

SimpleDateFormat sdf;

String os = System.getProperty("os.name").toLowerCase();
String os = System.getProperty(OS_NAME_KEY).toLowerCase();

// window system don't support ":" in file name
if (os.contains("win")) {
sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
if (os.contains(OS_WIN_PREFIX)) {
sdf = new SimpleDateFormat(WIN_DATETIME_FORMAT);
} else {
sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
sdf = new SimpleDateFormat(DEFAULT_DATETIME_FORMAT);
}

String dateStr = sdf.format(new Date());
//try-with-resources
try (FileOutputStream jStackStream = new FileOutputStream(new File(dumpPath, "Dubbo_JStack.log" + "." + dateStr))) {
try (FileOutputStream jStackStream = new FileOutputStream(
new File(dumpPath, "Dubbo_JStack.log" + "." + dateStr))) {
JVMUtil.jstack(jStackStream);
} catch (Throwable t) {
logger.error("dump jStack error", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public static boolean matchIpRange(String pattern, String host, int port) throws

host = inetAddress.getHostAddress();

String[] ip_address = host.split(splitCharacter);
String[] ipAddress = host.split(splitCharacter);
if (pattern.equals(host)) {
return true;
}
Expand All @@ -442,7 +442,7 @@ public static boolean matchIpRange(String pattern, String host, int port) throws
}
}
for (int i = 0; i < mask.length; i++) {
if (mask[i].equals("*") || mask[i].equals(ip_address[i])) {
if (mask[i].equals("*") || mask[i].equals(ipAddress[i])) {
continue;
} else if (mask[i].contains("-")) {
String[] rangeNumStrs = mask[i].split("-");
Expand All @@ -451,13 +451,13 @@ public static boolean matchIpRange(String pattern, String host, int port) throws
}
Integer min = getNumOfIpSegment(rangeNumStrs[0], isIpv4);
Integer max = getNumOfIpSegment(rangeNumStrs[1], isIpv4);
Integer ip = getNumOfIpSegment(ip_address[i], isIpv4);
Integer ip = getNumOfIpSegment(ipAddress[i], isIpv4);
if (ip < min || ip > max) {
return false;
}
} else if ("0".equals(ip_address[i]) && ("0".equals(mask[i]) || "00".equals(mask[i]) || "000".equals(mask[i]) || "0000".equals(mask[i]))) {
} else if ("0".equals(ipAddress[i]) && ("0".equals(mask[i]) || "00".equals(mask[i]) || "000".equals(mask[i]) || "0000".equals(mask[i]))) {
continue;
} else if (!mask[i].equals(ip_address[i])) {
} else if (!mask[i].equals(ipAddress[i])) {
return false;
}
}
Expand Down
Loading