http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndex.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndex.cs b/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndex.cs deleted file mode 100644 index 2ec1084..0000000 --- a/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndex.cs +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections; -using System.Configuration; -using System.IO; -using System.Xml; - -namespace Lucene.Net.Distributed.Configuration -{ - /// <summary> - /// Definition of a configurable search index made accessible by the - /// LuceneServer windows service. - /// - /// An example configuration would look like the following: - /// <code> - /// <LuceneServerIndexes Port="1089"> - /// <LuceneServerIndex ObjectUri="RemoteIndexes1"> - /// <Directory indexA="c:\lucene\indexA\index1" indexB="c:\lucene\indexB\index1" /> - /// <Directory indexA="c:\lucene\indexA\index2" indexB="c:\lucene\indexB\index2" /> - /// </LuceneServerIndex> - /// <LuceneServerIndex ObjectUri="RemoteIndexes2"> - /// <Directory indexA="c:\lucene\indexA\index3" indexB="c:\lucene\indexB\index3" /> - /// <Directory indexA="c:\lucene\indexA\index4" indexB="c:\lucene\indexB\index4" /> - /// </LuceneServerIndex> - /// </LuceneServerIndexes> - /// </code> - /// </summary> - public class LuceneServerIndex - { - private string _strObjectUri; - private int _intPort; - private DirectoryInfo[] _arIndexADirectories; - private DirectoryInfo[] _arIndexBDirectories; - private DirectoryInfo[] _arRefreshDirectories; - - /// <summary> - /// Public constructor for LuceneServerIndex. A LuceneServerIndex is defined - /// in XML configuration and is loaded via a custom configuration handler. - /// </summary> - /// <param name="xSection">The Xml definition in the configuration file</param> - /// <param name="defaultPort">The default Port value, as defined in the contained - /// LuceneServerIndexes configuration</param> - public LuceneServerIndex(XmlNode xSection, int defaultPort) - { - XmlAttributeCollection attributeCollection = xSection.Attributes; - try - { - this._strObjectUri = attributeCollection["ObjectUri"].Value; - } - catch (Exception) - { - throw new ConfigurationErrorsException("ObjectUri invalid: "+Environment.NewLine + xSection.OuterXml); - } - - try - { - this._intPort = (attributeCollection["port"] != null ? Convert.ToInt32(attributeCollection["port"].Value) : defaultPort); - } - catch (Exception) - { - throw new ConfigurationErrorsException("port invalid: " + Environment.NewLine + xSection.OuterXml); - } - - if (xSection.ChildNodes.Count == 0) - throw new ConfigurationErrorsException("LuceneServerIndex configuration missing: " + Environment.NewLine + xSection.OuterXml); - - _arIndexADirectories = new DirectoryInfo[xSection.ChildNodes.Count]; - _arIndexBDirectories = new DirectoryInfo[xSection.ChildNodes.Count]; - DirectoryInfo diA; - DirectoryInfo diB; - int x=0; - - foreach (XmlNode c in xSection.ChildNodes) - { - if (c.Name.ToLower()=="directory") - { - try - { - diA = new DirectoryInfo(c.Attributes["indexA"].Value); - _arIndexADirectories[x] = diA; - if (!diA.Exists) - throw new DirectoryNotFoundException("Directory not found: indexA=" + c.Attributes["indexA"].Value + Environment.NewLine + xSection.OuterXml); - } - catch (Exception) - { - throw new ConfigurationErrorsException("LuceneServerIndex configuration Directory error: indexA=" + c.Attributes["indexA"].Value + Environment.NewLine + xSection.OuterXml); - } - - try - { - diB = new DirectoryInfo(c.Attributes["indexB"].Value); - _arIndexBDirectories[x] = diB; - if (!diB.Exists) - throw new DirectoryNotFoundException("Directory not found: indexA=" + c.Attributes["indexA"].Value + Environment.NewLine + xSection.OuterXml); - } - catch (Exception) - { - throw new ConfigurationErrorsException("LuceneServerIndex configuration Directory error: indexA=" + c.Attributes["indexB"].Value + Environment.NewLine + xSection.OuterXml); - } - x++; - } - } - } - - /// <summary> - /// The published Uri name for a collective set of indexes. The ObjectUri - /// is referenced by clients consuming the well-known service type. As an example, - /// an ObjectUri of "RemoteSearchIndex" on a system located at 192.168.1.100, exposed - /// on port 1089, would be accessed at "tcp://192.168.1.100:1089/RemoteSearchIndex". - /// <para>This value is required in configuration.</para> - /// </summary> - public string ObjectUri - { - get {return this._strObjectUri;} - } - - /// <summary> - /// A definable port number for the published Uri. Use this value to override the default - /// Port setting for all published URIs. - /// <para>This value is optional in configuration.</para> - /// </summary> - public int Port - { - get {return this._intPort;} - } - - /// <summary> - /// File-system path to the "IndexA" location of the index files. - /// </summary> - public DirectoryInfo[] IndexADirectories - { - get {return this._arIndexADirectories;} - } - - /// <summary> - /// File-system path to the "IndexB" location of the index files. - /// </summary> - public DirectoryInfo[] IndexBDirectories - { - get {return this._arIndexBDirectories;} - } - - /// <summary> - /// Instance method that returns an array of directory paths associated - /// with the given IndexSetting. - /// </summary> - /// <param name="oIndexSettingRefresh">IndexSetting enumeration value</param> - /// <returns>DirectoryInfo[] of directory paths</returns> - public DirectoryInfo[] RefreshDirectories(IndexSetting oIndexSettingRefresh) - { - this._arRefreshDirectories=null; - if (oIndexSettingRefresh==IndexSetting.IndexA) - this._arRefreshDirectories = this._arIndexADirectories; - else if (oIndexSettingRefresh==IndexSetting.IndexB) - this._arRefreshDirectories = this._arIndexBDirectories; - return this._arRefreshDirectories; - } - } -}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndexConfigurationHandler.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndexConfigurationHandler.cs b/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndexConfigurationHandler.cs deleted file mode 100644 index 9d54022..0000000 --- a/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndexConfigurationHandler.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Configuration; -using System.Xml; - -namespace Lucene.Net.Distributed.Configuration -{ - /// <summary> - /// Implementation of custom configuration handler for the definition of search indexes - /// made accessible by the LuceneServer windows service. - /// </summary> - public class LuceneServerIndexConfigurationHandler: IConfigurationSectionHandler - { - public LuceneServerIndexConfigurationHandler() - { - } - #region IConfigurationSectionHandler Members - - public object Create(object parent, object configContext, XmlNode section) - { - LuceneServerIndexes rsConfig = new LuceneServerIndexes(section); - return rsConfig; - } - - #endregion - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndexes.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndexes.cs b/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndexes.cs deleted file mode 100644 index 19cb856..0000000 --- a/src/contrib/DistributedSearch/Distributed/Configuration/LuceneServerIndexes.cs +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Configuration; -using System.Xml; - -namespace Lucene.Net.Distributed.Configuration -{ - /// <summary> - /// Definition of configurable search indexes made accessible by the - /// LuceneServer windows service. - /// - /// An example configuration would look like the following: - /// <code> - /// <LuceneServerIndexes Port="1089"> - /// <LuceneServerIndex ObjectUri="RemoteIndexes1"> - /// <Directory indexA="c:\lucene\indexA\index1" indexB="c:\lucene\indexB\index1" /> - /// <Directory indexA="c:\lucene\indexA\index2" indexB="c:\lucene\indexB\index2" /> - /// </LuceneServerIndex> - /// <LuceneServerIndex ObjectUri="RemoteIndexes2"> - /// <Directory indexA="c:\lucene\indexA\index3" indexB="c:\lucene\indexB\index3" /> - /// <Directory indexA="c:\lucene\indexA\index4" indexB="c:\lucene\indexB\index4" /> - /// </LuceneServerIndex> - /// </LuceneServerIndexes> - /// </code> - /// </summary> - public class LuceneServerIndexes - { - private LuceneServerIndex[] _arLuceneServerIndexArray; - private int _intPort; - - /// <summary> - /// Accessor method for the configurable search indexes. - /// </summary> - public static LuceneServerIndexes GetConfig - { - get {return (LuceneServerIndexes)ConfigurationManager.GetSection("LuceneServerIndexes");} - } - - /// <summary> - /// Public constructor for LuceneServerIndexes. A LuceneServerIndex is defined - /// in XML configuration and is loaded via a custom configuration handler. - /// </summary> - /// <param name="xSection">The Xml definition in the configuration file</param> - public LuceneServerIndexes(XmlNode xSection) - { - XmlAttributeCollection attributeCollection = xSection.Attributes; - - try - { - this._intPort = Convert.ToInt32(attributeCollection["Port"].Value); - } - catch (Exception) - { - throw new ConfigurationErrorsException("LuceneServerIndexes port definition invalid: "+Environment.NewLine+xSection.OuterXml); - } - - if (xSection.ChildNodes.Count==0) - throw new ConfigurationErrorsException("LuceneServerIndexes configuration missing: " + Environment.NewLine + xSection.OuterXml); - - this._arLuceneServerIndexArray = new LuceneServerIndex[xSection.ChildNodes.Count]; - int x=0; - - foreach (XmlNode c in xSection.ChildNodes) - { - if (c.Name.ToLower()=="luceneserverindex") - { - LuceneServerIndex rs = new LuceneServerIndex(c, _intPort); - this._arLuceneServerIndexArray[x] = rs; - x++; - } - - } - } - - /// <summary> - /// Strongly-typed array of LuceneServerIndex objects as defined in - /// a configuration section. - /// </summary> - public LuceneServerIndex[] LuceneServerIndexArray - { - get {return this._arLuceneServerIndexArray;} - } - - /// <summary> - /// A default Port to be assigned to all defined LuceneServerIndex objects. - /// This value can be overridden for a specific LuceneServerIndex. - /// </summary> - public int Port - { - get {return this._intPort;} - } - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Enumerations.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Enumerations.cs b/src/contrib/DistributedSearch/Distributed/Enumerations.cs deleted file mode 100644 index 805800e..0000000 --- a/src/contrib/DistributedSearch/Distributed/Enumerations.cs +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; - -namespace Lucene.Net.Distributed -{ - - /// <summary> - /// Specifies the location of a DistributedSearcher - /// </summary> - public enum SearchMethod - { - Local = 0, - Distributed = 1, - Undefined = 2 - } - - /// <summary> - /// Specifies the type of Field in an IndexDocument - /// </summary> - public enum FieldStorageType - { - Keyword = 1, - UnIndexed = 2, - UnStored = 3, - Text = 4 - } - - /// <summary> - /// Specifies the type of action for an IndexSet to take when applying changes to an index - /// </summary> - public enum IndexAction - { - NoAction = 0, - Update = 1, - Overwrite = 2 - } - - /// <summary> - /// Specifies the type of Analyzer to use in creation of an IndexDocument - /// </summary> - public enum AnalyzerType - { - StandardAnalyzer = 0, - SimpleAnalyzer = 1, - WhitespaceAnalyzer = 2, - StopAnalyzer = 3 - } - -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Indexing/DeleteIndexDocument.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Indexing/DeleteIndexDocument.cs b/src/contrib/DistributedSearch/Distributed/Indexing/DeleteIndexDocument.cs deleted file mode 100644 index 8186b36..0000000 --- a/src/contrib/DistributedSearch/Distributed/Indexing/DeleteIndexDocument.cs +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections.Generic; -using System.Text; -using Lucene.Net.Distributed; - -namespace Lucene.Net.Distributed.Indexing -{ - [Serializable] - public class DeleteIndexDocument: IndexDocument - { - - public DeleteIndexDocument(int iRecordId) - : base(iRecordId) - { - } - - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Indexing/FileNameComparer.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Indexing/FileNameComparer.cs b/src/contrib/DistributedSearch/Distributed/Indexing/FileNameComparer.cs deleted file mode 100644 index 24eb329..0000000 --- a/src/contrib/DistributedSearch/Distributed/Indexing/FileNameComparer.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections; -using System.IO; - -namespace Lucene.Net.Distributed.Indexing -{ - /// <summary> - /// Summary description for FileNameComparer. - /// </summary> - public class FileNameComparer : IComparer - { - - public int Compare(object x, object y) - { - if ((x is FileInfo) && (y is FileInfo)) - { - FileInfo fX = (FileInfo)x; - FileInfo fY = (FileInfo)y; - return fX.Name.CompareTo(fY.Name); - } - else - { - return 0; - } - } - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Indexing/IndexDocument.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Indexing/IndexDocument.cs b/src/contrib/DistributedSearch/Distributed/Indexing/IndexDocument.cs deleted file mode 100644 index a8c20c8..0000000 --- a/src/contrib/DistributedSearch/Distributed/Indexing/IndexDocument.cs +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Configuration; -using System.IO; -using System.Reflection; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Formatters.Binary; -using Lucene.Net.Analysis; -using Lucene.Net.Documents; -using Lucene.Net.Distributed; - -namespace Lucene.Net.Distributed.Indexing -{ - - /// <summary> - /// Base class representing a record to be added to a Lucene index. - /// <para> - /// IndexDocument contains a RecordId and a Lucene.Net.Document. The RecordId - /// is interrogated to determine which index to add the associated - /// Lucene.Net.Document. - /// </para> - /// </summary> - [Serializable] - public abstract class IndexDocument - { - #region Variables - protected Document _oDocument; - protected int _intRecordId; - public static BinaryFormatter Formatter = new BinaryFormatter(); - private static string filepath = (ConfigurationManager.AppSettings["IndexDocumentPath"] != null ? ConfigurationManager.AppSettings["IndexDocumentPath"] : ""); - private static string endwhack = (filepath.EndsWith(@"\") ? "" : @"\"); - private DateTime _eDateTime; - #endregion - - #region Constructors - /// <summary> - /// Empty public constructor. - /// </summary> - public IndexDocument() - { - } - - /// <summary> - /// Base constructor accepting only a RecordId. Useful for classes that - /// will have no associated Document, i.e. deletes. - /// </summary> - /// <param name="iRecordId">The source recordId (see also <seealso cref="#">IndexSet.IdColumn</seealso>) </param> - public IndexDocument(int iRecordId) - { - this._intRecordId = iRecordId; - this._oDocument = new Document(); - this._eDateTime = DateTime.Now; - } - - public IndexDocument(Document oDocument, int iRecordId) - { - this._oDocument = oDocument; - this._intRecordId = iRecordId; - this._eDateTime = DateTime.Now; - } - - #endregion - - #region Properties - public Document Document - { - get {return this._oDocument;} - } - - public int RecordId - { - get {return this._intRecordId;} - } - - public virtual Analyzer GetAnalyzer() - { - return null; - } - - public string FileName - { - get { return Environment.MachineName + "_" + this.GetType().ToString() + "_" + this.RecordId.ToString() + "_" + this.DateTime.Ticks.ToString() + ".bin"; } - } - private DateTime DateTime - { - get { return this._eDateTime; } - } - - #endregion - - #region Methods - public void Save() - { - try - { - FileStream fs = File.Open(filepath + endwhack + this.FileName, FileMode.Create, FileAccess.ReadWrite); - IndexDocument.Formatter.Serialize(fs, this); - fs.Close(); - } - catch (SerializationException se) - { - throw (se); - } - catch (NullReferenceException nre) - { - throw (nre); - } - } - public void Save(string filePath) - { - try - { - FileStream fs = File.Open(filePath + endwhack + this.FileName, FileMode.Create, FileAccess.ReadWrite); - IndexDocument.Formatter.Serialize(fs, this); - fs.Close(); - } - catch (SerializationException se) - { - throw (se); - } - catch (NullReferenceException nre) - { - throw (nre); - } - } - #endregion - - - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Indexing/IndexSet.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Indexing/IndexSet.cs b/src/contrib/DistributedSearch/Distributed/Indexing/IndexSet.cs deleted file mode 100644 index 3638051..0000000 --- a/src/contrib/DistributedSearch/Distributed/Indexing/IndexSet.cs +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Configuration; -using System.Xml; -using Lucene.Net.Distributed; -//using Lucene.Net.Distributed.Search; -using Lucene.Net.Distributed.Configuration; -using Documents = Lucene.Net.Documents; -using Lucene.Net.Analysis; -using Lucene.Net.Analysis.Standard; -using Lucene.Net.Index; - -namespace Lucene.Net.Distributed.Indexing -{ - /// <summary> - /// Definition of configurable search indexes managed by the - /// LuceneUpdater windows service. - /// - /// An example configuration would look like the following: - /// <code> - /// <indexsets CompoundFile="true" DeltaDirectory="c:\indexes\indexdocuments"> - /// <indexSet id="1" action="1" analyzer="1"> - /// <add key="localpath" value="c:\lucene\masterindex\index1" /> - /// <copy> - /// <targetPath indexA="\\LuceneServer\lucene\indexA\index1" indexB="\\LuceneServer\lucene\indexA\index1" /> - /// <statusDir value="\\LuceneServer\lucene\statusfile\" /> - /// </copy> - /// <add key="bottomid" value="1"/> - /// <add key="topid" value="1000"/> - /// <add key="idcolumn" value="pkId"/> - /// </indexSet> - /// </indexsets> - /// </code> - /// </summary> - public class IndexSet - { - #region Variables - private int _intId = -1; - private string _strLocalPath; - private string _strIdColumn; - private int _intBottomId; - private int _intTopId; - private CurrentIndex _oCurrentIndex; - private IndexAction _eIndexAction=IndexAction.NoAction; - private AnalyzerType _eAnalyzerType=AnalyzerType.StandardAnalyzer; - private Hashtable _htDocuments = new Hashtable(); - private Hashtable _htIndexDocuments = new Hashtable(); - private List<string> _alFileSystemDocuments = new List<string>(); - #endregion - - #region Constructors - /// <summary> - /// Public constructor for IndexSet. An IndexSet is defined in XML configuration - /// and is loaded via a custom configuration handler. - /// </summary> - /// <param name="node">XmlNode definition for a given IndexSet</param> - public IndexSet(XmlNode node) - { - this.LoadValues(node); - } - - #endregion - - #region Internal voids - /// <summary> - /// Internal load method called from the constructor. Loads underlying values - /// based on Xml configuration. - /// </summary> - /// <param name="node">XmlNode definition for a given IndexSet</param> - internal void LoadValues(XmlNode node) - { - XmlAttributeCollection attributeCollection = node.Attributes; - try - { - this._intId = Convert.ToInt32(attributeCollection["id"].Value); - } - catch (Exception) - { - throw new ConfigurationErrorsException("IndexSet id invalid: " + Environment.NewLine + node.OuterXml); - } - - try - { - this._eIndexAction = (IndexAction)Enum.Parse(typeof(IndexAction), attributeCollection["action"].Value); - } - catch (Exception) - { - throw new ConfigurationErrorsException("IndexSet "+this._intId.ToString()+" IndexAction invalid: " + Environment.NewLine + node.OuterXml); - } - - try - { - if (attributeCollection["analyzer"] != null) - this._eAnalyzerType = (AnalyzerType)Enum.Parse(typeof(AnalyzerType), attributeCollection["analyzer"].Value); - } - catch (Exception) - { - throw new ConfigurationErrorsException("IndexSet " + this._intId.ToString() + " analyzer invalid: " + Environment.NewLine + node.OuterXml); - } - - if (node.ChildNodes.Count==0) - throw new ConfigurationErrorsException("IndexSet " + this._intId.ToString() + " configuration missing " + Environment.NewLine + node.OuterXml); - - foreach (XmlNode c in node.ChildNodes) - { - if (!c.HasChildNodes) - { - switch (c.Attributes["key"].Value.ToLower()) - { - case "localpath": - this._strLocalPath = c.Attributes["value"].Value; - break; - case "idcolumn": - this._strIdColumn = c.Attributes["value"].Value; - break; - case "bottomid": - try - { - this._intBottomId = Convert.ToInt32(c.Attributes["value"].Value); - } - catch (Exception) - { - throw new ConfigurationErrorsException("IndexSet " + this._intId.ToString() + " bottomid invalid: " + Environment.NewLine + node.OuterXml); - } - break; - case "topid": - try - { - this._intTopId = Convert.ToInt32(c.Attributes["value"].Value); - } - catch (Exception) - { - throw new ConfigurationErrorsException("IndexSet " + this._intId.ToString() + " topid invalid: " + Environment.NewLine + node.OuterXml); - } - break; - } - } - else - { - switch(c.Name.ToLower()) - { - case "copy": - if (this._strLocalPath!=null) - LoadCopy(c,this._strLocalPath); - else - LoadCopy(c,node); - break; - } - } - } - this.CheckValidSet(node); - - } - - internal void LoadCopy(XmlNode node, string localpath) - { - this._oCurrentIndex = new CurrentIndex(node,localpath); - } - - internal void LoadCopy(XmlNode node, XmlNode masternode) - { - foreach (XmlNode c in node.ChildNodes) - { - if (c.Attributes["key"] != null) - { - switch (c.Attributes["key"].Value.ToLower()) - { - case "localpath": - this.LoadCopy(node, c.Attributes["value"].Value); - break; - } - } - } - } - - private void CheckValidSet(XmlNode node) - { - if (this._strLocalPath==null) throw new ConfigurationErrorsException("IndexSet " + this._intId.ToString() + " LocalPath invalid: " + Environment.NewLine + node.OuterXml); - if (this._eIndexAction==IndexAction.NoAction) throw new ConfigurationErrorsException("IndexSet " + this._intId.ToString() + " IndexAction undefined: " + Environment.NewLine + node.OuterXml); - if (this._strIdColumn==null) throw new ConfigurationErrorsException("IndexSet " + this._intId.ToString() + " IdColumn undefined: " + Environment.NewLine + node.OuterXml); - } - - #endregion - - #region Properties - /// <summary> - /// Unique identifier for an IndexSet within a configuration of multiple IndexSet objects - /// </summary> - public int Id - { - get {return this._intId;} - } - - /// <summary> - /// Enumeration dictating the type of updates to be applied to the underlying master index - /// </summary> - public IndexAction IndexAction - { - get {return this._eIndexAction;} - } - - /// <summary> - /// Enumeration dictating the type of Analyzer to be applied to IndexDocuments in update scenarios - /// </summary> - public AnalyzerType AnalyzerType - { - get {return this._eAnalyzerType;} - } - - /// <summary> - /// The Analyzer object used in application of IndexDocument updates - /// </summary> - public Analyzer Analzyer - { - get {return CurrentIndex.GetAnalyzer(this._eAnalyzerType);} - } - - /// <summary> - /// Filesystem path to the master index - /// </summary> - public string LocalPath - { - get {return this._strLocalPath;} - } - - /// <summary> - /// String name representing the unique key for the given record in the index - /// </summary> - public string IdColumn - { - get {return this._strIdColumn;} - } - - /// <summary> - /// Minimum IdColumn value for a record in this index - /// </summary> - public int BottomId - { - get {return this._intBottomId;} - } - - /// <summary> - /// Maximum IdColumn value for a record in this index - /// </summary> - public int TopId - { - get {return this._intTopId;} - } - - /// <summary> - /// CurrentIndex object associated with this IndexSet. The CurrentIndex is used - /// in determining index settings and maintenance as well as managing physical file updates - /// for index updates. - /// </summary> - public CurrentIndex CurrentIndex - { - get {return this._oCurrentIndex;} - } - - /// <summary> - /// List of filesystem paths representing files for the master index - /// </summary> - public List<string> FileSystemDocuments - { - get { return this._alFileSystemDocuments; } - } - - /// <summary> - /// Pending updates to be applied to the master index - /// </summary> - public Hashtable IndexDocuments - { - get { return this._htIndexDocuments; } - } - - /// <summary> - /// Retrieves the DeleteIndexDocuments from IndexDocuments - /// </summary> - public Hashtable Documents - { - get - { - this._htDocuments.Clear(); - foreach (DictionaryEntry de in this._htIndexDocuments) - { - IndexDocument iDoc = (IndexDocument)de.Value; - if (!(iDoc is DeleteIndexDocument)) - this._htDocuments.Add(iDoc.Document, iDoc.GetAnalyzer()); - } - return this._htDocuments; - } - } - #endregion - - #region Methods - /// <summary> - /// Retrieves a NameValueCollection of records to first be deleted from an index. Name/Value - /// pair combination consists of IdColumn and RecordId from each IndexDocument in IndexDocuments. - /// </summary> - /// <returns></returns> - public NameValueCollection GetDeletionCollection() - { - NameValueCollection nvc = new NameValueCollection(this._htDocuments.Count); - foreach(DictionaryEntry de in this._htIndexDocuments) - nvc.Add(this.IdColumn, ((IndexDocument)de.Value).RecordId.ToString()); - return nvc; - } - - /// <summary> - /// Clears the contents of Documents and IndexDocuments - /// </summary> - public void Reset() - { - this._htIndexDocuments.Clear(); - this._htDocuments.Clear(); - } - - /// <summary> - /// Executes a Lucene.Net optimization against the referenced index. - /// </summary> - public void Optimize() - { - if (IndexReader.IndexExists(this._strLocalPath)) - { - IndexWriter idxWriter = new IndexWriter(this._strLocalPath, this.Analzyer, false); - idxWriter.SetMergeFactor(2); - idxWriter.Optimize(); - idxWriter.Close(); - } - } - - /// <summary> - /// Indicates if a given recordId exists within the configuration - /// definition of TopId and BottomId. - /// </summary> - /// <param name="recordId"></param> - /// <returns></returns> - public bool ContainsId(int recordId) - { - return (this._intTopId >= recordId && this._intBottomId <= recordId); - } - #endregion - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Indexing/IndexSetConfigurationHandler.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Indexing/IndexSetConfigurationHandler.cs b/src/contrib/DistributedSearch/Distributed/Indexing/IndexSetConfigurationHandler.cs deleted file mode 100644 index 2ae90fd..0000000 --- a/src/contrib/DistributedSearch/Distributed/Indexing/IndexSetConfigurationHandler.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Configuration; -using System.Xml; -using Lucene.Net.Distributed; - -namespace Lucene.Net.Distributed.Indexing -{ - /// <summary> - /// Implementation of custom configuration handler for the definition of master indexes - /// as managed by the LuceneUpdater windows service. - /// </summary> - public class IndexSetConfigurationHandler : IConfigurationSectionHandler - { - public IndexSetConfigurationHandler() - { - } - - #region IConfigurationSectionHandler Members - - public object Create(object parent, object configContext, XmlNode section) - { - IndexSets isConfig = new IndexSets(); - isConfig.LoadIndexSetArray(section); - return isConfig; - } - - #endregion - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Indexing/IndexSets.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Indexing/IndexSets.cs b/src/contrib/DistributedSearch/Distributed/Indexing/IndexSets.cs deleted file mode 100644 index e0403d8..0000000 --- a/src/contrib/DistributedSearch/Distributed/Indexing/IndexSets.cs +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Configuration; -using System.IO; -using System.Xml; -using Lucene.Net.Distributed; -using Lucene.Net.Distributed.Configuration; - -namespace Lucene.Net.Distributed.Indexing -{ - /// <summary> - /// Definition of configurable search indexes managed by the - /// LuceneUpdater windows service. - /// - /// An example configuration would look like the following: - /// <code> - /// <indexsets CompoundFile="true" DeltaDirectory="c:\indexes\indexdocuments"> - /// <indexSet id="1" action="1" analyzer="1"> - /// <add key="localpath" value="c:\lucene\masterindex\index1" /> - /// <copy> - /// <targetPath indexA="\\LuceneServer\lucene\indexA\index1" indexB="\\LuceneServer\lucene\indexA\index1" /> - /// <statusDir value="\\LuceneServer\lucene\statusfile\" /> - /// </copy> - /// <add key="bottomid" value="1"/> - /// <add key="topid" value="1000"/> - /// <add key="idcolumn" value="pkId"/> - /// </indexSet> - /// </indexsets> - /// </code> - /// </summary> - public class IndexSets - { - private bool _bCompoundFile; - private string _strDeltaDirectory; - private IndexSet[] _arIndexSet; - - /// <summary> - /// Accessor method for the configurable master indexes. - /// </summary> - public static IndexSets GetConfig - { - get { return (IndexSets)ConfigurationManager.GetSection("IndexSets"); } - } - - /// <summary> - /// Strongly-typed array of IndexSet objects as defined in a configuration section. - /// </summary> - /// <param name="node">XmlNode definition for a given IndexSet</param> - public void LoadIndexSetArray(XmlNode node) - { - XmlAttributeCollection attributeCollection = node.Attributes; - - try - { - this._bCompoundFile = Convert.ToBoolean(attributeCollection["CompoundFile"].Value); - } - catch (Exception) - { - throw new ConfigurationErrorsException("CompoundFile invalid: " + Environment.NewLine + node.OuterXml); - } - - try - { - this._strDeltaDirectory = attributeCollection["DeltaDirectory"].Value; - } - catch (Exception) - { - throw new ConfigurationErrorsException("DeltaDirectory invalid: " + Environment.NewLine + node.OuterXml); - } - - if (node.ChildNodes.Count == 0) - throw new ConfigurationErrorsException("No indexset definitions found " + Environment.NewLine + node.OuterXml); - this._arIndexSet = new IndexSet[node.ChildNodes.Count]; - - int x=0; - foreach (XmlNode c in node.ChildNodes) - { - if (c.Name.ToLower()=="IndexSet") - { - IndexSet idxSet = new IndexSet(c); - this._arIndexSet[x] = idxSet; - x++; - } - - } - } - - /// <summary> - /// Public constructor for IndexSets. An IndexSet is defined in XML configuration - /// and is loaded via a custom configuration handler. - /// </summary> - public IndexSets() - { - } - - /// <summary> - /// Indicates if the indexes under configuration should be built in the Compound format. - /// </summary> - public bool CompoundFile - { - get {return this._bCompoundFile;} - } - - /// <summary> - /// Filesystem location of where pending update IndexDocuments are retrieved. - /// </summary> - public string DeltaDirectory - { - get {return this._strDeltaDirectory;} - } - - /// <summary> - /// Strongly-typed array of IndexSet objects as defined in a configuration section. - /// </summary> - public IndexSet[] IndexSetArray - { - get {return this._arIndexSet;} - } - - /// <summary> - /// Returns an IndexSet object for a given IndexDocument id value - /// </summary> - /// <param name="deleteId">Id value of the IndexDocument</param> - /// <returns>The IndexSet containing the referenced IndexDocument</returns> - public IndexSet GetIndexSet(int deleteId) - { - IndexSet getSet=null; - foreach(IndexSet idxSet in this._arIndexSet) - { - if ((deleteId>=idxSet.BottomId)&&(deleteId<=idxSet.TopId)) - getSet=idxSet; - } - return getSet; - } - - /// <summary> - /// Queries the DeltaDirectory to access any IndexDocument files. All IndexDocuments - /// stored in the DeltaDirectory have been serialized to a file; the files are deserialized, - /// evaluated for their id value (idcolumn) and added to the pending additions for the associated - /// IndexSet. - /// </summary> - /// <param name="sourceDir">Filesystem path to the DeltaDirectory</param> - public void LoadIndexDocuments(string sourceDir) - { - DirectoryInfo oDirectoryInfo = new DirectoryInfo(sourceDir); - FileInfo[] arFiles = oDirectoryInfo.GetFiles("*.bin"); - Array.Sort(arFiles, new FileNameComparer()); - IndexSet idxSet; - - foreach (FileInfo fi in arFiles) - { - FileStream fs = new FileStream(fi.FullName, FileMode.Open); - IndexDocument iDoc = (IndexDocument)IndexDocument.Formatter.Deserialize(fs); - - idxSet = this.GetIndexSet(iDoc.RecordId); - if (idxSet != null) - { - idxSet.FileSystemDocuments.Add(fi.FullName); - if (idxSet.IndexDocuments.ContainsKey(iDoc.RecordId)) - { - IndexDocument curDoc = (IndexDocument)idxSet.IndexDocuments[iDoc.RecordId]; - idxSet.IndexDocuments.Add(iDoc.RecordId, iDoc); - } - else - idxSet.IndexDocuments.Add(iDoc.RecordId, iDoc); - } - else - { - //Handling exceptions -- write file out somewhere else? - if (ConfigurationManager.AppSettings["ExceptionsBasePath"] != null) - iDoc.Save(ConfigurationManager.AppSettings["ExceptionsBasePath"]); - } - fs.Close(); - } - oDirectoryInfo=null; - arFiles=null; - } - - /// <summary> - /// Method to apply pending updates (additions & deletions) for all configured IndexSet objects. - /// </summary> - public void ProcessIndexDocuments() - { - foreach(IndexSet idxSet in this._arIndexSet) - { - if (idxSet.IndexDocuments.Count>0) - { - idxSet.CurrentIndex.ProcessLocalIndexDeletes(idxSet.GetDeletionCollection()); - idxSet.CurrentIndex.ProcessLocalIndexAdditions(idxSet.Analzyer, idxSet.Documents, this.CompoundFile); - } - } - } - - /// <summary> - /// Method to apply updated index files from master index to slave indexes - /// </summary> - public void CopyUpdatedFiles() - { - Hashtable htUpdates = new Hashtable(); - bool bCopy=false; - foreach (IndexSet idxSet in this._arIndexSet) - { - bCopy=false; - if (idxSet.CurrentIndex!=null && idxSet.CurrentIndex.CanCopy) - bCopy=idxSet.CurrentIndex.CopyIncremental(); - if (bCopy && !htUpdates.ContainsKey(idxSet.CurrentIndex.StatusDirectory)) - htUpdates.Add(idxSet.CurrentIndex.StatusDirectory, idxSet.CurrentIndex); - } - - foreach(DictionaryEntry de in htUpdates) - { - string sTargetDir = de.Key.ToString(); - CurrentIndex ci = (CurrentIndex)de.Value; - ci.UpdateRefresh(); - } - } - - /// <summary> - /// Method to apply updated index files from master index to slave indexes - /// </summary> - /// <returns>Hashtable of updated indexes</returns> - public Hashtable CopyAllFiles() - { - Hashtable htUpdates = new Hashtable(); - bool bCopy = false; - foreach (IndexSet idxSet in this._arIndexSet) - { - bCopy = false; - if (idxSet.CurrentIndex != null && idxSet.CurrentIndex.CanCopy) - bCopy = idxSet.CurrentIndex.Copy(); - if (bCopy && !htUpdates.ContainsKey(idxSet.CurrentIndex.StatusDirectory)) - htUpdates.Add(idxSet.CurrentIndex.StatusDirectory, idxSet.CurrentIndex); - } - - foreach (DictionaryEntry de in htUpdates) - { - string sTargetDir = de.Key.ToString(); - CurrentIndex ci = (CurrentIndex)de.Value; - ci.UpdateRefresh(); - } - - return htUpdates; - } - - /// <summary> - /// Method to execute an index optimization for each configured IndexSet object - /// </summary> - public void OptimizeIndexes() - { - foreach (IndexSet idxSet in this._arIndexSet) - idxSet.Optimize(); - } - - /// <summary> - /// Method to finalize update process for each IndexSet object - /// </summary> - public void CompleteUpdate() - { - foreach (IndexSet idxSet in this._arIndexSet) - { - if (idxSet.FileSystemDocuments.Count>0) - { - foreach(string s in idxSet.FileSystemDocuments) - { - FileInfo fi = new FileInfo(s); - fi.Delete(); - } - idxSet.Reset(); - } - } - } - - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/Distributed/Search/DistributedSearchable.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/Distributed/Search/DistributedSearchable.cs b/src/contrib/DistributedSearch/Distributed/Search/DistributedSearchable.cs deleted file mode 100644 index 3488e26..0000000 --- a/src/contrib/DistributedSearch/Distributed/Search/DistributedSearchable.cs +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections.Generic; -using System.Runtime.Remoting.Lifetime; -using System.Text; - -namespace Lucene.Net.Distributed.Search -{ - /// <summary> - /// An derived implementation of RemoteSearchable, DistributedSearchable provides additional - /// support for integration with .Net remoting objects and constructs. - /// </summary> - [Serializable] - public class DistributedSearchable : Lucene.Net.Search.RemoteSearchable - { - - private static readonly int TIME_FACTOR = 30; - private static int initialLeaseTime = SupportClass.AppSettings.Get("LeaseTime", -1); - private static TimeSpan leaseTimeSpan; - - /// <summary> - /// Standard constructor for DistributedSearchable - /// </summary> - /// <param name="local">Any derived Searchable object</param> - public DistributedSearchable(Lucene.Net.Search.Searchable local) - : base(local) - { - } - - // Override on lifetime service; returning NULL yields an unlimited TTL - /// <summary> - /// Override of the base LifetimeService policy for this object. This method - /// manages the lifetime of objects marshaled and released in remoting environments - /// and distributed garbage collection. - /// </summary> - /// <returns>Object of type ILease</returns> - public override object InitializeLifetimeService() - { - DistributedSearchable.leaseTimeSpan = new TimeSpan(0, 0, DistributedSearchable.initialLeaseTime + DistributedSearchable.TIME_FACTOR); - if (DistributedSearchable.initialLeaseTime == -1) - { - return null; //Permanent TTL; never get's GC'd - } - else - { - ILease oLease = (ILease) base.InitializeLifetimeService(); - if (oLease.CurrentState == LeaseState.Initial) - { - oLease.InitialLeaseTime = TimeSpan.FromSeconds(DistributedSearchable.leaseTimeSpan.TotalSeconds); - oLease.RenewOnCallTime = TimeSpan.FromSeconds(DistributedSearchable.TIME_FACTOR); - } - return oLease; - } - } - - /// <summary> - /// Method to extend the lifetime of a DistributedSearchable object. - /// </summary> - public void Renew() - { - ILease oLease = (ILease)this.GetLifetimeService(); - oLease.Renew(DistributedSearchable.GetLeaseTimeSpan()); - } - - /// <summary> - /// Retrieves the lifetime lease length composed as a TimeSpan object - /// </summary> - /// <returns>TimeSpan representing the length of the lifetime lease for this object</returns> - public static TimeSpan GetLeaseTimeSpan() - { - return DistributedSearchable.leaseTimeSpan; - } - - /// <summary> - /// Returns the configured number of seconds for the lifetime length of this object - /// </summary> - /// <returns>int representing the configured number of seconds for the lifetime length of this object</returns> - public static int GetInitialLeaseTime() - { - return DistributedSearchable.initialLeaseTime; - } - - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/LuceneMonitor/LuceneMonitor.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/LuceneMonitor/LuceneMonitor.cs b/src/contrib/DistributedSearch/LuceneMonitor/LuceneMonitor.cs deleted file mode 100644 index e36beb7..0000000 --- a/src/contrib/DistributedSearch/LuceneMonitor/LuceneMonitor.cs +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections; -using System.ComponentModel; -using System.Configuration; -using System.Data; -using System.Diagnostics; -using System.Net; -using System.Net.Sockets; -using System.Runtime.Remoting; -using System.Runtime.Remoting.Channels; -using System.ServiceProcess; -using System.Threading; - -using log4net.Core; -[assembly: log4net.Config.XmlConfigurator(Watch=true)] - -namespace Lucene.Net.Distributed.Operations -{ - /// <summary> - /// A Windows service that provides system ping checking against LuceneServer. - /// </summary> - public class LuceneMonitor : System.ServiceProcess.ServiceBase - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.Container components = null; - private ServiceController scMonitor = new ServiceController(); - private Thread serviceThread; - private int sleepTime = 5000; - private bool bRun = true; - private string ipAddress = ""; - private int port = 0; - private static readonly log4net.ILog oLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - - public LuceneMonitor() - { - // This call is required by the Windows.Forms Component Designer. - InitializeComponent(); - - // TODO: Add any initialization after the InitComponent call - } - - // The main entry point for the process - static void Main() - { - System.ServiceProcess.ServiceBase[] ServicesToRun; - ServicesToRun = new System.ServiceProcess.ServiceBase[] { new LuceneMonitor() }; - System.ServiceProcess.ServiceBase.Run(ServicesToRun); - } - - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { - components = new System.ComponentModel.Container(); - this.ServiceName = "LuceneMonitor"; - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - /// <summary> - /// Set things in motion so your service can do its work. - /// </summary> - protected override void OnStart(string[] args) - { - ThreadStart threadStart = new ThreadStart(MonitorService); - serviceThread = new Thread(threadStart); - serviceThread.Start(); - } - - private void LogMessage(string message) - { - this.LogMessage(message, Level.Info); - } - private void LogMessage(string message, Level msgLevel) - { - if (msgLevel==Level.Info) - { - if (oLog.IsInfoEnabled) - oLog.Info(message); - } - else if (msgLevel==Level.Warn) - { - if (oLog.IsWarnEnabled) - oLog.Warn(message); - } - } - private void LogMessage(string message, Level msgLevel, int ErrorLevel) - { - if (msgLevel==Level.Error) - { - if (oLog.IsErrorEnabled) - { - oLog.Error(message); - EventLog.WriteEntry(this.ServiceName, message, EventLogEntryType.Error, ErrorLevel); - } - } - } - - private void MonitorService() - { - this.LogMessage(this.ServiceName+" started"); - scMonitor.ServiceName="LuceneServer"; - this.sleepTime = (ConfigurationManager.AppSettings["ServiceSleepTime"] != null ? Convert.ToInt32(ConfigurationManager.AppSettings["ServiceSleepTime"]) : this.sleepTime); - this.ipAddress = (ConfigurationManager.AppSettings["IPAddress"] != null ? ConfigurationManager.AppSettings["IPAddress"] : ""); - this.port = (ConfigurationManager.AppSettings["Port"] != null ? Convert.ToInt32(ConfigurationManager.AppSettings["Port"]) : 0); - this.LogMessage("ServiceSleepTime = "+this.sleepTime.ToString()+"; ipAddress="+this.ipAddress+"; port="+this.port.ToString()); - - while (bRun) - { - this.CheckService(); - Thread.Sleep(sleepTime); - } - } - - private void CheckService() - { - try - { - scMonitor.Refresh(); - - if (scMonitor.Status.Equals(ServiceControllerStatus.StopPending)) - scMonitor.WaitForStatus(ServiceControllerStatus.Stopped); - - if (scMonitor.Status.Equals(ServiceControllerStatus.Stopped)) - { - // Start the service if the current status is stopped. - foreach (IChannel ic in ChannelServices.RegisteredChannels) - ChannelServices.UnregisterChannel(ic); - scMonitor.Start(); - this.LogMessage(scMonitor.ServiceName + " started (Service stopped or StopPending)", Level.Error, 99); - } - } - catch (Exception e) - { - this.LogMessage(scMonitor.ServiceName + " error: "+e.Message+e.StackTrace, Level.Error, 199); - } - - } - - - /// <summary> - /// Stop this service. - /// </summary> - protected override void OnStop() - { - this.bRun=false; - } - } -} http://git-wip-us.apache.org/repos/asf/lucenenet/blob/02362804/src/contrib/DistributedSearch/LuceneMonitor/ProjectInstaller.cs ---------------------------------------------------------------------- diff --git a/src/contrib/DistributedSearch/LuceneMonitor/ProjectInstaller.cs b/src/contrib/DistributedSearch/LuceneMonitor/ProjectInstaller.cs deleted file mode 100644 index 9b635b5..0000000 --- a/src/contrib/DistributedSearch/LuceneMonitor/ProjectInstaller.cs +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections; -using System.ComponentModel; -using System.Configuration.Install; -using System.ServiceProcess; -using Microsoft.Win32; - -namespace LuceneMonitorInstall -{ - /// <summary> - /// Summary description for ProjectInstaller. - /// </summary> - [RunInstallerAttribute(true)] - public class ProjectInstaller : Installer - { - private ServiceProcessInstaller processInstaller; - private ServiceInstaller serviceInstaller; - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.Container components = null; - - public ProjectInstaller() - { - // This call is required by the Designer. - InitializeComponent(); - - // TODO: Add any initialization after the InitializeComponent call - } - - /// <summary> - /// Clean up any resources being used. - /// </summary> - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if(components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - - #region Component Designer generated code - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { - this.processInstaller = new ServiceProcessInstaller(); - this.serviceInstaller = new ServiceInstaller(); - this.processInstaller.Account = ServiceAccount.LocalSystem; - - this.serviceInstaller.ServiceName = "LuceneMonitor"; - this.serviceInstaller.StartType = ServiceStartMode.Manual; - - Installers.Add(this.processInstaller); - Installers.Add(this.serviceInstaller); - - } - #endregion - - public override void Install(IDictionary stateSaver) - { - RegistryKey system; - RegistryKey currentControlSet; //HKEY_LOCAL_MACHINE\Services\CurrentControlSet - RegistryKey services; //...\Services - RegistryKey service; //...\<Service Name> - - try - { - //Let the project installer do its job - base.Install(stateSaver); - - system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System"); //Open the HKEY_LOCAL_MACHINE\SYSTEM key - currentControlSet = system.OpenSubKey("CurrentControlSet"); //Open CurrentControlSet - services = currentControlSet.OpenSubKey("Services"); //Go to the services key - service = services.OpenSubKey(this.serviceInstaller.ServiceName, true); //Open the key for serviceInstaller - - service.SetValue("Description", "Lucene Monitor"); - - - } - catch(Exception e) - { - Console.WriteLine("An exception was thrown during service installation:\n" + e.ToString()); - } - } - - public override void Uninstall(IDictionary savedState) - { - RegistryKey system; - RegistryKey currentControlSet; //HKEY_LOCAL_MACHINE\Services\CurrentControlSet - RegistryKey services; //...\Services - RegistryKey service; //...\<Service Name> - - try - { - //Drill down to the service key and open it with write permission - system = Registry.LocalMachine.OpenSubKey("System"); - currentControlSet = system.OpenSubKey("CurrentControlSet"); - services = currentControlSet.OpenSubKey("Services"); - service = services.OpenSubKey(this.serviceInstaller.ServiceName, true); - service.DeleteSubKeyTree("Description"); //Delete keys created during installation - - } - catch(Exception e) - { - Console.WriteLine("Exception encountered while uninstalling service:\n" + e.ToString()); - } - finally - { - //Let the project installer do its job - base.Uninstall(savedState); - } - } - - - } -}
