Sunday, April 24, 2011

Setting up Coherence in Tomcat Clustered Environment

Update catalina.sh




XXX_OPTS="-Dtangosol.coherence.distributed.localstorage=false -Dtangosol.coherence.cacheconfig=$PROP_PATH/coherence_cache.xml -Dtangosol.coherence.override=$PROP_PATH/coherence_cache_override.xml"

export CATALINA_OPTS="-server -d64 -Xloggc:xxxx/gc.log -XX:+PrintGCDetails -Xms2048m -Xmx2048m -Dfile.encoding=UTF-8 -DKMSERVICES_HOME=$PROP_PATH $XXX_OPTS"
echo "Catalina OPTS "  $CATALINA_OPTS

below is the coherence_cache_override.xml



below is the coherence_cache.xml



Saturday, April 16, 2011

How to install/Test Coherence*WEB for Weblogic

Coherence Based Session Management

Assumptions: you have downloaded latest web logic server 10.3.3 and Coherence Web 3.6
                       from Oracle

Instructions

First we will create weblogic domains : something like DOMAIN_A and DOMAIN_B.
To configure those domains with coherence based session management, then the
changing of session variable value in one domain will propagate to another domain.

Main Steps

Application Server (WebLogic)

1) Create DOMAIN_A and DOMAIN_B
2) Copy coherence.jar to DOMAIN_A\lib and DOMAIN_B\lib
3) Start both the Domains
4) Deploy coherence-web-spi.war as a shared library

Coherence

1) duplicate cache-server.cmd at the same folder in the coherence and rename
    it to web-cache-server.cmd
2) modify web-cache-server.cmd as shown below
3) set java_opts="-Xms%memory% -Xmx%memory%"

"%java_exec%" -server -showversion "%java_opts%" -cp
c:\coherence\lib\coherence.jar;c:\coherence\lib\coherence-web-spi.war -
Dtangosol.coherence.management.remote=true -Dtangosol.coherence.cacheconfig=WEB-
INF/classes/session-cache-config.xml -Dtangosol.coherence.session.localstorage=true
com.tangosol.net.DefaultCacheServer %1

4) startup web-cache-server.cmd
5) Modify weblogic.xml to add a reference to coherence-web-spi as shown below
     in you application


 wls:library-ref
      wls:library-name   coherence-web-spi  wls:library-name
      wls:specification-version   1.0.0.0  wls:specification-version
      wls:exact true  wls:exact
wls:library-ref


deploy the webapp to DOMAIN_A and DOMAIN_B

Now test Session variable value at DOMAIN_A and check wether it is changed at DOMAIN_B, As show in the below figure

Coherence In Action

Tuesday, April 12, 2011

Setting Up Tomcat Multiple Instances

Setting up tomcat multiple instances

1) First Original Instance, download apache-tomcat-5.5.33 ( any version) this will be the original
Instance and change nothing here.

2) For the instance 2 ... to N do the following as mentioned below

a) Create a new Folder (TomcatInstance1….N) as many as you instances as you want
b) Copy following folders over to TomcatInstance1… to N
conf
logs
temp
webapps
work
c) Write a script to startup/shutdown the second instance(name it as startup.sh
and shutdown.sh) and place under TomcatInstance1..N folders
d) Add following to the newly created startup.sh


CATALINA_HOME=~/Documents/apache-tomcat-5.5.33
CATALINA_BASE=~/Documents/TomcatInstance1
export CATALINA_HOME CATALINA_BASE


$CATALINA_HOME/bin/catalina.sh start

e) Add the following to the newly created shutdown.sh


CATALINA_HOME=~/Documents/apache-tomcat-5.5.33
CATALINA_BASE=~/Documents/TomcatInstance1
export CATALINA_HOME CATALINA_BASE


$CATALINA_HOME/bin/catalina.sh stop

f) Modify the server.xml file in TomcatInstance1/conf/server.xml and change the port
number to 8180

AND change port number to 8109 for the Connector Port of "AJP/1.3"

That's it now start the server with following command " sh startup.sh" and login to
http://localhost:8180 and you should see the tomcat page, do the same for as many instances as you want

How to install/Test Coherence*WEB for Tomcat

Steps to Create

First Install Coherence*Web in your local directory

1) Complete the application inspection step by running the following command.
Specify the full path to your application and the name of your server
(replacing the and with them in the command line below):

java -jar webInstaller.jar
-inspect -server:

e;g java -jar WebInstaller.jar c:\MyCoherenceWeb -inspect -server:Tomcat/5.5


The system will create the coherence-web.xml

2) Complete the Coherence Web application installation step by running the following command,
replacing with the full path to your application:

java -jar webInstaller.jar
-install
e;g java -jar webInstaller.jar c:\MyCoherenceWeb -install


The installer requires a valid coherence-web.xml configuration file to reside
in the same directory as the application

checking if this process is correctly installed or not by verifying the application.war file.

1) Make sure you have a coherence-web.xml in you META-INF file.
2) Installer will Add the following directive to each JSP Page that you have in application

3) Installer will modify and add Coherence Web configuration context parameters in web.xml
descriptor and also add's a listener classes at the end of the web.xml file
4) Make sure you classes folder will have "session-cache-config.xml" file generated.
5) Make sure you lib folder contain coherence.jar and coherence-web.jar

Friday, July 24, 2009

Portlet IPC using JBOSS Portal


Portlet 2.0 is the recently finalized latest version of the Java portlet
specification. One of the shortcomings of the previous version of the spec
(JSR168)was lack of support for inter-portlet communication.As a result,
developers had to resort to all kinds of fancy workarounds using Dojo Toolkit

I am not going to explain what is JSR286 , but try to
achieve IPC for JBOSS Portal

Defining events

To define an event, you would have to declare it in
portlet.xml, as shown below

<event-definition>
<qname
xmlns:mycomp='http://www.something.com/jsr286'>
something:AppEvent</qname>
<value-type>com.ceon.ocp.portlet.WrapperEvent</value-type>
</event-definition>

Publishing an Event

<portlet>
....
<portlet-name>pubEventPortlet</portlet-name>
<supported-publishing-event>
<qname
xmlns:something='http://www.something.com/jsr286'>
something:AppEvent</qname>
</supported-publishing-event>
....
</portlet>

Processing an Event

<portlet>
....
<portlet-name>subEventPortlet</portlet-name>
<supported-processing-event>
<qname xmlns:something='http://www.something.com/jsr286'>
something:AppEvent</qname>
</supported-processing-event>
....
</portlet>

Each portlet definition can have both publishing and processing tags
and you could define multiple events within each portlet definition

Coding events

An Example event class

@XmlRootElement
public class WrapperEvent implements Serializable {
...
public static final QName QNAME = new QName(
"http://www.something.com/jsr286", "AppEvent");
private String name;
private String zipcode;
...
}

An event class must implement the Serializable interface and be annotated with
@XmlRootElement, I am using Java 5,so I used jaxb-api-2.1.jar from the JBoss portlet
container 2.0 lib directory

subscriber ( receiving portlet )

@Override
protected void doView(RenderRequest request, RenderResponse renderResponse)
throws PortletException, IOException {
renderResponse.setContentType(request.getResponseContentType());
// setting the attributes for JSP
request.setAttribute(QUOTE_ATTR, quoteId);
getPortletContext().getRequestDispatcher(VIEW_JSP).include(request,renderResponse);
}
@Override
public void processEvent(EventRequest eventRequest, EventResponse response)
throws PortletException, IOException {
Event event = eventRequest.getEvent();
if(event.getQName().equals(WrapperEvent.QNAME))
{
com.ceon.ocp.portlet.WrapperEvent
wrapEvent=(com.ceon.ocp.portlet.WrapperEvent)event.getValue();
quoteId = wrapEvent.getQuoteID();

}
}

Publisher( trigger event portlet)

@Override
protected void doView(RenderRequest request, RenderResponse renderResponse)
throws PortletException, IOException {
renderResponse.setContentType(request.getResponseContentType());
getPortletContext().getRequestDispatcher(VIEW_JSP)
.include(request,renderResponse);
}

@Override
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {
String quoteParam = request.getParameter("QuoteID");
if ( quoteParam == null || quoteParam.trim().equals("")) {
quoteParam = "No Quote ID Specified";
}
com.ceon.ocp.portlet.WrapperEvent event
= new com.ceon.ocp.portlet.WrapperEvent();
event.setQuoteID(quoteParam);
response.setEvent(com.ceon.ocp.portlet.WrapperEvent.QNAME, event);
}

And simple JSPs for both subscriber and publisher.

reciever.jsp

<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects />
Here are the details of Quote State:
QuoteState: <%= renderRequest.getAttribute("QuoteID")%>

publisher.jsp

<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects />
Please enter Quote ID and click submit,you should
see the Quote State in OCP Portlet

<form method='post' action="<portlet:actionURL />" >
QuoteID: <input type=text name=QuoteID>
<input type=submit>
</form>

One final step is go to

After you have installed and configured the container,look at its core Web
application, called simple-portal.This Web application holds the framework that
displays the portlets. You could either add your own page by modifying
layouts/nav/main.jsp, or modify one of the existing pages. I modified one of the
existing pages, demo/demo.jsp, by removing its portlets and adding my own custom
portlets. The JBoss portlet container uses a very simple tag library to include
portlets, which requires the portlet name as defined in portlet.xml and the
context name of the portlet Web application

<xportal:portlet name="pubEventPortlet" applicationName="JbossSample"/>
<xportal:portlet name="subEventPortlet" applicationName="JbossSample"/>

As you can see, it's quite easy for a portlet to receive events from another portlet,
whether the two portlets reside in the same or separate Web applications.
You just have to make sure to include the common event classes in all portlet Web
applications.If you would like to deploy this application to an other Portlet 2.0
container, make sure to check that container's requirements for web.xml,as some
containers expect specific elements in the web.xml files of Portlet 2.0 applications

How to configure a Jboss Datasource?

Configuring a Datasource in Jboss very easy
Step 1: copy the original oracle-ds.xml from $jboss-home\docs\examples\jca\oracle-ds.xml to
$jboss-home\server\default\deploy\
Step 2: modify the XML file as follows
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@IP:PORT:SID</connection-url>
<use-java-context>false</use-java-context>
<!-- this is required if u want to connect to DB remotely from Main method-- >
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>user</user-name>
<password>password</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>100</max-pool-size>
<query-timeout>60</query-timeout>

<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

Step 3. Drop the JDBC driver jar into Jboss classpath (easiest approach - drop the jar file in to /server/default/lib)

Invoking Datasource Remotely for JBOSS

DataSources are not exposed remotely by default.

In JBoss4 and above, you can set the following attribute to false in the datasource
definition: in oracle-ds.xml to lookup datasource remotely ( typically from external
java class from main method as shown below) <use-java-context>false</use-
java-context> if datasource is not invoked remotely then you can
comment the above line in oracle-ds.xml


 public static void main(String[] args) {
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs"
,"org.jboss.naming");
props.setProperty("java.naming.provider.url",
"127.0.0.1:1099");

InitialContext ctx = new InitialContext(props);
MyBeanRemote bean=(MyBeanRemote)ctx.lookup("MyBean/remote");
bean.doSomething();
DataSource ds = (DataSource)ctx.lookup("OracleDS");
Connection con = ds.getConnection();
ResultSet rs = con.createStatement()
.executeQuery("SELECT NAME FROM EMPLOYEE");
while (rs.next()) {
System.out.println("I got " + rs.getString(1));
}
rs.close();
con.close();
} catch (Exception e) {
.......
}
}

Note : if the datasource is not looked-up
remotely then the look-up might change to ctx.lookup("java:OracleDS") or
ctx.lookup("java:/OracleDS") depends on whatever DS is bound to , check the server
start up log

Create ElasticSearch cluster on single machine

I wanted to figure out how to create a multi-node ElasticSearch cluster on single machine. So i followed these instructions First i did...