Search in sources :

Example 1 with ServiceContainer

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;
}
Also used : ServiceContainer(j.service.server.ServiceContainer) ServiceBase(j.service.server.ServiceBase) RemoteException(java.rmi.RemoteException)

Example 2 with ServiceContainer

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);
}
Also used : ServiceContainer(j.service.server.ServiceContainer) ServiceBase(j.service.server.ServiceBase)

Aggregations

ServiceBase (j.service.server.ServiceBase)2 ServiceContainer (j.service.server.ServiceContainer)2 RemoteException (java.rmi.RemoteException)1