test_class.declarator: protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension()
test_class.modifier: private
test_class.original_string: private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
test_class.type: Protocol
test_class.var_name: protocol
test_class.declarator: proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension()
test_class.modifier: private
test_class.original_string: private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
test_class.type: ProxyFactory
test_class.var_name: proxy
test_class.file: dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocolTest.java
test_class.identifier: DubboProtocolTest
test_case.body: @Test
      public void testDubboProtocol() throws Exception {
          DemoService service = new DemoServiceImpl();
          int port = NetUtils.getAvailablePort();
          protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName())));
          service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName()).addParameter("timeout",
                  3000L)));
          assertEquals(service.enumlength(new Type[]{}), Type.Lower);
          assertEquals(service.getSize(null), -1);
          assertEquals(service.getSize(new String[]{"", "", ""}), 3);
          Map<String, String> map = new HashMap<String, String>();
          map.put("aa", "bb");
          Set<String> set = service.keys(map);
          assertEquals(set.size(), 1);
          assertEquals(set.iterator().next(), "aa");
          service.invoke("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName() + "", "invoke");
  
          service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName() + "?client=netty").addParameter("timeout",
                  3000L)));
          // test netty client
          StringBuffer buf = new StringBuffer();
          for (int i = 0; i < 1024 * 32 + 32; i++)
              buf.append('A');
          System.out.println(service.stringLength(buf.toString()));
  
          // cast to EchoService
          EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName() + "?client=netty").addParameter("timeout",
                  3000L)));
          assertEquals(echo.$echo(buf.toString()), buf.toString());
          assertEquals(echo.$echo("test"), "test");
          assertEquals(echo.$echo("abcdefg"), "abcdefg");
          assertEquals(echo.$echo(1234), 1234);
      }
test_case.class_method_signature: DubboProtocolTest.testDubboProtocol()
test_case.full_signature: @Test public void testDubboProtocol()
test_case.identifier: testDubboProtocol
test_case.invocations: getAvailablePort export getInvoker valueOf getName getProxy refer addParameter valueOf getName assertEquals enumlength assertEquals getSize assertEquals getSize put keys assertEquals size assertEquals next iterator invoke getName getProxy refer addParameter valueOf getName append println stringLength toString getProxy refer addParameter valueOf getName assertEquals echo toString toString assertEquals echo assertEquals echo assertEquals echo
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testDubboProtocol()
focal_class.declarator: NAME = "dubbo"
focal_class.modifier: public static final
focal_class.original_string: public static final String NAME = "dubbo";
focal_class.type: String
focal_class.var_name: NAME
focal_class.declarator: DEFAULT_PORT = 20880
focal_class.modifier: public static final
focal_class.original_string: public static final int DEFAULT_PORT = 20880;
focal_class.type: int
focal_class.var_name: DEFAULT_PORT
focal_class.declarator: IS_CALLBACK_SERVICE_INVOKE = "_isCallBackServiceInvoke"
focal_class.modifier: private static final
focal_class.original_string: private static final String IS_CALLBACK_SERVICE_INVOKE = "_isCallBackServiceInvoke";
focal_class.type: String
focal_class.var_name: IS_CALLBACK_SERVICE_INVOKE
focal_class.declarator: INSTANCE
focal_class.modifier: private static
focal_class.original_string: private static DubboProtocol INSTANCE;
focal_class.type: DubboProtocol
focal_class.var_name: INSTANCE
focal_class.declarator: referenceClientMap = new ConcurrentHashMap<>()
focal_class.modifier: private final
focal_class.original_string: private final Map<String, List<ReferenceCountExchangeClient>> referenceClientMap = new ConcurrentHashMap<>();
focal_class.type: Map<String, List<ReferenceCountExchangeClient>>
focal_class.var_name: referenceClientMap
focal_class.declarator: locks = new ConcurrentHashMap<>()
focal_class.modifier: private final
focal_class.original_string: private final ConcurrentMap<String, Object> locks = new ConcurrentHashMap<>();
focal_class.type: ConcurrentMap<String, Object>
focal_class.var_name: locks
focal_class.declarator: optimizers = new ConcurrentHashSet<>()
focal_class.modifier: private final
focal_class.original_string: private final Set<String> optimizers = new ConcurrentHashSet<>();
focal_class.type: Set<String>
focal_class.var_name: optimizers
focal_class.declarator: requestHandler = new ExchangeHandlerAdapter() {
  
          @Override
          public CompletableFuture<Object> reply(ExchangeChannel channel, Object message) throws RemotingException {
  
              if (!(message instanceof Invocation)) {
                  throw new RemotingException(channel, "Unsupported request: "
                          + (message == null ? null : (message.getClass().getName() + ": " + message))
                          + ", channel: consumer: " + channel.getRemoteAddress() + " --> provider: " + channel.getLocalAddress());
              }
  
              Invocation inv = (Invocation) message;
              Invoker<?> invoker = getInvoker(channel, inv);
              // need to consider backward-compatibility if it's a callback
              if (Boolean.TRUE.toString().equals(inv.getObjectAttachments().get(IS_CALLBACK_SERVICE_INVOKE))) {
                  String methodsStr = invoker.getUrl().getParameters().get("methods");
                  boolean hasMethod = false;
                  if (methodsStr == null || !methodsStr.contains(",")) {
                      hasMethod = inv.getMethodName().equals(methodsStr);
                  } else {
                      String[] methods = methodsStr.split(",");
                      for (String method : methods) {
                          if (inv.getMethodName().equals(method)) {
                              hasMethod = true;
                              break;
                          }
                      }
                  }
                  if (!hasMethod) {
                      logger.warn(new IllegalStateException("The methodName " + inv.getMethodName()
                              + " not found in callback service interface ,invoke will be ignored."
                              + " please update the api interface. url is:"
                              + invoker.getUrl()) + " ,invocation is :" + inv);
                      return null;
                  }
              }
              RpcContext.getContext().setRemoteAddress(channel.getRemoteAddress());
              Result result = invoker.invoke(inv);
              return result.thenApply(Function.identity());
          }
  
          @Override
          public void received(Channel channel, Object message) throws RemotingException {
              if (message instanceof Invocation) {
                  reply((ExchangeChannel) channel, message);
  
              } else {
                  super.received(channel, message);
              }
          }
  
          @Override
          public void connected(Channel channel) throws RemotingException {
              invoke(channel, ON_CONNECT_KEY);
          }
  
          @Override
          public void disconnected(Channel channel) throws RemotingException {
              if (logger.isDebugEnabled()) {
                  logger.debug("disconnected from " + channel.getRemoteAddress() + ",url:" + channel.getUrl());
              }
              invoke(channel, ON_DISCONNECT_KEY);
          }
  
          private void invoke(Channel channel, String methodKey) {
              Invocation invocation = createInvocation(channel, channel.getUrl(), methodKey);
              if (invocation != null) {
                  try {
                      received(channel, invocation);
                  } catch (Throwable t) {
                      logger.warn("Failed to invoke event method " + invocation.getMethodName() + "(), cause: " + t.getMessage(), t);
                  }
              }
          }
  
          /**
           * FIXME channel.getUrl() always binds to a fixed service, and this service is random.
           * we can choose to use a common service to carry onConnect event if there's no easy way to get the specific
           * service this connection is binding to.
           * @param channel
           * @param url
           * @param methodKey
           * @return
           */
          private Invocation createInvocation(Channel channel, URL url, String methodKey) {
              String method = url.getParameter(methodKey);
              if (method == null || method.length() == 0) {
                  return null;
              }
  
              RpcInvocation invocation = new RpcInvocation(method, url.getParameter(INTERFACE_KEY), "", new Class<?>[0], new Object[0]);
              invocation.setAttachment(PATH_KEY, url.getPath());
              invocation.setAttachment(GROUP_KEY, url.getParameter(GROUP_KEY));
              invocation.setAttachment(INTERFACE_KEY, url.getParameter(INTERFACE_KEY));
              invocation.setAttachment(VERSION_KEY, url.getParameter(VERSION_KEY));
              if (url.getParameter(STUB_EVENT_KEY, false)) {
                  invocation.setAttachment(STUB_EVENT_KEY, Boolean.TRUE.toString());
              }
  
              return invocation;
          }
      }
focal_class.modifier: private
focal_class.original_string: private ExchangeHandler requestHandler = new ExchangeHandlerAdapter() {
  
          @Override
          public CompletableFuture<Object> reply(ExchangeChannel channel, Object message) throws RemotingException {
  
              if (!(message instanceof Invocation)) {
                  throw new RemotingException(channel, "Unsupported request: "
                          + (message == null ? null : (message.getClass().getName() + ": " + message))
                          + ", channel: consumer: " + channel.getRemoteAddress() + " --> provider: " + channel.getLocalAddress());
              }
  
              Invocation inv = (Invocation) message;
              Invoker<?> invoker = getInvoker(channel, inv);
              // need to consider backward-compatibility if it's a callback
              if (Boolean.TRUE.toString().equals(inv.getObjectAttachments().get(IS_CALLBACK_SERVICE_INVOKE))) {
                  String methodsStr = invoker.getUrl().getParameters().get("methods");
                  boolean hasMethod = false;
                  if (methodsStr == null || !methodsStr.contains(",")) {
                      hasMethod = inv.getMethodName().equals(methodsStr);
                  } else {
                      String[] methods = methodsStr.split(",");
                      for (String method : methods) {
                          if (inv.getMethodName().equals(method)) {
                              hasMethod = true;
                              break;
                          }
                      }
                  }
                  if (!hasMethod) {
                      logger.warn(new IllegalStateException("The methodName " + inv.getMethodName()
                              + " not found in callback service interface ,invoke will be ignored."
                              + " please update the api interface. url is:"
                              + invoker.getUrl()) + " ,invocation is :" + inv);
                      return null;
                  }
              }
              RpcContext.getContext().setRemoteAddress(channel.getRemoteAddress());
              Result result = invoker.invoke(inv);
              return result.thenApply(Function.identity());
          }
  
          @Override
          public void received(Channel channel, Object message) throws RemotingException {
              if (message instanceof Invocation) {
                  reply((ExchangeChannel) channel, message);
  
              } else {
                  super.received(channel, message);
              }
          }
  
          @Override
          public void connected(Channel channel) throws RemotingException {
              invoke(channel, ON_CONNECT_KEY);
          }
  
          @Override
          public void disconnected(Channel channel) throws RemotingException {
              if (logger.isDebugEnabled()) {
                  logger.debug("disconnected from " + channel.getRemoteAddress() + ",url:" + channel.getUrl());
              }
              invoke(channel, ON_DISCONNECT_KEY);
          }
  
          private void invoke(Channel channel, String methodKey) {
              Invocation invocation = createInvocation(channel, channel.getUrl(), methodKey);
              if (invocation != null) {
                  try {
                      received(channel, invocation);
                  } catch (Throwable t) {
                      logger.warn("Failed to invoke event method " + invocation.getMethodName() + "(), cause: " + t.getMessage(), t);
                  }
              }
          }
  
          /**
           * FIXME channel.getUrl() always binds to a fixed service, and this service is random.
           * we can choose to use a common service to carry onConnect event if there's no easy way to get the specific
           * service this connection is binding to.
           * @param channel
           * @param url
           * @param methodKey
           * @return
           */
          private Invocation createInvocation(Channel channel, URL url, String methodKey) {
              String method = url.getParameter(methodKey);
              if (method == null || method.length() == 0) {
                  return null;
              }
  
              RpcInvocation invocation = new RpcInvocation(method, url.getParameter(INTERFACE_KEY), "", new Class<?>[0], new Object[0]);
              invocation.setAttachment(PATH_KEY, url.getPath());
              invocation.setAttachment(GROUP_KEY, url.getParameter(GROUP_KEY));
              invocation.setAttachment(INTERFACE_KEY, url.getParameter(INTERFACE_KEY));
              invocation.setAttachment(VERSION_KEY, url.getParameter(VERSION_KEY));
              if (url.getParameter(STUB_EVENT_KEY, false)) {
                  invocation.setAttachment(STUB_EVENT_KEY, Boolean.TRUE.toString());
              }
  
              return invocation;
          }
      };
focal_class.type: ExchangeHandler
focal_class.var_name: requestHandler
focal_class.file: dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java
focal_class.identifier: DubboProtocol
focal_class.class_method_signature: DubboProtocol.DubboProtocol()
focal_class.full_signature: public  DubboProtocol()
focal_class.identifier: DubboProtocol
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  DubboProtocol()
focal_class.class_method_signature: DubboProtocol.getDubboProtocol()
focal_class.full_signature: public static DubboProtocol getDubboProtocol()
focal_class.identifier: getDubboProtocol
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: DubboProtocol
focal_class.signature: DubboProtocol getDubboProtocol()
focal_class.class_method_signature: DubboProtocol.getExporters()
focal_class.full_signature: public Collection<Exporter<?>> getExporters()
focal_class.identifier: getExporters
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Collection<Exporter<?>>
focal_class.signature: Collection<Exporter<?>> getExporters()
focal_class.class_method_signature: DubboProtocol.isClientSide(Channel channel)
focal_class.full_signature: private boolean isClientSide(Channel channel)
focal_class.identifier: isClientSide
focal_class.modifiers: private
focal_class.parameters: (Channel channel)
focal_class.return: boolean
focal_class.signature: boolean isClientSide(Channel channel)
focal_class.class_method_signature: DubboProtocol.getInvoker(Channel channel, Invocation inv)
focal_class.full_signature:  Invoker<?> getInvoker(Channel channel, Invocation inv)
focal_class.identifier: getInvoker
focal_class.parameters: (Channel channel, Invocation inv)
focal_class.return: Invoker<?>
focal_class.signature: Invoker<?> getInvoker(Channel channel, Invocation inv)
focal_class.class_method_signature: DubboProtocol.getInvokers()
focal_class.full_signature: public Collection<Invoker<?>> getInvokers()
focal_class.identifier: getInvokers
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Collection<Invoker<?>>
focal_class.signature: Collection<Invoker<?>> getInvokers()
focal_class.class_method_signature: DubboProtocol.getDefaultPort()
focal_class.full_signature: @Override public int getDefaultPort()
focal_class.identifier: getDefaultPort
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getDefaultPort()
focal_class.class_method_signature: DubboProtocol.export(Invoker<T> invoker)
focal_class.full_signature: @Override public Exporter<T> export(Invoker<T> invoker)
focal_class.identifier: export
focal_class.modifiers: @Override public
focal_class.parameters: (Invoker<T> invoker)
focal_class.return: Exporter<T>
focal_class.signature: Exporter<T> export(Invoker<T> invoker)
focal_class.class_method_signature: DubboProtocol.openServer(URL url)
focal_class.full_signature: private void openServer(URL url)
focal_class.identifier: openServer
focal_class.modifiers: private
focal_class.parameters: (URL url)
focal_class.return: void
focal_class.signature: void openServer(URL url)
focal_class.class_method_signature: DubboProtocol.createServer(URL url)
focal_class.full_signature: private ProtocolServer createServer(URL url)
focal_class.identifier: createServer
focal_class.modifiers: private
focal_class.parameters: (URL url)
focal_class.return: ProtocolServer
focal_class.signature: ProtocolServer createServer(URL url)
focal_class.class_method_signature: DubboProtocol.optimizeSerialization(URL url)
focal_class.full_signature: private void optimizeSerialization(URL url)
focal_class.identifier: optimizeSerialization
focal_class.modifiers: private
focal_class.parameters: (URL url)
focal_class.return: void
focal_class.signature: void optimizeSerialization(URL url)
focal_class.class_method_signature: DubboProtocol.protocolBindingRefer(Class<T> serviceType, URL url)
focal_class.full_signature: @Override public Invoker<T> protocolBindingRefer(Class<T> serviceType, URL url)
focal_class.identifier: protocolBindingRefer
focal_class.modifiers: @Override public
focal_class.parameters: (Class<T> serviceType, URL url)
focal_class.return: Invoker<T>
focal_class.signature: Invoker<T> protocolBindingRefer(Class<T> serviceType, URL url)
focal_class.class_method_signature: DubboProtocol.getClients(URL url)
focal_class.full_signature: private ExchangeClient[] getClients(URL url)
focal_class.identifier: getClients
focal_class.modifiers: private
focal_class.parameters: (URL url)
focal_class.return: ExchangeClient[]
focal_class.signature: ExchangeClient[] getClients(URL url)
focal_class.class_method_signature: DubboProtocol.getSharedClient(URL url, int connectNum)
focal_class.full_signature: private List<ReferenceCountExchangeClient> getSharedClient(URL url, int connectNum)
focal_class.identifier: getSharedClient
focal_class.modifiers: private
focal_class.parameters: (URL url, int connectNum)
focal_class.return: List<ReferenceCountExchangeClient>
focal_class.signature: List<ReferenceCountExchangeClient> getSharedClient(URL url, int connectNum)
focal_class.class_method_signature: DubboProtocol.checkClientCanUse(List<ReferenceCountExchangeClient> referenceCountExchangeClients)
focal_class.full_signature: private boolean checkClientCanUse(List<ReferenceCountExchangeClient> referenceCountExchangeClients)
focal_class.identifier: checkClientCanUse
focal_class.modifiers: private
focal_class.parameters: (List<ReferenceCountExchangeClient> referenceCountExchangeClients)
focal_class.return: boolean
focal_class.signature: boolean checkClientCanUse(List<ReferenceCountExchangeClient> referenceCountExchangeClients)
focal_class.class_method_signature: DubboProtocol.batchClientRefIncr(List<ReferenceCountExchangeClient> referenceCountExchangeClients)
focal_class.full_signature: private void batchClientRefIncr(List<ReferenceCountExchangeClient> referenceCountExchangeClients)
focal_class.identifier: batchClientRefIncr
focal_class.modifiers: private
focal_class.parameters: (List<ReferenceCountExchangeClient> referenceCountExchangeClients)
focal_class.return: void
focal_class.signature: void batchClientRefIncr(List<ReferenceCountExchangeClient> referenceCountExchangeClients)
focal_class.class_method_signature: DubboProtocol.buildReferenceCountExchangeClientList(URL url, int connectNum)
focal_class.full_signature: private List<ReferenceCountExchangeClient> buildReferenceCountExchangeClientList(URL url, int connectNum)
focal_class.identifier: buildReferenceCountExchangeClientList
focal_class.modifiers: private
focal_class.parameters: (URL url, int connectNum)
focal_class.return: List<ReferenceCountExchangeClient>
focal_class.signature: List<ReferenceCountExchangeClient> buildReferenceCountExchangeClientList(URL url, int connectNum)
focal_class.class_method_signature: DubboProtocol.buildReferenceCountExchangeClient(URL url)
focal_class.full_signature: private ReferenceCountExchangeClient buildReferenceCountExchangeClient(URL url)
focal_class.identifier: buildReferenceCountExchangeClient
focal_class.modifiers: private
focal_class.parameters: (URL url)
focal_class.return: ReferenceCountExchangeClient
focal_class.signature: ReferenceCountExchangeClient buildReferenceCountExchangeClient(URL url)
focal_class.class_method_signature: DubboProtocol.initClient(URL url)
focal_class.full_signature: private ExchangeClient initClient(URL url)
focal_class.identifier: initClient
focal_class.modifiers: private
focal_class.parameters: (URL url)
focal_class.return: ExchangeClient
focal_class.signature: ExchangeClient initClient(URL url)
focal_class.class_method_signature: DubboProtocol.destroy()
focal_class.full_signature: @Override public void destroy()
focal_class.identifier: destroy
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void destroy()
focal_class.class_method_signature: DubboProtocol.closeReferenceCountExchangeClient(ReferenceCountExchangeClient client)
focal_class.full_signature: private void closeReferenceCountExchangeClient(ReferenceCountExchangeClient client)
focal_class.identifier: closeReferenceCountExchangeClient
focal_class.modifiers: private
focal_class.parameters: (ReferenceCountExchangeClient client)
focal_class.return: void
focal_class.signature: void closeReferenceCountExchangeClient(ReferenceCountExchangeClient client)
focal_class.class_method_signature: DubboProtocol.getInvocationWithoutData(Invocation invocation)
focal_class.full_signature: private Invocation getInvocationWithoutData(Invocation invocation)
focal_class.identifier: getInvocationWithoutData
focal_class.modifiers: private
focal_class.parameters: (Invocation invocation)
focal_class.return: Invocation
focal_class.signature: Invocation getInvocationWithoutData(Invocation invocation)
focal_class.superclass: extends AbstractProtocol
focal_method.body: public DubboProtocol() {
          INSTANCE = this;
      }
focal_method.class_method_signature: DubboProtocol.DubboProtocol()
focal_method.full_signature: public  DubboProtocol()
focal_method.identifier: DubboProtocol
focal_method.modifiers: public
focal_method.parameters: ()
focal_method.signature:  DubboProtocol()