Friday, November 27, 2015

Very Simple Log4j2 xml Configuration Example


<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
        <File name="MyFile" fileName="all.log" immediateFlush="false" append="false">
            <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </File>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="Console" />
            <AppenderRef ref="MyFile"/>
        </Root>
    </Loggers>
</Configuration>

Thursday, November 26, 2015

Simulating Network TCP Delay Using Linux Commands

Keep in mind that this only works for outbound traffic, so choose your network interface accordingly.

To add 100ms to all outbound traffic on etho

sudo tc qdisc add dev eth0 root netem delay 100ms

To check status

sudo tc -s qdisc

To remove the delay from eth0

sudo tc qdisc del dev eth0 root






Tuesday, November 17, 2015

How to deploy a local jar to maven repository

mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true

Where: <path-to-file>  the path to the file to load
   <group-id>      the group that the file should be registered under
   <artifact-id>   the artifact name for the file
   <version>       the version of the file
   <packaging>     the packaging of the file e.g. jar

Sunday, October 4, 2015

Working with hashCode and equals methods in java

In this post, I will point out my understanding about hashCode and equals methods in java. I will talk about how their default implementation and how to override them correctly.

hashCode() and equals() methods have been defined in Object class which is parent class for java objects. For this reason, all java objects inherit a default implementation of these methods.

Configuring a remote for a fork

To sync changes you make in a fork with the original repository, you must configure a remote that points to the upstream repository in Git.
  1. Open Terminal (for Mac users) or the command prompt (for Windows and Linux users).
  2. List the current configured remote repository for your fork.
    git remote -v
    # origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
    # origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
    
  3. Specify a new remote upstream repository that will be synced with the fork.
    git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
    
  4. Verify the new upstream repository you've specified for your fork.
  5. git remote -v
    # origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
    # origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
    # upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
    # upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)