Wednesday, December 30, 2009
My points on Websphere Message Broker
http://docs.google.com/present/edit?id=0AVqRcA4NAu8bZGc5MmJqc18xNmNiaDZtYzg3&hl=en
WebSphere Message Broker (WMB) is IBM's information broker from the WebSphere product family that allows business information to flow between disparate applications across multiple hardware and software platforms. Business rules can be applied to the data flowing through the message broker to route and transform the information. The product can be considered to be an Enterprise Service Bus providing connectivity between disparate applications.
The WebSphere Message Broker Toolkit enables developers to graphically design message flows and related artifacts. Once developed, these resources can be packaged into a broker archive (BAR) file and deployed into the runtime environment. At this point, the broker is able to continually process messages according to the logic described by the message flow.WebSphere Message Broker flows can be used in a Service Oriented Architecture, and if properly designed by Middleware Analysts, integrated into event-driven SOA schemas, sometimes referred to as SOA 2.0.
\Program Files\IBM\MQSI\6.1\bin>mqsiprofile
\Program Files\IBM\MQSI\6.1\bin>mqsicreatebroker -i < user Name > -a -q -s < User server Queue Manager > -n < Database Instance >
\Program Files\IBM\MQSI\6.1\bin>mqsicreateconfigmgr CONF_MGR -i mohanrao -a qwer*098 -q QM_evolvus_lap
\Program Files\IBM\MQSI\6.1\bin>mqsistart CONF_MGR
\Program Files\IBM\MQSI\6.1\bin>mqsicreateaclentry CONF_MGR -f \myList
WebSphere Message Broker (WMB) is IBM's information broker from the WebSphere product family that allows business information to flow between disparate applications across multiple hardware and software platforms. Business rules can be applied to the data flowing through the message broker to route and transform the information. The product can be considered to be an Enterprise Service Bus providing connectivity between disparate applications.
The WebSphere Message Broker Toolkit enables developers to graphically design message flows and related artifacts. Once developed, these resources can be packaged into a broker archive (BAR) file and deployed into the runtime environment. At this point, the broker is able to continually process messages according to the logic described by the message flow.WebSphere Message Broker flows can be used in a Service Oriented Architecture, and if properly designed by Middleware Analysts, integrated into event-driven SOA schemas, sometimes referred to as SOA 2.0.
Broker nodes available
A developer can choose from many pre-designed broker nodes. Nodes have different purposes. Some nodes map data from one format to another (for instance, Cobol or PL/I Copybook to canonical XML). Other nodes evaluate content of data and route the flow differently based on certain criteria.
Node types
Node types
There are many types of node that can be used in developing message flows; the following node transformation technology options are available:
- Extended Structured Query Language (ESQL)
- Graphical Message Mapping
- eXtensible Stylesheet Language Transformations (XSLT)
- JavaCompute (as of version 6)
- WebSphere Transformation Extender (formerly known as Ascential DataStage TX, DataStage TX and Mercator Integration Broker) is available as a separate licensing option
- PhpCompute (as of version 6.1.0.3)
Creating a broker in Windows
Ex:
D:\Program Files\IBM\MQSI\6.1\bin>mqsicreatebroker WBRK_BROKER -i mohanrao -a qwer*098 -q WBRK_QM -s WBRK_UNS_QM -n DEFBKD61
Creating Configure Manager In Windows
Start the Component
Creating Queue
runmqsc ----------it will start a session for given Queue Manger
DEFINE qlocal ()
Some of the Major Calls for MQ
MQCONN- to connect the Queue
MQCONNX-it will connect and also open the Queue
MQDISC- to Define A description about the Queue
MQOPEN- To Open the Connected Queue
MQCLOSE - To Close The Opened Queue
MQPUT- To insert/place the message in to the Opened Queue
MQCLOSE - To Close The Opened Queue
MQPUT- To insert/place the message in to the Opened Queue
MQGET - To retrieve the Message From The Opened Queue
MQBEGIN- To start the transaction Opened Queue
MQCMIT- To Commit the started transaction
Command Line Deployment
mqsideploy -b -e -bar
name>
Command Line Deployment
mqsideploy -b
name>
Example Java Classes For MQ
1)
import com.ibm.mq.*;
public class Put {
public static void main (String args[]) throws Exception
{
MQQueueManager qm = new MQQueueManager("QM");
MQQueue queue = new MQQueue(qm,"AQ",MQC.MQOO_OUTPUT,"","","");
MQMessage msg = new MQMessage();
msg.writeString(args[0]);
queue.put(msg);
queue.close();
qm.disconnect();
}
}
2)
import com.ibm.mq.*;
public class Get{
public static void main (String args[]) throws Exception
{
MQQueueManager qm = new MQQueueManager("QM");
MQQueue queue = new MQQueue(qm,"LQ",MQC.MQOO_INPUT_SHARED,"","","");
MQMessage msg = new MQMessage();
queue.get(msg);
System.out.println(msg.readString( msg.getMessageLength() ));
//queue.close();
//qm.disconnect();
}
}
Find The Following Documents- http://docs.google.com/fileview?id=0B1qRcA4NAu8bZWFmNTM5NGMtMTRkMC00ODk2LThiOTItNzY1NzU5MDBjZTJi&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bMDU0NzAxNjUtYWEwYS00NGZlLTk2MjgtYjE0ZDZhNTkzOTZk&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bOGExOGUzNTQtZjllOS00ZWIyLWJlODktNGViOWY3NDgwMjQx&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bNjFlZjc2YmEtMTRkZS00ZDdlLTgzYWEtNjBkODIwYWFhZjky&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bY2JmYWNjMGUtNjg0Yi00NzBhLTg4NDUtNGI1ODc0OTE2NGRh&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bZTY4OTg2MmEtNDBiNy00MTQwLTlkODMtZWNhZWVhZmI4ODE3&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bY2E1MjA2ZGQtOGE0OC00N2ZiLTk0MDMtNTJiOGI5OTcyZGJk&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bMmY3N2FhMjEtYmU2Ni00YTBkLTgzNTktMjRjNjQ2OGE3NWU2&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bYjEwN2M2ZjEtMDU1OC00ZWZlLWIzZGYtZDUzMThkMTU4Mjk0&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bNTEwZDU0MGUtY2JhOC00Yjc5LWE5ZDMtYTUxYTRiNTBmM2U3&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bNWVjYmNiYzktOWRjNi00ZjE1LTg1OTMtZjQ0NGZmMGUyNjVl&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bZTY3ZThkOGEtNDVkZi00YWRhLTkyYjAtMzgzZTg5M2M4ZjM5&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bY2I1YjVhZTItOTRiYS00NWRiLWI5NjctN2UzZGRjMmQ3ZDll&hl=en
- http://docs.google.com/fileview?id=0B1qRcA4NAu8bZTcxZTkxMjMtMDZhNy00NjgyLTlkODAtMjkyOTNiMjU5Y2Jm&hl=en
Thursday, December 10, 2009
Creating Database Connection Pool in Tomcat 5.0 and Tomcat 5.5 for MySQL and Java
This tutorial gives you a close look at Jakarta Commons Database Connection Pool (DBCP) in Tomcat 5.0 and Tomcat 5.5. DBCP is the database connection pooling technology built into the popular open-source Tomcat servlet engine. Because it’s included with Tomcat, you don’t need to download or install any files or libraries.
However, depending on which database you are connecting to, you will have to download the appropriate JDBC driver. In this example we are connecting to MySQL. Normally, to deploy an application to the Tomcat servlet engine, you just copy the application’s WAR file, or deployment directory, to the Tomcat webapps directory. However, to configure DBCP for your application, you need to do a bit more work: you need to add the application to the Tomcat server configuration file conf/server.xml.
To do this, you need to add a new entry to the Tomcat server.xml file. Open the server.xml file with your favorite editor and look for the Tomcat Root Context. You need to add the entry in the correct part of the server.xml file. For example, you can add it after the ROOT context and before the examples context, as in the snippet shown here:
factory
org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory maxActive 100 maxWait 100 username scott password tiger driverClassName org.gjt.mm.mysql.Driver url jdbc:mysql://localhost:3306/mydb?autoReconnect=true
reloadable="true" crossContext="true">
prefix="localhost_examples_log." suffix=".txt" timestamp="true"/>
The preceding example shows how to configure DBCP for an application called myapp. The first entry inside the element is the declaration. The declaration declares a javax.sql.DataSource and binds it to the JNDI name jdbc/mydb. The element and the nested elements within specify the DBCP parameters for the application’s database connection pool. We’ve already discussed the maxActive and maxWait parameters. The driverClassName and url parameters are standard JDBC connection parameters.
Note The value for the factory parameter will vary based on the Tomcat distribution. Tomcat 5.0 and earlier versions used the Jakarta Commons DBCP library. Starting with Tomcat 5.5, the DBCP library has been changed from the Commons version to a Tomcat-specific library. If you want to double check that the value you use is correct, check the Tomcat JAR files in Tomcat’s common\lib directory, find the BasicDataSourceFactory class, and use the fully qualified class name of the class you find.
The next code excerpt shows how to obtain a connection from the previous connection pool. First, you use JNDI to look up a javax.sql.DataSource interface, and then you ask that interface for a connection. When you’ve finished with the connection, you close it and return it to the pool for reuse. Closing the connection doesn’t actually close the underlying physical connection; it just returns the connection to the pool.
javax.naming.InitialContext context = new InitialContext();
// Look up the data source
javax.sql.DataSource dataSource =
(javax.sql.DataSource)context.lookup ("java:comp/env/jdbc/mydb");
// Get a connection from the pool
java.sql.Connection conn = dataSource.getConnection();
// ...Use the connection...
// Close the connection to return it to the pool
conn.close()
Thursday, November 19, 2009
Hashmap and HashTable
Hash map allows null values but hash table accept the null values but it gives runtime exception
some important points on static and non static method overriding
a static method (in a subclass) may hide another static method (in a superclass)
a static method (in a subclass) cannot hide a non-static method (in a superclass)
a non-static method (in a subclass) may override another non-static method (in a superclass)
a non-static method (in a subclass) cannot override a static method (in a superclass)
a static method (in a subclass) cannot hide a non-static method (in a superclass)
a non-static method (in a subclass) may override another non-static method (in a superclass)
a non-static method (in a subclass) cannot override a static method (in a superclass)
Wednesday, November 11, 2009
different types of Synchronization
| ||
Types of Synchronization: 1)Method level Synchronization: A method can be Synchronized by adding a perfix word Synchronize . Here we have Parametrised Synchronization options also. example: public Synchronize void foo(){} 2)Block level Synchronization: A block can be Synchronized by adding a perfix word Synchronize . Here we have Parametrised Synchronization options also. Synchronize { } |
Types of action clases in stuts
There are fine different types of actions in the struts
i) Forward Action (to forward a request to another resource in your
application)
ii) Include Action ( To include some action )
application)
ii) Include Action ( To include some action )
You Might be wondering what the difference between Forward Action and Include
Action so here it is : The difference is that you need to use the IncludeAction
only if the action is going to be included by another action or JSP. Use
ForwardAction to forward a request to another resource in your application such
as a Servlet that already does business logic processing or even another JSP
page.
Action so here it is : The difference is that you need to use the IncludeAction
only if the action is going to be included by another action or JSP. Use
ForwardAction to forward a request to another resource in your application such
as a Servlet that already does business logic processing or even another JSP
page.
iii) Dispatch Action ( to group related actions into one class)
iv) Lookup Dispatch Action (is useful if the method name in the Action is not
driven by its name in the front end but by the Locale independent key into the
resource bundle.)
iv) Lookup Dispatch Action (is useful if the method name in the Action is not
driven by its name in the front end but by the Locale independent key into the
resource bundle.)
The difference between LookupDispatchAction and DispatchAction is that the
actual method that gets called in LookupDispatchAction is based on a lookup of a
key value instead of specifying the method name directly.
actual method that gets called in LookupDispatchAction is based on a lookup of a
key value instead of specifying the method name directly.
v) Switch Action (The SwitchAction class provides a means to switch from a
resource in one module to another resource in a different module. SwitchAction
is useful only if you have multiple modules in your Struts application. The
SwitchAction class can be used as is without extending.)
resource in one module to another resource in a different module. SwitchAction
is useful only if you have multiple modules in your Struts application. The
SwitchAction class can be used as is without extending.)
Implicit Objects in jsp
Variable | Class | Description |
---|---|---|
application | The context for the JSP page's servlet and any Web components contained in the same application. See Accessing the Web Context. | |
config | Initialization information for the JSP page's servlet. | |
exception | Accessible only from an error page. See Handling Errors. | |
out | The output stream. | |
page | The instance of the JSP page's servlet processing the current request. Not typically used by JSP page authors. | |
pageContext | The context for the JSP page. Provides a single API to manage the various scoped attributes described in Using Scope Objects . This API is used extensively when implementing tag handlers (see Tag Handlers). | |
request | subtype of javax.servlet. | The request triggering the execution of the JSP page. See Getting Information from Requests. |
response | subtype of javax.servlet. | The response to be returned to the client. Not typically used by JSP page authors. |
session | The session object for the client. See Maintaining Client State. |
Difference between ServletContext and ServletConfig
ServletContext Defines a set of methods that a servlet uses to communicate with its servlet container.
ServletConfig is a servlet configuration object used by a servlet container used to pass information to a servlet during initialization. All of its initialization parameters can ONLY be set in deployment descriptor.
The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.
You can specify param-value pairs for ServletContext object in tags in web.xml file.
The ServletConfig parameters are specified for a particular servlet and are unknown to other servlets.
The ServletContext parameters are specified for an entire application outside of any particular servlet and are available to all the servlets within that application.
ServletConfig is a servlet configuration object used by a servlet container used to pass information to a servlet during initialization. All of its initialization parameters can ONLY be set in deployment descriptor.
The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.
You can specify param-value pairs for ServletContext object in
The ServletConfig parameters are specified for a particular servlet and are unknown to other servlets.
The ServletContext parameters are specified for an entire application outside of any particular servlet and are available to all the servlets within that application.
what is the use of immutable String class in java?...
Immutable means not changeable. when a string is declared and initiated with some values. Afterwards whenever we will concat that string or change that string. if we r going to add more characters in that string object. it will not allow dynamic size change. to cater such problem when any change will occur in string object the object will be recreated and previous object will be destroyed and new will be created with new size to accomodate change. thats y strings are immutable in java. Mutable Objects: When you have a reference to an instance of an object, the contents of that instance can be altered Immutable Objects: When you have a reference to an instance of an object, the contents of that instance cannot be altered |
what is Factory Method
Factory method is just a fancy name for a method that instantiates objects. Like a factory, the job of the factory method is to create -- or manufacture -- objects.
Simple example for revesing a string
public static void main(String[] args) {
String text="text";
for(int i=text.length();i>0;i--){
//System.out.print(text.substring(i-1,i));
System.out.print(text.toCharArray()[i-1]);
}
}
String text="text";
for(int i=text.length();i>0;i--){
//System.out.print(text.substring(i-1,i));
System.out.print(text.toCharArray()[i-1]);
}
}
Thursday, October 1, 2009
Tuesday, September 29, 2009
loading the values form a properties file
Properties pro = new Properties();
InputStream in = WelcomeAction.class
.getResourceAsStream("/IBLConstants.properties");
pro.load(in);
for (int i = 0; i < pro.size(); i++) {
if (pro.containsKey(roleType)) {
System.out.println(pro.getProperty(roleType));
}
}
InputStream in = WelcomeAction.class
.getResourceAsStream("/IBLConstants.properties");
pro.load(in);
for (int i = 0; i < pro.size(); i++) {
if (pro.containsKey(roleType)) {
System.out.println(pro.getProperty(roleType));
}
}
Thursday, September 10, 2009
Finding the Duplicate records from the Table
SELECT MAX(col_1) AS dupid,COUNT(col_1) AS dupcnt
FROM table_name
GROUP BY col_1 HAVING dupcnt > 1
FROM table_name
GROUP BY col_1 HAVING dupcnt > 1
Wednesday, September 2, 2009
Difference between hashcode and equal method
hashCode() and equals().
Object class provides two methods hashcode() and equals() to represent the identity of an object. It is a common convention that if one method is overridden then other should also be implemented.
Before explaining why, let see what the contract these two methods hold. As per the Java API documentation:
- Whenever it is invoked on the same object more than once during an execution of a Java application, the hashcode() method must consistently return the same integer, provided no information used in equals() comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the equals(object) method, then calling the hashCode() method on each of the two objects must produce the same integer result.
- It is NOT required that if two objects are unequal according to the equals(Java.lang.Object) method, then calling the hashCode() method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.
Now, consider an example where the key used to store the in Hashmap is an Integer. Consider that Integer class doesn’t implement hashcode() method. The code would look like:
map.put(new Integer(5),”Value1″);
String value = (String) map.get(new Integer(5));
System.out.println(value);
//Output : Value is null
String value = (String) map.get(new Integer(5));
System.out.println(value);
//Output : Value is null
Null value will be displayed since the hashcode() method returns a different hash value for the Integer object created at line 2and JVM tries to search for the object at different location.
Now if the integer class has hashcode() method like:
public int hashCode(){
return value;
}
return value;
}
Everytime the new Integer object is created with same integer value passed; the Integer object will return the same hash value. Once the same hash value is returned, JVM will go to the same memory address every time and if in case there are more than one objects present for the same hash value it will use equals() method to identify the correct object.
Another step of caution that needs to be taken is that while implementing the hashcode() method the fields that are present in the hashcode() should not be the one which could change the state of object.
Consider the example:
public class FourWheeler implements Vehicle {
private String name;
private int purchaseValue;
private int noOfTyres;
public FourWheeler(){}
public FourWheeler(String name, int purchaseValue) {
this.name = name;
this.purchaseValue = purchaseValue;
}
public void setPurchaseValue(int purchaseValue) {
this.purchaseValue = purchaseValue;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + purchaseValue;
return result;
}
}
FourWheeler fourWObj = new FourWheeler(“Santro”,”333333);
map.put(fourWObj,”Hyundai);
fourWObj.setPurchaseValue(“555555)
System.out.println(map.get(fourWObj));
//Output: null
map.put(fourWObj,”Hyundai);
fourWObj.setPurchaseValue(“555555)
System.out.println(map.get(fourWObj));
//Output: null
We can see that inspite of passing the same object the value returned is null. This is because the hashcode() returned on evaluation will be different since the purchaseValue is set to ‘555555’ from ‘333333’. Hence we can conclude that the hashcode() should contain fields that doesn’t change the state of object.
One compatible, but not all that useful, way to define hashCode() is like this:
public int hashcode(){
return 0;
}
return 0;
}
This approach will yield bad performance for the HashMap. The conclusion which can be made is that the hashcode() should(not must) return the same value if the objects are equal. If the objects are not equal then it must return different value.
Overriding equals() method
Consider the example:
public class StringHelper {
private String inputString;
public StringHelper(String string) {
inputString=string;
}
@Override
public int hashCode() {
return inputString.length();
}
public static void main(String[] args) {
StringHelper helperObj = new StringHelper(“string”);
StringHelper helperObj1 = new StringHelper(“string”);
if(helperObj.hashCode() == helperObj1.hashCode()){
System.out.println(“HashCode are equal”);
}
if(helperObj.equals(helperObj1)){
System.out.println(“Objects are equal”);
}else{
System.out.println(“Objects are not equal”);
}
}
public String getInputString() {
return inputString;
}
// Output:
HashCode are equal
Objects are not equal
HashCode are equal
Objects are not equal
We can see that even though the StringHelper object contains the same value the equals method has returned false but the hashcode method has return true value.
To prevent this inconsistency, we should make sure that we override both methods such that the contract between both methods doesn’t fail.
Steps that need to be taken into consideration while implementing equals method.
1. Use the == operator to check if the argument is a reference to this object. If so, return true. This is just a performance optimization, but one that is worth doing if the comparison is potentially expensive.
2. Use the instanceof operator to check if the argument has the correct type.
If not, return false. Typically, the correct type is the class in which the method occurs. Occasionally, it is some interface implemented by this class. Use an interface if the class implements an interface that refines the equals contract to permit comparisons across classes that implement the interface. Collection interfaces such as Set, List, Map, and Map.Entry have this property.
3. Cast the argument to the correct type. Because this cast was preceded by an instanceof test, it is guaranteed to succeed.
4. For each “significant” field in the class, checks if that field of the argument matches the corresponding field of this object. If all these tests succeed, return true; otherwise, return false
5. When you are finished writing your equals method, ask yourself three questions: Is it symmetric? Is it transitive? Is it consistent?
The correct implementation if equals method for the StringHelper class could be:
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final StringHelper other = (StringHelper) obj;
if (inputString == null) {
if (other.inputString != null)
return false;
} else if (!inputString.equals(other.inputString))
return false;
return true;
}
Subscribe to:
Posts (Atom)