Posts

Showing posts from 2016

VMware Virtual Machine Operations

VMware Virtual Machine Operations For these operations I used VI java as library: SourceCode: package com.shashwat.vijava;   import java.net.URL; import java.util.Scanner; import com.vmware.vim25.mo.Folder; import com.vmware.vim25.mo.InventoryNavigator; import com.vmware.vim25.mo.ServiceInstance; import com.vmware.vim25.mo.Task; import com.vmware.vim25.mo.VirtualMachine; public class VMPowerOps { @SuppressWarnings("deprecation") public static void main(String[] args) throws Exception { String address, userName, password, vmName, operation; Scanner scanner = new Scanner(System.in); System.out.println("Enter vCenter or ESXi IP address ?"); address = scanner.nextLine(); System.out.println("Enter username of " + address + " ?"); userName = scanner.nextLine(); System.out.println("Enter password of " + addr

How to remove QuickAccess field from your Eclipse application

Image
Sometimes we need to remove the QuickAccess widget from Eclipse RCP application. Even after following below steps Ctrl + 3 will work. Add these dependency in your eclipse rcp plugin org.eclipse.e4.ui.model.workbench org.eclipse.e4.ui.workbench org.eclipse.e4.core.contexts In ApplicationWorkbenchWindowAdvisor, in postWindowOpen add these statements at end IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window instanceof WorkbenchWindow) { MWindow mWindow = ((WorkbenchWindow) window).getModel(); EModelService modelService = mWindow.getContext().get(EModelService.class); MToolControl searchField = (MToolControl)modelService.find("SearchField", mWindow); if (searchField != null) { searchField.setToBeRendered(false); } }

Producer - Consumer Problem Java

Producer - Consumer Problem implementation: IntegerBuffer.java public class IntegerBuffer { private int index; private int[] buffer; private final int SIZE = 2; public IntegerBuffer() { this.buffer = new int[SIZE]; } public synchronized void add(int number) { while (index == buffer.length - 1) { try { wait(); System.out.println("IntegerBuffer.add() waiting"); } catch (InterruptedException e) { } } buffer[index++] = number; notifyAll(); } public synchronized int remove() { while (index == 0) { try { wait(); System.out.println("IntegerBuffer.remove() waiting"); } catch (InterruptedException e) { } } in

Types of Virtualization

Paravirtualization is virtualization in which the guest operating system (the one being virtualized) is aware that it is a guest and accordingly has drivers that, instead of issuing hardware commands, simply issue commands directly to the host operating system. This also includes memory and thread management as well, which usually require unavailable privileged instructions in the processor. Full Virtualization is virtualization in which the guest operating system is unaware that it is in a virtualized environment, and therefore hardware is virtualized by the host operating system so that the guest can issue commands to what it thinks is actual hardware, but really are just simulated hardware devices created by the host. Hardware Assisted Virtualization is a type of Full Virtualization where the microprocessor architecture has special instructions to aid the virtualization of hardware. These instructions might allow a virtual context to be setup so that the guest can execute pr

Implemention of LRU Cache

Source: import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; /** * Class LRU Cache * @author Shashwat * @param <Key> * @param <Value> */ public class LRUCache<Key, Value> { private final int MAX_SIZE; private ConcurrentHashMap<Key, Value> map; private ConcurrentLinkedDeque<Key> queue; public LRUCache(final int maxSize) { this.MAX_SIZE = maxSize; this.map = new ConcurrentHashMap<Key, Value>(this.MAX_SIZE); this.queue = new ConcurrentLinkedDeque<Key>(); } public Value get(Key key) { return this.map.get(key); } public void put(final Key key, final Value value) { if (this.map.containsKey(key)) { this.queue.remove(key); } while (this.queue.size() >= this.MAX_SIZE) { Key o

Java Puzzle

Question: class Puzzle { public static void main(String[] args) { System.out.print(12345 + 5432l); System.out.print(" "); System.out.print(01234 + 43210); } } Output : 17777 43878 In lines: System.out.print(12345 + 5432l); 5432l ---- Its last character is L -- means long System.out.print(01234 + 43210); 01234 ---- Here starting digit is 0 which means octal Fixed version : class Puzzle { public static void main(String[] args) { System.out.print(12345 + 5432L); // make the last character L System.out.print(" "); System.out.print(1234 + 43210); // drop the 0 } } Output : 66666 44444