From eadc1a19926f7da0310bd0418eb74e821c3ce151 Mon Sep 17 00:00:00 2001 From: Ace Date: Sun, 15 Nov 2020 22:56:46 +0530 Subject: [PATCH] Adding operation partitioning functionality - missing files --- .../beacon/HeartBeatBeaconConfig.java | 98 +++++++++++++++++++ ...HeartBeatBeaconConfigurationException.java | 45 +++++++++ 2 files changed, 143 insertions(+) create mode 100644 components/task-allocation/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconConfig.java create mode 100644 components/task-allocation/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconConfigurationException.java diff --git a/components/task-allocation/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconConfig.java b/components/task-allocation/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconConfig.java new file mode 100644 index 0000000000..5c5cc9def0 --- /dev/null +++ b/components/task-allocation/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconConfig.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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 io.entgra.server.bootup.heartbeat.beacon; + +import io.entgra.server.bootup.heartbeat.beacon.exception.InvalidConfigurationStateException; +import org.w3c.dom.Document; +import org.wso2.carbon.utils.CarbonUtils; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.io.File; + +@XmlRootElement(name = "HeartBeatBeaconConfig") +public class HeartBeatBeaconConfig { + + private int notifierFrequency; + private int notifierDelay; + private int serverTimeOutInterval; + + private static HeartBeatBeaconConfig config; + + private static final String HEART_BEAT_NOTIFIER_CONFIG_PATH = + CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "heart-beat-config.xml"; + + private HeartBeatBeaconConfig() { + } + + public static HeartBeatBeaconConfig getInstance() { + if (config == null) { + throw new InvalidConfigurationStateException("Webapp Authenticator Configuration is not " + + "initialized properly"); + } + return config; + } + + @XmlElement(name = "NotifierInitialDelay", required = true) + public int getNotifierDelay() { + return notifierDelay; + } + + public void setNotifierDelay(int notifierDelay) { + this.notifierDelay = notifierDelay; + } + + @XmlElement(name = "NotifierFrequency", required = true) + public int getNotifierFrequency() { + return notifierFrequency; + } + + public void setNotifierFrequency(int notifierFrequency) { + this.notifierFrequency = notifierFrequency; + } + + @XmlElement(name = "ServerTimeOutIntervalInSeconds", required = true) + public int getServerTimeOutIntervalInSeconds() { + return serverTimeOutInterval; + } + + public void setServerTimeOutInterval(int serverTimeOutInterval) { + this.serverTimeOutInterval = serverTimeOutInterval; + } + + public static void init() throws HeartBeatBeaconConfigurationException { + try { + File emailSenderConfig = new File(HEART_BEAT_NOTIFIER_CONFIG_PATH); + Document doc = HeartBeatBeaconUtils.convertToDocument(emailSenderConfig); + + /* Un-marshaling Email Sender configuration */ + JAXBContext ctx = JAXBContext.newInstance(HeartBeatBeaconConfig.class); + Unmarshaller unmarshaller = ctx.createUnmarshaller(); + //unmarshaller.setSchema(getSchema()); + config = (HeartBeatBeaconConfig) unmarshaller.unmarshal(doc); + } catch (JAXBException e) { + throw new HeartBeatBeaconConfigurationException("Error occurred while un-marshalling " + + "heart beat configuration file", e); + } + } + +} diff --git a/components/task-allocation/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconConfigurationException.java b/components/task-allocation/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconConfigurationException.java new file mode 100644 index 0000000000..c784318249 --- /dev/null +++ b/components/task-allocation/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconConfigurationException.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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 io.entgra.server.bootup.heartbeat.beacon; + +public class HeartBeatBeaconConfigurationException extends Exception { + + private static final long serialVersionUID = -1043317705230442099L; + + public HeartBeatBeaconConfigurationException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public HeartBeatBeaconConfigurationException(String message, Throwable cause) { + super(message, cause); + } + + public HeartBeatBeaconConfigurationException(String msg) { + super(msg); + } + + public HeartBeatBeaconConfigurationException() { + super(); + } + + public HeartBeatBeaconConfigurationException(Throwable cause) { + super(cause); + } + +}