load balancing algorithm using cloudsim java code
#1

[font=Times New Roman][/font
Reply
#2
/*
* Title: Load Balancing in Cloud Computing
*/
package org.cloudbus.cloudsim;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public final class MyPolicyNew extends VmAllocationPolicy {

private Map<String, Host> vmTable;
private Map<String, Integer> usedPes;
private List<Integer> freePes;

private int status[] = new int[100];

public MyPolicyNew(List<? extends Host> list) {
super(list);
setFreePes(new ArrayList<Integer>());
for (Host host : getHostList()) {
getFreePes().add(host.getPesNumber());

}

setVmTable(new HashMap<String, Host>());
setUsedPes(new HashMap<String, Integer>());
}

@Override

public boolean allocateHostForVm(Vm vm) {
int idx = -1;
int requiredPes;
requiredPes = vm.getPesNumber();
boolean result = false;
int tries = 0;
List<Integer> freePesTmp = new ArrayList<Integer>();

for (Integer freePes : getFreePes()) {
freePesTmp.add(freePes);
}
int tempstatus[] = new int[100];
for(int j=0; j<100; j++){
tempstatus[j]= status[j];
}
if (!getVmTable().containsKey(vm.getUid())) {
do {
int moreFree = Integer.MIN_VALUE;
for (int i=0; i < freePesTmp.size(); i++) {
if ((freePesTmp.get(i) > moreFree) && (tempstatus[i]!=1)) {
moreFree = freePesTmp.get(i);
idx = i;
}
tempstatus[idx]=1;
int flag=0;
for(int j=0; j< freePesTmp.size(); j++)
{ //
if(tempstatus[j]==1)
flag=1;
else
flag=0;
}
if(flag==1){
moreFree = Integer.MIN_VALUE;
for (int k=0; k < freePesTmp.size(); k++) {
if (freePesTmp.get(k) > moreFree) {
moreFree = freePesTmp.get(k);
idx = k;
}
}
}
}
Host host = getHostList().get(idx);
result = host.vmCreate(vm);

if (result) {
getVmTable().put(vm.getUid(), host);
getUsedPes().put(vm.getUid(), requiredPes);

getFreePes().set(idx, getFreePes().get(idx) - requiredPes);
status[idx]=1;
result = true;
break;
}
else {
freePesTmp.set(idx, Integer.MIN_VALUE);
tempstatus[idx]=0;
}
tries++;
}while(!result && tries < getFreePes().size());
}
return result;
}

@Override
public void deallocateHostForVm(Vm vm) {

Host host = getVmTable().remove(vm.getUid());
int idx = getHostList().indexOf(host);
int pes = getUsedPes().remove(vm.getUid());
if (host != null) {
host.vmDestroy(vm);
status[idx]= 0;
}
}

getFreePes().set(idx, getFreePes().get(idx) + pes);

@Override
public Host getHost(Vm vm) {
return getVmTable().get(vm.getUid());
}

@Override
public Host getHost(int vmId, int userId) {
return getVmTable().get(Vm.getUid(userId, vmId));
}

public Map<String, Host> getVmTable() {
return vmTable;
}

protected void setVmTable(Map<String, Host> vmTable) {
this.vmTable = vmTable;
}

protected Map<String, Integer> getUsedPes() {
return usedPes;
}

protected void setUsedPes(Map<String, Integer> usedPes) {
this.usedPes = usedPes;
}

protected List<Integer> getFreePes() {
return freePes;
}

protected void setFreePes(List<Integer> freePes) {
this.freePes = freePes;
}

@Override
public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
return null;
}

@Override
public boolean allocateHostForVm(Vm vm, Host host) {
if (host.vmCreate(vm)){
getVmTable().put(vm.getUid(), host);
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(), CloudSim.clock());
return true;
}
return false;
}

}
Reply
#3
to get full report or ppt or source code of cloudsim code for honey bee algorithm please visit the following pages
http://studentbank.in/report-load-balanc...ode--87935
http://studentbank.in/report-java-source...#pid181010
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: cloudsim java code genetic algorithm, cloudsim load balancing project, examples of load balancing using in cloudsim**ion**ad, free download project of load balancing using java thread, code to implement load balancing using ns2, cloudsim access control policy java code examples, examples of load balancing using in cloudsim,

[-]
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
  simple java rmi chat application source code 2 18,979 20-07-2018, 12:08 PM
Last Post: Guest
  authentication schemes for session passwords using color and images project source code 2 2,231 03-02-2018, 09:35 AM
Last Post: Nischithnash
  free download source code for online movie ticket booking in java 2 18,489 15-08-2017, 03:21 PM
Last Post: Morshed
  source code for rsa encryption and decryption in java 2 7,927 29-05-2017, 04:21 PM
Last Post: Meghna Jadhav
  image encryption and decryption using rsa algorithm in matlab 2 7,827 29-05-2017, 04:17 PM
Last Post: Priyanka Bidikar
  source code for task scheduling using genetic algorithm using java 2 8,445 11-04-2017, 08:31 PM
Last Post: Guest
Thumbs Up source code of online payment system using steganography and visual cryptography 3 8,427 06-04-2017, 09:56 AM
Last Post: jaseela123d
  vhdl code for radix 2 modified booth algorithm 4 1,015 04-04-2017, 10:24 AM
Last Post: Garlapati nikitha
  code to extract brain tumor detection using matlab 2 1,062 17-10-2016, 04:32 PM
Last Post: girish123ak
  secure chat using RSA algorithm karthik1218 2 2,576 14-10-2016, 02:48 PM
Last Post: info togel

Forum Jump: