Create master configuration file using JESConfigurationContext.dtd (DTD) or JESConfigurationContext.xsd (XML Schema) file, for example, refer to JESConfig.xml
Better way is to start editing the existing JESConfig.xml file. Just check out the sample Master Configuration File with Appropriate highlights for better understanding.
<?xml version="1.0" encoding="UTF-8"?> <ConfigurationContext xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\jes\config\JesConfigurationContext.xsd"> <ExecutionContext> <!-- Replace tags are global variables, which can be used across various component based configuration files inclusive of this file --> <ReplaceTags> <CustomProperty Name="AdminServerIP" Value="127.0.0.1"/> <CustomProperty Name="GlobalConfigDir" Value="d:\jes\config"/> <CustomProperty Name="LocalConfigDir" Value="D:\jes\localconfig"/> </ReplaceTags> </ExecutionContext> <!-- Default Configuration Server Configuration Information, Most often, you might not have to change this section --> <ServerContext Name="JESConfigurationContext" ApplicationName="JES Framework" Company="jes.sourceforge.net" Version="0.5 POC" Date="December 27,2003"> <Settings> <!-- The below mentioned port needs to be allowed by firwall--> <CommandPort>1005</CommandPort> <!-- The polling interval to determine,if files have changed --> <FileScanInterval>1000</FileScanInterval> <!-- Interval to clean up stale listeners --> <ListenerCleanupInterval>10000</ListenerCleanupInterval> <!-- EventBroadcaster is an abstraction over the transport layer. The default is an RMI based Broadcaster,one can have one or more broadcaster registered --> <BroadcastHandlers> <BroadcastHandler ID="RMIBroadcast"> <ClassName>org.jes.es.configurationserver.RMIEventBroadCaster</ClassName> <CustomProperty Name="RMIAdminServerHost" Value="${AdminServerIP}"/> <CustomProperty Name="RMIAdminServerPort" Value="1005"/> </BroadcastHandler> </BroadcastHandlers> <!-- Current Default Chain uses an RMI based Transport Layer--> <BroadcastChain> <BroadcastChainHandler HandlerID="RMIBroadcast"/> </BroadcastChain> <!-- UnMarshaller Handlers are custom Handlers, which parse configuration files and construct Configurator Object, A Custom UnMarshaller Handler can be a XML Handler, Database Handler, etc. However, Monitoring Non file based configuration sources is not currently supported ---> <UnmarshallerHandlers> <!-- XML UnMarshaller Handler using Castor Java XML binding package --> <UnmarshallerHandler ID="UMCastor" ClassName="org.jes.es.configurationserver.CastorUnmarshaller"/> </UnmarshallerHandlers> </Settings> </ServerContext> <!-- Context/Placeholder to declare configuration files and events for individual components --> <ServiceContext> <!-- Configuration Entry for JES Environment Service, This service sets environmental variables Options ID - Needs to be unique Target - ALL / (Or any Logical Name, You Wish to use ) ServiceName - Needs to be unique,Represents the service offered by the component Component Name - Logical Name of the Component ConfigurationXMLFilePath - Configuration File Path (Based on JESFormat i.e. following grammer defined in ServiceConfiguration.xsd) ConfiguratorClassName - Component's Configurator Class name i.e. Configuration Class extending JES's Configurator class CallbackClassName - Component's Classback Implementation Classname i.e. implementation of ComponentCallbackHandler Interface Startup - True | False, If True, callback is given when Configuration Manager is instantiated. Reload - ServiceFileChangeOnly | ReplicatedFileChangeOnly | Both | None Destroy - True | False --> <Service ID="JESEnvironmentService" Target="All"> <ServiceName>EnvironmentService</ServiceName> <ComponentName>JESEnvironmentProvider</ComponentName> <ConfigurationXMLFilePath> ${GlobalConfigDir}\JESEnvConfig.xml </ConfigurationXMLFilePath> <ConfiguratorClassName> org.jes.es.environment.EnvironmentConfigurator </ConfiguratorClassName> <CallbackClassName Startup="True" Reload="Both" Destroy="False">org.jes.es.environment.EnvironmentCallback </CallbackClassName> </Service> <!-- A Sample Configuration Entry for Logger, It is a hoax, doesn't log, just for demonstration, Just check out this example, to see how custom UNMarshaller handler has been used --> <Service ID="JESLoggingService" Target="WebApp"> <ServiceName>Logging Service</ServiceName> <ComponentName>JES Logger</ComponentName> <ConfigurationXMLFilePath> ${GlobalConfigDir}\JESLoggingConfig.xml </ConfigurationXMLFilePath> <ConfiguratorClassName> org.jes.es.logger.LoggerConfigurator </ConfiguratorClassName> <CallbackClassName Destroy="True" Reload="ServiceFileChangeOnly" Startup="True">org.jes.es.logger.LoggerCallbackHandler </CallbackClassName> <UnmarshallerInfo Timing="Server" UnmarshallerXMLFile="${GlobalConfigDir}\JESLoggingContext.xml" UnmarshallerClassName="org.jes.es.logger.config.LoggingContext" HandlerID="UMCastor" UnmarshallerTargetXMLFile="${LocalConfigDir}\JESLoggingContext.xml"/> </Service> </ServiceContext> </ConfigurationContext>
Create application component configuration file using ServiceConfiguration.dtd (DTD) or ServiceConfiguration.xsd(XML Schema) file, for example, refer to JESConfig.xml
Better way is to start editing or add the content to existing JESEnvConfig.xml file, the environment service is reusable. Alternatively you can also look at JESLoggingConfig.xml file.
Just Checkout simple configuration file below.
<?xml version="1.0" encoding="UTF-8"?> <ServiceConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="c:\jes\doc\config\ServiceConfiguration.xsd"> <PropertyGroup Name="SETTINGS"> <Property Name="DISPLAY_VALUES">true</Property> </PropertyGroup> <PropertyGroup Name="GLOBAL"> <Property Name="JESGLBLPROP1">JESGLBLPROP1Value</Property> <Property Name="JESGLBLPROP2">JESGLBLPROP1Value</Property> </PropertyGroup> <PropertyGroup Name="WebApp"> <Property Name="JESWEBAPPPROP1">JESGLBLPROP1Value</Property> <Property Name="JESWEBAPPPROP2">JESGLBLPROP1Value</Property> </PropertyGroup> </ServiceConfiguration>
The configurator objects are java object representation of the configuration information. There are two ways to create a Configuator Object By extending org.jes.es.configurationserver.Configurator and providing appropriate encapsulated methods to access configuration information parts.
Note: It very Property or PropertyGroup is addressable or accessible with key, the key represents namespace path within the configuration xml file.
To access a PropertyGroup called "Global" for the above example
private static final String GLOBAL_PARAMETERS_KEY = " GLOBAL "; /** * Returns Global Parameters list * @return HashMap */ public HashMap getGlobalParameters() { HashMap globalParameters = null; globalParameters = getPropertyGroup (GLOBAL_PARAMETERS_KEY); return globalParameters; }
To access a Property called "DISPLAY_VALUES" for the above example
private static final String DISPLAY_VALUES_PARAMETERS_KEY = " SETTINGS.DISPLAY_VALUES "; /** * Returns Global Parameters list * @return String */ public String getDisplayValues() { String displayValue = null; displayValue = getProperty (DISPLAY_VALUES _PARAMETERS_KEY); return displayValue; }
The simplest and recommended way to create Configurator Objects is by using the JES Configurator Generator tool, the usage of the same is shown below
java org.jes.es.configurationserver.util.configuratorcodegenerator.CodeGenerator [Options]> Usage: Option <value> Options -i <Input Service Configuration File> -t <template> -d <destination> -p <packageName> -c <classname> -dsid <default Service Id> -esid <Environment Service Id, A service ID can intern be referenced from Env Variable> -a [author] -v [version]
To get a handle of Configurator objects, the configuration framework provides a locator class called org.jes.es.configurationserver.ConfiguratorLocator, this is a singleton object, and hence one need to get handle to this locator object, thru which one get a handle to respective configurator object for an associate service id.
A code snippet for obtaining configurator object
private static final String CONFIGURATOR_ENV_SERVICE_ID_KEY = "JESSRVCENV"; private static final String CONFIGURATOR_DEFAULT_SERVICE_ID = "JESEnvironmentService"; /** * Returns Configurator for Environment Component * @return EnvironmentConfigurator */ public static EnvironmentConfigurator getConfigurator() { EnvironmentConfigurator configurator = null; // Resolve ServiceID String serviceID = System.getProperty(CONFIGURATOR_ENV_SERVICE_ID_KEY); if ((serviceID == null) || (serviceID.trim().length() == 0)) { serviceID = CONFIGURATOR_DEFAULT_SERVICE_ID; } //Get Configurator ConfiguratorLocator configLocator = ConfiguratorLocator.getReference(); configurator = (EnvironmentConfigurator) configLocator.getConfigurator(serviceID); return configurator; }
Note: It is recommended to have the above mentioned method as part of the application configurator class, the above access method is also generated using the JES configurator Code generation tool
JES Provides with a command line interface (CLI) to start configuration server, it easy to embedded starting of Configuration Server into any scripting language, J2EE application servers startup features (Ex. Weblogic (T3Startup), WebSphere (Generic Services))
Program: org.jes.es.configurationserver.startup.ConfigurationServerStartup VM Arguments: -DJESConfigFilePath=c:\JES\doc\config\JESConfig.xml
Note: Ensure that jes.jar and requied dependent jars are path of the classpath.
JES Configuration Manager is intended to be embedded in the clients application be it an application server or webserver or any java application.
The ConfigurationManager is a singleton class and instance of it can be created by just referencing it as shown below
// Import Statement import org.jes.es.configurationserver.ConfigurationManager; //Getting the instance of ConfigurationManager ConfigurationManager manager = ConfigurationManager.getReference();
The above code can be embedded in Servlet Initial Config or Weblogic T3 Startup Script or Websphere Generic Services
However, the following parameters need to be supplied for the configuration manager to function, these parameters are:-
The above parameters can be either supplied by setting the environment variables or passing them as VM arguments for Java runtime
JES Configuration Server Address
JESADMINURL=rmi://<ConfigurationServer IP Address>:<RMI Port>
Where admin address URL depends largely on the transport layer used, the default transport is RMI and above URL format should hold good. Please ensure that port number is the same as the one mentioned in master configuration file.
JES Configuration Manager Node Name
JESNODENAME=<.Unique or Group Name>
The node name provides an ability to name a configuration manager instance, the name can be unique in cluster or grid or can be a group name.
example: The node name can be "Webapp", where there are multiple instances of web application running with in a cluster. In this case all the nodes with "WebApp" will have the same configuration information.
Passing parameters as VM arguments
-DJESADMINURL=rmi://10.0.0.5:1005 -DJESNODENAME=WebApp
JES Configuration Server provides a remote utility to stop JES Configuration Server and all instances of JES Configuration Manager instances connected to it.
Program:org.jes.es.configurationserver.util.CSRemoteControl Program Arguments: open [hostname] [port]
Where hostname and port are JESConfiguration Server's IP address and RMI Port
On successful execution of the above command, the RemoteControl shall display a prompt as shown below, type in "stop" followed by "quit"
jes>stop jes>qui