Free Time Links

Difference Between Queues and Topics-JMS

Queues

JMS queues is a staging area that contains messages that have been sent and are waiting to be read. Queue represent PTP domain. A point-to-point (PTP) product or application is built around the concept of message queues, senders, and receivers. Each message is addressed to a specific queue, and receiving clients extract messages from the queue(s) established to hold their messages. Queues retain all messages sent to them until the messages are consumed or until the messages expire.There can be more but the message will be received to one of them. It also guarantees delivery of the message, means message will be there in the queue unless it is consumed by someone.

TOPICS

Topic represent Publish/Subscibe domain. A distribution mechanism for publishing messages that are delivered to multiple subscriber. In a publish/subscribe (pub/sub) product or application, clients address messages to a topic. Publishers and subscribers are generally anonymous and may dynamically publish or subscribe to the content hierarchy. The system takes care of distributing the messages arriving from a topic’s multiple publishers to its multiple subscribers. Topics retain messages only as long as it takes to distribute them to current subscribers.

Publish/Subscribe Model

The publish/subscribe model supports publishing messages to a particular message topic. Subscribers may register interest in receiving messages on a particular message topic. In this model, neither the publisher nor the subscriber knows about each other. A good analogy for this is an anonymous bulletin board.

The following are characteristics of this model:

  1. Zero or more consumers will receive the message.
  2. There is a timing dependency between publishers and subscribers. The publisher has to create a message topic for clients to subscribe. The subscriber has to remain continuously active to receive messages, unless it has established a durable subscription. In that case, messages published while the subscriber is not connected will be redistributed whenever it reconnects

Future of Search Engine Marketing

http://www.searchengineoptimizationjournal.com/
http://searchengineland.com/
http://www.searchenginejournal.com/
http://googlewebmastercentral.blogspot.com/
http://www.mattcutts.com/blog/
http://www.bing.com/toolbox/blogs/webmaster/default.aspx

Some Tips To Improve Performance Of Your Web-Application


What Slows your site down? (Most expensive to least)

  1. Database write access (read is cheaper)
  2. Database read access
  3. PHP, ASP, JSP and any other server side scripting
  4. Client side JavaScript
  5. Multiple/Fat Images, scripts or css files from different domains on your page
  6. Slow keep-alive client connections, clogging your available sockets

How to make your site run faster

  • Database layer

  1. Switch all database writes to offline processing.
  2. Minimize number of database read access to the bare minimum. No more than two queries per page.
  3. De-normalize your database and Optimize MySQL tables
  4. Implement MemCached and change your database-access layer to fetch information from the in-memory database first. The least you should do is store all sessions in memory.
  5. If your system has high reads, keep MySQL tables as MyISAM. If your system has high writes, switch MySQL tables to InnoDB. If you need 99.999% availablity – consider switching to MySQL Cluster storage.
  • Server side scripting

  1. Limit server side processing to the minimum.
  2. Short scripts that queue any heavyduty processing to be done offline. Use a caching engine that generates static files from dynamic ones, so that processing only takes place once.
  3. Per-compile all php scripts using eAccelrator. If you’re using WordPress, implement WP-Cache
  • Front end

  1. Reduce size of all images by using an image optimizer, Merge multiple css/js files into one, Minify your .js scripts
  2. Avoid hardlinking to images or scripts residing on other domains.
  3. Put .css references at the top of your page, .js scripts at the bottom.
  4. Install FireFox FireBug and YSlow. YSlow analyze your web pages on the fly, giving you a performance grade and recommending the changes you need to make.
  • Web Server

  1. Optimize httpd.conf to kill connections after 5 seconds of inactivity, turn gzip compression on.
  2. Configure Apache to add Expire and ETag headers, allowing client web browsers to cache images, .css and .js files
  3. Consider dumping Apache and replacing it with Lighttpd or Nginx. If you absolutely need to stick with Apache – upgrade to its latest version.
  • The Results

  1. Implementing the steps described above will result in a faster browsing experience for your visitors as well as significantly improved website scalability.
  2. The chart below illustrates heavy load impact on a non optimized machine (linear degradation in performance) vs an optimized machine.
  3. With our non optimized machine, CPU spiked to 90% with 50 concurrent connections. The optimized machine was effectively handling 500 concurrent connections per second with CPU at 8% and no degradation in performance.

Get All the Contacts From Gmail Using Google Data Protocol

How to Use Google Data Api

<html>
 <head><title>Get Authentication Token</title></head>
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <body>
  	<b>Get the Authentication  url from the google : </b><a href="token.do">click Here</a>
  </body>
</html>

Here is the general process to acquire an OAuth token for a given user

  1. Your registered web application makes a signed request for a request token at Google’s endpoint, https://www.google.com/accounts/OAuthGetRequestToken. Depending on the type of HTTP request being made, the required oauth_* query parameters can either be in the body of the request, as part of the Authorization header, or in the query part of the URL. In addition to the standard OAuth parameters, you must include a scope query parameter that is appropriate for the Google Data API(s) your application will interact with.
  2. Your web app sends the user to Google’s authorization endpoint, https://www.google.com/accounts/OAuthAuthorizeToken, referencing the request token and including the oauth_callback parameter. Google may prompt the user to log into their Google Account. Once authenticated with Google, the user chooses to share their data.
  3. The request token is authorized and Google redirects the user back to the URL you specified in the oauth_callback query parameter.
  4. Your web app sends a signed request to Google’s access token endpoint, https://www.google.com/accounts/OAuthGetAccessToken, to exchange the authorized request token for an access token.
  5. If the request is verified, Google responds with a valid access token.
  6. Your web app uses the access token to send signed requests to one or more of the Google Data APIs. The API(s) your application can interact with will depend on the value that was set in the initial scope query parameter.

Code For Getting auth token

</pre>
</pre>
package com.foo.bar;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gdata.client.http.AuthSubUtil;
/**
 *
 * @author RAJENDRA
 * GmailToken class is used to create the authentication token for accessing the gmail account. In this class you have
 * to define your return back action name so after authentication you can return back on your website.
 */
public class GmailToken  extends HttpServlet{

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

 String gmailAuthKey=getAuth();
 request.setAttribute("gmailAuthKey", gmailAuthKey);
 RequestDispatcher rd = getServletContext().getRequestDispatcher("/gmailToken.jsp");
 rd.forward(request, response);
 }

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 doPost(request, response);
 }

 /**
 * The method is used to set the action url , so after authentication you can return back on your main website.
 * getting the token from the gmail
 * @return gmailAuthenticationToken
 */
 private String getAuth() {
 String authSubLogin=new String();
 String next = "http://localhost:8081/Gmail-Contacts/friends.do";
 String scope = "http://www.google.com/m8/feeds/";
 boolean secure = false;
 boolean session = true;
 authSubLogin = AuthSubUtil.getRequestUrl(next, scope, secure, session);
 return authSubLogin;
 }

}</pre>
<pre>
<pre>
<pre>
<pre>

Using Auth Token Access Gmail Api

After a successful authentication request, use the Auth value to create an Authorization header for each request to  the Google Data API:
Authorization: GoogleLogin auth=yourAuthToken

<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title> Validate-the-email </title> </head> <body> <b>Validate the email id on the google account</b> <a href='<%=request.getAttribute("gmailAuthKey")%> />'>GMAIL</a> </body> </html>

package com.foo.bar;

import java.io.IOException;
import java.net.URL;
import java.security.GeneralSecurityException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gdata.client.contacts.ContactQuery;
import com.google.gdata.client.contacts.ContactsService;
import com.google.gdata.data.contacts.ContactFeed;
import com.google.gdata.util.ServiceException;
/**
 *
 * @author RAJENDRA
 * The GetAllContact class is used to validate and get all the contact list from your gmail.
 */
public class GetAllContact extends HttpServlet {

	public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
		String token = req.getParameter("token");
		try {
			ContactFeed contactFeed = getContactList(token);
			req.setAttribute("contactFeed", contactFeed);
		} catch (GeneralSecurityException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		}
		RequestDispatcher rd = getServletContext().getRequestDispatcher(
				"/showAllContacts.jsp");
		rd.forward(req, res);
	}

	public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
		doPost(req, res);
	}

	/**
	 * In this api we are setting the authentication token for the particular
	 * user and calling the google service
	 * @param token
	 * @return
	 * @throws IOException
	 * @throws GeneralSecurityException
	 * @throws ServiceException
	 */
	public ContactFeed getContactList(String token) throws IOException,GeneralSecurityException, ServiceException {
		ContactFeed contactFeed = null;
		try {
			ContactsService contactsService = new ContactsService(
					"GoogleInc-jsguide-1.0");
			contactsService.setAuthSubToken(token);
			contactFeed = getAllContacts(contactsService);
		} catch (Exception e) {
			e.printStackTrace();
		} catch (Error error) {
			error.printStackTrace();
		}
		return contactFeed;
	}

	/**
	 * Set other information regarding the email list and get the contact
	 * feed list
	 * @param myService
	 * @throws ServiceException
	 * @throws IOException
	 */
	public ContactFeed getAllContacts(ContactsService myService)
			throws ServiceException, IOException {
		URL feedUrl = new URL(
				"http://www.google.com/m8/feeds/contacts/default/full");
		ContactQuery contactQuery = new ContactQuery(feedUrl);
		contactQuery.setMaxResults(1000);
		ContactFeed resultFeed = myService.getFeed(contactQuery,
				ContactFeed.class);
		return resultFeed;
	}

}

Show All The Contacts On Jsp

<%@page import="com.google.gdata.data.contacts.ContactFeed"%> <html><head><title>Show all the email in my account</title></head><%@page import="com.google.gdata.data.contacts.ContactEntry" %><%@page import="com.google.gdata.data.extensions.Email"%><body><table>


<h1>ALL THE CONTACT FROM YOUR GMAIL CONTACT LIST<h1>
<%ContactFeed resultFeed = (ContactFeed)request.getAttribute("contactFeed");
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
 ContactEntry entry = resultFeed.getEntries().get(i);
  for (Email email : entry.getEmailAddresses()) {
       %><tr><td><b>Email add:</b></td><td><%=email.getAddress()%></td>
<%if (email.getRel() != null) { %> <% }if (email.getLabel() != null) {
 %><td><b>label</b></td><td> <%=email.getLabel()%></td></tr>
<% }if (email.getPrimary()) {}
%></table></body>
</html>

Access code from the google svn:

http://gmailcontact.googlecode.com/svn/trunk/





Installation of mysql on the linux machine

Many time I faced a problem to install mysql on the linux operating system,  So in this blog I mentioned  installation step of  mysql on  linux machine.

Get the mysql installation  from http://ftp.jaist.ac.jp/pub/mysql/ site

  1. wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.41-linux-i686-glibc23.tar.gz/.
  2. Unzip the mysql-5.1.41-linux-i686-glibc23.tar.gz file.
  3. Goto the mysql dir, and run the following commands

groupadd mysql
useradd -g mysql mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db  --user=mysql
chown -R root .
chown -R mysql data
bin/mysqld_safe --user=mysql &
bin/mysqladmin -u root password  'password'

Read more of this post

Microsoft DOS netstat command to displays all local network information

For Windows

Use netstat -na -b  to see names of programs along with the port they are using :
Windows command :netstat -na -b

netstat command for windows

For Linux

Use  netstat -nlp to see PID and names of programs along with the port they are using (note you can only see the PID of process you own, unless running as root)

Linux command :netstat -nl

Java Install Builder

Few month before I am searching for free multi-platform Java installer builder. But we didn’t find any free java installer builder then finally we move on to the “Install4j“. We worked on the install4j around 3-4 month. We found that for the basic functionalities(for few screens and for some action) install4j worked fine. But when we are building some complex installer that time install4j have lot of issues. The most common issues with the install4j which I faced is Dynamically bundle of JRE. When I dynamically bundle the jre I am able to bundle the jre, but once the jre bundled with the installer it always extract. There is no way to prevent the extraction of the jre. Even on the completion of the installer if I want to trigger any batch file or sh file for the deletion of the jre, the install4j didn’t allowed to delete the jre. I discussed same thing with the “Install4j” support team but I got straight forward answer that we can’t do that with the “Install4j”.

In this blog I want some support. Please provide me some other “Java install builder tool”.

Create Filters in Java

Filter is basically a component that is invoked when a client request a resource that the Filter is mapped to, such as a URL pattern or a Servlet name. Normally, a filter is used to wrap and manipulate Request, Response or header values before or after the execution of the original request target and do not itself return any response to the client.

Filters can be configured to act upon a certain request or upon different requests. Filters can also be put into a chain, where a number of Filters can be invoked after each other. Any Filter taking part of such a chain can at any time give control to the next Filter or redirect the request out of the chain .

Method for creating the filter

public void doFilter(final ServletRequest request, final ServletResponse response, FilterChain chain)

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

public void init(FilterConfig filterConfig)

Called by the web container to indicate to a filter that it is being placed into service. The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.
public void destroy()

Called by the web container to indicate to a filter that it is being taken out of service. This method is only called once all threads within the filter’s doFilter method have exited or after a timeout period has passed. After the web container calls this method, it will not call the doFilter method again on this instance of the filter.

For creating your own  filter you have to  map  your filter in  web.xml

<filter>
		<!-- controls access for administrators' resources -->
		<filter-name>AdminAccessFilter</filter-name>
		<filter class>foo.bar.filter.AccessControlFilter</filter-class>
	</filter>
	
	<filter-mapping
		<filter-name>AdminAccessFilter</filter-name>
		<url-pattern>/admin/*</url-pattern>
	</filter-mapping>
	
	<filter-mapping>
		<filter-name>AdminAccessFilter</filter-name>
		<url-pattern>/admin/</url-pattern>
	</filter-mapping>

after mapping create a filter class for e.g

package foo.bar.filter;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import foo.bar.model.Admin;

/**
 * Servlet Filter to attach the user under <code>USER_KEY</code> (session) to the current
 * execution thread.
 */
   public class AccessControlFilter implements Filter {

	private static Logger log = Logger.getLogger(AccessControlFilter.class.getName());
	private FilterConfig filterConfig;
        private static final String LOGIN_PAGE = "/admin/adminlogin.action";
	private static final String INTERCEPTION_PREFIX = "/admin/";
	public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException,       ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		String servletPath = request.getServletPath();
		if (! servletPath.startsWith(INTERCEPTION_PREFIX)) {
			HttpSession httpSession = request.getSession();
			Admin user = (Admin) httpSession.getAttribute("Adminuser");
			if (user == null) {
			 	RequestDispatcher dispatcher = request.getRequestDispatcher(LOGIN_PAGE);
				dispatcher.forward(request, (HttpServletResponse) res);
				return;
			}
		}
		chain.doFilter(req, res);
	return;
   }

   public void init(FilterConfig config)
    {
        this.filterConfig = config;
    }

   public void destroy()
    {
        this.filterConfig = null;
    }

    public FilterConfig getFilterConfig()
    {
        return filterConfig;
    }

}

Thickbox z-index of Flash Objects

I had an issue with thickbox where it would show the image behind a flash video in FireFox.I found really intersenting solution on this .I wanted to blog this  information for my own record , plus to help ‘index’ the solution for others.

Solution

    1. Wrap your flash content in a div
    2. Add <param name=”wmode” value=”transparent”> to your object tag
    3. Set wmode=”transparent” in the embed tag
    4. Use css to set the position and z-index for your div (don’t set negative z-index values as it will make your flash disappear)

The CSS

#flash {
position: relative; /*or absolute*/
z-index: 0;
}

The XHTML

<div id=”flash”>
<object …>
<param name=”wmode” value=”transparent”>
<embed … wmode=”transparent”>
</object>
</div>

Follow

Get every new post delivered to your Inbox.

Join 70 other followers