Posts

Showing posts from March, 2013

Toastmaster’s Table Topics – Life as an Object

Introduction to the theme – Life as an Object:Spring is around the corner. Most of us will have some plans for doing stuff like cleaning their homes, to go on some vacation, to throw parties, to do other outdoor activities and get healthy. Consider for a moment if we were not living beings - consider if we were lifeless objects like a Pen for instance. Now consider if the Pen had a mind of its own with which it can think just as we humans do. In the table topics today, each of the respondents to the table topics will lend their voice to an object which they pick from the grab bag of objects i have. They can then tell us about their life as that Object in general or what they think (as that object) about spring time. So let the fun begin... may i have volunteers please. Objects options:
Pen
PC Mouse
Keyboard
Laptop
Chair
Dooretc..

Toastmaster’s speech 1 – Virtual Networks

Speech contents are below:Speech – Virtual Networks1. What is Virtualization? a. Benefits: Run multiple OS on single server (hardware consolidation – 80% greater utilization), power savings, rack space saving, efficiency in maintenance and deploying patches, HA b. Savings - > $1500 per server virtualized. c. Types – Server, Storage (VMFS datastore), Network 2. Software Defined Datacenters – caters to capacity elasticity, on-demand application provisioning, policy based provisioning and automated operations management. 3. Types of Hypervisors a. Type 1- Bare metal (ESXi, Hyper-v, XenServer) b. Type 2 – Hypervisor within OS (VMware Workstation, MS VirtualServer) c. ESXi – 32 MB footprint. 4. Virtual Network Components: a. vSSb. vDSc. Port/Port group – VM Kernel, VM Port groupd. VLANe. Trunk portf. Access portg. Network Interface card team h. Virtual network adapters – vmxnet adapters 1Gbps – inside guest OS.5. Virtual Switch functions – a. VM to VM on same host b. Vmknic for vMotion,…

Java EE 6 - Part 8 - Transactions

Project: EJB31-ejb


package helloworld.beans;

import helloworld.interceptors.PMInterceptor;
import helloworld.vo.GreetingRequest;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.LocalBean;
import javax.ejb.Schedule;
import javax.ejb.Startup;
import javax.ejb.Timer;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.interceptor.Interceptors;

/**
 * This is a stateless bean using EJB timer service.
 *
 * @author rwatsh
 */
@Singleton
@LocalBean
@Startup
public class AutomaticSayHelloBean {

    @EJB
    private SingletonHelloWorldBean singletonHelloWorldBean;
    private int timerNotifications;
    private boolean cancelTimer = false;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    /**
     * Using schedule will cause a timer notification to occur every 5 seconds.
     */
    @Interceptors(PMInterceptor.class)
    @Schedule(second = "*/5"…

Java EE 6 - Part 7 - Writing Asynchronous Session Beans

This is a very useful enhancement in EJB 3.1 that lets the client make a server method call asynchronously.

In the past we needed to write a lot of code to achieve the same result. The client used to create a temporary JMS queue destination and pass it to the server in the remote method call and the server did its task asynchronously and used the temporary queue to send its response back to client. This has now been taken care of by Java EE 6 framework with the introduction of the @Asynchronous annotations for session beans.

Project: EJB31-Common


package helloworld.beans;

import java.util.concurrent.Future;
import javax.ejb.Remote;

/**
 * Interface for the asynch session bean.
 *
 * @author rwatsh
 */
@Remote
public interface HelloEjbAsynchronousRemote {

    Future ejbAsynchronousSayHello(String name);

}

Project: EJB31-ejb

package helloworld.beans;

import java.util.Date;
import java.util.concurrent.Future;
import javax.ejb.AsyncResult;
import javax.ejb.Asynchronous;
import javax.ejb.St…

Java EE 6 - Part 6 - Writing EJB TimerService and Interceptors

Project: EJB31-Common


package helloworld.beans;

import javax.ejb.Remote;
import javax.ejb.Timer;

/**
 * Interface to manage the EJB timer service.
 *
 * @author rwatsh
 */
@Remote
public interface AutomaticManagerBeanRemote {
    public void manageTimer(int interval, int threshold);

    void monitorAutomaticTimer(Timer timer);
}

Project:EJB31-ejb


package helloworld.beans;

import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;

/**
 * Bean implementation for controlling the timer service EJB.
 *
 * @author rwatsh
 */
@Stateless
public class AutomaticManagerBean implements AutomaticManagerBeanRemote {
    @EJB
    private AutomaticSayHelloBean automaticSayHelloBean;
    @Resource
    private TimerService timerService;
    private int threshold;

    @Override
    public void manageTimer(int interval, int threshold) {
        this.threshold= threshold;
        int currentCount = aut…

Java EE 6 - Part 5 - Writing Message Driven Beans

Project: EJB31-Common

package helloworld.beans;

import helloworld.vo.GreetingRequest;
import javax.ejb.Remote;

/**
 *
 * @author rwatsh
 */
@Remote
public interface MessageFacadeRemote {

    GreetingRequest sayHello();

}


Project: EJB31-ejb

package helloworld.beans;

import helloworld.vo.GreetingRequest;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.Session;

/**
 * Message Facade bean that produces message.
 * @author rwatsh
 */
@Stateless
public class MessageFacade implements MessageFacadeRemote {

    @Resource(mappedName = "jms/HelloWorldQueue")
    private Queue helloWorldQueue;
    @Resource(mappedName = "jms/HelloWorldQueueFactory")
 …

Java EE 6 - Part 4 - Writing JMS Message Producers

1. Create JMS resources - QueueConnectionFactory and Queue. 

For glassfish, it is done in the glassfish-resources.xml file. Netbeans puts in /setup folder (Right click App and select New > Other > Glassfish > JMS Resource. Do it twice, once to add Admin Object Resource and then to add Connector Object Resource.



2. Create MessageProducerApp client.
Project: EJB31-app-client


package ejb31;

import helloworld.beans.SingletonHelloWorldBeanRemote;
import helloworld.vo.GreetingRequest;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 * The message producer.
 * @author rwatsh
 */
public class MessageProducerApp {

    private static Message createJMSMessageForjmsHelloWorldQueue(Session sess…

Java EE 6 - Part 3 - Writing Singleton Session Beans

Project: EJB31-Common

package helloworld.beans;

import helloworld.vo.GreetingRequest;
import javax.ejb.Remote;

/**
 * Remote interface for singleton bean.
 * @author rwatsh
 */
@Remote
public interface SingletonHelloWorldBeanRemote {

    GreetingRequest sayHello();

    GreetingRequest[] auditRequests();

}

Project: EJB31-ejb

package helloworld.beans;

import helloworld.vo.GreetingRequest;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PreDestroy;
import javax.ejb.EJB;
import javax.ejb.Singleton;

/**
 * Singleton bean implementation.
 * Note: It depends on the TimeBasedHelloWorldBean (not shown in this post) which is
 * another singleton bean. The TimeBasedHelloWorldBean will be initialized before this bean.
 * @author rwatsh
 */
@Singleton
@DependsOn("TimeBasedHelloWorldBean")
public class SingletonHelloWorldBean implements SingletonHelloWorldBeanRemote {

    @EJB
    private TimeBasedHelloWorldBean timeBasedHelloWorldBean;
    private List greetingR…

Java EE 6 - Part 2 - Writing Stateful Session Beans

Below is an example program using Java EE 6 APIs for Stateful Session beans.
This example shows the client using JNDI lookup directly to access the session bean remote proxy instance. The other way is to use @EJB or using CDI's @Inject
Project: EJB31-Common
import helloworld.vo.GreetingRequest; import javax.ejb.Remote;
/**  * Remote interface for stateful session bean.  *  * @author rwatsh  */ @Remote public interface StatefulHelloWorldBeanRemote {
    GreetingRequest sayHello();
    GreetingRequest[] sayGoodBye(); } --------------
package helloworld.vo;
import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Calendar;
/**  * Serializable type which holds the session state.  *  * @author rwatsh  */ public class GreetingRequest implements Serializable {
    private Calendar requestTime;     private String greeting;
    public GreetingRequest(String greet) {         requestTime = Calendar.getInstance();         greeting = greet;     }
    public String toSt…

Java EE 6 - Part 1 - Writing Stateless Session Beans

EJB 3.1 Session Beans types:
Stateless - pooled instances Stateful - dedicated instance to a clientSingleton - Only 1 instance per application per JVM instance Following is some sample code for writing a stateful session bean (stateless is similar) - used Netbeans 7.3 with Glassfish v3 3.1.2: Create an AccountCommon project.Create an AccountEJB project as EJB Module or EJB Appplication.Add a stateful session bean class - AccountBean.Select the AccountCommon project as the project in which to create the AccountBeanRemote interface definition. This is done automaticalrly by Netbeans 7.3.Add business methods to AccountBeanRemote interface in the AccountCommon project.Implement those methods in the AccountBean class in AccountEJB project.Project: AccountCommon import javax.ejb.Remote;
/**  * This is the Account remote interface.  *   * @author rwatsh  */ @Remote public interface AccountBeanRemote {     public double deposit(double amount);     public double withdraw (double amount); }
Projec…

A Quick VBScript Tutorial

Option explicit
 Dim x, i

 i = 10

 x="Hello World"
 Wscript.Echo x

 'subroutine cannot return value like function returning void
 mysub()

 ' calling function which returns date
 Wscript.Echo myfunc()


 ' if then elseif else
 if i=10 then
 Msgbox("hello")
 i = i+1
 elseif i = 12 then
 Msgbox ("i is 12")

 else
 Msgbox("came to else")

 end if

' select case
Select case i
 case 11
Msgbox "i is 11"
case 20
Msgbox "i is 20"
case else
Msgbox "default case"
End Select

' for loop
For i= 0 To 5 step 1
Wscript.Echo "hello for loop"
Next

 'Msgbox x

 ' subroutine
 sub mysub()
Wscript.echo "This is mysub()"
 end sub

 ' function which returns date
 function myfunc()
myfunc= Date()
 end function

Java 7 Locale Changes impacting Double.parseDouble() for some European Locales

Details on the Java 7 Locale related changes and its impact is captured succinctly at: http://blog.ej-technologies.com/2011/12/default-locale-changes-in-java-7.htmlA fix for the old code using Double.parseDouble() method which used to work fine with European locales like French (fr) and German (de) are broken since the parseDouble() method considers the value being passed to it to be in English format whereas a decimal value in French/German is represented with a comma and not a dot thus leading to a NumberFormatException. Prior to Java 7, the behavior for parseDouble() method was to expect the value to be in the current locale and not en_US. A fix to the above issue is:Locale loc = Locale.getDefault(Locale.Category.FORMAT); // get current localeNumberFormat nf = NumberFormat.getNumberInstance(loc); // get number format for current localeDecimalFormat df = (DecimalFormat)nf;df.applyPattern(“#.##”); //Then replace occurrence of Double.parseDouble(df.format(c)) with the following:Number…

Linux Mint 14 XFCE notebook

Image
I got a Toshiba Satellite C855-S5194 notebook in a deal recently and installed Linux Mint 14 with Cinnamon and XFCE desktop.

This notebook came very cheap (for $330) and has Intel i3 processor which is dual core 2.5 GHz clock speed and has 6GB RAM (expandable upto 16GB), 650GB HDD and other usual stuff. I initially started with Cinnamon for my desktop but soon discovered that it was too heavy weight for my modest notebook so i installed Xubuntu desktop and noted that there was a significant performance improvement (CPU remains < 10%) with several applications like the email client, the browser with several tabs, the terminal sessions and the Eclipse IDE running simultaneously.

For more details on this notebook see:
http://us.toshiba.com/computers/laptops/satellite/C850/C855-S5194/

The build quality is pretty average (so handle with some gentleness :)) but i am amazed at the performance of the i3 processor which has hyper-threading support and so it shows up with 4 CPU threads in th…