code for round robin partition in java
#1

Code for round robin partition technique
Reply
#2

/*
* 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://apachelicenses/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.apache.stratos.autoscaler.algorithms.partition;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.algorithms.PartitionAlgorithm;
import org.apache.stratos.autoscaler.context.partition.PartitionContext;

/**
* This class is used for selecting a {@link PartitionContext} in round robin manner and checking availability of
* {@link PartitionContext}s according to the partitions defined
* in {@link org.apache.stratos.autoscaler.pojo.policy.deployment.DeploymentPolicy}
*/
public class RoundRobin implements PartitionAlgorithm {

private static final Log log = LogFactory.getLog(RoundRobin.class);

@Override
public PartitionContext getNextScaleUpPartitionContext(PartitionContext[] partitionContexts) {

if (partitionContexts == null) {
return null;
}

int selectedIndex = 0;
int lowestInstanceCount = partitionContexts[0].getNonTerminatedMemberCount();

for (int partitionIndex = 0; partitionIndex < partitionContexts.length; partitionIndex++) {

// it means we have to choose the current partitionIndex, no need to continue the loop
if (lowestInstanceCount == 0) {
break;
}

if (partitionContexts[partitionIndex].getNonTerminatedMemberCount() < lowestInstanceCount
&& !partitionContexts[partitionIndex].isObsoletePartition()) {
lowestInstanceCount = partitionContexts[partitionIndex].getNonTerminatedMemberCount();
selectedIndex = partitionIndex;
}
}

if (partitionContexts[selectedIndex].getNonTerminatedMemberCount() < partitionContexts[selectedIndex].getMax()) {

if (log.isDebugEnabled()) {
log.debug(String.format("[round-robin algorithm] [scale-up] [partition] %s has space to create members. " +
"[non terminated count] %s [max] %s"
, partitionContexts[selectedIndex].getPartitionId(),
partitionContexts[selectedIndex].getNonTerminatedMemberCount(),
partitionContexts[selectedIndex].getMax()));
}
return partitionContexts[selectedIndex];
} else {

return null;
}
}

@Override
public PartitionContext getNextScaleDownPartitionContext(PartitionContext[] partitionContexts) {

if (partitionContexts == null) {
return null;
}

int selectedIndex = 0;
int highestInstanceCount = partitionContexts[0].getNonTerminatedMemberCount();

for (int partitionIndex = partitionContexts.length - 1; partitionIndex >= 0; partitionIndex--) {

if (partitionContexts[partitionIndex].getNonTerminatedMemberCount() > highestInstanceCount
&& !partitionContexts[partitionIndex].isObsoletePartition()) {

highestInstanceCount = partitionContexts[partitionIndex].getNonTerminatedMemberCount();
selectedIndex = partitionIndex;
}
}

if (partitionContexts[selectedIndex].getNonTerminatedMemberCount() <= partitionContexts[selectedIndex].getMax()) {

if (log.isDebugEnabled()) {
log.debug(String.format("[round-robin algorithm] [scale-down] [partition] %s has has members that" +
" can be removed.[non terminated count] %s ", partitionContexts[selectedIndex].getPartitionId(),
partitionContexts[selectedIndex].getNonTerminatedMemberCount()));
}
return partitionContexts[selectedIndex];
} else {

return null;
}
}


}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: round robin scheduling matlab code on lte, code fuzzy round robin with matlab, round robin scheduling java source code, how to implement round robin algorithm in matlap simulink, operating system round robin seminr topic, round robin source code java, round robin scheduling code project in matlab,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  with each other to round up a glimpse of who can impel more variety 0 14,292 03-10-2019, 02:37 PM
Last Post:
  program for ticket reservation using multithreading in java 0 1,065 08-10-2018, 10:00 AM
Last Post: Guest
  icse java projects class 10 free download 0 848 25-09-2018, 10:32 PM
Last Post: Guest
  java source code for voice based email for blinds 0 736 25-09-2018, 09:40 AM
Last Post: Guest
  techmax core java book pdf download 0 656 20-09-2018, 12:54 PM
Last Post: Guest
  rnsit java notes download 0 763 08-08-2018, 10:23 PM
Last Post: Guest
  image steganography source code in java pdf 0 759 04-08-2018, 09:38 PM
Last Post: Guest
  download prisoner face identification system in java source code 0 528 02-08-2018, 01:28 PM
Last Post: Guest
  data flow diagram for chess game in core java 0 694 02-08-2018, 10:39 AM
Last Post: Guest
  java project on automated robot for military system 0 621 23-07-2018, 11:27 AM
Last Post: Guest

Forum Jump: