proj_name stringclasses 131
values | relative_path stringlengths 30 228 | class_name stringlengths 1 68 | func_name stringlengths 1 48 | masked_class stringlengths 78 9.82k | func_body stringlengths 46 9.61k | len_input int64 29 2.01k | len_output int64 14 1.94k | total int64 55 2.05k | relevant_context stringlengths 0 38.4k |
|---|---|---|---|---|---|---|---|---|---|
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/rpc/init/InitializationFactory.java | AllSpiInitialization | init | class AllSpiInitialization implements Initializable {
@Override
// find all initilizable spi and init it.
public synchronized void init() {<FILL_FUNCTION_BODY>}
} |
if (!inited) {
try {
LoggerUtil.info("AllSpiInitialization init.");
ExtensionLoader<Initializable> extensionLoader = ExtensionLoader.getExtensionLoader(Initializable.class);
List<Initializable> allInit = extensionLoader.getExtensio... | 54 | 235 | 289 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/runtime/CircularRecorder.java | CircularRecorder | clear | class CircularRecorder<T> {
int size;
AtomicInteger index = new AtomicInteger(0);
Entry<?>[] array;
public CircularRecorder(int size) {
this.size = size;
array = new Entry[size];
}
public void add(T t) {
int i = index.getAndIncrement();
if (i < 0) {
... |
for (int i = 0; i < size; i++) {
array[i] = null;
}
index.set(0);
| 349 | 40 | 389 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/runtime/GlobalRuntime.java | GlobalRuntime | getMergedMeta | class GlobalRuntime {
// all runtime registries
private static final ConcurrentHashMap<String, Registry> runtimeRegistries = new ConcurrentHashMap<>();
// all runtime exporters
private static final ConcurrentHashMap<String, Exporter<?>> runtimeExporters = new ConcurrentHashMap<>();
// all runtime ... |
Map<String, String> currentMeta = new HashMap<>();
currentMeta.putAll(envMeta);
currentMeta.putAll(dynamicMeta);
return currentMeta;
| 1,024 | 47 | 1,071 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/serialize/BreezeSerialization.java | BreezeSerialization | readToMotanException | class BreezeSerialization implements Serialization {
public static int DEFAULT_BUFFER_SIZE = 1024;
@Override
public byte[] serialize(Object o) throws IOException {
BreezeBuffer buffer = new BreezeBuffer(DEFAULT_BUFFER_SIZE);
if (o instanceof Throwable) { // compatible with motan1 protocol e... |
byte bType = buffer.get();
if (bType >= MESSAGE && bType <= DIRECT_REF_MESSAGE_MAX_TYPE) {
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("remote exception class : ")
.append(BreezeReader.readMessageName(buffer, bType))
... | 782 | 220 | 1,002 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/serialize/DeserializableObject.java | DeserializableObject | deserializeMulti | class DeserializableObject {
private Serialization serialization;
private byte[] objBytes;
public DeserializableObject(Serialization serialization, byte[] objBytes) {
this.serialization = serialization;
this.objBytes = objBytes;
}
public <T> T deserialize(Class<T> clz) throws IOExc... |
Object[] ret = null;
if (paramTypes != null && paramTypes.length > 0) {
ret = serialization.deserializeMulti(objBytes, paramTypes);
}
return ret;
| 143 | 55 | 198 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/serialize/FastJsonSerialization.java | FastJsonSerialization | deserializeMulti | class FastJsonSerialization implements Serialization {
@Override
public byte[] serialize(Object data) throws IOException {
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.config(SerializerFeature.WriteEnumUsingToString, true);... |
List<Object> list = JSON.parseArray(new String(data), classes);
if (list != null) {
return list.toArray();
}
return null;
| 259 | 49 | 308 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/serialize/Hessian2Serialization.java | Hessian2Serialization | initDefaultSerializerFactory | class Hessian2Serialization implements Serialization {
private static volatile SerializerFactory serializerFactory; // global serializer factory
private static final Boolean canSetDeny; // does the current Hessian version support blacklist setting
static {
canSetDeny = checkCompatibility();
... |
SerializerFactory defaultSerializerFactory = new SerializerFactory();
if (canSetDeny) {
try {
ClassFactory classFactory = defaultSerializerFactory.getClassFactory();
classFactory.setWhitelist(false); // blacklist mode
classFactory.deny("ch.qos... | 714 | 1,092 | 1,806 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/switcher/LocalSwitcherService.java | LocalSwitcherService | putSwitcher | class LocalSwitcherService implements SwitcherService {
private static ConcurrentMap<String, Switcher> switchers = new ConcurrentHashMap<String, Switcher>();
private ConcurrentHashMap<String, List<SwitcherListener>> listenerMap = new ConcurrentHashMap<>();
public static Switcher getSwitcherStatic(String ... |
if (switcher == null) {
throw new MotanFrameworkException("LocalSwitcherService addSwitcher Error: switcher is null");
}
switchers.put(switcher.getName(), switcher);
| 685 | 56 | 741 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/AbstractPoolClient.java | AbstractPoolClient | returnObject | class AbstractPoolClient extends AbstractClient {
private static ThreadPoolExecutor executor = new StandardThreadExecutor(1, 300, 20000,
new DefaultThreadFactory("AbstractPoolClient-initPool-", true));
protected static long defaultMinEvictableIdleTimeMillis = (long) 1000 * 60 * 60;//默认链接空闲时间
pro... |
if (channel == null) {
return;
}
try {
pool.returnObject(channel);
} catch (Exception ie) {
LoggerUtil.error(this.getClass().getSimpleName() + " return client Error: url=" + url.getUri(), ie);
}
| 1,191 | 81 | 1,272 | <methods>public void <init>(com.weibo.api.motan.rpc.URL) ,public java.net.InetSocketAddress getLocalAddress() ,public java.net.InetSocketAddress getRemoteAddress() ,public void heartbeat(com.weibo.api.motan.rpc.Request) ,public void setLocalAddress(java.net.InetSocketAddress) ,public void setRemoteAddress(java.net.Inet... |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/AbstractServer.java | AbstractServer | getRuntimeInfo | class AbstractServer implements Server {
protected InetSocketAddress localAddress;
protected InetSocketAddress remoteAddress;
protected URL url;
protected Codec codec;
protected volatile ChannelState state = ChannelState.UNINIT;
public AbstractServer() {
}
public AbstractServer(URL ... |
Map<String, Object> infos = new HashMap<>();
infos.put(RuntimeInfoKeys.URL_KEY, url.toFullStr());
infos.put(RuntimeInfoKeys.CODEC_KEY, codec.getClass().getSimpleName());
infos.put(RuntimeInfoKeys.STATE_KEY, state.name());
return infos;
| 438 | 91 | 529 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/AbstractSharedPoolClient.java | AbstractSharedPoolClient | initConnections | class AbstractSharedPoolClient extends AbstractClient {
private static final ThreadPoolExecutor EXECUTOR = new StandardThreadExecutor(1, 300, 20000,
new DefaultThreadFactory("AbstractPoolClient-initPool-", true));
private final AtomicInteger idx = new AtomicInteger();
protected SharedObjectFacto... |
if (async) {
EXECUTOR.execute(() -> {
createConnections();
LoggerUtil.info("async initPool {}. url:{}", state == ChannelState.ALIVE ? "success" : "fail", getUrl().getUri());
});
} else {
createConnections();
}
| 828 | 83 | 911 | <methods>public void <init>(com.weibo.api.motan.rpc.URL) ,public java.net.InetSocketAddress getLocalAddress() ,public java.net.InetSocketAddress getRemoteAddress() ,public void heartbeat(com.weibo.api.motan.rpc.Request) ,public void setLocalAddress(java.net.InetSocketAddress) ,public void setRemoteAddress(java.net.Inet... |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/DefaultMeshClient.java | DefaultMeshClient | call | class DefaultMeshClient implements MeshClient {
static final DefaultMeshClient DEFAULT_MESH_CLIENT; // package-private for test
Referer<MeshClient> innerReferer;
private URL meshUrl;
static {
URL defaultUrl = new URL(MotanConstants.PROTOCOL_MOTAN2,
MotanConstants.MESH_DEFAULT_HO... |
Response response = innerReferer.call(request);
T result = null;
if (response != null) {
if (response.getValue() instanceof DeserializableObject) {
try {
result = ((DeserializableObject) response.getValue()).deserialize(returnType);
... | 1,362 | 165 | 1,527 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/DefaultProtectedStrategy.java | DefaultProtectedStrategy | call | class DefaultProtectedStrategy implements ProviderProtectedStrategy, StatisticCallback {
protected ConcurrentMap<String, AtomicInteger> requestCounters = new ConcurrentHashMap<>();
protected ConcurrentMap<String, AtomicInteger> rejectCounters = new ConcurrentHashMap<>();
protected AtomicInteger totalCounter... |
// 支持的最大worker thread数
int maxThread = provider.getUrl().getIntParameter(URLParamType.maxWorkerThread.getName(), URLParamType.maxWorkerThread.getIntValue());
String requestKey = MotanFrameworkUtil.getFullMethodString(request);
try {
int requestCounter = incrCounter(request... | 1,349 | 204 | 1,553 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/ProviderMessageRouter.java | ProviderMessageRouter | handle | class ProviderMessageRouter implements MessageHandler {
private static final boolean STRICT_CHECK_GROUP = Boolean.parseBoolean(MotanGlobalConfigUtil.getConfig(MotanConstants.SERVER_END_STRICT_CHECK_GROUP_KEY, "false"));
protected Map<String, Provider<?>> providers = new HashMap<>();
// framework-level gener... |
if (channel == null || message == null) {
throw new MotanFrameworkException("RequestRouter handler(channel, message) params is null");
}
if (!(message instanceof Request)) {
throw new MotanFrameworkException("RequestRouter message type not support: " + message.getClass(... | 1,400 | 491 | 1,891 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/async/MotanAsyncProcessor.java | MotanAsyncProcessor | writeAsyncClass | class MotanAsyncProcessor extends AbstractProcessor {
protected static String ASYNC = MotanConstants.ASYNC_SUFFIX;
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
}
@Override
public SourceVersion getSupportedSourceVersion() {
return S... |
if (elem.getKind().isInterface()) {
TypeElement interfaceClazz = (TypeElement) elem;
String className = interfaceClazz.getSimpleName().toString();
TypeSpec.Builder classBuilder =
TypeSpec.interfaceBuilder(className + ASYNC).addModifiers(Modifier.PUBLIC)
... | 974 | 337 | 1,311 | <methods>public Iterable<? extends javax.annotation.processing.Completion> getCompletions(javax.lang.model.element.Element, javax.lang.model.element.AnnotationMirror, javax.lang.model.element.ExecutableElement, java.lang.String) ,public Set<java.lang.String> getSupportedAnnotationTypes() ,public Set<java.lang.String> g... |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/support/AbstractEndpointFactory.java | AbstractEndpointFactory | createServer | class AbstractEndpointFactory implements EndpointFactory {
/**
* 维持share channel 的service列表
**/
protected final Map<String, Server> ipPort2ServerShareChannel = new HashMap<>();
protected ConcurrentMap<Server, Set<String>> server2UrlsShareChannel = new ConcurrentHashMap<>();
private EndpointM... |
messageHandler = getHeartbeatFactory(url).wrapMessageHandler(messageHandler);
synchronized (ipPort2ServerShareChannel) {
String ipPort = url.getServerPortStr();
String protocolKey = MotanFrameworkUtil.getProtocolKey(url);
boolean shareChannel =
... | 1,047 | 551 | 1,598 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/support/DefaultRpcHeartbeatFactory.java | HeartMessageHandleWrapper | handle | class HeartMessageHandleWrapper implements MessageHandler {
private MessageHandler messageHandler;
public HeartMessageHandleWrapper(MessageHandler messageHandler) {
this.messageHandler = messageHandler;
}
@Override
public Object handle(Channel channel, Object messag... |
if (isHeartbeatRequest(message)) {
Response response = getDefaultHeartbeatResponse(((Request) message).getRequestId());
response.setRpcProtocolVersion(((Request) message).getRpcProtocolVersion());
return response;
}
return messageHandl... | 111 | 78 | 189 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/transport/support/HeartbeatClientEndpointManager.java | HeartbeatClientEndpointManager | init | class HeartbeatClientEndpointManager implements EndpointManager {
private ConcurrentMap<Client, HeartbeatFactory> endpoints = new ConcurrentHashMap<>();
// 一般这个类创建的实例会比较少,如果共享的话,容易“被影响”,如果某个任务阻塞了
private ScheduledExecutorService executorService = null;
@Override
public void init() {<FILL_FUNCTION... |
executorService = Executors.newScheduledThreadPool(1);
executorService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
for (Map.Entry<Client, HeartbeatFactory> entry : endpoints.entrySet()) {
Client endpoint = entry.getK... | 360 | 303 | 663 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/AsyncUtil.java | AsyncUtil | createResponseFutureForServerEnd | class AsyncUtil {
private static final int DEFAULT_ASYNC_TIMEOUT = 1000; // This variable has no practical meaning on the server side, because the server side does not use Future's getValue method to block waiting for results.
private static ThreadPoolExecutor defaultCallbackExecutor = new StandardThreadExecuto... |
Request request = RpcContext.getContext().getRequest();
if (request == null) {
throw new MotanFrameworkException("can not get request from RpcContext");
}
return new DefaultResponseFuture(request, DEFAULT_ASYNC_TIMEOUT, request.getAttachment(URLParamType.host.getName()));
... | 271 | 81 | 352 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/ByteUtil.java | ByteUtil | gzip | class ByteUtil {
public static List<Byte> toList(byte[] array) {
if (array == null) {
return null;
}
List<Byte> list = new ArrayList<Byte>(array.length);
for (byte value : array) {
list.add(value);
}
return list;
}
public static by... |
ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
GZIPOutputStream gzip = null;
try {
gzip = new GZIPOutputStream(bos);
gzip.write(data);
gzip.finish();
return bos.toByteArray();
} finally {
if (gzip != null) ... | 1,334 | 104 | 1,438 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/CollectionUtil.java | CollectionUtil | shuffleByteArray | class CollectionUtil {
@SuppressWarnings("rawtypes")
public static boolean isEmpty(Collection collection) {
return collection == null || collection.isEmpty();
}
@SuppressWarnings("rawtypes")
public static boolean isEmpty(Map map) {
return map == null || map.isEmpty();
}
pu... |
Random rnd = new Random();
for (int i = array.length - 1; i > 0; i--) {
int index = rnd.nextInt(i + 1);
// swap
byte b = array[index];
array[index] = array[i];
array[i] = b;
}
| 114 | 85 | 199 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/ExceptionUtil.java | ExceptionUtil | toMessage | class ExceptionUtil {
public static final StackTraceElement[] REMOTE_MOCK_STACK = new StackTraceElement[]{new StackTraceElement("remoteClass",
"remoteMethod", "remoteFile", 1)};
/**
* 判定是否是业务方的逻辑抛出的异常
* <p>
* <pre>
* true: 来自业务方的异常
* false: 来自框架本身的异常
* </pre>
... |
JSONObject jsonObject = new JSONObject();
int type = 1;
int code = 500;
String errmsg = null;
if (e instanceof MotanFrameworkException) {
MotanFrameworkException mfe = (MotanFrameworkException) e;
type = 0;
code = mfe.getErrorCode();
... | 723 | 322 | 1,045 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/InternalMetricsFactory.java | InternalMetricsFactory | getRegistryInstance | class InternalMetricsFactory {
private static final ConcurrentMap<String, MetricRegistry> getRegistryCache;
private static final MetricRegistry defaultMetricsRegistry;
static {
getRegistryCache = new ConcurrentHashMap<String, MetricRegistry>();
getRegistryCache.put("default", defaultMetrics... |
final String key = MetricRegistry.name(name, names);
MetricRegistry instance = getRegistryCache.get(key);
if (instance == null) {
getRegistryCache.putIfAbsent(key, new MetricRegistry());
instance = getRegistryCache.get(key);
}
return instance;
| 630 | 81 | 711 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/MathUtil.java | MathUtil | findGCD | class MathUtil {
/**
* 针对int类型字符串进行解析,如果存在格式错误,则返回默认值(defaultValue)
* Parse intStr, return defaultValue when numberFormatException occurs
*
* @param intStr
* @param defaultValue
* @return
*/
public static int parseInt(String intStr, int defaultValue) {
try {
... |
int result = arr[0];
for (int i = 1; i < arr.length; i++) {
result = IntMath.gcd(arr[i], result);
if (result == 1) {
return 1;
}
}
return result;
| 567 | 73 | 640 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/MeshProxyUtil.java | MeshProxyUtil | setInitChecked | class MeshProxyUtil {
// config keys
private static final String MODE_KEY = "mode"; // proxy type key
private static final String PORT_KEY = "port"; // mesh transport port for client end
private static final String IP_KEY = "ip"; // mesh management port
private static final String PROTOCOL_KEY = "pr... |
boolean oldValue = initChecked;
initChecked = value;
return oldValue;
| 1,964 | 27 | 1,991 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/MetaUtil.java | MetaUtil | getRemoteDynamicMeta | class MetaUtil {
public static final String defaultEnvMetaPrefix = "META_";
// Check whether the default prefix is configured from the global configuration, if not, use the default prefix
public static final String ENV_META_PREFIX = MotanGlobalConfigUtil.getConfig(MotanConstants.ENV_META_PREFIX_KEY, default... |
String key = getCacheKey(referer.getUrl());
// if not support meta service, throws the specified exception.
if (notSupportCache.getIfPresent(key) != null
|| !isSupport(referer.getUrl())) {
throw new MotanServiceException(MotanErrorMsgConstant.SERVICE_NOT_SUPPORT_ERRO... | 1,533 | 339 | 1,872 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/MotanClientUtil.java | MotanClientUtil | buildRequest | class MotanClientUtil {
public static Request buildRequest(String interfaceName, String methodName, Object[] arguments) {
return buildRequest(interfaceName, methodName, arguments, null);
}
public static Request buildRequest(String interfaceName, String methodName, Object[] arguments, Map<String, S... |
DefaultRequest request = new DefaultRequest();
request.setRequestId(RequestIdGenerator.getRequestId());
request.setInterfaceName(interfaceName);
request.setMethodName(methodName);
request.setArguments(arguments);
if (StringUtils.isNotEmpty(paramtersDesc)) {
r... | 151 | 125 | 276 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/MotanDigestUtil.java | MotanDigestUtil | getCrc32 | class MotanDigestUtil {
private static Logger log = LoggerFactory.getLogger(MotanDigestUtil.class);
private static ThreadLocal<CRC32> crc32Provider = new ThreadLocal<CRC32>() {
@Override
protected CRC32 initialValue() {
return new CRC32();
}
};
public static long g... |
try {
return getCrc32(str.getBytes(MotanConstants.DEFAULT_CHARACTER));
} catch (UnsupportedEncodingException e) {
log.warn(String.format("Error: getCrc32, str=%s", str), e);
return -1;
}
| 396 | 79 | 475 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/MotanGlobalConfigUtil.java | MotanGlobalConfigUtil | init | class MotanGlobalConfigUtil {
public static final String MOTAN_CONFIG_FILE = "motan.properties";
private static final Map<String, String> DEFAULT_CONFIGS = new HashMap<>();
private static volatile GlobalConfig innerGlobalConfig;
static {
init();
}
public static Map<String, String> getD... |
URL url = Thread.currentThread().getContextClassLoader().getResource(MOTAN_CONFIG_FILE);
if (url != null) {
try (InputStream is = url.openStream()) {
LoggerUtil.info("load default motan properties from " + url.getPath());
Properties properties = new Propertie... | 411 | 233 | 644 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/NetUtils.java | NetUtils | getLocalAddressByNetworkInterface | class NetUtils {
private static final Logger logger = LoggerFactory.getLogger(NetUtils.class);
public static final String LOCALHOST = "127.0.0.1";
public static final String ANYHOST = "0.0.0.0";
private static volatile InetAddress LOCAL_ADDRESS = null;
private static final Pattern LOCAL_IP_PATT... |
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
if (interfaces != null) {
while (interfaces.hasMoreElements()) {
try {
NetworkInterface network = interfaces.nextElement();
... | 1,450 | 289 | 1,739 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/RequestIdGenerator.java | RequestIdGenerator | getRequestId | class RequestIdGenerator {
protected static final AtomicLong offset = new AtomicLong(0);
protected static final int BITS = 20;
protected static final long MAX_COUNT_PER_MILLIS = 1 << BITS;
/**
* 获取 requestId
*
* @return
*/
public static long getRequestId() {<FILL_FUNCTION_BODY... |
long currentTime = System.currentTimeMillis();
long count = offset.incrementAndGet();
while(count >= MAX_COUNT_PER_MILLIS){
synchronized (RequestIdGenerator.class){
if(offset.get() >= MAX_COUNT_PER_MILLIS){
offset.set(0);
}
... | 139 | 116 | 255 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/StringTools.java | StringTools | urlDecode | class StringTools {
public static int parseInteger(String intStr) {
if (intStr == null) {
return MotanConstants.DEFAULT_INT_VALUE;
}
try {
return Integer.parseInt(intStr);
} catch (NumberFormatException e) {
return MotanConstants.DEFAULT_INT_VALUE... |
if (StringUtils.isBlank(value)) {
return "";
}
try {
return URLDecoder.decode(value, MotanConstants.DEFAULT_CHARACTER);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage(), e);
}
| 586 | 77 | 663 | <no_super_class> |
weibocom_motan | motan/motan-core/src/main/java/com/weibo/api/motan/util/UrlUtils.java | UrlUtils | parseURL | class UrlUtils {
public static List<URL> parseURLs(String address, Map<String, String> defaults) {
if (address == null || address.length() == 0) {
return null;
}
String[] addresses = MotanConstants.REGISTRY_SPLIT_PATTERN.split(address);
if (addresses == null || addresse... |
if (address == null || address.length() == 0) {
return null;
}
String[] addresses = MotanConstants.COMMA_SPLIT_PATTERN.split(address);
String url = addresses[0];
String defaultProtocol = defaults == null ? null : defaults.get("protocol");
if (defaultProtoco... | 668 | 660 | 1,328 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-api/src/main/java/com/weibo/motan/demo/service/model/User.java | User | toString | class User implements Serializable {
private int id;
private String name;
public User() {
}
public User(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
... |
return "User{" +
"id=" + id +
", name='" + name + '\'' +
'}';
| 168 | 36 | 204 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-api/src/main/java/io/grpc/examples/routeguide/Point.java | Builder | clear | class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:routeguide.Point)
io.grpc.examples.routeguide.PointOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
retu... |
super.clear();
latitude_ = 0;
longitude_ = 0;
return this;
| 1,735 | 32 | 1,767 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-api/src/main/java/io/grpc/examples/routeguide/RouteGuideGrpc.java | RouteGuideImplBase | bindService | class RouteGuideImplBase implements io.grpc.BindableService {
/**
* <pre>
* A simple RPC.
* Obtains the feature at a given position.
* A feature with an empty name is returned if there's no feature at the given
* position.
* </pre>
*/
public void getFeature(io.grpc.examples.r... |
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
METHOD_GET_FEATURE,
asyncUnaryCall(
new MethodHandlers<
io.grpc.examples.routeguide.Point,
io.grpc.examples.routeguide.Feature>(
thi... | 682 | 338 | 1,020 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/AnnotationRpcClientDemo.java | AnnotationRpcClientDemo | baseRefererConfig | class AnnotationRpcClientDemo {
public static void main(String[] args) throws InterruptedException {
ApplicationContext ctx = new ClassPathXmlApplicationContext(new
String[]{"classpath:motan_demo_client_annotation.xml"});
DemoRpcHandler handler = (DemoRpcHandler) ctx.getBean("dem... |
BasicRefererConfigBean config = new BasicRefererConfigBean();
config.setProtocol("demoMotan");
config.setGroup("motan-demo-rpc");
config.setModule("motan-demo-rpc");
config.setApplication("myMotanDemo");
config.setRegistry("registry");
config.setCheck(false);
... | 512 | 130 | 642 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/DemoMeshClient.java | DemoMeshClient | main | class DemoMeshClient {
public static void main(String[] args) throws Throwable {<FILL_FUNCTION_BODY>}
// agent yaml配置样例参考:
//motan-agent:
// application: agent-test
//motan-registry:
// direct-registry:
// protocol: direct
// host: localhost
// port: 8002
//motan-refer:
// test-demo:
// registry: d... |
//使用MeshClient需要先部署mesh agent(可以参考https://github.com/weibocom/motan-go)。
// 在mesh agent中已经配置好对应的服务。
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:demo_mesh_client.xml"});
MotanDemoService service = (MotanDemoService) ctx.getBean("refererWithMeshClie... | 166 | 263 | 429 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/DemoRpcAsyncClient.java | DemoRpcAsyncClient | main | class DemoRpcAsyncClient {
/**
* 使用motan异步调用方法: 1、在声明的service上增加@MotanAsync注解。 如MotanDemoService
* 2、在项目pom.xml中增加build-helper-maven-plugin,用来把自动生成类的目录设置为source path。 参见motan-demo-api模块的pom声明。
* 也可以不使用plugin,手动将target/generated-sources/annotations目录设置为source path。
* 3、在client配置的motan:referer标签中... |
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"classpath:motan_demo_async_client.xml"});
MotanDemoServiceAsync service = (MotanDemoServiceAsync) ctx.getBean("motanDemoReferer");
for (int i = 0; i < Integer.MAX_VALUE; i++) {
// sync call
Syste... | 220 | 438 | 658 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/DemoRpcClient.java | DemoRpcClient | main | class DemoRpcClient {
public static void main(String[] args) throws InterruptedException {<FILL_FUNCTION_BODY>}
} |
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:motan_demo_client.xml"});
MotanDemoService service = (MotanDemoService) ctx.getBean("motanDemoReferer");
for (int i = 0; i < Integer.MAX_VALUE; i++) {
System.out.println(service.hello("motan" + i))... | 40 | 139 | 179 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/DemoRpcHandler.java | DemoRpcHandler | test | class DemoRpcHandler {
@MotanReferer
private MotanDemoService motanDemoService;
public void test() {<FILL_FUNCTION_BODY>}
} |
for (int i = 0; i < 10; i++) {
System.out.println(motanDemoService.hello("motan handler" + i));
LoggerUtil.info("motan handler" + i);
}
| 52 | 63 | 115 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/GrpcClientDemo.java | GrpcClientDemo | main | class GrpcClientDemo {
public static void main(String[] args) throws Exception {<FILL_FUNCTION_BODY>}
private static RouteNote newNote(String message, int lat, int lon) {
return RouteNote.newBuilder().setMessage(message).setLocation(Point.newBuilder().setLatitude(lat).setLongitude(lon).build())
... |
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"classpath:motan_demo_client_grpc.xml"});
GrpcService service = (GrpcService) ctx.getBean("motanDemoReferer");
// unary
for (int i = 0; i < 2; i++) {
Point request = Point.newBuilder().setLatitude(10... | 102 | 905 | 1,007 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/Motan2RpcClient.java | Motan2RpcClient | main | class Motan2RpcClient {
public static void main(String[] args) throws Throwable {<FILL_FUNCTION_BODY>}
public static void print(MotanDemoService service) throws InterruptedException {
for (int i = 0; i < 3; i++) {
try {
System.out.println(service.hello("motan" + i));
... |
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:motan2_demo_client.xml"});
MotanDemoService service;
// hessian
service = (MotanDemoService) ctx.getBean("motanDemoReferer");
print(service);
// simple serialization
service = (M... | 906 | 361 | 1,267 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/Motan2RpcClientWithMesh.java | Motan2RpcClientWithMesh | main | class Motan2RpcClientWithMesh {
public static void main(String[] args) throws Throwable {<FILL_FUNCTION_BODY>}
} |
//需要先部署mesh agent。可以参考https://github.com/weibocom/motan-go。agent配置中需要有匹配的注册中心配置
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:motan2_demo_client_mesh.xml"});
MotanDemoService service;
service = (MotanDemoService) ctx.getBean("motanDemoReferer");
... | 44 | 182 | 226 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/MotanApiClientDemo.java | MotanApiClientDemo | main | class MotanApiClientDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
RefererConfig<MotanDemoService> motanDemoServiceReferer = new RefererConfig<MotanDemoService>();
// 设置接口及实现类
motanDemoServiceReferer.setInterface(MotanDemoService.class);
// 配置服务的group以及版本号
motanDemoServiceReferer.setGroup("motan-demo-rpc");
motanDemoServiceReferer.set... | 36 | 420 | 456 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/RestfulClient.java | RestfulClient | main | class RestfulClient {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:motan_demo_client_restful.xml"});
// use restful
RestfulService service1 = (RestfulService) ctx.getBean("restfulReferer");
System.out.println(service1.getUsers(345).get(0).getName());
// use mo... | 33 | 145 | 178 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/SpringBootRpcClientDemo.java | SpringBootRpcClientDemo | main | class SpringBootRpcClientDemo {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
@Bean
public AnnotationBean motanAnnotationBean() {
AnnotationBean motanAnnotationBean = new AnnotationBean();
motanAnnotationBean.setPackage("com.weibo.motan.demo.client");
return motanAn... |
System.setProperty("server.port", "8080");
SpringApplication.run(SpringBootRpcClientDemo.class, args);
//start client and curl 'http://localhost:8080/' ,
// will requst to HelloController.home(), add than, request to the rpc server
| 104 | 82 | 186 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-client/src/main/java/com/weibo/motan/demo/client/YarClient.java | YarClient | main | class YarClient {
public static void main(String[] args) throws Exception {<FILL_FUNCTION_BODY>}
} |
HttpYarClient yarClient = new HttpYarClient();
String result = yarClient.call("http://127.0.0.1:8003/openapi/yarserver/test", "testString", String.class, "yar");
System.out.println(result);
| 36 | 78 | 114 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/AnnotationRpcServerDemo.java | AnnotationRpcServerDemo | registryConfig | class AnnotationRpcServerDemo {
public static void main(String[] args) throws InterruptedException {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new
String[]{"classpath*:motan_demo_server_annotation.xml"});
MotanSwitcherUtil.setSwitcherValue(MotanConst... |
RegistryConfigBean config = new RegistryConfigBean();
// config.setRegProtocol("zk");
// config.setAddress("127.0.0.1:2181");
config.setRegProtocol("local");
return config;
| 536 | 67 | 603 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/DemoRpcServer.java | DemoRpcServer | main | class DemoRpcServer {
public static void main(String[] args) throws InterruptedException {<FILL_FUNCTION_BODY>}
} |
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {"classpath*:motan_demo_server.xml"});
MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
System.out.println("server start...");
| 40 | 82 | 122 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/GrpcServerDemo.java | GrpcServerDemo | calcDistance | class GrpcServerDemo implements GrpcService {
static Collection<Feature> features;
public static void main(String[] args) throws Exception {
features = RouteGuideUtil.parseFeatures(RouteGuideUtil.getDefaultFeaturesFile());
ApplicationContext applicationContext = new ClassPathXmlApplicationContex... |
double lat1 = RouteGuideUtil.getLatitude(start);
double lat2 = RouteGuideUtil.getLatitude(end);
double lon1 = RouteGuideUtil.getLongitude(start);
double lon2 = RouteGuideUtil.getLongitude(end);
int r = 6371000; // metres
double φ1 = toRadians(lat1);
double φ2 = t... | 1,500 | 242 | 1,742 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/Motan2Server.java | Motan2Server | main | class Motan2Server {
public static void main(String[] args) throws InterruptedException {<FILL_FUNCTION_BODY>}
} |
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {"classpath*:motan2_demo_server.xml"});
MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
System.out.println("server start...");
| 38 | 83 | 121 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/Motan2ServerWithMesh.java | Motan2ServerWithMesh | main | class Motan2ServerWithMesh {
public static void main(String[] args) throws InterruptedException {<FILL_FUNCTION_BODY>}
} |
//需要先部署mesh agent。可以参考https://github.com/weibocom/motan-go。agent配置中需要有匹配的注册中心配置
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"classpath*:motan2_demo_server_mesh.xml"});
MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true... | 41 | 124 | 165 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/MotanApiExportDemo.java | MotanApiExportDemo | main | class MotanApiExportDemo {
public static void main(String[] args) throws InterruptedException {<FILL_FUNCTION_BODY>}
} |
ServiceConfig<MotanDemoService> motanDemoService = new ServiceConfig<MotanDemoService>();
// 设置接口及实现类
motanDemoService.setInterface(MotanDemoService.class);
motanDemoService.setRef(new MotanDemoServiceImpl());
// 配置服务的group以及版本号
motanDemoService.setGroup("motan-demo-rp... | 41 | 376 | 417 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/MotanDemoServiceAsyncImpl.java | MotanDemoServiceAsyncImpl | renameAsync | class MotanDemoServiceAsyncImpl implements MotanDemoServiceAsync {
ExecutorService testExecutorService = Executors.newCachedThreadPool();
@Override
public String hello(String name) throws MotanServiceException {
System.out.println(name);
return "Hello " + name + "!";
}
@Override
... |
System.out.println("in async rename");
final ResponseFuture motanResponseFuture = AsyncUtil.createResponseFutureForServerEnd();
testExecutorService.submit(() -> {
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace... | 279 | 141 | 420 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/MotanDemoServiceImpl.java | MotanDemoServiceImpl | rename | class MotanDemoServiceImpl implements MotanDemoService {
@Override
public String hello(String name) {
System.out.println(name);
return "Hello " + name + "!";
}
@Override
public User rename(User user, String name) throws Exception {<FILL_FUNCTION_BODY>}
} |
Objects.requireNonNull(user);
System.out.println(user.getId() + " rename " + user.getName() + " to " + name);
user.setName(name);
return user;
| 92 | 57 | 149 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/RestfulServerDemo.java | RestfulServerDemo | main | class RestfulServerDemo implements RestfulService {
public static void main(String[] args) throws Exception {<FILL_FUNCTION_BODY>}
@Override
public List<User> getUsers(@CookieParam("uid") int uid) {
return Arrays.asList(new User(uid, "name" + uid));
}
@Override
public String testPrimit... |
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:motan_demo_server_restful.xml");
System.out.println("restful server start...");
Thread.sleep(Long.MAX_VALUE);
| 213 | 59 | 272 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/RouteGuideUtil.java | RouteGuideUtil | parseFeatures | class RouteGuideUtil {
private static final double COORD_FACTOR = 1e7;
/**
* Gets the latitude for the given point.
*/
public static double getLatitude(Point location) {
return location.getLatitude() / COORD_FACTOR;
}
/**
* Gets the longitude for the given point.
*/
public static double ge... |
InputStream input = file.openStream();
try {
Reader reader = new InputStreamReader(input);
try {
FeatureDatabase.Builder database = FeatureDatabase.newBuilder();
JsonFormat.parser().merge(reader, database);
return database.getFeatureList();
} finally {
reader.c... | 293 | 98 | 391 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/server/YarServerDemo.java | YarServerDemo | testMap | class YarServerDemo implements YarService {
public String hello(String name) {
System.out.println(name + " invoked rpc service");
return "hello " + name;
}
// local
public static void main(String[] args) throws InterruptedException {
ApplicationContext applicationContext = new ... |
System.out.println("in testmap");
Map<String, Object> retmap = new HashMap<String, Object>(map);
retmap.put("size", map.size());
return retmap;
| 492 | 56 | 548 | <no_super_class> |
weibocom_motan | motan/motan-demo/motan-demo-server/src/main/java/com/weibo/motan/demo/springboot/SpringBootRpcServerDemo.java | SpringBootRpcServerDemo | baseServiceConfig | class SpringBootRpcServerDemo {
public static void main(String[] args) {
System.setProperty("server.port", "8081");
ConfigurableApplicationContext context = SpringApplication.run(SpringBootRpcServerDemo.class, args);
MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITC... |
BasicServiceConfigBean config = new BasicServiceConfigBean();
config.setExport("demoMotan:8002");
config.setGroup("testgroup");
config.setAccessLog(false);
config.setShareChannel(true);
config.setModule("motan-demo-rpc");
config.setApplication("myMotanDemo");
... | 355 | 110 | 465 | <no_super_class> |
weibocom_motan | motan/motan-extension/filter-extension/filter-opentracing/src/main/java/com/weibo/api/motan/filter/opentracing/OpenTracingContext.java | OpenTracingContext | getActiveSpan | class OpenTracingContext {
// replace TracerFactory with any tracer implementation
public static TracerFactory tracerFactory = TracerFactory.DEFAULT;
public static final String ACTIVE_SPAN = "ot_active_span";
public static Tracer getTracer() {
return tracerFactory.getTracer();
}
public... |
Object span = RpcContext.getContext().getAttribute(ACTIVE_SPAN);
if (span != null && span instanceof Span) {
return (Span) span;
}
return null;
| 180 | 55 | 235 | <no_super_class> |
weibocom_motan | motan/motan-extension/filter-extension/filter-opentracing/src/main/java/com/weibo/api/motan/filter/opentracing/OpenTracingFilter.java | OpenTracingFilter | extractTraceInfo | class OpenTracingFilter implements Filter {
@Override
public Response filter(Caller<?> caller, Request request) {
Tracer tracer = getTracer();
if (tracer == null || tracer instanceof NoopTracer) {
return caller.call(request);
}
if (caller instanceof Provider) { // se... |
String operationName = buildOperationName(request);
SpanBuilder span = tracer.buildSpan(operationName);
try {
SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(request.getAttachments()));
if (spanContext != null) {
... | 897 | 141 | 1,038 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-grpc/src/main/java/com/weibo/api/motan/protocol/grpc/GrpcClient.java | GrpcClient | request | class GrpcClient {
private URL url;
private Class<?> interfaceClazz;
private ManagedChannel channel;
private CallOptions callOption = CallOptions.DEFAULT; // TODO 需要配置线程池时使用
@SuppressWarnings("rawtypes")
private HashMap<String, MethodDescriptor> methodDescMap;
public GrpcClient(URL url, ... |
MethodDescriptor<ReqT, RespT> methodDesc = methodDescMap.get(request.getMethodName());
if (methodDesc == null) {
throw new MotanServiceException("request method grpc descriptornot found.method:" + request.getMethodName());
}
int timeout =
url.getMethodParame... | 283 | 714 | 997 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-grpc/src/main/java/com/weibo/api/motan/protocol/grpc/GrpcProtocol.java | GrpcProtocol | createExporter | class GrpcProtocol extends AbstractProtocol {
protected ConcurrentHashMap<String, GrpcServer> serverMap = new ConcurrentHashMap<String, GrpcServer>();
@Override
protected <T> Exporter<T> createExporter(Provider<T> provider, URL url) {<FILL_FUNCTION_BODY>}
@Override
protected <T> Referer<T> createR... |
String ipPort = url.getServerPortStr();
GrpcServer server = serverMap.get(ipPort);
if (server == null) {
boolean shareChannel =
url.getBooleanParameter(URLParamType.shareChannel.getName(), URLParamType.shareChannel.getBooleanValue());
int workerQueue... | 673 | 453 | 1,126 | <methods>public non-sealed void <init>() ,public void destroy() ,public Exporter<T> export(Provider<T>, com.weibo.api.motan.rpc.URL) ,public Map<java.lang.String,Exporter<?>> getExporterMap() ,public Referer<T> refer(Class<T>, com.weibo.api.motan.rpc.URL) ,public Referer<T> refer(Class<T>, com.weibo.api.motan.rpc.URL, ... |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-grpc/src/main/java/com/weibo/api/motan/protocol/grpc/GrpcResponseFuture.java | GrpcResponseFuture | onError | class GrpcResponseFuture<RespT> extends DefaultResponseFuture implements StreamObserver<RespT> {
private final ClientCall<?, RespT> call;
public GrpcResponseFuture(Request requestObj, int timeout, URL serverUrl, ClientCall<?, RespT> call) {
super(requestObj, timeout, serverUrl);
this.call = cal... |
if (t instanceof Exception) {
this.exception = (Exception) t;
} else {
this.exception = new MotanServiceException("grpc response future has fatal error.", t);
}
done();
| 249 | 57 | 306 | <methods>public void <init>(com.weibo.api.motan.rpc.Request, int, com.weibo.api.motan.rpc.URL) ,public void <init>(com.weibo.api.motan.rpc.Request, int, java.lang.String) ,public void addFinishCallback(java.lang.Runnable, java.util.concurrent.Executor) ,public void addListener(com.weibo.api.motan.rpc.FutureListener) ,p... |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-grpc/src/main/java/com/weibo/api/motan/protocol/grpc/GrpcServer.java | GrpcServer | addExporter | class GrpcServer{
private int port;
private MotanHandlerRegistry registry;
private Server server;
private Map<URL, ServerServiceDefinition> serviceDefinetions;
private boolean init;
private boolean shareChannel;
private ExecutorService executor;
private NettyHttpRequestHandler httpHandle... |
Provider provider = exporter.getProvider();
ServerServiceDefinition serviceDefine = GrpcUtil.getServiceDefByAnnotation(provider.getInterface());
boolean urlShareChannel = exporter.getUrl().getBooleanParameter(URLParamType.shareChannel.getName(),
URLParamType.shareChannel.getBo... | 610 | 220 | 830 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-grpc/src/main/java/com/weibo/api/motan/protocol/grpc/GrpcUtil.java | GrpcUtil | getGrpcClassName | class GrpcUtil {
@SuppressWarnings("rawtypes")
private static HashMap<String, HashMap<String, MethodDescriptor>> serviceMap = new HashMap<String, HashMap<String, MethodDescriptor>>();
public static final String JSON_CODEC = "grpc-pb-json";
@SuppressWarnings({"unchecked", "rawtypes"})
public static S... |
GrpcConfig config = clazz.getAnnotation(GrpcConfig.class);
if (config == null || StringUtils.isBlank(config.grpc())) {
throw new MotanFrameworkException("can not find grpc config in class " + clazz.getName());
}
return config.grpc();
| 1,389 | 78 | 1,467 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-grpc/src/main/java/com/weibo/api/motan/protocol/grpc/MotanHandlerRegistry.java | MotanHandlerRegistry | addService | class MotanHandlerRegistry extends HandlerRegistry {
private ConcurrentHashMap<String, ServerMethodDefinition<?, ?>> methods = new ConcurrentHashMap<String, ServerMethodDefinition<?, ?>>();
@Override
public ServerMethodDefinition<?, ?> lookupMethod(String methodName, String authority) {
return meth... |
for (ServerMethodDefinition<?, ?> method : service.getMethods()) {
Method providerMethod = GrpcUtil.getMethod(method.getMethodDescriptor().getFullMethodName(), provider.getInterface());
MotanServerCallHandler handler;
if (method.getServerCallHandler() instanceof MotanServer... | 255 | 299 | 554 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-grpc/src/main/java/com/weibo/api/motan/protocol/grpc/http/HttpProtocolNegotiator.java | HttpAdapter | channelRead | class HttpAdapter extends ChannelInboundHandlerAdapter implements Handler {
private Http2ConnectionHandler handler;
private int maxContentLength = 1024 * 1024 * 64;
public HttpAdapter(Http2ConnectionHandler handler) {
super();
this.handler = handler;
}
... |
// TODO graceful validation
ByteBuf bf = ((ByteBuf) msg).copy();
Http2Validator validator = new Http2Validator();
validator.channelRead(null, bf);
if (validator.isHttp2()) {
ctx.pipeline().replace(this, null, handler);
} else {
... | 196 | 203 | 399 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/RestfulProtocol.java | RestfulExporter | unexport | class RestfulExporter<T> extends AbstractExporter<T> {
private RestServer server;
private EndpointFactory endpointFactory;
public RestfulExporter(Provider<T> provider, URL url) {
super(provider, url);
endpointFactory = ExtensionLoader.getExtensionLoader(EndpointF... |
server.getDeployment().getRegistry().removeRegistrations(provider.getInterface());
String protocolKey = MotanFrameworkUtil.getProtocolKey(url);
@SuppressWarnings("unchecked")
Exporter<T> exporter = (Exporter<T>) exporterMap.remove(protocolKey);
if ... | 275 | 139 | 414 | <methods>public non-sealed void <init>() ,public void destroy() ,public Exporter<T> export(Provider<T>, com.weibo.api.motan.rpc.URL) ,public Map<java.lang.String,Exporter<?>> getExporterMap() ,public Referer<T> refer(Class<T>, com.weibo.api.motan.rpc.URL) ,public Referer<T> refer(Class<T>, com.weibo.api.motan.rpc.URL, ... |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/support/AbstractEndpointFactory.java | AbstractEndpointFactory | createClient | class AbstractEndpointFactory implements EndpointFactory {
/** 维持share channel 的service列表 **/
protected final Map<String, RestServer> ipPort2ServerShareChannel = new HashMap<String, RestServer>();
// 维持share channel 的client列表 <ip:port,client>
protected final Map<String, ResteasyWebTarget> ipPort2Cli... |
String ipPort = url.getServerPortStr();
String protocolKey = MotanFrameworkUtil.getProtocolKey(url);
LoggerUtil.info(this.getClass().getSimpleName() + " create share_channel client: url={}", url);
synchronized (ipPort2ClientShareChannel) {
ResteasyWebTarget client =... | 1,167 | 217 | 1,384 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/support/RestfulInjectorFactory.java | RestfulMethodInjector | invoke | class RestfulMethodInjector extends MethodInjectorImpl {
public RestfulMethodInjector(ResourceLocator resourceMethod, ResteasyProviderFactory factory) {
super(resourceMethod, factory);
}
@Override
public Object invoke(HttpRequest request, HttpResponse httpResponse, O... |
if (!Provider.class.isInstance(resource)) {
return super.invoke(request, httpResponse, resource);
}
Object[] args = injectArguments(request, httpResponse);
RestfulContainerRequest req = new RestfulContainerRequest();
req.setInterface... | 111 | 314 | 425 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/support/RestfulUtil.java | RestfulUtil | encodeAttachments | class RestfulUtil {
public static final String ATTACHMENT_HEADER = "X-Attach";
public static final String EXCEPTION_HEADER = "X-Exception";
public static boolean isRpcRequest(MultivaluedMap<String, String> headers) {
return headers != null && headers.containsKey(ATTACHMENT_HEADER);
}
... |
if (attachments == null || attachments.isEmpty())
return;
StringBuilder value = new StringBuilder();
for (Map.Entry<String, String> entry : attachments.entrySet()) {
value.append(StringTools.urlEncode(entry.getKey())).append("=")
.append(Strin... | 814 | 162 | 976 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/support/RpcExceptionMapper.java | RpcExceptionMapper | toResponse | class RpcExceptionMapper implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception exception) {<FILL_FUNCTION_BODY>}
} |
HttpRequest httpRequest = ResteasyProviderFactory.getContextData(HttpRequest.class);
// 当为rpc调用时,序列化异常
if (httpRequest != null && RestfulUtil.isRpcRequest(httpRequest.getMutableHeaders())) {
return RestfulUtil.serializeError(exception);
}
return Response.stat... | 49 | 119 | 168 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/support/netty/NettyEndpointFactory.java | NettyEndpointFactory | innerCreateServer | class NettyEndpointFactory extends AbstractEndpointFactory {
@Override
protected RestServer innerCreateServer(URL url) {<FILL_FUNCTION_BODY>}
} |
NettyJaxrsServer server = new NettyJaxrsServer();
server.setMaxRequestSize(url.getIntParameter(URLParamType.maxContentLength.getName(),
URLParamType.maxContentLength.getIntValue()));
ResteasyDeployment deployment = new ResteasyDeployment();
server.setDeployment(... | 49 | 234 | 283 | <methods>public non-sealed void <init>() ,public ResteasyWebTarget createClient(com.weibo.api.motan.rpc.URL) ,public com.weibo.api.motan.protocol.restful.RestServer createServer(com.weibo.api.motan.rpc.URL) ,public void safeReleaseResource(com.weibo.api.motan.protocol.restful.RestServer, com.weibo.api.motan.rpc.URL) ,p... |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/support/proxy/RestfulClientInvoker.java | RestfulClientInvoker | invoke | class RestfulClientInvoker extends ClientInvoker {
public RestfulClientInvoker(ResteasyWebTarget parent, Class<?> declaring, Method method, ProxyConfig config) {
super(parent, declaring, method, config);
}
public Object invoke(Object[] args, Request req, RestfulClientResponse resp) {<FILL_FUNCTION... |
ClientInvocation request = createRequest(args, req);
ClientResponse response = (ClientResponse) request.invoke();
resp.setAttachments(RestfulUtil.decodeAttachments(response.getStringHeaders()));
resp.setHttpResponse(response);
ClientContext context = new ClientContext(request, ... | 163 | 96 | 259 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/support/proxy/RestfulProxyBuilder.java | RestfulProxyBuilder | proxy | class RestfulProxyBuilder<T> {
private final Class<T> iface;
private final ResteasyWebTarget webTarget;
private ClassLoader loader = Thread.currentThread().getContextClassLoader();
private MediaType serverConsumes;
private MediaType serverProduces;
public static <T> RestfulProxyBuilder<T> build... |
if (iface.isAnnotationPresent(Path.class)) {
Path path = iface.getAnnotation(Path.class);
if (!path.value().equals("") && !path.value().equals("/")) {
base = base.path(path.value());
}
}
HashMap<Method, RestfulClientInvoker> methodMap = new H... | 639 | 170 | 809 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/support/servlet/RestfulServletContainerListener.java | RestfulServletContainerListener | contextInitialized | class RestfulServletContainerListener extends ResteasyBootstrap implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {<FILL_FUNCTION_BODY>}
@Override
public void contextDestroyed(ServletContextEvent sce) {
super.contextDestroyed(sce);
}
} |
ServletContext servletContext = sce.getServletContext();
servletContext.setInitParameter("resteasy.injector.factory", RestfulInjectorFactory.class.getName());
servletContext.setInitParameter(ResteasyContextParameters.RESTEASY_PROVIDERS,
RpcExceptionMapper.class.getName());
... | 90 | 118 | 208 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/support/servlet/ServletRestServer.java | ServletRestServer | checkEnv | class ServletRestServer implements RestServer {
private static ResteasyDeployment deployment;
public static void setResteasyDeployment(ResteasyDeployment deployment) {
ServletRestServer.deployment = deployment;
}
public void checkEnv() {<FILL_FUNCTION_BODY>}
@Override
public... |
if (deployment == null) {
throw new MotanFrameworkException("please config <listener-class>"
+ RestfulServletContainerListener.class.getName() + "</listener-class> in your web.xml file");
}
| 159 | 68 | 227 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-yar/src/main/java/com/weibo/api/motan/protocol/yar/YarExporter.java | YarExporter | validateInterface | class YarExporter<T> extends AbstractExporter<T> {
protected Server server;
private YarRpcProtocol yarProtocol;
public YarExporter(URL url, Provider<T> provider, YarRpcProtocol yarProtocol) {
super(provider, url);
EndpointFactory endpointFactory =
ExtensionLoader.getExtensio... |
HashMap<String, List<Integer>> tempMap = new HashMap<String, List<Integer>>();
for (Method m : interfaceClazz.getDeclaredMethods()) {
if (!tempMap.containsKey(m.getName())) {
List<Integer> templist = new ArrayList<Integer>();
templist.add(m.getParameterTypes(... | 387 | 200 | 587 | <methods>public void <init>(Provider<T>, com.weibo.api.motan.rpc.URL) ,public java.lang.String desc() ,public Provider<T> getProvider() ,public Map<java.lang.String,java.lang.Object> getRuntimeInfo() <variables>protected Provider<T> provider |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-yar/src/main/java/com/weibo/api/motan/protocol/yar/YarMessageRouter.java | YarMessageRouter | handle | class YarMessageRouter extends ProviderMessageRouter {
protected ConcurrentHashMap<String, Provider<?>> providerMap = new ConcurrentHashMap<String, Provider<?>>();
public YarMessageRouter() {
super();
}
public YarMessageRouter(URL url) {
super(url);
}
@Override
public Obje... |
YarRequest yarRequest = (YarRequest) message;
String packagerName = yarRequest.getPackagerName();
Provider<?> provider = providerMap.get(yarRequest.getRequestPath());
if (provider == null) {
throw new MotanServiceException("can not find service provider. request path:" + ya... | 272 | 170 | 442 | <methods>public void <init>() ,public void <init>(com.weibo.api.motan.rpc.URL) ,public void <init>(Provider<?>) ,public synchronized void addProvider(Provider<?>) ,public int getPublicMethodCount() ,public Map<java.lang.String,java.lang.Object> getRuntimeInfo() ,public java.lang.Object handle(com.weibo.api.motan.transp... |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-yar/src/main/java/com/weibo/api/motan/protocol/yar/YarProtocolUtil.java | YarProtocolUtil | adaptParams | class YarProtocolUtil {
public static String getYarPath(Class<?> interfaceClazz, URL url) {
if (interfaceClazz != null) {
YarConfig config = interfaceClazz.getAnnotation(YarConfig.class);
if (config != null && StringUtils.isNotBlank(config.path())) {
return config.pa... |
// FIXME the real parameter type may not same with formal parameter, for instance, formal
// parameter type is int, the real parameter maybe use String in php
// any elegant way?
for (int i = 0; i < argumentClazz.length; i++) {
try {
if ("int".equals(argument... | 1,143 | 833 | 1,976 | <no_super_class> |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-yar/src/main/java/com/weibo/api/motan/protocol/yar/YarRpcProtocol.java | YarRpcProtocol | unexport | class YarRpcProtocol extends AbstractProtocol {
private ConcurrentHashMap<String, ProviderMessageRouter> ipPort2RequestRouter = new ConcurrentHashMap<String, ProviderMessageRouter>();
@Override
protected <T> Exporter<T> createExporter(Provider<T> provider, URL url) {
return new YarExporter... |
String protocolKey = MotanFrameworkUtil.getProtocolKey(url);
String ipPort = url.getServerPortStr();
Exporter<?> exporter = (Exporter<?>) exporterMap.remove(protocolKey);
if (exporter != null) {
exporter.destroy();
}
synchronized (ipPort2RequestRouter) {
... | 333 | 174 | 507 | <methods>public non-sealed void <init>() ,public void destroy() ,public Exporter<T> export(Provider<T>, com.weibo.api.motan.rpc.URL) ,public Map<java.lang.String,Exporter<?>> getExporterMap() ,public Referer<T> refer(Class<T>, com.weibo.api.motan.rpc.URL) ,public Referer<T> refer(Class<T>, com.weibo.api.motan.rpc.URL, ... |
weibocom_motan | motan/motan-extension/protocol-extension/motan-protocol-yar/src/main/java/com/weibo/api/motan/transport/netty4/yar/YarMessageHandlerWrapper.java | YarMessageHandlerWrapper | handle | class YarMessageHandlerWrapper implements HttpMessageHandler {
public static final String BAD_REQUEST = "/bad-request";
public static final String ROOT_PATH = "/";
public static final String STATUS_PATH = "/rpcstatus";
protected String switcherName = MotanConstants.REGISTRY_HEARTBEAT_SWITCHER;
priva... |
QueryStringDecoder decoder = new QueryStringDecoder(httpRequest.uri());
String path = decoder.path();
// check badRequest
if (BAD_REQUEST.equals(path)) {
return NettyHttpUtil.buildDefaultResponse("bad request!", HttpResponseStatus.BAD_REQUEST);
}
// service... | 305 | 696 | 1,001 | <no_super_class> |
weibocom_motan | motan/motan-extension/serialization-extension/src/main/java/com/weibo/api/motan/serialize/GrpcPbSerialization.java | GrpcPbSerialization | deserializeMulti | class GrpcPbSerialization implements Serialization {
@Override
public byte[] serialize(Object obj) throws IOException {
if (obj == null) {
throw new IllegalArgumentException("can't serialize null.");
}
if (MessageLite.class.isAssignableFrom(obj.getClass())) {
retu... |
if (classes.length != 1) {
throw new MotanServiceException("only single value serialize was supported in GrpcPbSerialization");
}
Object[] objects = new Object[1];
objects[0] = deserialize(data, classes[0]);
return objects;
| 429 | 75 | 504 | <no_super_class> |
weibocom_motan | motan/motan-extension/serialization-extension/src/main/java/com/weibo/api/motan/serialize/HproseSerialization.java | HproseSerialization | serializeMulti | class HproseSerialization implements Serialization {
@Override
public byte[] serialize(Object data) throws IOException {
ByteBufferStream stream = null;
try {
stream = new ByteBufferStream();
HproseWriter writer = new HproseWriter(stream.getOutputStream());
w... |
ByteBufferStream stream = null;
try {
stream = new ByteBufferStream();
HproseWriter writer = new HproseWriter(stream.getOutputStream());
for (Object o : data) {
writer.serialize(o);
}
byte[] result = stream.toArray();
... | 354 | 109 | 463 | <no_super_class> |
weibocom_motan | motan/motan-extension/serialization-extension/src/main/java/com/weibo/api/motan/serialize/ProtobufSerialization.java | ProtobufSerialization | serialize | class ProtobufSerialization implements Serialization {
@Override
public byte[] serialize(Object obj) throws IOException {<FILL_FUNCTION_BODY>}
@SuppressWarnings("unchecked")
@Override
public <T> T deserialize(byte[] bytes, Class<T> clazz) throws IOException {
CodedInputStream in = CodedInpu... |
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
CodedOutputStream output = CodedOutputStream.newInstance(baos);
// 兼容motan1 协议,对throwable仅将异常信息进行序列化
if (obj != null && Throwable.class.isAssignableFrom(obj.getClass())) {
serialize(output, ((Throwable)obj).getMes... | 1,311 | 136 | 1,447 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/controller/CommandController.java | CommandController | deleteCommand | class CommandController {
@Resource(name = "${registry.type}" + "CommandService")
private CommandService commandService;
/**
* 获取所有指令
*
* @return
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseEntity<List<JSONObject>> getAllCommands() {
List<J... |
if (StringUtils.isEmpty(group)) {
return new ResponseEntity<Boolean>(HttpStatus.BAD_REQUEST);
}
boolean result = commandService.deleteCommand(group, index);
HttpStatus status;
if (result) {
status = HttpStatus.OK;
} else {
status = Ht... | 1,114 | 109 | 1,223 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/controller/ServerController.java | ServerController | getAllNodes | class ServerController {
@Resource(name = "${registry.type}" + "RegistryService")
private RegistryService registryService;
/**
* 获取所有group分组名称
*
* @return
*/
@RequestMapping(value = "/groups", method = RequestMethod.GET)
public ResponseEntity<List<String>> getAllGroups() {
... |
if (StringUtils.isEmpty(group)) {
return new ResponseEntity<List<JSONObject>>(HttpStatus.BAD_REQUEST);
}
List<JSONObject> results = registryService.getAllNodes(group);
return new ResponseEntity<List<JSONObject>>(results, HttpStatus.OK);
| 581 | 78 | 659 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/controller/UserController.java | UserController | createRoleMap | class UserController {
@Autowired
private UserDetailsService userDetailsService;
@Autowired
@Qualifier("authenticationManager")
private AuthenticationManager authManager;
/**
* Retrieves the currently logged in user.
*
* @return A transfer containing the username and the roles.
... |
Map<String, Boolean> roles = new HashMap<String, Boolean>();
for (GrantedAuthority authority : userDetails.getAuthorities()) {
roles.put(authority.getAuthority(), Boolean.TRUE);
}
return roles;
| 375 | 65 | 440 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/filter/AuthenticationTokenProcessingFilter.java | AuthenticationTokenProcessingFilter | extractAuthTokenFromRequest | class AuthenticationTokenProcessingFilter extends GenericFilterBean {
private final UserDetailsService userDetailsService;
@Autowired
public AuthenticationTokenProcessingFilter(UserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;
}
@Override
public vo... |
String authToken = httpServletRequest.getHeader("X-Auth-Token");
if (authToken == null) {
authToken = httpServletRequest.getParameter("token");
}
return authToken;
| 376 | 55 | 431 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/service/LoggingAspect.java | LoggingAspect | logAfter | class LoggingAspect {
@Autowired(required = false)
private OperationRecordMapper recordMapper;
// 任意公共方法的执行
@Pointcut("execution(public * * (..))")
private void anyPublicOperation() {
}
// CommandService接口定义的任意方法的执行
@Pointcut("execution(* com.weibo.service.CommandService+.*(..))")
... |
Object[] args = joinPoint.getArgs();
OperationRecord record = new OperationRecord();
record.setOperator(getUsername());
record.setType(joinPoint.getSignature().getName());
record.setGroupName(args[0].toString());
record.setCommand(JSON.toJSONString(args[1]));
in... | 268 | 154 | 422 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/service/UnauthorizedEntryPoint.java | UnauthorizedEntryPoint | commence | class UnauthorizedEntryPoint implements AuthenticationEntryPoint
{
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException
{<FILL_FUNCTION_BODY>}
} |
response.sendError(
HttpServletResponse.SC_UNAUTHORIZED,
"Unauthorized: Authentication token was either missing or invalid.");
| 65 | 43 | 108 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/service/impl/AbstractCommandService.java | AbstractCommandService | deleteCommand | class AbstractCommandService implements CommandService {
@Autowired(required = false)
private OperationRecordMapper recordMapper;
/**
* 向指定group添加指令
*
* @param group
* @param command
* @return
*/
@Override
public boolean addCommand(String group, RpcCommand.ClientComma... |
LoggerUtil.info(String.format("delete command: group=%s, index=%d: ", group, index));
RpcCommand remoteCommand = RpcCommandUtil.stringToCommand(getCommands(group));
if (remoteCommand == null) {
LoggerUtil.info("delete failed, command not found");
return false;
}
... | 1,122 | 265 | 1,387 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/service/impl/ConsulCommandService.java | ConsulCommandService | getCommands | class ConsulCommandService extends AbstractCommandService {
@Autowired
private ConsulClientWrapper clientWrapper;
private ConsulClient consulClient;
@PostConstruct
void init() {
consulClient = clientWrapper.getConsulClient();
}
/**
* 获取所有指令
*
* @return
*/
@O... |
Response<GetValue> response = consulClient.getKVValue(ConsulConstants.CONSUL_MOTAN_COMMAND + groupName);
GetValue value = response.getValue();
String command = "";
if (value != null && value.getValue() != null) {
command = new String(Base64.decodeBase64(value.getValue()));
... | 925 | 101 | 1,026 | <methods>public non-sealed void <init>() ,public boolean addCommand(java.lang.String, com.weibo.api.motan.registry.support.command.RpcCommand.ClientCommand) ,public com.weibo.api.motan.registry.support.command.RpcCommand buildCommand(java.lang.String, com.weibo.api.motan.registry.support.command.RpcCommand.ClientComman... |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/service/impl/ConsulRegistryService.java | ConsulRegistryService | getAllNodes | class ConsulRegistryService implements RegistryService {
@Autowired
private ConsulClientWrapper clientWrapper;
private ConsulClient consulClient;
public ConsulRegistryService() {
}
/**
* Unit Test中使用
*
* @param consulClient
*/
public ConsulRegistryService(ConsulClient c... |
List<JSONObject> results = new ArrayList<JSONObject>();
List<String> serviceNameSet = getServicesByGroup(dcGroup);
for (String dcServiceName : serviceNameSet) {
JSONObject service = new JSONObject();
service.put("service", dcServiceName);
List<JSONObject> ava... | 871 | 178 | 1,049 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/service/impl/ZookeeperCommandService.java | ZookeeperCommandService | getChildren | class ZookeeperCommandService extends AbstractCommandService {
@Autowired
private ZkClientWrapper clientWrapper;
private ZkClient zkClient;
@PostConstruct
void init() {
zkClient = clientWrapper.getZkClient();
}
/**
* 获取所有指令
*
* @return
*/
@Override
publ... |
List<String> children = new ArrayList<String>();
if (zkClient.exists(path)) {
children = zkClient.getChildren(path);
}
return children;
| 574 | 51 | 625 | <methods>public non-sealed void <init>() ,public boolean addCommand(java.lang.String, com.weibo.api.motan.registry.support.command.RpcCommand.ClientCommand) ,public com.weibo.api.motan.registry.support.command.RpcCommand buildCommand(java.lang.String, com.weibo.api.motan.registry.support.command.RpcCommand.ClientComman... |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/service/impl/ZookeeperRegistryService.java | ZookeeperRegistryService | getNodes | class ZookeeperRegistryService implements RegistryService {
@Autowired
private ZkClientWrapper clientWrapper;
private ZkClient zkClient;
public ZookeeperRegistryService() {
}
public ZookeeperRegistryService(ZkClient zkClient) {
this.zkClient = zkClient;
}
@PostConstruct
v... |
List<JSONObject> result = new ArrayList<JSONObject>();
List<String> nodes = getChildren(toNodeTypePath(group, service, nodeType));
for (String nodeName : nodes) {
JSONObject node = new JSONObject();
String info = zkClient.readData(toNodePath(group, service, nodeType, nod... | 724 | 128 | 852 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/utils/ConsulClientWrapper.java | ConsulClientWrapper | init | class ConsulClientWrapper {
@Value("${registry.url}")
private String registryUrl;
private ConsulClient consulClient;
@PostConstruct
void init() {<FILL_FUNCTION_BODY>}
@PreDestroy
void destory() {
consulClient = null;
}
public ConsulClient getConsulClient() {
retur... |
try {
String[] arr = registryUrl.split(":");
String host = arr[0];
int port = Integer.parseInt(arr[1]);
consulClient = new ConsulClient(host, port);
} catch (Exception e) {
throw new MotanFrameworkException("Fail to connect consul, cause: " + ... | 113 | 93 | 206 | <no_super_class> |
weibocom_motan | motan/motan-manager/src/main/java/com/weibo/utils/TokenUtils.java | TokenUtils | computeSignature | class TokenUtils {
public static final String MAGIC_KEY = "obfuscate";
public static String createToken(UserDetails userDetails) {
/* Expires in one hour */
long expires = System.currentTimeMillis() + 1000L * 60 * 60;
StringBuilder tokenBuilder = new StringBuilder();
tokenBuil... |
StringBuilder signatureBuilder = new StringBuilder();
signatureBuilder.append(userDetails.getUsername());
signatureBuilder.append(":");
signatureBuilder.append(expires);
signatureBuilder.append(":");
signatureBuilder.append(userDetails.getPassword());
signatureBu... | 347 | 177 | 524 | <no_super_class> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.