Posts

Git Commands

GIT Status ======= git status git add . git commit -m "Updated README" git push

Creating Ignite Windows Service

Copy NSSM.exe under the bin folder Open command prompt and run the following commands   nssm install ignite-poc {{IGNIT_INSTALL_DIR}}\bin\ignite.bat nssm set ignite-poc AppDirectory {{IGNIT_INSTALL_DIR}} nssm set ignite-poc AppStdout {{IGNIT_INSTALL_DIR}}\logs\sysout.log nssm set ignite-poc AppStderr {{IGNIT_INSTALL_DIR}}\logs\syserr.log nssm set ignite-poc AppStdoutCreationDisposition 2 nssm set ignite-poc AppStderrCreationDisposition 2 nssm set ignite-poc AppStopMethodSkip 6

Apache CXF : How to expose endpoints as MBean using platform MBean server

Latest CXF versions use bus property settings to enable JMX but it is not well documented for the users. The following configuration enables CXF endpoints as MBean using the platform MBean server <core:bus>   <core:properties>          <entry key=" bus.jmx.enabled " value="true"/>   <entry key=" bus.jmx.usePlatformMBeanServer " value="true"/>   <entry key=" bus.jmx.createMBServerConnectorFactory " value="false"/>     </core:properties> </core:bus> The bus.jmx.enabled property enables the JMX bus.jmx.usePlatformMBeanServer tells CXF to use the platform MBean server, so if your JVM in webcontaienr has a rmi port enabled, then that port can be used to access the mbean. bus.jmx.createMBServerConnectorFactory  is by default true, in turn each JVM exposes the port 9914 port. so if you have more than one JVM configured in your server then there will be a port conflict. so to ...

Castor Marshalling error due to race condition (version 1.3.x)

If you are using Castor for Object to XML mapping, you may have encountered exceptions like  Nested error: org.exolab.castor.xml.MarshalException: White space is required between the processing instruction target and data.{File: [not available]; line: 1; column: 10} pool-1-thread-20org.castor.mapping.MappingUnmarshaller.loadMappingInternal(MappingUnmarshaller.java:282) org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:155) org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:130) org.exolab.castor.xml.Marshaller.setMapping(Marshaller.java:628) Original issue is the mapping file is being shared by many threads. To fix this we can use castor 1.4.X or consider creating ThreadLocal instances of   ThreadLocal <Mapping> localMapping = new ThreadLocal <Mapping>() { @Override protected Mapping initialValue() {                       ...

Processing redelivery of AMQP messages

Spring AMQP SimpleMessageListenerContainer (SMLC)  is session transacted,  it has a AckMode field whose default value is AUTO. AUTO Acknowledge ensures that if a message processing fails with an exception then it sends NACK and requeues the message back to queue. Your application may need to handle the retry logic, you just cant let a message fail forever (unless you have a requirement to not lose any message). Here is how you can handle it   Create a MessageListener class implementing the interface org.springframework.amqp.core.MessageListener. In its onMessage  check the basic property    boolean isRedelivered = amqpMessage . getMessageProperties (). getRedelivered ();    You can get the redelivery count from deliveryTag       long deliveryTag = amqpMessage .getMessageProperties(). getDeliveryTag ();  Now write your logic    if(deliveryTag >= maxRedeliveryCount) {        //Store ...

Quartz Cron Expressions

The documentation can be found here - http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html

Ignite Running in Static IP multicast mode

Apache Ignite throws multicast exception in local machine when multicast is on and internet is connect. The following is an example of multicast IP discovery  <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->         <property name="discoverySpi">             <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">                 <property name="ipFinder">                      <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder. multicast . TcpDiscoveryMulticastIpFinder ">                         <property name="addresses">                             <list>               ...

NSSM service eats 100% CPU

Image
NSSM logstash service can cause a fatal CPU hungry outage in your clients unless you override the AppExit default value. By default it comes as default 'Restart' To change it to ' Stop service ' you need to run the following command nssm set logstash AppExit Default Exit It will change the service definition as follow Other v alid exit actions are: Restart Ignore Exit Suicide  

Reading a resource file in Spring boot

Some applications store XML files in src/main/resources folder and want to access it from a java class, using the following syntax   InputStream ioStream = Application . class . getResourceAsStream (" template.xml "); But it returns a null object. The problem with spring boot webapp is the file is actually a classpath resource. To access it use the following syntax InputStream ioStream = Application . class . getClassLoader() . getResourceAsStream (" template.xml ");

Hibernate/JPA is not a silver bullet

I have been working with different data access frameworks since 2005. I started with simple JDBC and learnt various pros and cons of it. then moved to connection pooling and advanced topics. explored Open JPA , Hibernate , Spring data , Spring JDBC , serialization using thrift and protocol buffer etc. Hibernate or JPA is not built for batch operations or anything where you need to fetch an object from database and perform some business logic in a loop. When you loop through the entities and each entity holds a huge payload such as big XMLs/Strings or binary data, they pollute the 1st level cache of hibernate. It results in repeated and frequent GCs and slow down your application, sometimes causes out of memory . So never ever use hibernate or JPA for batch or loop-> process uses cases. Spring jdbc performs better compare to JPA when you need to perform a batching/looping.

When LogStash 5.X windows service STOP, doesn't close Orphan Java processes

In windows LogStash service is created using NSSM.  NSSM takes IO redirection inputs and a flag value which determines how to signal Windows kernel and what to do when the windows service is stopped. when we set  nssm set logstash AppStopMethodSkip 6 It just sends the signal ^C (ctrl +c ) or stop to the Windows kernel, just like we stop a java process in command prompt using a Ctrl+c. But if the parent process spawns threads then only ^C  cannot stop the child processes. Just like windows task manager's kill process tree option, in this case we need to send the WM_CLOSE signal to Windows. For  a NSSM windows service it is done when you set  nssm set logstash AppStopMethodSkip 5 Along, with that you need to pass an additional flag to the logstash arg param. the shutdown_watcher.rb in logstash is a listener to the shutdown event. when logstash spawns many worker processes to send different logs, then the shutdown gets stalled if ay of...

LogStash 5.X Windows service creation

Elastic has changed the command line arguments of logstash. To create a new logstash 5 windows service you have to follow these steps - $logstash_install_location represents the location of Logstash folder. logstash is the service name browse the  $logstash_install_location folder and create two folders conf and logs conf contains all configuration files of logstash. you dont have to change a single file, you can keep as many files you want. such as one for windows logs conf , one for java logs Open command prompt and locate the folder where NSSM exe file is put. then issue the following commands one after another. nssm install logstash $logstash_install_location \bin\logstash.bat nssm set logstash AppParameters --path.config $logstash_install_location\ conf nssm set logstash AppDirectory $logstash_install_location\ nssm set logstash AppStdout $logstash_install_location \logs\sysout.log nssm set logstash AppStderr $logstash_install_location \...

Monitoring and alerting Microservices

Microservices exist for rapid development and deployment. Time to market a product is reduced significantly. But to monitor the container and API performance one needs tools. If we build a client and from java code call the API or from AOP, it will send update to a time series database using JMS or REST call. Maybe a server component to get the data and update One can configure Rules and actions - if CPU > 100 raise alert -> action send SMS or email or call a HTTP URL with json data. For visualization one can use grafana or custom tools.

CAP theorem proof

https://www.youtube.com/watch?v=Jw1iFr4v58M 

Spring Boot start up Maven Failure

Sometimes we get weird error that Spring cannot read manifest file from .m2 location. If you browse, you will get the jar and find the mf file. To resolve the issue do the following From Eclipse/STS - right click on the project and choose Maven build. In target type dependency:purge-local-repository -DreResolve=false and run. or open command prompt/bash shell, go to the project directory and run the following maven command to delete the cache mvn dependency:purge-local-repository -DreResolve=false

Spring Security Hiccups

In any web-application some pages are secured (only logged in and authorized users with proper role can access) and some pages are not secured such as login or landing page. But sometimes we need a mix-n-match, such as some information user can view without proper access(login) but they need rights(such as login) to perform additional activities. here is an example - in amazon or any retail site you can view products, but you need to login to buy the product - the buy now button will ask for your credentials.  Images, css , Javascript dont require security < sec:http pattern = "/css/**" security = "none" /> < sec:http pattern = "/gwt/**" security = "none" /> < sec:http pattern = "/images/**" security = "none" /> < sec:http pattern = "/img/**" security = "none" /> < sec:http pattern = "/scripts/**" security = "none" /> Logon...

JPA Vs SpringJDBC

Recently I conducted many interviews for my employer, one 8-9 yrs exp candidate asked me what data access object layer do we use in our project. I was thinking a bit as , like they do with persistence - polyglot persistence, we maintain different DAO technologies - JPA, proprietary JDBC, JDO, Spring JDBC. you cannot say which one is the best. It depends on the context but definitely having so many things for performing dataaccess is not advisable. In this topic I will try to explore the JPA and Spring JDBC. Spring is a life savior, it's template concept reduces the boilerplate code but still the jdbc template comes with baggages - row mapper, SQL, parameters etc. If you have good knowledge of database schema, you want to execute stored procedure, you want more handle on your code to access the db. Then go for Spring, you can debug easily and have control on your DTO. If you need to abstract away the SQL, hide complexity, write less code, dont need to execute the stored proced...

ElasticSearch multiple strings in multiple fields search

I was working on an ElasticSearch(ES) POC to store millions of database entries to ES and search for multiple strings in multiple fields for all these entries. Let me explain the problem in depth - we use different defect tracking tools such as Rational CharmNT, JIRA and so on, to log defects. In defects we update the exception trace to identify the logs. For example - a stack may look like Exception in thread "main" java . lang . NullPointerException at com . mycompany . myproject . Book . getTitle ( Book . java : 16 ) at com . mycompany . myproject . Author . getBookTitles ( Author . java : 25 )   Similarly another stack may look like Exception in thread "main" java . lang . NullPointerException at com . mycompany . myproject . Course . getSchedule ( Course . java : 162 ) at com . mycompany . myproject . CourseDao . getCourses ( CourseDao. java : 50 )   So, we when a tester sees a NullPointerException he will log the trace t...

Requirement Engineering

Try this with your buddies- Take a picture of a crowded road Ask a friend to depict the picture in paper Pass the paper to another friend and ask him/her to draw the picture using the description Let me know how it goes :-)

GWT, MVP and Eventbus

I have been using GWT and MVP for 2 years and so. I loved the way MVP provides flexibility of working with multiple views. In GWT or Swing based application design muddles very quickly.  Maintenance becomes nightmare. We don’t think about the separation of concern, then mix up the UI code and business logic together. MVP (Model View Presenter) proposes following things - ·     View is an interface which is a contract for presenter. here you can define the operations and expose widgets that will be present in the UI. for example if an UI needs an input box for user name and  a  button then you can expose two methods getName() and getOkButton().  Get name can be implemented using whatever widget user wants- a textbox or a custom widget. ·     View implementaion implements the view interface and only concentrate on layout or grouping of widgets. Doesn't perform and logic, doesnt attach any DOM handler to any wi...