use of j.service.server.ServiceContainer in project JFramework by gugumall.
the class Client method httpGetService.
/**
* 获得服务入口
* @param code
* @return
* @throws RemoteException
*/
public static String httpGetService(JHttp jhttp, HttpClient client, String code, boolean local) throws Exception {
boolean callLocal = local ? true : false;
if (!local) {
if ("true".equalsIgnoreCase(Client.callLocalServiceIfExists))
callLocal = true;
else if ("random".equalsIgnoreCase(Client.callLocalServiceIfExists)) {
int x = JUtilRandom.nextInt(3);
if (x == 0)
callLocal = true;
}
}
if (callLocal) {
// 调用本地服务
ServiceContainer container = ServiceManager.getServiceContainer(code);
if (container != null) {
ServiceBase servant = container.getServantOfService(code);
if (servant != null) {
return servant.getServiceConfig().getHttp().getEntrance();
}
}
}
if (local)
return null;
String md54Routing = "";
md54Routing += Manager.getClientNodeUuid();
md54Routing += Manager.getClientKeyToRouter();
md54Routing = JUtilMD5.MD5EncodeToHex(md54Routing);
String entrance = RouterManager.serviceHttp(jhttp, client, Manager.getClientNodeUuid(), code, md54Routing);
if (Constants.AUTH_FAILED.equals(entrance) || Constants.SERVICE_NOT_FOUND.equals(entrance) || Constants.SERVICE_NOT_AVAIL.equals(entrance)) {
throw new Exception("无可用服务(http) - " + entrance + " - " + code);
}
if (entrance == null || !entrance.startsWith("http")) {
throw new Exception("无可用服务(http) - " + entrance + " - " + code);
}
return entrance;
}
use of j.service.server.ServiceContainer in project JFramework by gugumall.
the class Client method rmiGetService.
/**
* 获得服务入口
* @param code
* @param local
* @return
* @throws Exception
*/
public static ServiceBase rmiGetService(String code, boolean local) throws Exception {
boolean callLocal = local ? true : false;
if (!local) {
if ("true".equalsIgnoreCase(Client.callLocalServiceIfExists))
callLocal = true;
else if ("random".equalsIgnoreCase(Client.callLocalServiceIfExists)) {
int x = JUtilRandom.nextInt(3);
if (x == 0)
callLocal = true;
}
}
if (callLocal) {
// 调用本地服务
ServiceContainer container = ServiceManager.getServiceContainer(code);
if (container != null) {
ServiceBase servant = container.getServantOfService(code);
if (servant != null) {
return servant;
}
}
}
if (local)
return null;
String md54Routing = "";
md54Routing += Manager.getClientNodeUuid();
md54Routing += Manager.getClientKeyToRouter();
md54Routing = JUtilMD5.MD5EncodeToHex(md54Routing);
return (ServiceBase) RouterManager.serviceRmi(Manager.getClientNodeUuid(), code, md54Routing);
}
Aggregations