From 4d0eb509efdc3cafd233df0a43199bd68191ac10 Mon Sep 17 00:00:00 2001 From: lidongdai Date: Thu, 5 Sep 2019 16:56:20 +0800 Subject: [PATCH] add AbstractServer.java --- .../server/master/AbstractServer.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 escheduler-server/src/main/java/cn/escheduler/server/master/AbstractServer.java diff --git a/escheduler-server/src/main/java/cn/escheduler/server/master/AbstractServer.java b/escheduler-server/src/main/java/cn/escheduler/server/master/AbstractServer.java new file mode 100644 index 0000000000..a3db90b010 --- /dev/null +++ b/escheduler-server/src/main/java/cn/escheduler/server/master/AbstractServer.java @@ -0,0 +1,85 @@ +/* + * 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. + */ +package cn.escheduler.server.master; + +import cn.escheduler.common.IStoppable; +import org.apache.commons.configuration.Configuration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.CommandLineRunner; +import org.springframework.context.annotation.ComponentScan; + +/** + * master server + */ +@ComponentScan("cn.escheduler") +public abstract class AbstractServer implements CommandLineRunner, IStoppable { + + private static final Logger logger = LoggerFactory.getLogger(AbstractServer.class); + + /** + * conf + */ + protected static Configuration conf; + + /** + * object lock + */ + protected final Object lock = new Object(); + + /** + * whether or not to close the state + */ + protected boolean terminated = false; + + + /** + * heartbeat interval, unit second + */ + protected int heartBeatInterval; + + + + /** + * blocking implement + * @throws InterruptedException + */ + public void awaitTermination() throws InterruptedException { + synchronized (lock) { + while (!terminated) { + lock.wait(); + } + } + } + + + /** + * Callback used to run the bean. + * @param args incoming main method arguments + * @throws Exception on error + */ + @Override + public abstract void run(String... args) throws Exception; + + /** + * gracefully stop + * @param cause why stopping + */ + @Override + public abstract void stop(String cause); +} +