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. 

Monday, April 27, 2015

Checkboxes are colored black in IE 10 with ng-repeat

I have encountered a quite strange issue in Internet Explorer 10. Generally a checkboxe’s background color is filled with black and then transitions back to white, to the normal styling in IE 10. But the issue came with the behavior of my application. I had to keep a list of checkboxes and sort them in checked status and in ascending order.
When I click on the first checkbox it works fine; first turn into black and then turns back to normal color. But if I click any link other than the first one, IE 10 doesn’t seems to fire the event that turns the checkbox background color back into the normal color. Somehow I implemented the sorting part with orderBy filter inside the ng-repeat directive and I captured the checkbox select event via $event. Maybe capturing the $event caused the issue.

I have found a similar issue reported in Microsoft Connect, which is marked as won’t fix. Ultimately I decided to create my own directive.

Here is the HTML that does the ng-repeat for checkboxes, and filter's them according to status and name:
<div ng-repeat="item in (items | orderBy:['!status','itemName'])">
       <input type="checkbox" ng-click="itemClickEvent($event, item.itemId)" ng-model="item.status"/>
</div>

Controller method that captures the click event:
$scope.itemClickEvent = function ($event, itemId) {
                var checkbox = $event.target;
                var checkboxState = checkbox.checked;
                if (checkboxState) {
                    $scope.items = itemsFactory.doSomething(itemId);
                } else {
                    $scope.items = itemsFactory.doAnotherthing(itemId);
                }
        };

Custom directive I created:


IE10 version: IE10.0.9200.17229
Angularjs version: AngularJS v1.2.23
I’m still not certain about the cause of the issue and hope someone could shine some light on this J

Sunday, January 4, 2015

Concise UPnP

I had to sit for an exam last Saturday and I did a case study about few protocols during my preparation. One protocol that I was reading about is Universal Plug and Play (UPnP), to be precise its a protocol stack. Meantime I'm thinking of writing a post about potential of UPnP in IoT. So, here I'm summarizing UPnP.

XBox 360, PS4, Wii and Azureus usesUPnP

UPnP allows networked devices to search other devices on the network and establish connections among them.
UPnP supports Zero-Configuration networking. For instance when a UPnP compatible device connects to a network, it assigns an IP address, announces it and provide information about its capabilities upon requests and learn the availability and capabilities of other connected devices.
UPnP uses a concept called Control Points (CP), which are the devices use UPnP protocols to control other connected devices. Each device multicast requests to discover others using HTTP and UDP. UDP is used to avoid acknowledgements from receivers and retransmission in interrupts.
When a device first connects to a network it should search for a DHCP Server (Dynamic Host Control Protocol) and request for an IP address. If there aren't any DHCP servers, device must assign itself an IP address. This is known as AutoIP.
After establishing an IP addresses devices can inform the services they are offering and register them in control points on the network. The protocol used in UPnP to do this is called Simple Service Discovery Protocol (SSDP).
Even though devices are resisted with CPs it is required to get to know how devices are providing their services. Therefore CPs has to request device description, which contains device details, vendor specific details, and services and actions offered by the device. Device descriptions are in form of XML data. Having received device descriptions, CPs can invoke devices actions by sending a control message to the control URL.
A main drawback in UPnP is that it doesn't have a device authentication mechanism. Therefore UPnP systems assumes all connected devices are trustworthy.

References:
  • George F. Coulouris (2012) Distributed systems: concepts and design, 5th edn., Boston: Addison-Wesley.
  •  UPnP Forum (2014) UPnP AV The technology basis of DLNA, United States of America: UPnP Forum.

Saturday, January 3, 2015

Genetic Algorithms

Genetic algorithms are a major topic in evolutionary computing. It is based on the evolutionary process of the nature.
Basically a genetic algorithms is a search function where its objective is to find a good solution; technically a very fit chromosome. A chromosome is usually a set of bits or a complex data structure that represents a state of a system.
A set of chromosomes can be referred as a population where a generation in genetics algorithms in one reproductive cycle of replacing existing chromosome with new chromosomes generated by genetic crossover operations and mutation.
The advantage of genetic algorithms in search functions is that search result won't stuck in a local minimum. Because genetic crossover process produces radically different chromosomes in each generation and occasional mutations causes small changes within population.
Genetic algorithm's search can perform in very large and multidimensional search spaces. If there are N dimensions, N parameters should be encoded in each chromosome. 
For example, maximum value of the function F with one dependent variable x in execution.


F(x) = sin(x) * sin(0.4 * x) * sin(0.3 * x)

Lets find a good value for x where F(x) has its nearly possible maximum value.
References:
  •  Russel, S. J., 2009. Artificial Intelligence: A Modern Approach. 3rd ed. Uncertain Knowledge and Reasoning: Printice Hall.