forked from community/device-mgt-core
parent
7b28665135
commit
37ef7b9047
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (pvt) Ltd. 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 org.wso2.carbon.device.mgt.common;
|
||||||
|
|
||||||
|
public class ServerCtxInfo {
|
||||||
|
private int activeServerCount;
|
||||||
|
private int localServerHashIdx;
|
||||||
|
|
||||||
|
public ServerCtxInfo(int activeServerCount, int localServerHashIdx){
|
||||||
|
this.activeServerCount = activeServerCount;
|
||||||
|
this.localServerHashIdx = localServerHashIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getActiveServerCount() {
|
||||||
|
return activeServerCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActiveServerCount(int activeServerCount) {
|
||||||
|
this.activeServerCount = activeServerCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLocalServerHashIdx() {
|
||||||
|
return localServerHashIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocalServerHashIdx(int localServerHashIdx) {
|
||||||
|
this.localServerHashIdx = localServerHashIdx;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +0,0 @@
|
|||||||
package org.wso2.carbon.device.mgt.common.dynamic.task.allocation;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
|
||||||
import org.wso2.carbon.ntask.core.Task;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class DynamicPartitionedScheduleTask implements Task {
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,43 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.core.task.impl;
|
||||||
|
|
||||||
|
import io.entgra.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.ServerCtxInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.ntask.core.Task;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class DynamicPartitionedScheduleTask implements Task {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DynamicPartitionedScheduleTask.class);
|
||||||
|
|
||||||
|
private static int serverHashIndex;
|
||||||
|
private static int activeServerCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void init() {
|
||||||
|
try {
|
||||||
|
ServerCtxInfo ctxInfo = DeviceManagementDataHolder.getInstance().getHeartBeatService().getServerCtxInfo();
|
||||||
|
if(ctxInfo!=null){
|
||||||
|
activeServerCount = ctxInfo.getActiveServerCount();
|
||||||
|
serverHashIndex = ctxInfo.getLocalServerHashIdx();
|
||||||
|
setup();
|
||||||
|
} else {
|
||||||
|
log.error("Error Instantiating Variables necessary for Dynamic Task Scheduling. Dynamic Tasks will not function.");
|
||||||
|
}
|
||||||
|
} catch (HeartBeatManagementException e) {
|
||||||
|
log.error("Error Instantiating Variables necessary for Dynamic Task Scheduling. Dynamic Tasks will not function." , e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void setup();
|
||||||
|
|
||||||
|
public int getLocalServerHash(){
|
||||||
|
return serverHashIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getActiveServerCount(){
|
||||||
|
return activeServerCount;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue