Wednesday, May 6, 2015

JBoss EPA 6.1 : javax.persistence.PersistenceException PersistenceProvider in org.apache.openjpa.persistence.PersistenceProviderImpl not found

This is an issue I was having few weeks back and solved by creating a module inside the JBoss EPA. The issue came because of missing a class which should be available inside the EPA, and raised the above exception during the deployment. I’m still hesitating about the root cause, whether this requirement came with a Spring dependency I had or due to MS SQL Server driver I used. Somehow I managed to solve this issue by creating an OpenJPA module inside the JBOSS_HOME>\modules\org\apache\openjpa directory.
First of all we need to download the OpenJPA from this link. Then extract the content to above mentioned directory and the create the module.xml file as follows.

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.jboss.as.jpa.openjpa">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>
    <resources>
        <resource-root path="jboss-as-jpa-openjpa-7.1.1.Final.jar"/>
    </resources>
    <dependencies>
        <module name="javax.annotation.api"/>
        <module name="javax.persistence.api"/>
        <module name="javax.transaction.api"/>
        <module name="org.jboss.as.jpa.spi"/>
        <module name="org.jboss.logging"/>
        <module name="org.jboss.jandex"/>
        <module name="org.apache.openjpa" optional="true"/>
    </dependencies>

</module>

Tuesday, May 5, 2015

Java Messaging Service (JMS) - I

JMS is a collection of interfaces that define the specifications of messaging clients to use when there are communicating with messaging systems. It is much similar to the way JDBC abstract relational database access.
JMS API supports three major types of messaging systems. Those are General messaging applications, Point-to-Point applications and Publish-Subscribe applications. In order to build a general messaging application, there are few components/interfaces that the application should adhere to its implementation,
  • ConnectionFactory
  • Destination
  • Connection
  • Session
  • Message
  • MessageProducer
  • MessageConsumer

According to JMS specifications, both ConnectionFactory and Destination should be obtained through JNDI. Other objects can create with JMS vendor implementations. The sequence is like as follows, once we have a ConnectionFactory, we can create a Connection. With a Connection, we can create a Session. Once we have a Session, we can create a Message, MessageProducer or a MessageConsumer.
Overview of a general JMS application.


Here below I have attached a github link to a demo application that demonstrates the above connectivity.

GitHub repo: https://github.com/rootpox/JBoss-A-MQ-MessagingQueue

Image reference: Mark Richards, 2009. Java Message Service. Second Edition Edition. O'Reilly Media.

Monday, May 4, 2015

Bayes’ Theorem

Here's a rough note I have prepared for a friend during last semester's exams.

Bayes theorem can be seen as a way of understanding how the probability that a theory is true is affected by a new piece of evidence.

Prob(M|D) = Prob(D|M) * Prob(M) / Prob(D)

M: Theory of hypothesis that we are interested in testing.
D: New piece of evidence that seems to confirm or dis-confirm the theory.
Prob(M|D): Known as posterior probability. This is the new theory or hypothesis after accepting the new evidence or data.
P(D|M): Known as the likelihood. This is the probability that a piece of evidence could be observed in a given dataset.

Intention is to discover the probability that M is true by considering that new evidence is true. This is a conditional probability, the probability that one proposition is true provided that another proposition is true.

A theory is basically a property or a pattern described by the given dataset. For example sales patterns identified using credit card transactions history. In this case, a theory may describe Bank A’s credit card holders are tend to be deal with Company B. Therefore Company B can offer sales price discounts to Bank A’s card holders, which will attract more customers.

Installing a JBoss-A-MQ Broker Instance

Jboss A-MQ is a messaging service implemented on top of Apache ActiveMQ, which supports multiple messaging paradigms like publish-subscribe, point-to-point, and store and forward. This enables real-time messaging among multiple clients based on various platforms such as Java, C, and C++ via multiple protocols like JMS 1.1, TCP, SSL, STOMP and NMS. The broker which is responsible for exchanging messages among clients is hosted on Apache Karaf, a light weight OSGI-based real-time container.

 Installation

  1. Download the JBoss A-MQ from https://www.jboss.org/products/amq/get-started/#
  2. Extract the downloaded zip file to a place of choice [JAMQDir].
  3. Edit [JAMQDir]\etc\users.properties file and uncomment the admin=admin,admin line to define administrators credentials of the broker.
  4. Open the command prompt and navigate tp [JAMQDir]\bin.
  5. Run the command amq on the terminal. Terminal output should look like below.
  6. Navigate to localhost:8181 in the browser and verify the JBoss A-MQ management consol.