Tabnine Logo
info.xiancloud.core.distribution
Code IndexAdd Tabnine to your IDE (free)

How to use info.xiancloud.core.distribution

Best Java code snippets using info.xiancloud.core.distribution (Showing top 15 results out of 315)

origin: xiancloud/xian

private Multimap<String, UnitProxy> buildUnits() {
  Multimap<String, UnitProxy> groupedUnits = ArrayListMultimap.create();
  List<String> unitFullNames = UnitDiscovery.singleton.queryForNames();
  for (String unitFullName : unitFullNames) {
    UnitProxy unitProxy = UnitDiscovery.singleton.newestDefinition(unitFullName);
    if (unitProxy != null)
      groupedUnits.put(unitProxy.getGroup().getName(), unitProxy);
  }
  return groupedUnits;
}
origin: xiancloud/xian

private static Multimap<String, UnitProxy> filteredUnits(Multimap<String, UnitProxy> units, final List<String> fullUnitNames) {
  Multimap<String, UnitProxy> results = ArrayListMultimap.create();
  for (UnitProxy unitProxy : units.values()) {
    for (String unitFullName : fullUnitNames) {
      if (Objects.equals(Unit.fullName(unitProxy), unitFullName)) {
        results.put(unitProxy.getGroup().getName(), unitProxy);
      }
    }
  }
  return results;
}
origin: info.xiancloud/xian-core

private static void doStart() throws Exception {
  if (IRegistry.singleton != null)
    IRegistry.singleton.init();
  if (ApplicationDiscovery.singleton != null)
    ApplicationDiscovery.singleton.init();
  if (GroupDiscovery.singleton != null)
    GroupDiscovery.singleton.init();
  if (UnitDiscovery.singleton != null)
    UnitDiscovery.singleton.init();
  Blocking.blockUntilReady();
  if (ResInit.singleton != null)
    ResInit.singleton.init();
  if (RpcServer.singleton != null)
    RpcServer.singleton.init();
  LocalNodeManager.init();
  for (IStartService service : startServices) {
    LOG.info("开始执行startService " + service.getInitArgName());
    ApplicationDiscovery.singleton.selfRegister();
  if (GroupDiscovery.singleton != null)
    GroupDiscovery.singleton.selfRegister();
  if (UnitDiscovery.singleton != null)
    UnitDiscovery.singleton.selfRegister();
  ReadySignal.singleton.init();
origin: xiancloud/xian

GroupProxy groupProxy = GroupDiscovery.singleton.newestDefinition(groupName);
bw.write("## " + String.format("%s\r\n", StringUtil.isEmpty(groupProxy.getDescription()) ? groupProxy.getName() : groupProxy.getDescription()));
bw.newLine();
bw.write(" 接口列表\r\n");
Collection<UnitProxy> unitProxies = unitMultimap.get(groupName);
for (UnitProxy unitBean : unitProxies) {
  if (!unitBean.getMeta().isDocApi()) {
    LOG.info(String.format(" ---api-doc-unit接口:%s/%s非公开访问的,跳过生成", groupProxy.getName(),
        unitBean.getName()));
    continue;
  LOG.info(String.format(" ---api-doc-unit接口开始生成:%s/%s", groupProxy.getName(), unitBean.getName()));
  Input io = unitBean.getInput();
  bw.write(String.format("### /%s/%s", groupProxy.getName(), unitBean.getName()));
  bw.newLine();
  bw.write(String.format(" * 接口描述: %s\r\n",
      StringUtil.isEmpty(unitBean.getMeta().getDescription()) ? "暂无" : unitBean.getMeta().getDescription()));
  bw.newLine();
  bw.write(" * 调用方式: POST");
  bw.newLine();
  bw.write(String.format("````json\r\n%s\r\n````\r\n",
      unitBean.getMeta().getSuccessfulUnitResponse() == null ?
          "暂无" : unitBean.getMeta().getSuccessfulUnitResponse().toVoJSONString(true)));
  bw.write("&nbsp;&nbsp;\r\n");
origin: xiancloud/xian

private static boolean isSecure(String uri) {
  if (Arrays.asList(XianConfig.getStringArray("api_gateway_white_uri_list")).contains(uri)) {
    //todo add 'secure' property for rule engine,instead of static config
    //todo please deprecate white uri, kept for compatibility only.
    return false;
  }
  URIBean uriBean = URIBean.create(uri);
  try {
    if (!UnitRouter.SINGLETON.newestDefinition(Unit.fullName(uriBean.getGroup(), uriBean.getUnit())).getMeta().isSecure()) {
      return false;
    }
  } catch (UnitUndefinedException ignored) {
  }
  return true;
}
origin: xiancloud/xian

private boolean canTry() {
  try {
    LOG.debug("//每次都检查注册的服务最新rpc状态,以支持远程服务器动态切换其rpc状态");
    boolean rpcEnabled = ApplicationRouter.singleton.getInstance(nodeId).getPayload().getPort() > 0;
    if (!rpcEnabled) {
      return false;
origin: xiancloud/xian

  @Test
  public void test() {
    final NodeStatus status = new NodeStatus();
    status.setActiveCount(1);
    ServiceInstance<NodeStatus> instance = JSON.parseObject(new JSONObject() {{
      put("payload", status);
    }}.toJSONString(), new TypeReference<ServiceInstance<NodeStatus>>() {
    });
    Assert.assertEquals(instance.getPayload().getActiveCount(), 1);
  }
}
origin: xiancloud/xian

public static ServiceInstance<GroupProxy> thisCuratorServiceInstance(String groupName) throws Exception {
  return ServiceInstance.<GroupProxy>builder()
      .address(EnvUtil.getLocalIp())
      .enabled(true)
      .id(new GroupInstanceIdBean(groupName, LocalNodeManager.LOCAL_NODE_ID).getGroupInstanceId())
      .name(groupName)
      .port(Node.RPC_PORT)
      .payload(GroupProxy.create(LocalUnitsManager.getGroupByName(groupName)))
      .build();
}
origin: xiancloud/xian

public static ServiceInstance<UnitProxy> thisCuratorServiceInstance(Unit unit) throws Exception {
  String fullUnitName = Unit.fullName(unit);
  return ServiceInstance.<UnitProxy>builder()
      .address(EnvUtil.getLocalIp())
      .enabled(true)
      .id(new UnitInstanceIdBean(fullUnitName, LocalNodeManager.LOCAL_NODE_ID).getUnitInstanceId())
      .name(fullUnitName)
      .port(Node.RPC_PORT)
      .payload(UnitProxy.create(unit))
      .serviceType(ServiceType.DYNAMIC)
      .build();
}
origin: xiancloud/xian

  @Test
  public void testGetList() {
    List<Integer> list = new UnitRequest(new JSONObject() {{
      put("yy", new int[]{0, 1});
    }}).getList("yy");
    Assert.assertTrue(list.get(0) == 0);
    Assert.assertTrue(list.get(1) == 1);

    List<Unit> unitList = new UnitRequest(new JSONObject() {{
      put("yy", new Unit[]{new UnitResponseTestUnit()});
    }}).getList("yy");
    Assert.assertTrue(unitList.get(0).getName().equals(new UnitResponseTestUnit().getName()));

    List<UnitProxy> proxyList = new UnitRequest(new JSONObject() {{
      put("yy", new String[]{new UnitResponseTestUnit().toJSONString()});
    }}).getList("yy", UnitProxy.class);
    Assert.assertTrue(proxyList.get(0).getName().equals(new UnitResponseTestUnit().getName()));
  }
}
origin: xiancloud/xian

public static ServiceInstance<NodeStatus> thisCuratorServiceInstance() throws Exception {
  return ServiceInstance.<NodeStatus>builder()
      .address(EnvUtil.getLocalIp())
      .enabled(true)
      .id(LocalNodeManager.LOCAL_NODE_ID)
      .name(EnvUtil.getApplication())
      .port(Node.RPC_PORT)
      .payload(LocalNodeManager.singleton.getFullStatus())
      .build();
}
origin: xiancloud/xian

private static void registerService(String application, NodeStatus payload) {
  try {
    /*while (ZkBootstrap.zkNeverStarted()) {
      Thread.sleep(1000);
      LOG.warn("zk注册服务尚未初始化,所以无法将当前服务发送到注册中心,请等待...");
    }
    if (ZkBootstrap.zkEverStartedButNowStoped()) {
      LOG.warn("zk客户端已断开连接,不再执行注册服务动作");
      return;
    }*/
    synchronized (lock) {
      LOG.info("注册服务,详情:  " + JSON.toJSON(payload));
      registry.serviceDiscovery.registerService(ServiceInstance.<NodeStatus>builder()
          .id(payload.getNodeId())
          .name(application)
          .payload(payload)
          .build()
      );
    }
  } catch (Throwable e) {
    LOG.error(e);
  } finally {
    LOG.info(String.format("%s的服务注册完毕", application));
  }
}
origin: xiancloud/xian

/**
 * factory method for producing the right forwarder
 *
 * @param uri request uri
 * @return the selected forwarder
 */
static IAsyncForwarder getForwarder(String uri) {
  URIBean uriBean = URIBean.create(uri);
  try {
    UnitMeta unitMeta = UnitRouter.SINGLETON.newestDefinition(Unit.fullName(uriBean.getGroup(), uriBean.getUnit())).getMeta();
    if (unitMeta.isBodyRequired() && unitMeta.isDataOnly()) {
      return BodyRequiredAndResponseDataOnlyAsyncForwarder.singleton;
    } else if (unitMeta.isBodyRequired() && !unitMeta.isDataOnly()) {
      return BodyRequiredAsyncForwarder.singleton;
    } else if (!unitMeta.isBodyRequired() && unitMeta.isDataOnly()) {
      return RequestBodyNotRequiredAndDataOnlyResponseAsyncForwarder.singleton;
    } else {
      return DefaultAsyncForwarder.singleton;
    }
  } catch (UnitUndefinedException ignored) {
    // we return default processor for unmapped uri request.
    return DefaultAsyncForwarder.singleton;
  }
}
origin: xiancloud/xian

/**
 * 启动服务注册,只有启动了服务注册,才可以调用{@link #registerService(String, NodeStatus)}
 */
public static void start() {
  synchronized (lock) {
    if (registry != null) return;
    try {
      LOG.info("开始启动zk服务注册入口");
      registry = new ZkServiceRegistry();
      FastJsonServiceInstanceSerializer<NodeStatus> serializer = new FastJsonServiceInstanceSerializer<>();
      registry.serviceDiscovery = ServiceDiscoveryBuilder.builder(NodeStatus.class)
          .client(ZkConnection.client)
          .basePath(ZkPathManager.getNodeBasePath())
          .serializer(serializer)
          .build();
      registry.serviceDiscovery.start();
      LOG.info("zk服务注册入口启动完毕");
      registerService(EnvUtil.getApplication(), LocalNodeManager.singleton.getFullStatus());
    } catch (Exception e) {
      throw new RuntimeException("启动zkServiceRegistry失败", e);
    }
  }
}
origin: info.xiancloud/xian-gateway

/**
 * factory method for producing the right forwarder
 *
 * @param uri request uri
 * @return the selected forwarder
 */
static IAsyncForwarder getForwarder(String uri) {
  URIBean uriBean = URIBean.create(uri);
  try {
    UnitMeta unitMeta = UnitRouter.SINGLETON.newestDefinition(Unit.fullName(uriBean.getGroup(), uriBean.getUnit())).getMeta();
    if (unitMeta.isBodyRequired() && unitMeta.isDataOnly()) {
      return BodyRequiredAndResponseDataOnlyAsyncForwarder.singleton;
    } else if (unitMeta.isBodyRequired() && !unitMeta.isDataOnly()) {
      return BodyRequiredAsyncForwarder.singleton;
    } else if (!unitMeta.isBodyRequired() && unitMeta.isDataOnly()) {
      return RequestBodyNotRequiredAndDataOnlyResponseAsyncForwarder.singleton;
    } else {
      return DefaultAsyncForwarder.singleton;
    }
  } catch (UnitUndefinedException ignored) {
    // we return default processor for unmapped uri request.
    return DefaultAsyncForwarder.singleton;
  }
}
info.xiancloud.core.distribution

Most used classes

  • UnitProxy
  • NodeStatus
  • GroupProxy
  • ApplicationRouter
  • UnitRouter
  • ApplicationInstance,
  • GroupDiscovery,
  • UnitDiscovery,
  • INode,
  • IRegistry,
  • LocalNodeManager,
  • ResInit,
  • ApplicationDiscovery,
  • GroupInstance,
  • GroupInstanceIdBean,
  • UnitInstance,
  • UnitInstanceIdBean
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now