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

[DUBBO-3137]: step4 - start to review RemotingConstants #4057

Merged
merged 1 commit into from
May 15, 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 @@ -30,17 +30,6 @@ public interface RemotingConstants {
*/
int DEFAULT_PAYLOAD = 8 * 1024 * 1024;

String BUFFER_KEY = "buffer";

/**
* default buffer size is 8k.
*/
int DEFAULT_BUFFER_SIZE = 8 * 1024;

int MAX_BUFFER_SIZE = 16 * 1024;

int MIN_BUFFER_SIZE = 1 * 1024;

String CONNECT_TIMEOUT_KEY = "connect.timeout";

int DEFAULT_CONNECT_TIMEOUT = 3000;
Expand All @@ -49,22 +38,12 @@ public interface RemotingConstants {

int DEFAULT_HEARTBEAT = 60 * 1000;

String IDLE_TIMEOUT_KEY = "idle.timeout";

int DEFAULT_IDLE_TIMEOUT = 600 * 1000;

String ACCEPTS_KEY = "accepts";

int DEFAULT_ACCEPTS = 0;

String SERIALIZATION_KEY = "serialization";

String DEFAULT_REMOTING_SERIALIZATION = "hessian2";

String CODEC_KEY = "codec";

String DEFAULT_REMOTING_CODEC = "dubbo";

String SERVER_KEY = "server";

String DEFAULT_REMOTING_SERVER = "netty";
Expand All @@ -91,22 +70,8 @@ public interface RemotingConstants {

String SENT_KEY = "sent";

boolean DEFAULT_SENT = false;

String DISPATCHER_KEY = "dispatcher";

String CHANNEL_HANDLER_KEY = "channel.handler";

String DEFAULT_CHANNEL_HANDLER = "default";

String SERVICE_DESCIPTOR_KEY = "serviceDescriptor";

String CONNECT_QUEUE_CAPACITY = "connect.queue.capacity";

String CONNECT_QUEUE_WARNING_SIZE = "connect.queue.warning.size";

int DEFAULT_CONNECT_QUEUE_WARNING_SIZE = 1000;

String CHANNEL_ATTRIBUTE_READONLY_KEY = "channel.readonly";

String CHANNEL_READONLYEVENT_SENT_KEY = "channel.readonly.sent";
Expand All @@ -115,29 +80,8 @@ public interface RemotingConstants {

String EXECUTOR_SERVICE_COMPONENT_KEY = ExecutorService.class.getName();

String CHARSET_KEY = "charset";

String DEFAULT_CHARSET = "UTF-8";

String BACKUP_KEY = "backup";

/**
* Every heartbeat duration / HEATBEAT_CHECK_TICK, check if a heartbeat should be sent. Every heartbeat timeout
* duration / HEATBEAT_CHECK_TICK, check if a connection should be closed on server side, and if reconnect on
* client side
*/
int HEARTBEAT_CHECK_TICK = 3;

/**
* the least heartbeat during is 1000 ms.
*/
long LEAST_HEARTBEAT_DURATION = 1000;

/**
* ticks per wheel.
*/
int TICKS_PER_WHEEL = 128;

String HEARTBEAT_TIMEOUT_KEY = "heartbeat.timeout";

String RECONNECT_KEY = "reconnect";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dubbo.remoting;


public interface Constants {

String BUFFER_KEY = "buffer";

/**
* default buffer size is 8k.
*/
int DEFAULT_BUFFER_SIZE = 8 * 1024;

int MAX_BUFFER_SIZE = 16 * 1024;

int MIN_BUFFER_SIZE = 1 * 1024;

String IDLE_TIMEOUT_KEY = "idle.timeout";

int DEFAULT_IDLE_TIMEOUT = 600 * 1000;

String ACCEPTS_KEY = "accepts";

int DEFAULT_ACCEPTS = 0;

String CONNECT_QUEUE_CAPACITY = "connect.queue.capacity";

String CONNECT_QUEUE_WARNING_SIZE = "connect.queue.warning.size";

int DEFAULT_CONNECT_QUEUE_WARNING_SIZE = 1000;

String CHARSET_KEY = "charset";

String DEFAULT_CHARSET = "UTF-8";

/**
* Every heartbeat duration / HEATBEAT_CHECK_TICK, check if a heartbeat should be sent. Every heartbeat timeout
* duration / HEATBEAT_CHECK_TICK, check if a connection should be closed on server side, and if reconnect on
* client side
*/
int HEARTBEAT_CHECK_TICK = 3;

/**
* the least heartbeat during is 1000 ms.
*/
long LEAST_HEARTBEAT_DURATION = 1000;

/**
* ticks per wheel.
*/
int TICKS_PER_WHEEL = 128;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

import static org.apache.dubbo.common.utils.UrlUtils.getHeartbeat;
import static org.apache.dubbo.common.utils.UrlUtils.getIdleTimeout;
import static org.apache.dubbo.remoting.Constants.HEARTBEAT_CHECK_TICK;
import static org.apache.dubbo.remoting.Constants.LEAST_HEARTBEAT_DURATION;
import static org.apache.dubbo.remoting.Constants.TICKS_PER_WHEEL;

/**
* DefaultMessageClient
Expand All @@ -45,7 +48,7 @@ public class HeaderExchangeClient implements ExchangeClient {
private final ExchangeChannel channel;

private static final HashedWheelTimer IDLE_CHECK_TIMER = new HashedWheelTimer(
new NamedThreadFactory("dubbo-client-idleCheck", true), 1, TimeUnit.SECONDS, RemotingConstants.TICKS_PER_WHEEL);
new NamedThreadFactory("dubbo-client-idleCheck", true), 1, TimeUnit.SECONDS, TICKS_PER_WHEEL);
private HeartbeatTimerTask heartBeatTimerTask;
private ReconnectTimerTask reconnectTimerTask;

Expand Down Expand Up @@ -206,10 +209,10 @@ private void doClose() {
* Each interval cannot be less than 1000ms.
*/
private long calculateLeastDuration(int time) {
if (time / RemotingConstants.HEARTBEAT_CHECK_TICK <= 0) {
return RemotingConstants.LEAST_HEARTBEAT_DURATION;
if (time / HEARTBEAT_CHECK_TICK <= 0) {
return LEAST_HEARTBEAT_DURATION;
} else {
return time / RemotingConstants.HEARTBEAT_CHECK_TICK;
return time / HEARTBEAT_CHECK_TICK;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@

import static java.util.Collections.unmodifiableCollection;

import static org.apache.dubbo.remoting.Constants.HEARTBEAT_CHECK_TICK;
import static org.apache.dubbo.remoting.Constants.LEAST_HEARTBEAT_DURATION;
import static org.apache.dubbo.remoting.Constants.TICKS_PER_WHEEL;

/**
* ExchangeServerImpl
*/
Expand All @@ -53,7 +57,7 @@ public class HeaderExchangeServer implements ExchangeServer {
private AtomicBoolean closed = new AtomicBoolean(false);

private static final HashedWheelTimer IDLE_CHECK_TIMER = new HashedWheelTimer(new NamedThreadFactory("dubbo-server-idleCheck", true), 1,
TimeUnit.SECONDS, RemotingConstants.TICKS_PER_WHEEL);
TimeUnit.SECONDS, TICKS_PER_WHEEL);

private CloseTimerTask closeTimerTask;

Expand Down Expand Up @@ -246,10 +250,10 @@ public void send(Object message, boolean sent) throws RemotingException {
* Each interval cannot be less than 1000ms.
*/
private long calculateLeastDuration(int time) {
if (time / RemotingConstants.HEARTBEAT_CHECK_TICK <= 0) {
return RemotingConstants.LEAST_HEARTBEAT_DURATION;
if (time / HEARTBEAT_CHECK_TICK <= 0) {
return LEAST_HEARTBEAT_DURATION;
} else {
return time / RemotingConstants.HEARTBEAT_CHECK_TICK;
return time / HEARTBEAT_CHECK_TICK;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.dubbo.remoting.telnet.codec;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
Expand All @@ -34,6 +33,9 @@
import java.util.LinkedList;
import java.util.List;

import static org.apache.dubbo.remoting.Constants.CHARSET_KEY;
import static org.apache.dubbo.remoting.Constants.DEFAULT_CHARSET;

/**
* TelnetCodec
*/
Expand All @@ -60,7 +62,7 @@ public class TelnetCodec extends TransportCodec {

private static Charset getCharset(Channel channel) {
if (channel != null) {
Object attribute = channel.getAttribute(RemotingConstants.CHARSET_KEY);
Object attribute = channel.getAttribute(CHARSET_KEY);
if (attribute instanceof String) {
try {
return Charset.forName((String) attribute);
Expand All @@ -72,7 +74,7 @@ private static Charset getCharset(Channel channel) {
}
URL url = channel.getUrl();
if (url != null) {
String parameter = url.getParameter(RemotingConstants.CHARSET_KEY);
String parameter = url.getParameter(CHARSET_KEY);
if (StringUtils.isNotEmpty(parameter)) {
try {
return Charset.forName(parameter);
Expand All @@ -83,7 +85,7 @@ private static Charset getCharset(Channel channel) {
}
}
try {
return Charset.forName(RemotingConstants.DEFAULT_CHARSET);
return Charset.forName(DEFAULT_CHARSET);
} catch (Throwable t) {
logger.warn(t.getMessage(), t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
import static org.apache.dubbo.remoting.Constants.IDLE_TIMEOUT_KEY;
import static org.apache.dubbo.remoting.Constants.DEFAULT_IDLE_TIMEOUT;
import static org.apache.dubbo.remoting.Constants.ACCEPTS_KEY;
import static org.apache.dubbo.remoting.Constants.DEFAULT_ACCEPTS;

/**
* AbstractServer
Expand All @@ -61,8 +65,8 @@ public AbstractServer(URL url, ChannelHandler handler) throws RemotingException
bindIp = ANYHOST_VALUE;
}
bindAddress = new InetSocketAddress(bindIp, bindPort);
this.accepts = url.getParameter(RemotingConstants.ACCEPTS_KEY, RemotingConstants.DEFAULT_ACCEPTS);
this.idleTimeout = url.getParameter(RemotingConstants.IDLE_TIMEOUT_KEY, RemotingConstants.DEFAULT_IDLE_TIMEOUT);
this.accepts = url.getParameter(ACCEPTS_KEY, DEFAULT_ACCEPTS);
this.idleTimeout = url.getParameter(IDLE_TIMEOUT_KEY, DEFAULT_IDLE_TIMEOUT);
try {
doOpen();
if (logger.isInfoEnabled()) {
Expand All @@ -87,8 +91,8 @@ public void reset(URL url) {
return;
}
try {
if (url.hasParameter(RemotingConstants.ACCEPTS_KEY)) {
int a = url.getParameter(RemotingConstants.ACCEPTS_KEY, 0);
if (url.hasParameter(ACCEPTS_KEY)) {
int a = url.getParameter(ACCEPTS_KEY, 0);
if (a > 0) {
this.accepts = a;
}
Expand All @@ -97,8 +101,8 @@ public void reset(URL url) {
logger.error(t.getMessage(), t);
}
try {
if (url.hasParameter(RemotingConstants.IDLE_TIMEOUT_KEY)) {
int t = url.getParameter(RemotingConstants.IDLE_TIMEOUT_KEY, 0);
if (url.hasParameter(IDLE_TIMEOUT_KEY)) {
int t = url.getParameter(IDLE_TIMEOUT_KEY, 0);
if (t > 0) {
this.idleTimeout = t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.dubbo.remoting.transport.dispatcher.connection;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.RemotingConstants;
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.remoting.Channel;
Expand All @@ -38,6 +37,9 @@

import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_NAME;
import static org.apache.dubbo.remoting.Constants.CONNECT_QUEUE_CAPACITY;
import static org.apache.dubbo.remoting.Constants.CONNECT_QUEUE_WARNING_SIZE;
import static org.apache.dubbo.remoting.Constants.DEFAULT_CONNECT_QUEUE_WARNING_SIZE;

public class ConnectionOrderedChannelHandler extends WrappedChannelHandler {

Expand All @@ -49,11 +51,11 @@ public ConnectionOrderedChannelHandler(ChannelHandler handler, URL url) {
String threadName = url.getParameter(THREAD_NAME_KEY, DEFAULT_THREAD_NAME);
connectionExecutor = new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(url.getPositiveParameter(RemotingConstants.CONNECT_QUEUE_CAPACITY, Integer.MAX_VALUE)),
new LinkedBlockingQueue<Runnable>(url.getPositiveParameter(CONNECT_QUEUE_CAPACITY, Integer.MAX_VALUE)),
new NamedThreadFactory(threadName, true),
new AbortPolicyWithReport(threadName, url)
); // FIXME There's no place to release connectionExecutor!
queuewarninglimit = url.getParameter(RemotingConstants.CONNECT_QUEUE_WARNING_SIZE, RemotingConstants.DEFAULT_CONNECT_QUEUE_WARNING_SIZE);
queuewarninglimit = url.getParameter(CONNECT_QUEUE_WARNING_SIZE, DEFAULT_CONNECT_QUEUE_WARNING_SIZE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREADS;
import static org.apache.dubbo.remoting.Constants.BUFFER_KEY;
import static org.apache.dubbo.remoting.Constants.DEFAULT_BUFFER_SIZE;

/**
* PerformanceServer
Expand Down Expand Up @@ -71,7 +73,7 @@ private static ExchangeServer statServer() throws Exception {
final String threadpool = PerformanceUtils.getProperty(THREADPOOL_KEY, DEFAULT_THREADPOOL);
final int threads = PerformanceUtils.getIntProperty(THREADS_KEY, DEFAULT_THREADS);
final int iothreads = PerformanceUtils.getIntProperty(IO_THREADS_KEY, RemotingConstants.DEFAULT_IO_THREADS);
final int buffer = PerformanceUtils.getIntProperty(RemotingConstants.BUFFER_KEY, RemotingConstants.DEFAULT_BUFFER_SIZE);
final int buffer = PerformanceUtils.getIntProperty(BUFFER_KEY, DEFAULT_BUFFER_SIZE);
final String channelHandler = PerformanceUtils.getProperty(RemotingConstants.DISPATCHER_KEY, ExecutionDispatcher.NAME);


Expand Down
Loading