Search in sources :

Example 1 with ServiceBase

use of j.service.server.ServiceBase in project JFramework by gugumall.

the class _JRouterAbstract_Tie method _invoke.

public OutputStream _invoke(String method, InputStream _in, ResponseHandler reply) throws SystemException {
    try {
        JRouterAbstract target = this.target;
        if (target == null) {
            throw new java.io.IOException();
        }
        org.omg.CORBA_2_3.portable.InputStream in = (org.omg.CORBA_2_3.portable.InputStream) _in;
        switch(method.length()) {
            case 7:
                if (method.equals("startup")) {
                    target.startup();
                    OutputStream out = reply.createReply();
                    return out;
                }
            case 8:
                if (method.equals("shutdown")) {
                    target.shutdown();
                    OutputStream out = reply.createReply();
                    return out;
                }
            case 11:
                if (method.equals("heartbeat__")) {
                    String result = target.heartbeat();
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, String.class);
                    return out;
                }
            case 17:
                if (method.equals("_get_routerConfig")) {
                    RouterConfig result = target.getRouterConfig();
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, RouterConfig.class);
                    return out;
                } else if (method.equals("_set_routerConfig")) {
                    RouterConfig arg0 = (RouterConfig) in.read_value(RouterConfig.class);
                    target.setRouterConfig(arg0);
                    OutputStream out = reply.createReply();
                    return out;
                }
            case 67:
                if (method.equals("service__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue")) {
                    String arg0 = (String) in.read_value(String.class);
                    String arg1 = (String) in.read_value(String.class);
                    String arg2 = (String) in.read_value(String.class);
                    ServiceBase result = target.service(arg0, arg1, arg2);
                    OutputStream out = reply.createReply();
                    Util.writeRemoteObject(out, result);
                    return out;
                }
            case 86:
                if (method.equals("getAllServiceNodeAvailable__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue")) {
                    String arg0 = (String) in.read_value(String.class);
                    String arg1 = (String) in.read_value(String.class);
                    String arg2 = (String) in.read_value(String.class);
                    ServiceBase[] result = target.getAllServiceNodeAvailable(arg0, arg1, arg2);
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(cast_array(result), ServiceBase[].class);
                    return out;
                }
            case 90:
                if (method.equals("unregister__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue")) {
                    String arg0 = (String) in.read_value(String.class);
                    String arg1 = (String) in.read_value(String.class);
                    String arg2 = (String) in.read_value(String.class);
                    String arg3 = (String) in.read_value(String.class);
                    String result = target.unregister(arg0, arg1, arg2, arg3);
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, String.class);
                    return out;
                }
            case 144:
                if (method.equals("service__j_app_webserver_JSession__javax_servlet_http_HttpSession__javax_servlet_http_HttpServletRequest__javax_servlet_http_HttpServletResponse")) {
                    JSession arg0 = (JSession) in.read_value(JSession.class);
                    HttpSession arg1 = (HttpSession) in.read_value(HttpSession.class);
                    HttpServletRequest arg2 = (HttpServletRequest) in.read_value(HttpServletRequest.class);
                    HttpServletResponse arg3 = (HttpServletResponse) in.read_value(HttpServletResponse.class);
                    target.service(arg0, arg1, arg2, arg3);
                    OutputStream out = reply.createReply();
                    return out;
                }
            case 145:
                if (method.equals("register__j_app_webserver_JSession__javax_servlet_http_HttpSession__javax_servlet_http_HttpServletRequest__javax_servlet_http_HttpServletResponse")) {
                    JSession arg0 = (JSession) in.read_value(JSession.class);
                    HttpSession arg1 = (HttpSession) in.read_value(HttpSession.class);
                    HttpServletRequest arg2 = (HttpServletRequest) in.read_value(HttpServletRequest.class);
                    HttpServletResponse arg3 = (HttpServletResponse) in.read_value(HttpServletResponse.class);
                    target.register(arg0, arg1, arg2, arg3);
                    OutputStream out = reply.createReply();
                    return out;
                }
            case 146:
                if (method.equals("heartbeat__j_app_webserver_JSession__javax_servlet_http_HttpSession__javax_servlet_http_HttpServletRequest__javax_servlet_http_HttpServletResponse")) {
                    JSession arg0 = (JSession) in.read_value(JSession.class);
                    HttpSession arg1 = (HttpSession) in.read_value(HttpSession.class);
                    HttpServletRequest arg2 = (HttpServletRequest) in.read_value(HttpServletRequest.class);
                    HttpServletResponse arg3 = (HttpServletResponse) in.read_value(HttpServletResponse.class);
                    target.heartbeat(arg0, arg1, arg2, arg3);
                    OutputStream out = reply.createReply();
                    return out;
                }
            case 147:
                if (method.equals("unregister__j_app_webserver_JSession__javax_servlet_http_HttpSession__javax_servlet_http_HttpServletRequest__javax_servlet_http_HttpServletResponse")) {
                    JSession arg0 = (JSession) in.read_value(JSession.class);
                    HttpSession arg1 = (HttpSession) in.read_value(HttpSession.class);
                    HttpServletRequest arg2 = (HttpServletRequest) in.read_value(HttpServletRequest.class);
                    HttpServletResponse arg3 = (HttpServletResponse) in.read_value(HttpServletResponse.class);
                    target.unregister(arg0, arg1, arg2, arg3);
                    OutputStream out = reply.createReply();
                    return out;
                }
            case 148:
                if (method.equals("register__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue")) {
                    String arg0 = (String) in.read_value(String.class);
                    String arg1 = (String) in.read_value(String.class);
                    String arg2 = (String) in.read_value(String.class);
                    String arg3 = (String) in.read_value(String.class);
                    String arg4 = (String) in.read_value(String.class);
                    String arg5 = (String) in.read_value(String.class);
                    String arg6 = (String) in.read_value(String.class);
                    String result = target.register(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, String.class);
                    return out;
                }
            case 163:
                if (method.equals("getAllServiceNodeAvailable__j_app_webserver_JSession__javax_servlet_http_HttpSession__javax_servlet_http_HttpServletRequest__javax_servlet_http_HttpServletResponse")) {
                    JSession arg0 = (JSession) in.read_value(JSession.class);
                    HttpSession arg1 = (HttpSession) in.read_value(HttpSession.class);
                    HttpServletRequest arg2 = (HttpServletRequest) in.read_value(HttpServletRequest.class);
                    HttpServletResponse arg3 = (HttpServletResponse) in.read_value(HttpServletResponse.class);
                    target.getAllServiceNodeAvailable(arg0, arg1, arg2, arg3);
                    OutputStream out = reply.createReply();
                    return out;
                }
        }
        throw new BAD_OPERATION();
    } catch (SystemException ex) {
        throw ex;
    } catch (Throwable ex) {
        throw new UnknownException(ex);
    }
}
Also used : InputStream(org.omg.CORBA.portable.InputStream) HttpSession(javax.servlet.http.HttpSession) OutputStream(org.omg.CORBA.portable.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) JSession(j.app.webserver.JSession) HttpServletRequest(javax.servlet.http.HttpServletRequest) SystemException(org.omg.CORBA.SystemException) ServiceBase(j.service.server.ServiceBase) UnknownException(org.omg.CORBA.portable.UnknownException) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION)

Example 2 with ServiceBase

use of j.service.server.ServiceBase in project JFramework by gugumall.

the class _JRouter_Stub method service.

public ServiceBase service(String arg0, String arg1, String arg2) throws java.rmi.RemoteException {
    if (!Util.isLocal(this)) {
        try {
            org.omg.CORBA_2_3.portable.InputStream in = null;
            try {
                org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) _request("service__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue", true);
                out.write_value(arg0, String.class);
                out.write_value(arg1, String.class);
                out.write_value(arg2, String.class);
                in = (org.omg.CORBA_2_3.portable.InputStream) _invoke(out);
                return (ServiceBase) PortableRemoteObject.narrow(in.read_Object(), ServiceBase.class);
            } catch (ApplicationException ex) {
                in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream();
                String $_id = in.read_string();
                throw new UnexpectedException($_id);
            } catch (RemarshalException ex) {
                return service(arg0, arg1, arg2);
            } finally {
                _releaseReply(in);
            }
        } catch (SystemException ex) {
            throw Util.mapSystemException(ex);
        }
    } else {
        ServantObject so = _servant_preinvoke("service__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue", JRouter.class);
        if (so == null) {
            return service(arg0, arg1, arg2);
        }
        try {
            ServiceBase result = ((JRouter) so.servant).service(arg0, arg1, arg2);
            return (ServiceBase) Util.copyObject(result, _orb());
        } catch (Throwable ex) {
            Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
            throw Util.wrapException(exCopy);
        } finally {
            _servant_postinvoke(so);
        }
    }
}
Also used : UnexpectedException(java.rmi.UnexpectedException) InputStream(org.omg.CORBA.portable.InputStream) OutputStream(org.omg.CORBA.portable.OutputStream) RemarshalException(org.omg.CORBA.portable.RemarshalException) ApplicationException(org.omg.CORBA.portable.ApplicationException) SystemException(org.omg.CORBA.SystemException) ServiceBase(j.service.server.ServiceBase) ServantObject(org.omg.CORBA.portable.ServantObject)

Example 3 with ServiceBase

use of j.service.server.ServiceBase in project JFramework by gugumall.

the class RouterAgent method serviceRmi.

/**
 * RouterManager通过均衡策略选择本路由节点代理,调用此方法从关联路由节点获得服务入口
 * @param clientUuid
 * @param code
 * @param md54Routing
 * @return
 * @throws Exception
 */
protected ServiceBase serviceRmi(String clientUuid, String code, String md54Routing) throws Exception {
    String cacheKey = "rmi|" + clientUuid + "|" + code;
    if (cache.containsKey(cacheKey)) {
        return (ServiceBase) cache.get(cacheKey);
    }
    if (this.routerConfig.getRmi() == null) {
        throw new Exception("router(rmi) is not supported.");
    }
    if (!routerRmiAvailable || servant == null) {
        throw new Exception("router(rmi) " + routerConfig.getUuid() + " is unavailable.");
    }
    ServiceBase obj = servant.service(clientUuid, code, md54Routing);
    cache.put(cacheKey, obj);
    return obj;
}
Also used : ServiceBase(j.service.server.ServiceBase) JUtilString(j.util.JUtilString) RemoteException(java.rmi.RemoteException)

Example 4 with ServiceBase

use of j.service.server.ServiceBase in project JFramework by gugumall.

the class _JRouter_Stub method getAllServiceNodeAvailable.

public ServiceBase[] getAllServiceNodeAvailable(String arg0, String arg1, String arg2) throws java.rmi.RemoteException {
    if (!Util.isLocal(this)) {
        try {
            org.omg.CORBA_2_3.portable.InputStream in = null;
            try {
                org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) _request("getAllServiceNodeAvailable__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue", true);
                out.write_value(arg0, String.class);
                out.write_value(arg1, String.class);
                out.write_value(arg2, String.class);
                in = (org.omg.CORBA_2_3.portable.InputStream) _invoke(out);
                return (ServiceBase[]) in.read_value(ServiceBase[].class);
            } catch (ApplicationException ex) {
                in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream();
                String $_id = in.read_string();
                throw new UnexpectedException($_id);
            } catch (RemarshalException ex) {
                return getAllServiceNodeAvailable(arg0, arg1, arg2);
            } finally {
                _releaseReply(in);
            }
        } catch (SystemException ex) {
            throw Util.mapSystemException(ex);
        }
    } else {
        ServantObject so = _servant_preinvoke("getAllServiceNodeAvailable__CORBA_WStringValue__CORBA_WStringValue__CORBA_WStringValue", JRouter.class);
        if (so == null) {
            return getAllServiceNodeAvailable(arg0, arg1, arg2);
        }
        try {
            ServiceBase[] result = ((JRouter) so.servant).getAllServiceNodeAvailable(arg0, arg1, arg2);
            return (ServiceBase[]) Util.copyObject(result, _orb());
        } catch (Throwable ex) {
            Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
            throw Util.wrapException(exCopy);
        } finally {
            _servant_postinvoke(so);
        }
    }
}
Also used : UnexpectedException(java.rmi.UnexpectedException) InputStream(org.omg.CORBA.portable.InputStream) OutputStream(org.omg.CORBA.portable.OutputStream) RemarshalException(org.omg.CORBA.portable.RemarshalException) ApplicationException(org.omg.CORBA.portable.ApplicationException) SystemException(org.omg.CORBA.SystemException) ServiceBase(j.service.server.ServiceBase) ServantObject(org.omg.CORBA.portable.ServantObject)

Example 5 with ServiceBase

use of j.service.server.ServiceBase in project JFramework by gugumall.

the class JRouterImpl method monitor.

/**
 * @param node
 */
private void monitor(Service node) {
    try {
        monitoring = true;
        ConcurrentMap servantsOfCluster = (ConcurrentMap) servantsOfClusters.get(node.clusterCode);
        ConcurrentMap httpsOfCluster = (ConcurrentMap) httpsOfClusters.get(node.clusterCode);
        if (servantsOfCluster == null) {
            servantsOfCluster = new ConcurrentMap();
            servantsOfClusters.put(node.clusterCode, servantsOfCluster);
        }
        if (httpsOfCluster == null) {
            httpsOfCluster = new ConcurrentMap();
            httpsOfClusters.put(node.clusterCode, httpsOfCluster);
        }
        boolean serviceRmiAvailable = true;
        if (node.rmi != null && !"".equals(node.rmi)) {
            Context context = null;
            try {
                Properties props = null;
                props = j.Properties.getProperties("rmi");
                props.put("java.naming.provider.url", node.rmi);
                context = new InitialContext(props);
            } catch (Exception e) {
                serviceRmiAvailable = false;
                context = null;
            // log.log(e,Logger.LEVEL_DEBUG);
            }
            ServiceBase servant = (ServiceBase) servantsOfCluster.get(node.uuid);
            if (serviceRmiAvailable) {
                try {
                    servant = (ServiceBase) context.lookup(node.uuid);
                    servantsOfCluster.put(node.uuid, servant);
                    if (!Constants.STATUS_OK.equals(servant.heartbeat())) {
                        throw new Exception("心跳不正常(rmi)");
                    }
                } catch (Exception e) {
                    servantsOfCluster.remove(node.uuid);
                    serviceRmiAvailable = false;
                    servant = null;
                // log.log(e,Logger.LEVEL_DEBUG);
                }
            } else {
                servantsOfCluster.remove(node.uuid);
                serviceRmiAvailable = false;
                servant = null;
            }
        } else {
            servantsOfCluster.remove(node.uuid);
            serviceRmiAvailable = false;
        }
        if (!serviceRmiAvailable) {
            log.log("service(rmi) " + node.clusterCode + "," + node.uuid + " is unavailable.", Logger.LEVEL_DEBUG);
        } else {
            log.log("service(rmi) " + node.clusterCode + "," + node.uuid + " is available(" + servantsOfCluster.size() + " nodes).", Logger.LEVEL_DEBUG);
        }
        boolean serviceHttpAvailable = true;
        if (node.http != null && !"".equals(node.http)) {
            try {
                String url = node.http;
                if (url.indexOf("?") > 0)
                    url += "&request=heartbeat";
                else
                    url += "?request=heartbeat";
                JHttpContext context = jhttp.get(null, jclient, url, SysConfig.sysEncoding);
                String result = context.getResponseText();
                context.finalize();
                context = null;
                if (!Constants.STATUS_OK.equals(result)) {
                    throw new Exception("心跳不正常(http)");
                } else {
                    httpsOfCluster.put(node.uuid, node);
                }
            } catch (Exception e) {
                httpsOfCluster.remove(node.uuid);
                serviceHttpAvailable = false;
            // log.log(e,Logger.LEVEL_DEBUG);
            }
        } else {
            httpsOfCluster.remove(node.uuid);
            serviceHttpAvailable = false;
        }
        if (!serviceHttpAvailable) {
            log.log("service(http) " + node.clusterCode + "," + node.uuid + " is unavailable.", Logger.LEVEL_DEBUG);
        } else {
            log.log("service(http) " + node.clusterCode + "," + node.uuid + " is available(" + httpsOfCluster.size() + " nodes).", Logger.LEVEL_DEBUG);
        }
        monitoring = false;
    } catch (Exception e) {
        monitoring = false;
        log.log(e, Logger.LEVEL_ERROR);
    }
}
Also used : InitialContext(javax.naming.InitialContext) JHttpContext(j.http.JHttpContext) Context(javax.naming.Context) JHttpContext(j.http.JHttpContext) ServiceBase(j.service.server.ServiceBase) ConcurrentMap(j.util.ConcurrentMap) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) RemoteException(java.rmi.RemoteException)

Aggregations

ServiceBase (j.service.server.ServiceBase)10 RemoteException (java.rmi.RemoteException)6 ConcurrentMap (j.util.ConcurrentMap)3 SystemException (org.omg.CORBA.SystemException)3 InputStream (org.omg.CORBA.portable.InputStream)3 OutputStream (org.omg.CORBA.portable.OutputStream)3 Client (j.service.Client)2 ServiceContainer (j.service.server.ServiceContainer)2 ConcurrentList (j.util.ConcurrentList)2 JUtilString (j.util.JUtilString)2 UnexpectedException (java.rmi.UnexpectedException)2 List (java.util.List)2 HttpClient (org.apache.http.client.HttpClient)2 ApplicationException (org.omg.CORBA.portable.ApplicationException)2 RemarshalException (org.omg.CORBA.portable.RemarshalException)2 ServantObject (org.omg.CORBA.portable.ServantObject)2 JSession (j.app.webserver.JSession)1 JHttpContext (j.http.JHttpContext)1 Properties (java.util.Properties)1 Context (javax.naming.Context)1