Exemplo n.º 1
0
        /// <summary>
        /// Configure the CacheFactory.
        /// </summary>
        /// <param name="xmlCache">
        /// An optional <see cref="IXmlElement"/> that conforms to
        /// <c>cache-config.xsd</c>.
        /// </param>
        /// <param name="xmlCoherence">
        /// An optional <see cref="IXmlElement"/> that conforms to
        /// <c>coherence.xsd</c>.
        /// </param>
        /// <since>Coherence 3.7</since>
        public static void Configure(IXmlElement xmlCache, IXmlElement xmlCoherence)
        {
            // create an IOperationalContext
            var ctx = new DefaultOperationalContext(xmlCoherence);

            // create a IConfigurableCacheFactory
            var xmlFactory = ctx.Config.GetSafeElement("configurable-cache-factory-config");
            var typeName   = xmlFactory.GetSafeElement("class-name").GetString(null);
            IConfigurableCacheFactory factory;

            if (typeName == null)
            {
                factory = new DefaultConfigurableCacheFactory(xmlCache);
            }
            else
            {
                var type  = TypeResolver.Resolve(typeName);
                var param = XmlHelper.ParseInitParams(
                    xmlFactory.GetSafeElement("init-params"));

                factory = (IConfigurableCacheFactory)
                          ObjectUtils.CreateInstance(type, param);
            }
            if (factory is DefaultConfigurableCacheFactory)
            {
                ((DefaultConfigurableCacheFactory)factory).OperationalContext = ctx;
            }

            Configure(factory, ctx);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Configure the CacheFactory.
        /// </summary>
        /// <param name="factory">
        /// The rquired singleton <see cref="IConfigurableCacheFactory"/>.
        /// </param>
        /// <param name="ctx">
        /// An optional <see cref="IOperationalContext"/> that contains
        /// operational configuration information.
        /// </param>
        /// <since>Coherence 3.7</since>
        public static void Configure(IConfigurableCacheFactory factory,
                                     IOperationalContext ctx)
        {
            // validate input parameters
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            lock (typeof(CacheFactory))
            {
                IConfigurableCacheFactory factoryOld = s_factory;
                if (factoryOld != null)
                {
                    // shutdown the old factory
                    factoryOld.Shutdown();
                }

                Logger logger = s_logger;
                if (ctx != null && logger != null)
                {
                    // switch to a new logger
                    logger.Shutdown();
                    logger = null;
                }

                if (logger == null)
                {
                    // create, configure, and start a new logger
                    if (ctx == null)
                    {
                        ctx = new DefaultOperationalContext();
                    }
                    logger = new Logger();
                    logger.Configure(ctx);
                    logger.Start();

                    // output the product startup banner
                    logger.Log((int)LogLevel.Always,
                               string.Format("\n{0} Version {1} Build {2}\n {3} Build\n{4}\n",
                                             logger.Product,
                                             logger.Version,
                                             logger.BuildInfo,
                                             logger.Edition + " " + logger.BuildType,
                                             logger.Copyright), null);

                    IList initLogMessages = s_initLogMessages;
                    lock (initLogMessages)
                    {
                        foreach (object[] logMessage in initLogMessages)
                        {
                            var message  = (string)logMessage[0];
                            var exc      = (Exception)logMessage[1];
                            var severity = (LogLevel)logMessage[2];
                            logger.Log((int)severity, exc, message, null);
                        }
                        initLogMessages.Clear();
                    }
                }

                if (factory.Config is IXmlDocument)
                {
                    IXmlDocument doc = (IXmlDocument)factory.Config;
                    doc.IterateThroughAllNodes(PreprocessProp);
                    factory.Config = doc;
                }
                else
                {
                    XmlDocument tempDoc = new XmlDocument();
                    tempDoc.LoadXml(factory.Config.GetString());
                    IXmlDocument doc = XmlHelper.ConvertDocument(tempDoc);
                    doc.IterateThroughAllNodes(PreprocessProp);
                    factory.Config = doc;
                }

                // update all singletons
                s_factory = factory;
                s_logger  = logger;
            }
        }