30.4.15

Essential tools to manage import statements in Eclipse | Eclipse On E


This is helpful for me:


4. Let Eclipse collapse imports in the same package a wildcard (.*) or always expand them

There isn’t really consensus on whether you should use wildcards on package imports (eg. org.eclipse.swt.*) or whether to specify them individually (eg. org.eclipse.swt.SWT).
By default, Eclipse imports classes individually but you can tell it to always convert them into wildcards:
  1. Go to Window > Preferences > Java > Code Style > Organize Imports.
  2. Change the value of Number of imports need for .* to 0.
  3. (Optional) Change the value of Number of static imports needed for .* to 0.

25.4.15

KVM



ubuntu-vm-builder kvm hardy \
                  --domain newvm \
                  --dest newvm \
                  --arch i386 \
                  --hostname hostnameformyvm \
                  --mem 256 \
                  --user john \
                  --pass doe \
                  --ip 192.168.0.12 \
                  --mask 255.255.255.0 \
                  --net 192.168.0.0 \
                  --bcast 192.168.0.255 \
                  --gw 192.168.0.1 \
                  --dns 192.168.0.1 \
                  --mirror http://archive.localubuntumirror.net/ubuntu \
                  --components main,universe \
                  --addpkg acpid \ 
                  --addpkg vim \
                  --addpkg openssh-server \
                  --addpkg avahi-daemon \
                  --libvirt qemu:///system ;

8.4.15

Eh CacheManager for Unit Test

    static final String EHCACHE_CONFIG_TEMPLATE =
            "" + "";
    
    @Test
    public void testMulti() throws Exception {
        final CyclicBarrier barrier = new CyclicBarrier(11);
        final AtomicInteger ai = new AtomicInteger();
        final AtomicInteger ai2 = new AtomicInteger();
        
        Runnable r = new Runnable() {
            
            @Override
            public void run() {
                try {
                    testCacheManager(barrier, ai, ai2);
                } catch (InterruptedException | BrokenBarrierException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        
        ExecutorService pool = Executors.newCachedThreadPool();
        
        for(int i=0; i<10; ++i) {
            pool.execute(r);
        }
        
        barrier.await();
        
        pool.shutdown();
        assertTrue(pool.awaitTermination(1, TimeUnit.MINUTES));
        assertEquals(10, ai.get());
        assertEquals(55, ai2.get());
        
    }

    void testCacheManager(CyclicBarrier barrier, AtomicInteger ai, AtomicInteger ai2) throws InterruptedException, BrokenBarrierException {
        String threadName = Thread.currentThread().getName();
        String cacheManagerName = "CM-" + threadName;
        
        String configContent = String.format(EHCACHE_CONFIG_TEMPLATE, cacheManagerName);
        ReaderInputStream configStream = new ReaderInputStream(new StringReader(configContent ));
        CacheManager cacheManager = CacheManager.newInstance(configStream);
        
        Cache testCache = new Cache(
                new CacheConfiguration("testCache", 123)
                  .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
                  .eternal(false)
                  .timeToLiveSeconds(60)
                  .timeToIdleSeconds(30)
                  .diskExpiryThreadIntervalSeconds(0)
                  .persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP)));
        
        barrier.await();
        
        System.err.println(Thread.currentThread().getName() + ": CM " + String.valueOf(cacheManager));
        
        assertNull(cacheManager.getCache("testCache"));
        cacheManager.addCache(testCache);
        
        Integer v = ai.incrementAndGet();
        Element e = new Element("i", v);
        
        testCache.put(e);
        
        assertEquals(v, (Integer)cacheManager.getCache("testCache").get("i").getObjectValue());
        
        while(true) {
            int x = ai2.get();
            if(ai2.compareAndSet(x, x + v)) {
                System.err.printf("%s : X => (%d, %d)\n", threadName, x, v);
                break;
            }
        }
        
        cacheManager.shutdown();
    }