SOLR Distributed Index "Combat one, Shard Configuration read: Tool class Configutil.java, read configuration code snippet, configuration instance"

Source: Internet
Author: User
Tags allkeys solr

1     Private StaticProperties prop =NewProperties ();2 3     Private StaticString Conffilepath = "conf" + file.separator + "config.properties";//Configuration file Directory4     Static {5         //Load Properties6InputStream is =NULL;7InputStreamReader ISR =NULL;8         Try {9File f =NewFile (conffilepath);Ten             if(F.exists ()) { Oneis =NewBufferedinputstream (NewFileInputStream (f)); AISR =NewInputStreamReader (IS, "Utf-8"); - Prop.load (ISR); - is.close (); theis =NULL; - isr.close (); -ISR =NULL; -}Else { +                 /**modified to read the resource file, convenient for later project packaging*/ -is = Configutil.class. getClassLoader (). getResourceAsStream ("Config.properties"); +                 if(Is! =NULL) { AISR =NewInputStreamReader (IS, "Utf-8"); at Prop.load (ISR); - is.close (); -is =NULL; - isr.close (); -ISR =NULL; -}Else { inSYSTEM.ERR.PRINTLN ("Critical Warning: The Project Profile" Config.properties "is missing, the file should be in the SRC directory or the Conf folder in the project directory," -+ "Continue running will likely cause significant exceptions due to missing configuration parameters such as databases! "); to  +                     //System.exit ( -1); -                 } the             } *}Catch(Exception e) { $ e.printstacktrace ();Panax Notoginseng}finally { -             if(Is! =NULL) { the                 Try { + is.close (); A}Catch(IOException e) { the e.printstacktrace (); +                 } -is =NULL; $             } $         } -  -}

read the Configuration code snippet :

/** gets all the shards of the cloud configuration ordinal * @return */public static set<string> getallcloudsplitmodeconfigindex () {set<string> result = new hashset<string> (); Properties props = Configutil.getproperties (); set<object> AllKeys = Props.keyset ();
Traverse the configuration file to read all key-value pairs. for (Object S:allkeys) {string key = (string) s;if (Key.startswith ("Solr_mode_")) {String value = Stringutil.trim ( Configutil.getprop (key)); In the case of distributed mode
if ("Cloud". Equalsignorecase (value)) {String ConfigName = Key.replacefirst ("Solr_mode_", "" "); If it is fragmented by time

  

Configuration file instance:

######## SOLR ######
Defaultconfigname = 1

# # # # #solr1 ########
Solr_url_1 = HTTP://***********:8080/SOLR (standalone)
zkhost_1 = 192.168.*.*:2181,192.168.*.*:2181,192.168.*.*:2181 (zookeeper address)
Solr_mode_1 = Cloud (distributed mode)
Corename_1 = collection1 (kernel name)
Zkclienttimeout_1 = 200000
Zkconnecttimeout_1 = 10000
Connectiontimeout_1 = 100000
Idfield_1 = GUIDSOLR (UniqueKey)
Split_mode_1 = True (Shard mode turned on)
Splittimefield_1 = publishtime (shard field)

# # # # #solr2 #######
Solr_url_2 = HTTP://192.168.*.*:8080/SOLR (standalone)
Zkhost_2 = 192.168.*.*:2181,192.168.*.*:2181,192.168.*.*:2181
solr_mode_2 = Cloud
corename_2 = Collection2
Zkclienttimeout_2 = 200000
Zkconnecttimeout_2 = 10000
Connectiontimeout_2 = 100000
Idfield_2 = GUIDSOLR
Split_mode_2 = False (Shard mode off)

SOLR Distributed Index "Combat one, Shard Configuration read: Tool class Configutil.java, read configuration code snippet, configuration instance"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.