Java tutorial
/** Copyright 2014 OpenSearchServer, Inc. * http://www.opensearchserver.com * * Licensed 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. **/ package com.opensearchserver.hadse; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.apache.log4j.Logger; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.util.StringUtils; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.databind.JsonMappingException; import com.opensearchserver.hadse.cluster.ClusterCatalog; import com.opensearchserver.hadse.index.IndexCatalog; import com.opensearchserver.hadse.index.IndexItem; @ComponentScan @EnableAutoConfiguration public class Hadse { public final static File data_dir; private final static String HADSE_DATA = "HADSE_DATA"; public static final Logger LOG = Logger.getLogger(Hadse.class); static { String data = System.getProperty(HADSE_DATA); if (StringUtils.isEmpty(data)) data = System.getenv(HADSE_DATA); if (StringUtils.isEmpty(data)) throw new RuntimeException("HADSE_DATA variable not set."); File dataFile = new File(data); if (!dataFile.exists()) throw new RuntimeException("Please create the directory (HADSE_DATA) " + dataFile.getAbsolutePath()); if (!dataFile.isDirectory()) throw new RuntimeException("The path (HADSE_DATA) is not a directory " + dataFile.getAbsolutePath()); data_dir = dataFile; } private static int port = 8080; @PostConstruct void start() throws JsonGenerationException, JsonMappingException, URISyntaxException, IOException { ClusterCatalog.init(port); IndexCatalog.loadAll(); } @PreDestroy void stop() { IndexItem.closeAll(); } public static void main(String[] args) { if (args != null) for (String arg : args) { String s[] = StringUtils.split(arg, "="); if (s.length < 2) continue; if ("--server.port".equals(s[0])) port = Integer.parseInt(s[1]); } SpringApplication app = new SpringApplication(Hadse.class); app.setShowBanner(false); app.run(args); } }