public static synchronized UnifyContainer startup(UnifyContainerEnvironment uce, UnifyContainerConfig ucc) throws UnifyException { if (uc != null) { throw new UnifyException(UnifyCoreErrorConstants.CONTAINER_IN_RUNTIME); } try { uc = new UnifyContainer(); uc.startup(uce, ucc); } catch (UnifyException e) { uc = null; throw e; } catch (Exception e) { uc = null; throw new UnifyException(e, UnifyCoreErrorConstants.CONTAINER_STARTUP_ERROR); } return uc; }
/** * Gets a component by name. If a component is configured as a singleton, this * method would always return the same instance for specified name, otherwise a * new component instance is always created. * * @param name * the component name * @return the component * @throws UnifyException * if container is not started. If component with name is unknown. * If component instantiation error occurs. */ public UnifyComponent getComponent(String name) throws UnifyException { return getComponent(name, null, null); }
/** * Gets component configuration by name. * * @param name * the component name * @return the component configuration if found, otherwise null. * @throws UnifyException * if container is not started. If an error occurs */ public UnifyComponentConfig getComponentConfig(String name) throws UnifyException { checkStarted(); InternalUnifyComponentInfo iuci = getInternalUnifyComponentInfo(name); if (iuci != null) { return iuci.getUnifyComponentConfig(); } return null; }
public static synchronized void shutdown(String accessKey) throws UnifyException { Unify.getContainer(); if (!uc.getAccessKey().equals(accessKey)) { throw new UnifyException(UnifyCoreErrorConstants.INVALID_CONTAINER_RUNTIME_ACCESSKEY); } uc.shutdown(); uc = null; }
List<String> banner = getApplicationBanner(); if (!banner.isEmpty()) { for (String line : banner) { toConsole(line); new ApplicationContext(this, Locale.getDefault(), lineSeparator != null ? lineSeparator : "\n"); long startTimeMillis = System.currentTimeMillis(); initializeContainerMessages(); initializeContainerLogger(); toConsole("Container initialization started..."); toConsole("Validating and loading configuration..."); for (UnifyComponentConfig unifyComponentConfig : ucc.getComponentConfigs()) { logDebug("Detecting and replacing customized components..."); getSetting(UnifyCorePropertyConstants.APPLICATION_CUSTOMIZATION), null); internalResolutionMap = UnifyConfigUtils.resolveConfigurationOverrides(internalUnifyComponentInfos, customizationSuffixList); logDebug("Detecting business service components..."); Map<String, Map<String, Periodic>> componentPeriodMethodMap = new HashMap<String, Map<String, Periodic>>(); Map<String, Set<String>> componentPluginSocketsMap = new HashMap<String, Set<String>>(); logDebug("Periodic methods detected for component '" + iuci.getName() + "'."); componentPeriodMethodMap.put(iuci.getName(), periodicMethodMap); logDebug("Plug-in sockets detected for component '" + iuci.getName() + "'."); componentPluginSocketsMap.put(iuci.getName(), pluginSockets);
unifyContainer = new UnifyContainer(); unifyContainer.startup(uce, ucc); requestContextManager = (RequestContextManager) unifyContainer .getComponent(ApplicationComponents.APPLICATION_REQUESTCONTEXTMANAGER); applicationController = (ApplicationController) unifyContainer .getComponent(WebApplicationComponents.APPLICATION_HTTPCONTROLLER); userSessionManager = (UserSessionManager) unifyContainer .getComponent(ApplicationComponents.APPLICATION_USERSESSIONMANAGER); } catch (Exception e) { if (unifyContainer != null && unifyContainer.isStarted()) { unifyContainer.shutdown();
if (broadcastInfo != null) { List<String> params = clusterCommand.getParams(); broadcastInfo.getMethod().invoke(getComponent(broadcastInfo.getComponentName()), new Object[] { params.toArray(new String[params.size()]) }); String command = cc.getCommand(); if ("shutdown".equalsIgnoreCase(command)) { shutdown();
Class<?> arrFieldClass = fieldClass.getComponentType(); if (UnifyComponent.class.isAssignableFrom(arrFieldClass)) { Object[] tempArray = getComponents(arrFieldClass, configValues).values().toArray(); valueToInject = Array.newInstance(arrFieldClass, tempArray.length); for (int i = 0; i < tempArray.length; i++) { if (UnifyComponent.class.isAssignableFrom(colFieldClass)) { Collection<Object> c = new ArrayList<Object>(); c.addAll(getComponents((Class<? extends UnifyComponent>) colFieldClass, configValues).values()); valueToInject = c; Class<?> valFieldClass = ReflectUtils.getArgumentType(field.getGenericType(), 1); if (UnifyComponent.class.isAssignableFrom(valFieldClass)) { valueToInject = getComponents((Class<? extends UnifyComponent>) valFieldClass, configValues); valueToInject = getComponent(configValues[0]);
private UnifyComponent getComponent(String name, UnifyComponentSettings altSettings, UplElementAttributes uplElementAttributes) throws UnifyException { checkStarted(); UnifyComponent unifyComponent = null; try { UnifyComponentConfig unifyComponentConfig = null; InternalUnifyComponentInfo iuci = getInternalUnifyComponentInfo(name); if (iuci != null) { unifyComponentConfig = iuci.getUnifyComponentConfig(); iuci = getInternalUnifyComponentInfo(actualName); initializeComponent(unifyComponentConfig, altSettings, unifyComponent, uplElementAttributes);
if (!shutdown) { shutdown = true; logInfo("Shutting down container..."); closeInterfaces(); } catch (Exception e) { componentContextMap = null; logInfo("Container shutdown completed.");
/** * Broadcasts a cluster command to other nodes. * * @param command * the command to braodcast * @param params * the command parameters * @throws UnifyException * if an error occurs */ public void broadcastToOtherNodes(String command, String... params) throws UnifyException { applicationContext.getContainer().broadcastToOtherNodes(command, params); }
/** * Sends a message to the application container. * * @param command * the command to send * @param params * the command parameters * @throws UnifyException * if an error occurs */ public void sendCommand(String command, String... params) throws UnifyException { applicationContext.getContainer().command(command, params); }
/** * Broadcasts attribute to all sessions in this node. * * @param name * the attribute name * @param value * the attribute value. A null value clears attribute. * @throws UnifyException * if an error occurs */ public void broadcastToSessions(String name, Object value) throws UnifyException { applicationContext.getContainer().broadcastToSessions(name, value); }
/** * Broadcasts attribute to specific application session context in this node. * * @param sessionId * the session ID * @param name * the attribute name * @param value * the attribute value. A null value clears attribute. * @throws UnifyException * if an error occurs */ public void broadcastToSession(String sessionId, String name, Object value) throws UnifyException { applicationContext.getContainer().broadcastToSession(sessionId, name, value); }
/** * Gets all component configurations with types that extend or implement * specific component type. * * @param componentType * the component types to match * @return a list of component configurations that match with supplied type. * @throws UnifyException * if container is not started. */ public List<UnifyComponentConfig> getComponentConfigs(Class<? extends UnifyComponent> componentType) throws UnifyException { checkStarted(); List<UnifyComponentConfig> configList = new ArrayList<UnifyComponentConfig>(); for (InternalUnifyComponentInfo iuc : internalUnifyComponentInfos.values()) { if (componentType.isAssignableFrom(iuc.getType())) { configList.add(iuc.getUnifyComponentConfig()); } } return configList; }
/** * Gets a component by name using alternate settings. Applies to non-singletons * only.. * * @param name * the component name * @param altSettings * the alternate settings * @return the component * @throws UnifyException * if container is not started. If component with name is unknown. * If component is a singleton. If component instantiation error * occurs. */ public UnifyComponent getComponent(String name, UnifyComponentSettings altSettings) throws UnifyException { return getComponent(name, altSettings, null); }
private RequestContextManager getRequestContextManager() throws UnifyException { if (requestContextManager == null) { requestContextManager = (RequestContextManager) applicationContext.getContainer() .getComponent(ApplicationComponents.APPLICATION_REQUESTCONTEXTMANAGER); } return requestContextManager; } }
@SuppressWarnings("unchecked") private <T> Map<String, T> getComponents(Class<T> type, String[] names) throws UnifyException { Map<String, T> map = new LinkedHashMap<String, T>(); for (String name : names) { UnifyComponent component = getComponent(name); if (!type.isAssignableFrom(component.getClass())) { throw new UnifyException(UnifyCoreErrorConstants.FIELD_INJECTION_INCOMPATIBLE, type, component.getClass()); } map.put(name, (T) component); } return map; }
/** * Gets component by name. * * @param name * the component name * @return the component with name * @throws UnifyException * If component is unknown. If an error occurs */ public UnifyComponent getComponent(String name) throws UnifyException { return applicationContext.getContainer().getComponent(name); }