private void loadAppServants(ApplicationContext applicationContext) { Map<String, ServantConfig> servantMap = applicationContext.getBeansOfType(ServantConfig.class); for (Map.Entry<String, ServantConfig> entry : servantMap.entrySet()) { try { ServantHomeSkeleton skeleton = loadServant(entry.getValue()); skeletonMap.put(skeleton.name(), skeleton); appServantStarted(skeleton); } catch (Exception e) { System.err.println("init a service failed"); e.printStackTrace(); } } }
public Object invoke(Method method, Object... args) throws Exception { Object value = null; try { preInvokeCapHomeSkeleton(); value = method.invoke(this.servantImpl, fixParamValueType(method, args)); } finally { if (!ContextManager.getContext().response().isAsyncMode()) { postInvokeCapHomeSkeleton(); } } return value; }
private Object[] fixParamValueType(Method method, Object args[]) { if (args == null || args.length == 0) return args; Class<?> parameterTypes[] = method.getParameterTypes(); if (parameterTypes == null || parameterTypes.length == 0) return args; if (args.length != parameterTypes.length) return args; for (int i = 0; i < parameterTypes.length; i++) { args[i] = fixValueDataType(parameterTypes[i], args[i]); } return args; }
void initServants() { for (String skeletonName : skeletonMap.keySet()) { ServantHomeSkeleton skeleton = skeletonMap.get(skeletonName); Class<?> api = skeleton.getApiClass(); try { if (api.isAssignableFrom(ExtendedServant.class)) { continue; } AnalystManager.getInstance().registry(name(), api, skeleton.name()); } catch (Exception e) { System.err.println("app[] init servant[" + api.getName() + "] failed"); e.printStackTrace(); } } }
void injectAdminServant() { try { String skeletonName = OmConstants.AdminServant; ServantHomeSkeleton skeleton = new ServantHomeSkeleton(skeletonName, new AdminFServantImpl(), AdminFServant.class, null, null, -1); skeleton.setAppContext(this); ServerConfig serverCfg = ConfigurationManager.getInstance().getServerConfig(); ServantAdapterConfig config = serverCfg.getServantAdapterConfMap().get(OmConstants.AdminServant); ServantAdapter servantAdapter = new ServantAdapter(config); servantAdapter.bind(skeleton); servantAdapterMap.put(skeletonName, servantAdapter); skeletonMap.put(skeletonName, skeleton); } catch (Exception e) { System.err.println("init om service failed:context=[]"); e.printStackTrace(); } }
private Codec createCodec(ServerConfig serverCfg) throws TarsException { Codec codec = null; Class<? extends Codec> codecClass = skeleton.getCodecClass(); if (codecClass == null) { ServantCodec servantCodec = skeleton.getApiClass().getAnnotation(ServantCodec.class); if (servantCodec != null) { codecClass = servantCodec.codec(); } } if (codecClass == null) { codecClass = TarsCodec.class; } if (codecClass != null) { Constructor<? extends Codec> constructor; try { constructor = codecClass.getConstructor(new Class[] { String.class }); codec = constructor.newInstance(serverCfg.getCharsetName()); } catch (Exception e) { throw new TarsException("error occurred on create codec, codec=" + codecClass.getName()); } } return codec; }
if (skeleton == null) throw new RuntimeException("failed to find the servant named[" + servantName + "]"); Method method = skeleton.getApiClass().getMethods()[0]; skeleton.invoke(method, request, response); } catch (Throwable cause) {
void injectAdminServant() { try { String skeletonName = OmConstants.AdminServant; ServantHomeSkeleton skeleton = new ServantHomeSkeleton(skeletonName, new AdminFServantImpl(), AdminFServant.class, null, null, -1); skeleton.setAppContext(this); ServerConfig serverCfg = ConfigurationManager.getInstance().getServerConfig(); ServantAdapterConfig config = serverCfg.getServantAdapterConfMap().get(OmConstants.AdminServant); ServantAdapter servantAdapter = new ServantAdapter(config); servantAdapter.bind(skeleton); servantAdapterMap.put(skeletonName, servantAdapter); skeletonMap.put(skeletonName, skeleton); } catch (Exception e) { System.err.println("init om service failed:context=[]"); e.printStackTrace(); } }
void initServants() { for (String skeletonName : skeletonMap.keySet()) { ServantHomeSkeleton skeleton = skeletonMap.get(skeletonName); Class<?> api = skeleton.getApiClass(); try { if (api.isAssignableFrom(ExtendedServant.class)) { continue; } AnalystManager.getInstance().registry(name(), api, skeleton.name()); } catch (Exception e) { System.err.println("app[] init servant[" + api.getName() + "] failed"); e.printStackTrace(); } } }
private Codec createCodec(ServerConfig serverCfg) throws TarsException { Codec codec = null; Class<? extends Codec> codecClass = skeleton.getCodecClass(); if (codecClass == null) { ServantCodec servantCodec = skeleton.getApiClass().getAnnotation(ServantCodec.class); if (servantCodec != null) { codecClass = servantCodec.codec(); } } if (codecClass == null) { codecClass = TarsCodec.class; } if (codecClass != null) { Constructor<? extends Codec> constructor; try { constructor = codecClass.getConstructor(new Class[] { String.class }); codec = constructor.newInstance(serverCfg.getCharsetName()); } catch (Exception e) { throw new TarsException("error occurred on create codec, codec=" + codecClass.getName()); } } return codec; }
if (skeleton == null) throw new RuntimeException("failed to find the servant named[" + servantName + "]"); Method method = skeleton.getApiClass().getMethods()[0]; skeleton.invoke(method, request, response); } catch (Throwable cause) {
private ServantHomeSkeleton loadServant(Object bean) throws Exception { String homeName; Class<?> homeApiClazz = null; Object homeClassImpl; ServantHomeSkeleton skeleton; int maxLoadLimit = -1; ServerConfig serverCfg = ConfigurationManager.getInstance().getServerConfig(); homeName = bean.getClass().getAnnotation(TarsServant.class).name(); if (StringUtils.isEmpty(homeName)) { throw new RuntimeException("servant name is null."); } homeName = String.format("%s.%s.%s", serverCfg.getApplication(), serverCfg.getServerName(), homeName); for (Class clazz : bean.getClass().getInterfaces()) { if (clazz.isAnnotationPresent(Servant.class)) { homeApiClazz = clazz; break; } } homeClassImpl = bean; if (TarsHelper.isServant(homeApiClazz)) { String servantName = homeApiClazz != null ? homeApiClazz.getAnnotation(Servant.class).name() : null; if (!StringUtils.isEmpty(servantName) && servantName.matches("^[\\w]+\\.[\\w]+\\.[\\w]+$")) { homeName = servantName; } } skeleton = new ServantHomeSkeleton(homeName, homeClassImpl, homeApiClazz, null, null, maxLoadLimit); skeleton.setAppContext(this); ConfigurationManager.getInstance().getServerConfig().getServantAdapterConfMap().put(homeName, servantAdapterConfig); return skeleton; }
private void loadAppServants() { Map<String, Object> servantMap = applicationContext.getBeansWithAnnotation(TarsServant.class); for (Map.Entry<String, Object> entry : servantMap.entrySet()) { try { ServantHomeSkeleton skeleton = loadServant(entry.getValue()); skeletonMap.put(skeleton.name(), skeleton); appServantStarted(skeleton); } catch (Exception e) { log.error("load servant faild", e); } } }
public Object invoke(Method method, Object... args) throws Exception { Object value = null; try { preInvokeCapHomeSkeleton(); value = method.invoke(this.servantImpl, fixParamValueType(method, args)); } finally { if (!ContextManager.getContext().response().isAsyncMode()) { postInvokeCapHomeSkeleton(); } } return value; }
private Object[] fixParamValueType(Method method, Object args[]) { if (args == null || args.length == 0) return args; Class<?> parameterTypes[] = method.getParameterTypes(); if (parameterTypes == null || parameterTypes.length == 0) return args; if (args.length != parameterTypes.length) return args; for (int i = 0; i < parameterTypes.length; i++) { args[i] = fixValueDataType(parameterTypes[i], args[i]); } return args; }
skeleton = new ServantHomeSkeleton(homeName, homeClassImpl, homeApiClazz, codecClazz, processorClazz, maxLoadLimit); skeleton.setAppContext(this); ServerAdapter.bind(skeleton); servantAdapterMap.put(homeName, ServerAdapter);
private void loadAppServants() { Map<String, Object> servantMap = applicationContext.getBeansWithAnnotation(TarsServant.class); for (Map.Entry<String, Object> entry : servantMap.entrySet()) { try { ServantHomeSkeleton skeleton = loadServant(entry.getValue()); skeletonMap.put(skeleton.name(), skeleton); appServantStarted(skeleton); } catch (Exception e) { System.err.println("init a Servant failed"); e.printStackTrace(); } } }
skeleton = new ServantHomeSkeleton(homeName, homeClassImpl, homeApiClazz, codecClazz, processorClazz, maxLoadLimit); skeleton.setAppContext(this); ServerAdapter.bind(skeleton); servantAdapterMap.put(homeName, ServerAdapter);
private void loadAppServants(ArrayList<XMLConfigElement> elements) throws ClassNotFoundException, InstantiationException, IllegalAccessException { for (XMLConfigElement element : elements) { if ("servant".equals(element.getName())) { try { ServantHomeSkeleton skeleton = loadServant(element); skeletonMap.put(skeleton.name(), skeleton); appServantStarted(skeleton); } catch (Exception e) { System.err.println("init a service failed:context=[]"); } } } }
skeleton = new ServantHomeSkeleton(homeName, homeClassImpl, homeApiClazz, codecClazz, processorClazz, maxLoadLimit); skeleton.setAppContext(this); ServerAdapter.bind(skeleton); servantAdapterMap.put(homeName, ServerAdapter);