Showing posts with label j2ee. Show all posts
Showing posts with label j2ee. Show all posts

Wednesday, January 11, 2023

My GitHub Repo #12 : Sherlock

Code Samples for the Blog Article [CEP Using Drools Fusion 6.1.x]
MIT License, Copyright (c) 2018-19, Sumith Kumar Puri
https://github.com/sumithpuri









Project Codename

Sherlock

Blog Post URL

http://www.techilashots.blog/2015/09/introduction-to-complex-event.html

Blog Short URL

https://rebrand.ly/skp-ts-blog-12

Package Prefix

me.sumithpuri.github.sherlock

GitHub URL

https://github.com/sumithpuri/skp-code-marathon-sherlock

Contact E-Mail

code@sumithpuri.xyz

Contact Number

+91 9591497974 (WhatsApp, Viber, Telegram)

Historical

 Started this Movement of 1000s of Lines of Java / J2EE* Code to GitHub

 Was a Senior Software Architect (Java/J2EE) in Manila*, 2018 (At Start) 

 Named this Initial Code Journey as [ Manila Code Marathon - 2018 ]

 Code Is Non-Proprietary and Non-Copyright from my Work Experience.

 Was Back to Bangalore, Named as [ Bangalore Code Nights - 2019. ]

 Added More Code under [ -20 Days of Code in Benglauru- ] in 2020

 Celebration of Java/Java EE Code as Java Turned 25 in the Year ~ 2020!

  

Tuesday, January 10, 2023

My GitHub Repo #11 : Phuket

Code Samples for the Blog Article [GoF Design Patterns - Part 01]
MIT License, Copyright (c) 2018-19, Sumith Kumar Puri
https://github.com/sumithpuri









Project Codename

Phuket

Blog Post URL

http://techilashots.blogspot.com/2008/11/design-patterns-series-i.html

Blog Short URL

https://rebrand.ly/skp-ts-blog-11

Package Prefix

me.sumithpuri.github.phuket

GitHub URL

https://github.com/sumithpuri/skp-code-marathon-phuket

Contact E-Mail

code@sumithpuri.xyz

Contact Number

+91 9591497974 (WhatsApp, Viber, Telegram)

Historical

 Started this Movement of 1000s of Lines of Java / J2EE* Code to GitHub

 Was a Senior Software Architect (Java/J2EE) in Manila*, 2018 (At Start) 

 Named this Initial Code Journey as [ Manila Code Marathon - 2018 ]

 Code Is Non-Proprietary and Non-Copyright from my Work Experience.

 Was Back to Bangalore, Named as [ Bangalore Code Nights - 2019. ]

 Added More Code under [ -20 Days of Code in Benglauru- ] in 2020

 Celebration of Java/Java EE Code as Java Turned 25 in the Year ~ 2020!

  

Monday, January 9, 2023

My GitHub Repo #10 : Pattaya

Code Samples for the Blog Article [GoF Design Patterns - Part 02]
MIT License, Copyright (c) 2018-19, Sumith Kumar Puri
https://github.com/sumithpuri









Project Codename

Pattaya

Blog Post URL

http://techilashots.blogspot.com/2008/12/design-patterns-series-ii.html

Blog Short URL

https://rebrand.ly/skp-ts-blog-10

Package Prefix

me.sumithpuri.github.pattaya

GitHub URL

https://github.com/sumithpuri/skp-code-marathon-pattaya

Contact E-Mail

code@sumithpuri.xyz

Contact Number

+91 9591497974 (WhatsApp, Viber, Telegram)

Historical

 Started this Movement of 1000s of Lines of Java / J2EE* Code to GitHub

 Was a Senior Software Architect (Java/J2EE) in Manila*, 2018 (At Start) 

 Named this Initial Code Journey as [ Manila Code Marathon - 2018 ]

 Code Is Non-Proprietary and Non-Copyright from my Work Experience.

 Was Back to Bangalore, Named as [ Bangalore Code Nights - 2019. ]

 Added More Code under [ -20 Days of Code in Benglauru- ] in 2020

 Celebration of Java/Java EE Code as Java Turned 25 in the Year ~ 2020!

  

Wednesday, February 17, 2021

Mowglee, Multi-Threaded Geo Web Crawler In Java

[Updates to the Article and Codebase / Code Snippets ~ 17/Feb/2021]
- Fixed Possible Con. Leaks in Network Connections
- Fixed Poor Code and Bad Programming Practices
- Improved Code Formatting, Practiced Clean Code*
- Mowglee v0.02a is Released (Previously, v0.01a')


 This article provides the implementation of a web crawling system called Mowglee that uses geography as the main classifying criteria for crawling. Also, it runs in a multi-threaded mode that provides a default implementation of the robots exclusion protocol, sitemap generation, data classifiers, data analyzers, and a general framework for application to be built of a web crawler. The implementation is in core Java. Mowglee is a multi-threaded geo web crawler in Java.

To do this, you should have intermediate to expert level core Java skills, an understand of the intricacies of multi-threading in Java, and an understand of the real-world usage of and need for web crawlers.


What You Will Learn

  • How to write simple and distributed node-based web crawlers in core Java.

  • How to design a web crawler for geographic affinity.

  • How to write multi-threaded or asynchronous task executor-based crawlers.

  • How to write web crawlers that have modular or pluggable architecture.

  • How to analyze multiple types of structured or unstructured data. (Covered Minimally)

Geo Crawling

The crawling system that I describe here works to maximize geography penetration in terms of higher reachability. It uses the most important or higher throughput hyperlinks of a specific geography as the starting points or crawl homes. The throughput refers to a number of varied links, text, or media with a higher data relevance for a given geography. It is developed using concepts of asynchronous task execution and multi-threading in Java.
The crawler is called Mowglee. It would be better to keep the "user-agent" name the same, but you can add your own variant. For example, if you want to add the word "raremile" to identify your variant, rename the user-agent "mowglee-raremile". Please make sure you have JDK 1.6+ installed on your system before you try to run this. Some of these classes have their own main() method, but they were written only for unit testing.
The main class to run the application is in.co.mowglee.crawl.core.Mowglee. You can also run the bundled JAR file under dist using java –jar mowglee.jar . If you are using JDK 6 for execution (recommended), then you can use jvisualvm for profiling.
In the figurethe class Mowglee is shown as MowgleeCentral. 
 

Figure 01: Mowglee – Core Crawler

Figure 1: Mowglee — Core Crawler


Mowglee's core crawling system uses a hierarchy of crawlers for efficient crawling. MowgleeCrawl is a class that sequentially invokes all crawl types in Mowglee: static crawling, periphery crawling, and site crawling.
MowgleeStaticCrawl is the starting class for the crawling process. This will read the static geographical home page or crawl home. You may configure multiple crawl homes for each geography and start a MowgleeStaticCrawl process for each of them. You can visualize this as a very loose representation of a multi-agent system. There is a default safe waiting period of ten seconds that can be configured as per your needs. This is to make sure that all data is available from other running processes or other running threads before we begin the main crawl.
MowgleePeripheryCrawl is the pass one crawler that deduces the top-level domains from a given page or hyperlink. It is built with the sole purpose of making MowgleeSiteCrawl (Pass 2) easier and more measurable. The periphery crawl process can also be used to remove any duplicate top-level domains across crawls for a more concentrated effort for the next pass. In Pass 1, we only concentrate on the links and not the data.
MowgleeSiteCrawl is the Pass 2 crawler for instantiating individual thread pools using the JDK 6 executor service for each MowgleeSite. The Mowglee crawl process at this stage is very extensive and very intrusive in terms of the type of data to detect. In Pass 2, we classify link types as protocol, images, video, or audio, and we also try to gain information on metadata for the page. The most important aspect of this phase is that we do analysis in a dynamic yet controlled fashion, as we try to increase the thread pool size as per the number of the pages on the site.
Mowglee is organized as a set of workers within each of these crawling passes. For Pass 1, the actual work of reading and deduction is done by MowgleePeripheryWorkerFor Pass 2, the work of reading and analyzing links is done by MowgleeSiteWorker. The helper classes that it uses during this includes data analyzers, as explained later.
MowgleePeripheryWorker uses MowgleeDomainMap for storing the top-level domains. The most important lines of code are in MowgleeUrlStream and are used to open a socket to any given URL and read its contents, which are provided below. 


  public StringBuffer read(String httpUrl, String crawlMode) {  
   
      StringBuffer httpUrlContents = new StringBuffer();  
      InputStream inputStream = null;  
      InputStreamReader inputStreamReader = null;  
   
      MowgleeLogger mowgleeLogger = MowgleeLogger.getInstance("FILE");  
   
      // check if the url is http  
      try {  
   
        if (crawlMode.equals(MowgleeConstants.MODE_STATIC_CRAWL)) {  
           mowgleeLogger.log("trying to open the file from " + httpUrl, MowgleeUrlStream.class);  
           inputStream = new FileInputStream(new File(httpUrl));  
   
           inputStreamReader = new InputStreamReader(inputStream);  
   
        } else {  
           mowgleeLogger.log("trying to open a socket to " + httpUrl, MowgleeUrlStream.class);  
           inputStream = new URL(httpUrl).openStream();  
   
           inputStreamReader = new InputStreamReader(inputStream);  
        }  
   
        // defensive  
        StringBuffer urlContents = new StringBuffer();  
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);  
        String currentLine = bufferedReader.readLine();  
   
        while (currentLine != null) {  
           urlContents.append(currentLine);  
           currentLine = bufferedReader.readLine();  
        }  
   
        if (httpUrl != null & httpUrl.trim().length() > 0) {  
           MowgleePageReader mowgleePageReader = new MowgleePageReader();  
           mowgleePageReader.read(httpUrl, urlContents, crawlMode);  
   
           mowgleeLogger.log("the size of read contents are " + new String(urlContents).trim().length(),  
                MowgleeUrlStream.class);  
        }  
   
        // severe error fixed - possible memory leak in case of an exception! - [connection leak fixed]  
        // inputStream.close();  
      } catch (FileNotFoundException e) {  
   
        mowgleeLogger.log("the url was not found on the server due to " + e.getLocalizedMessage(),  
             MowgleeUrlStream.class);  
      } catch (MalformedURLException e) {  
   
        mowgleeLogger.log("the url was either malformed or does not exist", MowgleeUrlStream.class);  
      } catch (IOException e) {  
   
        mowgleeLogger.log("an error occured while reading the url due to " + e.getLocalizedMessage(),  
             MowgleeUrlStream.class);  
      } finally {  
   
        try {  
           // close the connection / file input stream 
           if (inputStream != null)
               inputStream.close();  
        } catch (IOException e) {  
   
           mowgleeLogger.log("an error occured while closing the connection " + e.getLocalizedMessage(),  
                MowgleeUrlStream.class);  
        }  
      }  
      return httpUrlContents;  
   }  
Listing 1: Mowglee — Opening Stream/Crawling.



Figure 02: Mowglee – Analyzers

Figure 2: Mowglee — Analyzers.


In Mowglee, there are various analyzers for multiple types of data and media. The analyzer that is implemented as part of this codebase is MowgleeLinkAnalyzer. It uses MowgleeSiteMap as the memory store for all links within a given top-level domainIt also maintains a list of visited and collected URLs from all the crawled and analyzed hyperlinks within a given top level domain.
 
 

Image title

 

Figure 3: Mowglee – Filter, Logger, and Utilities.


MowgleeGarbageCollector is a daemon thread that is instantiated and started at the time of running the main application. As there are a large number of objects instantiated per thread, this thread tries to control and enforce the internal garbage collection mechanism within safe limits of memory usage. MowgleeLogger provides the abstract class for all types of loggers in Mowglee. Also, there is an implementation of RobotsExclusionProtocol provided under MowgleeRobotsExclusionFilterThis inherits from MowgleeCrawlFilter. All other types of filters that are closer to the functioning of a crawler system may extend from this particular class.
 
MowgleeCommonUtils provides a number of common helper functions, such as deduceTopLevelDomain().  owgleeSitemapGenerator is the placeholder class for generating the sitemap as per the sitemaps protocol, and a starting point for a more extensive or custom implementation. The implementations for analyzing images, video, and audio can be added. Only the placeholders are provided along.


Applications

The following would be the ideal applications of this category of web crawlers.

Website Governance and Government Enforcements

The enforcement of any localized or customized geographical rules can be done using this system. Also, any type of classification that is either done through manual deduction or automatic detection of patterns of data for any administrative purposes can be easily done through the generated data.

Ranking Sites and Links

The ranking of sites and links for a search engine system that is further localized to a particular geography or to specific areas can be performed on the data from this site. It would be easier to find relations and click patterns of links within the same geography.

Analytics and Data Patterns

The data collected from this crawler can be analyzed using third-party or custom tools for further knowledge creation. Also, relevant digital repositories can be created from generated volumes of data.

Advertising on the Basis of Keywords

An important application would be to drive advertising based on the data collected from this crawling system. An analyzer can be used to find specific terms, keywords, phrases, and embed relevant advertising or to generate advice for advertisers.


Enhancements

Following are some enhancements involving this category of web crawlers.

Store Using Graph Database

You may add your implementation of the graph database or use one of the popular NoSQL graph storage options. The starting point is the MowgleePersistenceCore class.

Varied Analyzers

You can add more analyzers for your own organizational or academic needs. The base class that you have to extend is MowgleeAnalyzer , and you can refer to MowgleeLinkAnalyzer to understand the analyzer's implementation.

Focused Classifiers

You can add a hierarchy of classifiers or plugins to automatically classify the data based on terms, keywords, geographic lingo, or phrases. An example is MowgleeReligiousAbusePlugin.

Complex Deduction Mechanisms

More complex deduction mechanisms to create further relevance of crawling within a specific geography may be added. This includes ignoring links outside of a geographic region, country, or even continent for a specific crawl session. At a higher level, such as at the continent level, this may be implemented as a coordinated multi-agent system.

Sitemap Generation

A starting point for the sitemap generation mechanism is provided here. You may also either use other sitemap generation libraries internally or develop your own custom implementation to enhance this functionality.


Conclusion

Mowglee does not guarantee that a sitemap will be created or used for crawling. It uses an async mechanism and makes sure that all links that may be not reachable from within a site to itself are also crawled. Mowglee does not have a termination mechanism currently. I have provided a placeholder for you to decide as per your usage. This could be based on the number of top level domains crawled, data volume, number of pages crawled, geography boundaries, types of sites to crawl, or an arbitrary mechanism.
Please shut down all applications on your system to dedicate all available system resources to Mowglee. The default starting crawl point is http://www.timesofindia.com. You may try by changing the starting crawl point to other sites as well. In the current form, you can use the mowglee.crawl file to read the crawl analysis. There is no other storage mechanism provided. You may keep this file open in an editor like EditPlus to continuously monitor its contents.
This article should have given you an excellent grounding in building a layered multi-threaded crawler, especially for applications that need geographically based classifications and affinity. It should also help you save time (by re-using this code base) to build your crawlers or applications out of this. You may also want to build enhancements out of Mowglee as mentioned above and post it back on DZone for the benefit of the entire community!

[Trivia Facts About the Piece of Code / Software]
Mowglee, Efficient Geo Web Crawler [Core Java]
Mowglee v0.02a (2021) - http://bit.do/mowglee
-
0. Published on My Own Online Technical Blog and Site – Techila Shots (.in)
1. Published in Online (Java) Developer Magazine – DZone
2. Article in Online/Print Java Magazine – JavaMag (.org)
3. Published in [CS] Mag – Computer Society of India Communications
4. Final Project for Part-Time AI Course at Indian Institute of Science (IISc)
 
 

Thursday, February 6, 2020

Elevated to the Elite Developers/Contributors List! ;-)

All Blog Followers, Random Visitors, Developers, Contributors => Take Note.

My Blog / I Got [Promoted / Elevated] to DZone Core! The Elite Developers/Contributors List on Planet Earth!  Spent Decent Enough Time - About ~17+ Years Now => Championing, Evangelizing, Learning, Teaching, Applying, Prototyping, Building, [Doing], Glorifying Core Java and Jakarta EE ;-)  Primarily I am a Backend (Presentation, Business/Service, Web Services/Integration, Persistence, Database) Developer or Architect. [Feb 2020] Right Now, I am Employed as a Senior Product Development Manager at Ultria Software Private Limited, Bengaluru, Karnataka, India.

By the Way, I hold 7 Certifications* in Core Java/Java EE, 3 in C/CPP/Data Structures => Also, I am a Java Code Geek; Senior Member, ACM; Senior Member, IEEE;

Thanks, DZone [Blake Ethridge].

 
 

Wednesday, January 7, 2015

JBoss Cache XSD Config in Eclipse

I was facing this issue in Eclipse Europa where the Spring configuration XML was not getting validated, when i included JBoss Cache related configuration in it. This is primarily because the Namespace and the Schema URI,
 
 
are not available at the respective locations, hence i guess these were not bundled in Eclipse Europa. I spent about 4-5 hours breaking my head on this issue before I found the solution in another blog.

The way to get your XML to be reported as validated is:
 
1. In Eclipse, Click on Window > Preferences.. > Web and XML > XML Catalog
2. Under XML Catalog, Click on User Specified Entries and then click on Add...
3. Create the following Entries/Locations

>>>>> [Replace pathto with the actual location of the JAR on your local machine.]
>>>>>> jar:file:pathto/spring-modules-cache.jar!/org/springmodules/cache/config/springmodules-cache.xsd
>>>>>> KEY TYPE Schema Location

>>>>> jar:file:pathto/spring-modules-cache.jar!/org/springmodules/cache/config/jboss/springmodules-jboss.xsd
>>>>> KEY TYPE Schema Location
>>>>> KEY http://www.springmodules.org/schema/cache/springmodules-jboss.xsd


4. Refresh the XML file in the Project Explorer and... all XML validation errors have gone!
 

Tuesday, October 7, 2014

Spring - DWR - Ext JS Chat Application

[GitHub Repository for Code Samples]
https://github.com/sumithpuri/skp-code-marathon-kabootar


I was curious to explore the capabilities of Reverse Ajax. That's when I created this simple chat application using Spring/DWR/Ext JS.

From my experience, I can easily say that DWR is easy to learn and configure, especially when you are planning to integrate with Spring on the application tier. DWR has a powerful API to perform all relevant operations, right from accessing page script sessions to util classes for sending updates to the client.

I used Ext JS for creating the user interface, which renders stunning display for elements like forms, buttons, etc. Ext JS has a very steep learning curve and each operation requires a lot of configuration and reference. Also, I found that the event handling mechanism, though complete, is very complex to use. I relied on external Javascript coding for handling events. On the upside, the documentation and support is really good for this framework. Inspite, I would instantly recommend use of Ext JS for large sized customer facing web-based applications, especially for the internet. For medium scale projects or enterprise based projects, I would think twice.


Login Screen


Chat Screen

Simply, drop the .war file in your web/app server. All dependencies are available in the archive itself. The only external reference is 'servlet-api.jar', which is part of the default lib in all latest containers. The source is packaged separately. Once deployed, the url to access should be: http://[server_name]:[server_port]/kabootar/login.kabootar
If you are trying to figure out what 'Kabootar' means, it's Hindi for 'Pigeon'... 


[GitHub Repository for Code Samples]
https://github.com/sumithpuri/skp-code-marathon-kabootar
 

Monday, July 14, 2014

EJB v3 Client for JBoss Gotcha!

If you are writing a standalone client for either a local or remotely deployed EJB v3, and face the following issue:

javax.naming.CommunicationException
[Root exception is java.lang.ClassNotFoundException: org.jboss.ejb3.proxy.JBossProxy
(no security manager: RMI class loader disabled)]
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:788)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
at javax.naming.InitialContext.lookup(Unknown Source)

...



The simple fix is to include 'jbossall-client.jar' in the client classpath.

Monday, July 7, 2014

EJB v3 Buy-In

Studying for my SCBCD 5 certification, I noticed these differences between the EJB v3 specification and Spring v2 framework. Thought i should share these. I will add the performance results as well, once i have something substantial.


In Favour of EJB v3,
Easier Implementation for Web Services
Time Tested & Robust Method for Remote Access
Better Instance Pooling Mechanisms
Stateful Session Beans
Annotations Make It Easier
JEE Standard / Sun Support / Industry Affiliation
Wide App Server Feature Support


In Favour of Spring v2, 
JDBCTemplate and JMSTemplate
DI Even for POJO (Outside Container)
AOP Is Feature-Rich (But Complex)


And No... I Do Not Sell for Sun.
 

Thursday, January 8, 2009

Thoughtworks - A Different Company!

It might be an inappropriate entry for this blog - sharing an interview experience. But one that might help people the most [ :-) ] especially when it is about... Thoughtworks!

The company has a very interesting interview process, different than most i have come across, which speaks a lot of the company culture and the work that you might do there. I write this from the perspecive of an interviewee who participated in the interview process there, twice!

1. It all starts with an online application [Unless you are the lucky one whose CV has been sourced!]
2. Once shortlisted, you get a call from the HR who checks your comfort submitting code and explains the interview process.
3. You get two problem statements by mail, and have the choice of submitting solution for either of them - focus is on object oriented design [Mars Rovers Problem is 'Famous' By Now]
4. Next I had a Phone screen, in which i was presented with a problem again for which one has to design and implement a solution - again object oriented skills are the focus. During the course, you might be presented with a change in requirement and have to explain how easily your design can adapt to these changes.
5. When i was interviewed the first time, the next round was in-office and I had logical and reasoning ability tests - which are really a breeze.
6. The first time I did not want to proceed beyond this point due to some personal reasons... The second time around I wasn't selected [ :-) ], But what I know is that the subsequent interviews focus on how well you can code pair with other Thoughtworkers and a series of technical interviews on your primary technology skill.
7. The offer, I am sure once in you would never want to be out - working with the best technical minds....

What I love about this process, as a developer, is that unlike other interviews it tests and validates all your abilities in real-time [technology knowledge, problem solving, design skills, implementation skills and most of all that you can code - no matter whether you are an architect, tech lead or a senior developer]. The other important aspects that I like [and have read or heard] about the company is the flat hierarchy, entrepreneurial culture, agile process and that it values technology.

[Thoughtworks - 3/3]

[Update : 2012-2016]
Anyways, the final update as of 2012-2016 is that Thoughtworks no longer is my dream company - The other point to note here is that I did not get through even after 3 Interview Processes! :-) ;-)

On a Serious and Correct note, I thought about my career goals, my unfulfilled academic/professional goals and everything that I am as an individual - The Journey of Myself - The Ex-Yahoo, Ex-Symantec, Ex-Siebel (Oracle), Ex-Huawei, Ex-GXS (OpenText), Ex-Misys - AND - The name that I want to see on my resume is - Google!
 

Friday, August 29, 2008

Techila Shots!

Well, That's a Catchy Name... You'd be Thinking! This wasn't a Very Well Thought out Title or One that Required a Christening Ceremony. Had It in My Mind for a Few Years > Tried Implementing it as a Weekly Technical Talk Series in an Organization, As Well.

So, What is Techila Shots?
Techila Shots is a Measure of Techie Talk Delivered with a Dash of Passion and a Slice of Experience, that Gives a Kick to my Developer Psyche (What a Pitch?). It is a Forum that Presents my Thoughts on Technical Topics that I am most Enthusiastic About. Mostly, It is about the Geek in me. Hope that Someone Reading It will Find it at the Least Helpful, If Not as Much to Deliver a Kick!
 
 
[Above Post was Written at the Start of this Blog > 29th August, 2008 - Written from my Rental Apartment at Washington Building, Deals Gateway, Deptford, London SE13 7SE, United Kingdom - Was in London, UK for ~1 Year under the Highly Skilled Migrant Programme (HSMP) Visa]
 

 
[Update : On 03rd September, 2020 from my Own Apartment at C2-2010, VBHC Palm Haven 2, Doddabele, Kengeri Hobli, Bengaluru 560060, Karnataka, India - Take a Note of of All the Blog Recognitions / Engineering Recognitions that I Have Received From August 2008 - August 2020]

Java Code Geek Program (JCG)
DZone Most Valuable Blogger (MVB)
DZone Core (Promoted)
Member, Computer Society of India*
Senior Member, IEEE (Elevated)
Senior Member, ACM (Elevated)

For the First 3, The Main Criteria was my Blog and for the Last 2, One of the Important Input was my Leadership as a Technical Blogger.