This is an automated email from the ASF dual-hosted git repository.
huxing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 309b694 optimize array code style (#4031)
309b694 is described below
commit 309b69432800cf5ecb342fef8f6484c849739bd6
Author: jimin <[email protected]>
AuthorDate: Sun May 12 10:44:08 2019 +0800
optimize array code style (#4031)
Signed-off-by: jimin.jm <[email protected]>
---
.../org/apache/dubbo/common/io/StreamUtils.java | 2 +-
.../common/io/UnsafeByteArrayInputStream.java | 10 ++---
.../common/io/UnsafeByteArrayOutputStream.java | 4 +-
.../dubbo/common/json/GenericJSONConverter.java | 2 +-
.../org/apache/dubbo/common/json/J2oVisitor.java | 2 +-
.../java/org/apache/dubbo/common/json/Yylex.java | 10 ++---
.../threadpool/support/AbortPolicyWithReport.java | 49 ++++++++++++++--------
.../telnet/support/command/LogTelnetHandler.java | 2 +-
.../dubbo/remoting/transport/AbstractCodec.java | 33 ++++++++-------
.../protocol/dubbo/telnet/LogTelnetHandler.java | 2 +-
.../io/RandomAccessByteArrayOutputStream.java | 4 +-
11 files changed, 69 insertions(+), 51 deletions(-)
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/io/StreamUtils.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/io/StreamUtils.java
index 2a463c3..ab2836e 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/io/StreamUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/io/StreamUtils.java
@@ -40,7 +40,7 @@ public class StreamUtils {
}
@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();
}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/io/UnsafeByteArrayInputStream.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/io/UnsafeByteArrayInputStream.java
index c5b72bd..df96a1c 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/io/UnsafeByteArrayInputStream.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/io/UnsafeByteArrayInputStream.java
@@ -23,19 +23,19 @@ import java.io.InputStream;
* 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);
@@ -47,7 +47,7 @@ public class UnsafeByteArrayInputStream extends InputStream {
}
@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();
}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/io/UnsafeByteArrayOutputStream.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/io/UnsafeByteArrayOutputStream.java
index 1ac43c8..6e75eb8 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/io/UnsafeByteArrayOutputStream.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/io/UnsafeByteArrayOutputStream.java
@@ -25,7 +25,7 @@ import java.nio.ByteBuffer;
* UnsafeByteArrayOutputStream.
*/
public class UnsafeByteArrayOutputStream extends OutputStream {
- protected byte mBuffer[];
+ protected byte[] mBuffer;
protected int mCount;
@@ -51,7 +51,7 @@ public class UnsafeByteArrayOutputStream extends OutputStream
{
}
@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();
}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java
index 74cf09a..9082eb1 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java
@@ -474,7 +474,7 @@ public class GenericJSONConverter implements JSONConverter {
jb.objectBegin();
Wrapper w = Wrapper.getWrapper(c);
- String pns[] = w.getPropertyNames();
+ String[] pns = w.getPropertyNames();
for (String pn : pns) {
if ((obj instanceof Throwable) && (
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/J2oVisitor.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/J2oVisitor.java
index fdcf674..3aa3fd9 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/J2oVisitor.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/J2oVisitor.java
@@ -83,7 +83,7 @@ class J2oVisitor implements JSONVisitor {
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());
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java
index 822175e..32a73a7 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java
@@ -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
};
@@ -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,
@@ -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"
@@ -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
*/
@@ -447,7 +447,7 @@ public class Yylex {
/* 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;
}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java
index 8a13761..cb368db 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/AbortPolicyWithReport.java
@@ -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.
@@ -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) {
@@ -56,11 +66,13 @@ public class AbortPolicyWithReport extends
ThreadPoolExecutor.AbortPolicy {
@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);
@@ -70,7 +82,7 @@ public class AbortPolicyWithReport extends
ThreadPoolExecutor.AbortPolicy {
long now = System.currentTimeMillis();
//dump every 10 minutes
- if (now - lastPrintTime < 10 * 60 * 1000) {
+ if (now - lastPrintTime < TEN_MINUTES_MILLS) {
return;
}
@@ -84,18 +96,19 @@ public class AbortPolicyWithReport extends
ThreadPoolExecutor.AbortPolicy {
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);
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/LogTelnetHandler.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/LogTelnetHandler.java
index db531dc..2d39c23 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/LogTelnetHandler.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/command/LogTelnetHandler.java
@@ -48,7 +48,7 @@ public class LogTelnetHandler implements TelnetHandler {
if (message == null || message.trim().length() == 0) {
buf.append("EXAMPLE: log error / log 100");
} else {
- String str[] = message.split(" ");
+ String[] str = message.split(" ");
if (!StringUtils.isInteger(str[0])) {
LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
} else {
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java
index 346f54c..e5f7696 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractCodec.java
@@ -16,6 +16,9 @@
*/
package org.apache.dubbo.remoting.transport;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
@@ -26,9 +29,6 @@ import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.Codec2;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
/**
* AbstractCodec
*/
@@ -36,13 +36,18 @@ public abstract class AbstractCodec implements Codec2 {
private static final Logger logger =
LoggerFactory.getLogger(AbstractCodec.class);
+ private static final String CLIENT_SIDE = "client";
+
+ private static final String SERVER_SIDE = "server";
+
protected static void checkPayload(Channel channel, long size) throws
IOException {
int payload = RemotingConstants.DEFAULT_PAYLOAD;
if (channel != null && channel.getUrl() != null) {
payload =
channel.getUrl().getParameter(RemotingConstants.PAYLOAD_KEY,
RemotingConstants.DEFAULT_PAYLOAD);
}
if (payload > 0 && size > payload) {
- ExceedPayloadLimitException e = new
ExceedPayloadLimitException("Data length too large: " + size + ", max payload:
" + payload + ", channel: " + channel);
+ ExceedPayloadLimitException e = new ExceedPayloadLimitException(
+ "Data length too large: " + size + ", max payload: " + payload
+ ", channel: " + channel);
logger.error(e);
throw e;
}
@@ -53,21 +58,21 @@ public abstract class AbstractCodec implements Codec2 {
}
protected boolean isClientSide(Channel channel) {
- String side = (String) channel.getAttribute(Constants.SIDE_KEY);
- if ("client".equals(side)) {
+ String side = (String)channel.getAttribute(Constants.SIDE_KEY);
+ if (CLIENT_SIDE.equals(side)) {
return true;
- } else if ("server".equals(side)) {
+ } else if (SERVER_SIDE.equals(side)) {
return false;
} else {
InetSocketAddress address = channel.getRemoteAddress();
URL url = channel.getUrl();
- boolean client = url.getPort() == address.getPort()
- && NetUtils.filterLocalHost(url.getIp()).equals(
- NetUtils.filterLocalHost(address.getAddress()
- .getHostAddress()));
- channel.setAttribute(Constants.SIDE_KEY, client ? "client"
- : "server");
- return client;
+ boolean isClient = url.getPort() == address.getPort()
+ && NetUtils.filterLocalHost(url.getIp()).equals(
+ NetUtils.filterLocalHost(address.getAddress()
+ .getHostAddress()));
+ channel.setAttribute(Constants.SIDE_KEY, isClient ? CLIENT_SIDE
+ : SERVER_SIDE);
+ return isClient;
}
}
diff --git
a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/LogTelnetHandler.java
b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/LogTelnetHandler.java
index b62198d..86bcd9b 100644
---
a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/LogTelnetHandler.java
+++
b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/LogTelnetHandler.java
@@ -48,7 +48,7 @@ public class LogTelnetHandler implements TelnetHandler {
if (message == null || message.trim().length() == 0) {
buf.append("EXAMPLE: log error / log 100");
} else {
- String str[] = message.split(" ");
+ String[] str = message.split(" ");
if (!StringUtils.isInteger(str[0])) {
LoggerFactory.setLevel(Level.valueOf(message.toUpperCase()));
} else {
diff --git
a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/io/RandomAccessByteArrayOutputStream.java
b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/io/RandomAccessByteArrayOutputStream.java
index a5d0d11..660dd80 100644
---
a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/io/RandomAccessByteArrayOutputStream.java
+++
b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/io/RandomAccessByteArrayOutputStream.java
@@ -25,7 +25,7 @@ import java.nio.ByteBuffer;
@Deprecated
public class RandomAccessByteArrayOutputStream extends OutputStream {
- protected byte buffer[];
+ protected byte[] buffer;
protected int count;
@@ -54,7 +54,7 @@ public class RandomAccessByteArrayOutputStream extends
OutputStream {
}
@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();