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

Standard code comment format. #10251

Merged
merged 1 commit into from
Jul 1, 2022
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 @@ -120,7 +120,7 @@ public synchronized static int getAvailablePort(int port) {

/**
* Check the port whether is in use in os
*
*
* @param port the port to check if in use
* @return is the given port in use or not
*/
Expand Down Expand Up @@ -346,7 +346,7 @@ private static boolean ignoreNetworkInterface(NetworkInterface networkInterface)
for(String ignoredInterface: ignoredInterfaces.split(",")){
String trimIgnoredInterface = ignoredInterface.trim();
boolean matched = false;
try {
try {
matched = networkInterfaceDisplayName.matches(trimIgnoredInterface);
} catch (PatternSyntaxException e) {
// if trimIgnoredInterface is a invalid regular expression, a PatternSyntaxException will be thrown out
Expand Down Expand Up @@ -592,7 +592,7 @@ public static boolean matchIpRange(String pattern, String host, int port) throws
splitCharacter = SPLIT_IPV6_CHARACTER;
}
String[] mask = pattern.split(splitCharacter);
//check format of pattern
// check format of pattern
checkHostPattern(pattern, mask, isIpv4);

host = inetAddress.getHostAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,12 @@ public void testDateTimeTimestamp() throws Exception {
String dateTimeStr = "2018-09-12 10:12:33";
String[] dateFormat = new String[]{"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", "HH:mm:ss"};

//java.util.Date
// java.util.Date
Object date = PojoUtils.realize(dateTimeStr, Date.class, (Type) Date.class);
assertEquals(Date.class, date.getClass());
assertEquals(dateTimeStr, new SimpleDateFormat(dateFormat[0]).format(date));

//java.sql.Time
// java.sql.Time
Object time = PojoUtils.realize(dateTimeStr, java.sql.Time.class, (Type) java.sql.Time.class);
assertEquals(java.sql.Time.class, time.getClass());
assertEquals(timeStr, new SimpleDateFormat(dateFormat[2]).format(time));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public <T> Future<T> asyncCall(Callable<T> callable) {
try {
setAttachment(Constants.ASYNC_KEY, Boolean.TRUE.toString());
final T o = callable.call();
//local invoke will return directly
// local invoke will return directly
if (o != null) {
FutureTask<T> f = new FutureTask<T>(new Callable<T>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String execute(CommandContext commandContext) throws NoSuchCommandExcepti
String extName = StringUtils.camelToSplitName(commandContext.getCommandName(), PROPERTIES_CHAR_SEPARATOR);
command = ExtensionLoader.getExtensionLoader(BaseCommand.class).getExtension(extName);
} catch (Throwable throwable) {
//can't find command
// can't find command
}
if (command == null) {
throw new NoSuchCommandException(commandContext.getCommandName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void destroy() {
// unsubscribe.
try {
if (getSubscribeConsumerurl() != null && registry != null && registry.isAvailable()) {
//overwrite by child, so need call function
// overwrite by child, so need call function
unSubscribe(getSubscribeConsumerurl());
}
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void testExport() {
newRegistryUrl, new ExchangeClient[] {new MockedClient("10.20.20.20", 2222, true)});
Exporter<DemoService> exporter = registryProtocol.export(invoker);
Exporter<DemoService> exporter2 = registryProtocol.export(invoker);
//The same invoker, exporter that multiple exported are different
// The same invoker, exporter that multiple exported are different
Assertions.assertNotSame(exporter, exporter2);
exporter.unexport();
exporter2.unexport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static Serialization getSerialization(String name) {
private Object decode(byte[] request) throws IOException {
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(request);
AbstractMockChannel channel = getServerSideChannel(url);
//decode
// decode
Object obj = codec.decode(channel, buffer);
return obj;
}
Expand Down Expand Up @@ -146,17 +146,17 @@ public void test_Decode_Error_Length() throws IOException {
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(join(request, baddata));
Response obj = (Response) codec.decode(channel, buffer);
Assertions.assertEquals(person, obj.getResult());
//only decode necessary bytes
// only decode necessary bytes
Assertions.assertEquals(request.length, buffer.readerIndex());
}

@Test
public void test_Decode_Error_Response_Object() throws IOException {
//00000010-response/oneway/hearbeat=true |20-stats=ok|id=0|length=0
// 00000010-response/oneway/hearbeat=true |20-stats=ok|id=0|length=0
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, 0x02, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Person person = new Person();
byte[] request = getRequestBytes(person, header);
//bad object
// bad object
byte[] badbytes = new byte[]{-1, -2, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4};
System.arraycopy(badbytes, 0, request, 21, badbytes.length);

Expand Down Expand Up @@ -220,13 +220,13 @@ public void test_Decode_MigicCodec_Contain_ExchangeHeader() throws IOException {
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(header);
Object obj = codec.decode(channel, buffer);
Assertions.assertEquals(TelnetCodec.DecodeResult.NEED_MORE_INPUT, obj);
//If the telnet data and request data are in the same data packet, we should guarantee that the receipt of request data won't be affected by the factor that telnet does not have an end characters.
// If the telnet data and request data are in the same data packet, we should guarantee that the receipt of request data won't be affected by the factor that telnet does not have an end characters.
Assertions.assertEquals(2, buffer.readerIndex());
}

@Test
public void test_Decode_Return_Response_Person() throws IOException {
//00000010-response/oneway/hearbeat=false/hessian |20-stats=ok|id=0|length=0
// 00000010-response/oneway/hearbeat=false/hessian |20-stats=ok|id=0|length=0
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, 2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Expand All @@ -249,7 +249,7 @@ public void test_Decode_Return_Response_Error() throws IOException {

@Test
public void test_Decode_Return_Request_Event_Object() throws IOException {
//|10011111|20-stats=ok|id=0|length=0
// |10011111|20-stats=ok|id=0|length=0
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, (byte) 0xe2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Expand All @@ -266,7 +266,7 @@ public void test_Decode_Return_Request_Event_Object() throws IOException {

@Test
public void test_Decode_Return_Request_Event_String() throws IOException {
//|10011111|20-stats=ok|id=0|length=0
// |10011111|20-stats=ok|id=0|length=0
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, (byte) 0xe2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
String event = READONLY_EVENT;
byte[] request = getRequestBytes(event, header);
Expand All @@ -281,7 +281,7 @@ public void test_Decode_Return_Request_Event_String() throws IOException {

@Test
public void test_Decode_Return_Request_Heartbeat_Object() throws IOException {
//|10011111|20-stats=ok|id=0|length=0
// |10011111|20-stats=ok|id=0|length=0
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, (byte) 0xe2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte[] request = getRequestBytes(null, header);
Request obj = (Request) decode(request);
Expand All @@ -294,7 +294,7 @@ public void test_Decode_Return_Request_Heartbeat_Object() throws IOException {

@Test
public void test_Decode_Return_Request_Object() throws IOException {
//|10011111|20-stats=ok|id=0|length=0
// |10011111|20-stats=ok|id=0|length=0
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, (byte) 0xc2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Expand All @@ -309,11 +309,11 @@ public void test_Decode_Return_Request_Object() throws IOException {

@Test
public void test_Decode_Error_Request_Object() throws IOException {
//00000010-response/oneway/hearbeat=true |20-stats=ok|id=0|length=0
// 00000010-response/oneway/hearbeat=true |20-stats=ok|id=0|length=0
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, (byte) 0xe2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Person person = new Person();
byte[] request = getRequestBytes(person, header);
//bad object
// bad object
byte[] badbytes = new byte[]{-1, -2, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4};
System.arraycopy(badbytes, 0, request, 21, badbytes.length);

Expand All @@ -324,7 +324,7 @@ public void test_Decode_Error_Request_Object() throws IOException {

@Test
public void test_Header_Response_NoSerializationFlag() throws IOException {
//00000010-response/oneway/hearbeat=false/noset |20-stats=ok|id=0|length=0
// 00000010-response/oneway/hearbeat=false/noset |20-stats=ok|id=0|length=0
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, (byte) 0x02, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Expand All @@ -337,7 +337,7 @@ public void test_Header_Response_NoSerializationFlag() throws IOException {

@Test
public void test_Header_Response_Heartbeat() throws IOException {
//00000010-response/oneway/hearbeat=true |20-stats=ok|id=0|length=0
// 00000010-response/oneway/hearbeat=true |20-stats=ok|id=0|length=0
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, 0x02, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Expand All @@ -358,7 +358,7 @@ public void test_Encode_Request() throws IOException {

codec.encode(channel, encodeBuffer, request);

//encode resault check need decode
// encode resault check need decode
byte[] data = new byte[encodeBuffer.writerIndex()];
encodeBuffer.readBytes(data);
ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
Expand All @@ -385,7 +385,7 @@ public void test_Encode_Response() throws IOException {
byte[] data = new byte[encodeBuffer.writerIndex()];
encodeBuffer.readBytes(data);

//encode resault check need decode
// encode resault check need decode
ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
Response obj = (Response) codec.decode(channel, decodeBuffer);

Expand Down Expand Up @@ -416,7 +416,7 @@ public void test_Encode_Error_Response() throws IOException {
byte[] data = new byte[encodeBuffer.writerIndex()];
encodeBuffer.readBytes(data);

//encode resault check need decode
// encode result check need decode
ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
Response obj = (Response) codec.decode(channel, decodeBuffer);
Assertions.assertEquals(response.getId(), obj.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected byte[] objectToByte(Object obj) {
bytes = (byte[]) obj;
} else {
try {
//object to bytearray
// object to bytearray
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ObjectOutputStream oo = new ObjectOutputStream(bo);
oo.writeObject(obj);
Expand Down Expand Up @@ -109,19 +109,19 @@ protected void testDecode_assertEquals(byte[] request, Object ret) throws IOExce
}

protected void testDecode_assertEquals(byte[] request, Object ret, boolean isServerside) throws IOException {
//init channel
// init channel
Channel channel = isServerside ? getServerSideChannel(url) : getCliendSideChannel(url);
//init request string
// init request string
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(request);

//decode
// decode
Object obj = codec.decode(channel, buffer);
Assertions.assertEquals(ret, obj);
}


protected void testEecode_assertEquals(Object request, byte[] ret, boolean isServerside) throws IOException {
//init channel
// init channel
Channel channel = isServerside ? getServerSideChannel(url) : getCliendSideChannel(url);

ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(1024);
Expand All @@ -147,29 +147,29 @@ private void testDecode_assertEquals(Object request, Object ret, Object channelR
}

private void testDecode_assertEquals(AbstractMockChannel channel, Object request, Object expectret, Object channelReceive) throws IOException {
//init channel
// init channel
if (channel == null) {
channel = getServerSideChannel(url);
}

byte[] buf = objectToByte(request);
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(buf);

//decode
// decode
Object obj = codec.decode(channel, buffer);
Assertions.assertEquals(expectret, obj);
Assertions.assertEquals(channelReceive, channel.getReceivedMessage());
}

private void testDecode_PersonWithEnterByte(byte[] enterbytes, boolean isNeedmore) throws IOException {
//init channel
// init channel
Channel channel = getServerSideChannel(url);
//init request string
// init request string
Person request = new Person();
byte[] newbuf = join(objectToByte(request), enterbytes);
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(newbuf);

//decode
// decode
Object obj = codec.decode(channel, buffer);
if (isNeedmore) {
Assertions.assertEquals(Codec2.DecodeResult.NEED_MORE_INPUT, obj);
Expand All @@ -179,11 +179,11 @@ private void testDecode_PersonWithEnterByte(byte[] enterbytes, boolean isNeedmor
}

private void testDecode_WithExitByte(byte[] exitbytes, boolean isChannelClose) throws IOException {
//init channel
// init channel
Channel channel = getServerSideChannel(url);
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(exitbytes);

//decode
// decode
codec.decode(channel, buffer);
Assertions.assertEquals(isChannelClose, channel.isClosed());
}
Expand Down Expand Up @@ -304,26 +304,26 @@ public void testDecode_UPorDOWN_WithError() throws IOException {
public void testEncode_String_ClientSide() throws IOException {
testEecode_assertEquals("aaa", "aaa\r\n".getBytes(), false);
}

/*@Test()
public void testDecode_History_UP_DOWN_MULTI() throws IOException{
AbstractMockChannel channel = getServerSideChannel(url);
String request1 = "aaa\n";

String request1 = "aaa\n";
Object expected1 = request1.replace("\n", "");
//init history
//init history
testDecode_assertEquals(channel, request1, expected1, null);
String request2 = "bbb\n";

String request2 = "bbb\n";
Object expected2 = request2.replace("\n", "");
//init history
//init history
testDecode_assertEquals(channel, request2, expected2, null);
String request3 = "ccc\n";

String request3 = "ccc\n";
Object expected3= request3.replace("\n", "");
//init history
//init history
testDecode_assertEquals(channel, request3, expected3, null);

byte[] UP = new byte[] {27, 91, 65};
byte[] DOWN = new byte[] {27, 91, 66};
//history[aaa,bbb,ccc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ public <T> CompletableFuture<T> asyncCall(Callable<T> callable) {
try {
setAttachment(ASYNC_KEY, Boolean.TRUE.toString());
final T o = callable.call();
//local invoke will return directly
// local invoke will return directly
if (o != null) {
if (o instanceof CompletableFuture) {
return (CompletableFuture<T>) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static String exportOrUnexportCallbackService(Channel channel, URL url,
}
}
tmpMap.putAll(params);

tmpMap.remove(VERSION_KEY);// doesn't need to distinguish version for callback
tmpMap.remove(Constants.BIND_PORT_KEY); //callback doesn't needs bind.port
tmpMap.put(INTERFACE_KEY, clazz.getName());
Expand Down Expand Up @@ -173,8 +173,8 @@ private static Object referOrDestroyCallbackService(Channel channel, URL url, Cl
channel.setAttribute(invokerCacheKey, invoker);
increaseInstanceCount(channel, countkey);

//convert error fail fast .
//ignore concurrent problem.
// convert error fail fast .
// ignore concurrent problem.
Set<Invoker<?>> callbackInvokers = (Set<Invoker<?>>) channel.getAttribute(CHANNEL_CALLBACK_KEY);
if (callbackInvokers == null) {
callbackInvokers = new ConcurrentHashSet<>(1);
Expand Down Expand Up @@ -229,7 +229,7 @@ private static boolean isInstancesOverLimit(Channel channel, URL url, String int
Integer count = (Integer) channel.getAttribute(isServer ? getServerSideCountKey(channel, interfaceClass) : getClientSideCountKey(interfaceClass));
int limit = url.getParameter(CALLBACK_INSTANCES_LIMIT_KEY, DEFAULT_CALLBACK_INSTANCES);
if (count != null && count >= limit) {
//client side error
// client side error
throw new IllegalStateException("interface " + interfaceClass + " `s callback instances num exceed providers limit :" + limit
+ " ,current num: " + (count + 1) + ". The new callback service will not work !!! you can cancle the callback service which exported before. channel :" + channel);
} else {
Expand All @@ -239,7 +239,7 @@ private static boolean isInstancesOverLimit(Channel channel, URL url, String int

private static void increaseInstanceCount(Channel channel, String countkey) {
try {
//ignore concurrent problem?
// ignore concurrent problem?
Integer count = (Integer) channel.getAttribute(countkey);
if (count == null) {
count = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ private void replaceWithLazyClient() {
if (!(client instanceof LazyConnectExchangeClient)) {
// this is a defensive operation to avoid client is closed by accident, the initial state of the client is false
URL lazyUrl = url.addParameter(LAZY_CONNECT_INITIAL_STATE_KEY, Boolean.TRUE)
//.addParameter(RECONNECT_KEY, Boolean.FALSE)
// .addParameter(RECONNECT_KEY, Boolean.FALSE)
.addParameter(SEND_RECONNECT_KEY, Boolean.TRUE.toString());
//.addParameter(LazyConnectExchangeClient.REQUEST_WITH_WARNING_KEY, true);
// .addParameter(LazyConnectExchangeClient.REQUEST_WITH_WARNING_KEY, true);
client = new LazyConnectExchangeClient(lazyUrl, client.getExchangeHandler());
}
}
Expand Down