Updates from October, 2010 Toggle Comment Threads | Keyboard Shortcuts

  • Subinkrishna Gopi 11:11 am on October 28, 2010 Permalink |
    Tags: , , , guide, how-to, , simple, tutorial   

    Today’s read: Get Started Developing for Android with Eclipse 

    This one is pretty good. Perhaps one of the very useful how-tos! I read this article in smashingmagazine.com a few days back. I was thinking of sharing it from that moment. It’s better late than never. The article talks a lot of things. From about installing the Android SDK, configuring it and even about writing a sample application.

    There’s a lot to get excited about in mobile application development today. With increasingly sophisticated hardware, tablet PCs and a variety of software platforms (Symbian OS, iOS, WebOS, Windows Phone 7…), the landscape for mobile developers is full of opportunities — and a little complex as well.

    So much choice can be overwhelming when you just want to get started building mobile applications. Which platform should you choose? What programming language should you learn? What kit do you need for your planned project? In this tutorial, you’ll learn how to start writing applications for Android, the open-source mobile operating system popularized by Google.

    Source: Smashing Magazine

    Read the article | http://developer.android.com

     
  • Subinkrishna Gopi 4:51 pm on June 23, 2010 Permalink |
    Tags: cache, , distributed cache, ehcache,   

    Distributed Ehcache – RMI replication (configuration) 

    I am having some fun with Ehcache esp. in distributed caching. Distributed caching is really important in a clustered environment. Read more about distributed caching here – http://ehcache.org/documentation/distributed_caching.html.

    I have downloaded Ehcache 2.1 from http://sourceforge.net/projects/ehcache/files/ (ehcache-2.1.0-distribution.tar.gz, 48 mb approx.) which contains Ehcache core and the Terracotta libraries. Once if we have these libraries, we can configure the caches, peers and listeners. I have created a basic cache – MyCache – and my configuration file looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="ehcache.xsd"
             updateCheck="true" monitoring="autodetect"
             dynamicConfig="true" >
    
        <diskStore path="java.io.tmpdir"/>
        <cacheManagerEventListenerFactory class="" properties=""/>
    
        <defaultCache
               maxElementsInMemory="0"
               eternal="false"
               timeToIdleSeconds="1200"
               timeToLiveSeconds="1200">
        </defaultCache>
    
            <!-- For RMI replication (Setting the peer provider factory) -->
    	<cacheManagerPeerProviderFactory
    		class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
    		properties="peerDiscovery=manual, rmiUrls=//remoteHostIpAddress:40000/MyCache"
    		propertySeparator="," />
    
    	<!-- For RMI replication (Setting the peer listener factory) -->
    	<cacheManagerPeerListenerFactory
                class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
                properties="hostName=localMachineIpAddress, port=40000, socketTimeoutMillis=120000"
                propertySeparator=","/>
    
    	<cache name="MyCache"
    		maxElementsInMemory="1000"
    		eternal="false"
    		overflowToDisk="true"
    		diskSpoolBufferSizeMB="20"
    		timeToLiveSeconds="3000"
    		timeToIdleSeconds="3000"
    		memoryStoreEvictionPolicy="LFU">
    
    		<!-- Cache event listener -->
    		<cacheEventListenerFactory
    			class="subin.cache.listener.factory.CacheEventListenerFactoryImpl"
    			properties="" />
    
    		<!-- RMI replication listener -->
    		<cacheEventListenerFactory
            	class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            	properties="replicateAsynchronously=true,
    		         replicatePuts=true,
    		         replicatePutsViaCopy=true,
    		         replicateUpdates=true,
    		         replicateUpdatesViaCopy=true,
    		         replicateRemovals=true" />
    
    		<!-- RMI Cache bootstrap -->
    		<bootstrapCacheLoaderFactory
    			class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
    			properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
    			propertySeparator="," />
    
    	</cache>
    
    </ehcache>
    

    Initializing the CacheManager & Accessing the cache

    // Testing the cache creation in ver 2.1
    CacheManager manager = new CacheManager("/path/to/config/file.xml");
    
    // Get the instance of "MyCache"
    Cache myCache = manager.getCache("MyCache");
    
    // Add an element to "MyCache". Its preferred to have both key and value
    // serializable
    Element aCacheElement = new Element(key, value);
    myCache.put(aCacheElement);
    

    Useful Links

    RMI replication: http://ehcache.org/documentation/distributed_caching_with_rmi.html
    Configuration: http://ehcache.org/documentation/configuration.html

     
  • Subinkrishna Gopi 3:12 pm on February 19, 2010 Permalink |
    Tags: , executor, , , , thread pool, threadpoolexecutor   

    ThreadPoolExecutor – basics 

    ThreadPoolExecutor is an implementation of the ExecutorService, which can be used to execute the submitted tasks using the available Thread pool. Read the Sun Java API docs for more information.

    The buzz words

    1. Core & max pool size
    This is the size of the core (minimam) and maximum possible thread that need to be in the thread pool every time. We can even specify the keep-alive time limit for the threads.

    2. Work queue
    Work queue is a BlockingQueue, which is used to hold the work/task which is being sent to the executor when all the threads in the pool are busy executing the tasks. Read more about the BlockingQueue in Sun Java API docs.

    3. RejectedExecutionHandler
    So we have a limited number of threads in the pool to execute the tasks and a fixed sized work queue to hold the additional tasks. But what if the work queue overflows! RejectedExecutionHandler can help us in such situations. Read the Sun Java API docs for more.

    Some sample code

    Initializing the ThreadPoolExecutor and sending the task. Here we’ve defined a worksQueue with size 2, core & max pool size is 3 and the threads will expire after 10 seconds. We are also starting a daemon thread to monitor the executor status.

    BlockingQueue<Runnable> worksQueue = new ArrayBlockingQueue<Runnable>(2);
    RejectedExecutionHandler executionHandler = new MyRejectedExecutionHandelerImpl();
    
    // Create the ThreadPoolExecutor
    ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 3, 10,
            TimeUnit.SECONDS, worksQueue, executionHandler);
    executor.allowCoreThreadTimeOut(true);
    
    // Starting the monitor thread as a daemon
    Thread monitor = new Thread(new MyMonitorThread(executor));
    monitor.setDaemon(true);
    monitor.start();
    
    // Adding the tasks
    executor.execute(new MyWork("1"));
    executor.execute(new MyWork("2"));
    executor.execute(new MyWork("3"));
    executor.execute(new MyWork("4"));
    executor.execute(new MyWork("5"));
    executor.execute(new MyWork("6"));
    executor.execute(new MyWork("7"));
    executor.execute(new MyWork("8"));
    
    try
    {
        Thread.sleep(30000);
        executor.execute(new MyWork("9"));
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    

    RejectedExecutionHandler implementation.

    /**
     * The custom {@link RejectedExecutionHandler} to handle the rejected
     * tasks / {@link Runnable}
     */
    public class MyRejectedExecutionHandelerImpl
    implements RejectedExecutionHandler
    {
        @Override
        public void rejectedExecution(Runnable runnable,
                ThreadPoolExecutor executor)
        {
            System.out.println(runnable.toString() + " : I've been rejected ! ");
        }
    }
    

    My task (implements Runnable).

    /**
     * My {@link Runnable} class. Represents a task which need to be executed.
     */
    public class MyWork implements Runnable
    {
        String name;
    
        public MyWork(String name)
        {
            this.name = name;
        }
    
        @Override
        public void run()
        {
            System.out.println(this.name + " : I'm running ! ");
    
            try
            {
                Thread.sleep(5000);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
    
            System.out.println(this.name + " : I'm done ! ");
        }
    
        @Override
        public String toString()
        {
            return (this.name);
        }
    }
    

    And the monitor thread.

    /**
     * My monitor thread. To monitor the status of {@link ThreadPoolExecutor}
     * and its status.
     */
    public class MyMonitorThread implements Runnable
    {
        ThreadPoolExecutor executor;
    
        public MyMonitorThread(ThreadPoolExecutor executor)
        {
            this.executor = executor;
        }
    
        @Override
        public void run()
        {
            try
            {
                do
                {
                    System.out.println(
                        String.format("[monitor] [%d/%d] Active: %d, Completed: %d, Task: %d, isShutdown: %s, isTerminated: %s",
                            this.executor.getPoolSize(),
                            this.executor.getCorePoolSize(),
                            this.executor.getActiveCount(),
                            this.executor.getCompletedTaskCount(),
                            this.executor.getTaskCount(),
                            this.executor.isShutdown(),
                            this.executor.isTerminated()));
                    Thread.sleep(3000);
                }
                while (true);
            }
            catch (Exception e)
            {
            }
        }
    }
    

    So we have all necessary code blocks in place. If we execute the above code we may get something like this.

    1 : I'm running !
    2 : I'm running !
    3 : I'm running !
    6 : I've been rejected !
    7 : I've been rejected !
    8 : I've been rejected !
    [monitor] [0/3] Active: 1, Completed: 0, Task: 1, isShutdown: false, isTerminated: false
    [monitor] [3/3] Active: 3, Completed: 0, Task: 5, isShutdown: false, isTerminated: false
    1 : I'm done !
    4 : I'm running !
    2 : I'm done !
    5 : I'm running !
    3 : I'm done !
    [monitor] [3/3] Active: 2, Completed: 3, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [3/3] Active: 2, Completed: 3, Task: 5, isShutdown: false, isTerminated: false
    4 : I'm done !
    5 : I'm done !
    [monitor] [3/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [2/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [2/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [0/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [0/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    [monitor] [0/3] Active: 0, Completed: 5, Task: 5, isShutdown: false, isTerminated: false
    9 : I'm running !
    [monitor] [1/3] Active: 1, Completed: 5, Task: 6, isShutdown: false, isTerminated: false
    [monitor] [1/3] Active: 1, Completed: 5, Task: 6, isShutdown: false, isTerminated: false
    9 : I'm done !
    [monitor] [1/3] Active: 0, Completed: 6, Task: 6, isShutdown: false, isTerminated: false
    [monitor] [1/3] Active: 0, Completed: 6, Task: 6, isShutdown: false, isTerminated: false
    [monitor] [1/3] Active: 0, Completed: 6, Task: 6, isShutdown: false, isTerminated: false
    

     
    • nguyenhuuquan 9:28 pm on April 29, 2013 Permalink

      thanks, it’s helpful. I have a question: if a task take a long time to execute, how to terminate it?

  • Subinkrishna Gopi 12:53 am on January 22, 2010 Permalink |
    Tags: Book, Francesco Marchioni, , , packt publishing,   

    Book review – JBoss AS 5 Development 

    1847196829 
    JBoss AS 5 Development
    Written by Francesco Marchioni 
    Published by Packt Publishing

    When I started reading this book my expectations were a little less as I was expecting a “1 + 1 = 2” kinda stuff! But after reading the very first chapter – Installing core components – I realized that this one is going to be different. The story in this book is very simple which even my 11 year old nephew can understand and enjoy. Yes, it’s indeed a story.

    The first three chapters tells us what JBoss is, from where to get it, how to install it, how to configure Eclipse & JBoss tools, the JBoss sub-systems, basic deployment configurations, the background story and a lot of things. It’s very detailed, simple. I had real fun reading it. Because we assume a lot of things which we think is right. These three chapters proved me wrong at many places.

    The following chapters deal more with EJB 3, JMS, JPA, Web Services, JBoss management, JBoss clustering & security. These chapters try to cover the basics as much as it can. It will be really helpful as the first step towards J2EE/JBoss.

    Okay, now it’s time for the final verdict.

    This book – with 400+ pages & 14 chapters – is very well written. This is for the common man. This book tells the whole story in the simplest possible way. This book tells us what all things we need to do to master JBoss. It may not help you in mastering JBoss, but can definitely show you a way with all possible sign boards, maps & guides.

    I really enjoyed reading this book. I am not an expert in JBoss, EJBs JPA or JTA, but a “modestly aware” coder. Yeah, this will be a first good step towards mastering the art 🙂

    What I liked about this book
    It’s very simple & well-organized.

    What I did not like about this book
    Lacks depth. I think the target audience is beginners & enthusiasts.

    So, do I recommend this?
    Yes. I do. It’s going to be an easy & good read.

    Check this link for more details.

    Useful links
    http://www.jboss.org/ – JBoss Home
    http://www.jboss.org/jbossas/downloads/ – JBoss downloads
    http://www.eclipse.org/ – Eclipse IDE Home
    http://www.eclipse.org/downloads/ – Eclipse downloads

     
  • Subinkrishna Gopi 3:40 pm on December 21, 2009 Permalink |
    Tags: beginners, , selenium, testing,   

    A selenium blog for beginners 

    Selenium Logo

    Simple Tech Talks is a very good place for Selenium beginners.The author, Jinesh, well categorized the content in to seven simple posts.

    Part 1: Why Selenium
    Part 2: Why Not Selenium
    Part 3: Selenium Flavors (Components)
    Part 4: How Does Selenium work
    Part 5: Locating the Elements in a Web Page (Objec…
    Part 6: Running The Tests
    Part 7: Beginners How to Start With??

    This is very well written and worth a read for all enthusiasts.

    What is selenium?
    Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language. Selenium provides a test domain specific language (DSL) to write tests in a number of popular programming languages, including Java, Ruby, Groovy, Python, PHP, and Perl. Test playback is in most modern web browsers. Selenium deploys on Windows, Linux, and Macintosh platforms.

    Source: Wikipedia

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel