Thursday, September 1, 2016

intellij show spring beans near line number

File > Project Structure > Facets >  Click the green + icon in the middle Panel > Select Spring


After Applying You will be seeing the Bean Definition Pointers as shown below


Wednesday, August 24, 2016

java CompletableFuture example









Saturday, March 19, 2016

Unix sniff network traffic on specific port with tcpflow

Install it : sudo apt-get install tcpflow
Run the command on console : sudo tcpflow -i any -C -J port 1234


sunels@sunels:~$ sudo tcpflow -i any -C -J port 8888
tcpflow: listening on any




GET /hi?name=serkan, HTTP/1.1
Host: localhost:8888
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/48.0.2564.116 Chrome/48.0.2564.116 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8


HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Content-Length: 18
Date: Sat, 19 Mar 2016 20:22:39 GMT


Hi there, serkan,!



Tuesday, November 17, 2015

soap web service call from unix shell / command line

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:GetMSISDNList" --data @request.xml http://172.31.70.139:10037/serkans/SunelServices

--------------Content of the request.xml--------------
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://modafone.com.tr/Business/SerkanServices" xmlns:head="http://modafone.com.tr/EAI/Common/Header" xmlns:v1="http://modafone.com.tr/GetMSISDNList">
   <soapenv:Header/>
   <soapenv:Body>
      <s:GetMSISDNList>
         <Header>
            <head:RequestId>323488131</head:RequestId>
            <head:SourceSystem>www</head:SourceSystem>
         </Header>
         <Body>
            <v1:Request>
               <v1:MSISDN>5444444440</v1:MSISDN>
            </v1:Request>
         </Body>
      </s:GetMSISDNList>
   </soapenv:Body>

Friday, June 12, 2015

Things to remember ... -- Submitting tasks to the ExecutorService (newFixedThreadPool )

In the Javadoc , it is written :

java.util.concurrent.ExecutorService newFixedThreadPool : If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available.

Here it is said that "They will wait"..

This does not mean any waiting thread. It means tasks that are submitted will be waiting in a queue for processing.

Submitting  the tasks is not a blocking operation. Fixed Thread Pool uses a unbounded queue to hold the submitted tasks.

Task Submitter Thread will not be blocked ...

And the code for copy & paste & run & bye ...

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/** * Created by ssunel on 6/1/2015. */public class TaskSubmitTest {

    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(5);

        MyMonitorThread monitor = new MyMonitorThread((ThreadPoolExecutor) executor, 3);
        
        Thread monitorThread = new Thread(monitor);
        monitorThread.start();

        for (int i = 0; i < 1000000; i++) {
            Runnable worker = new WorkerThread("" + i);
            executor.execute(worker);
        }
        System.out.println("All tasks are submitted !!!");

        executor.shutdown();
        while (!executor.isTerminated()) {
        }
        System.out.println("Finished all threads");
    }

    static class WorkerThread implements Runnable {

        private String command;

        public WorkerThread(String s){
            this.command=s;
        }

        @Override        public void run() {
            System.out.println(Thread.currentThread().getName()+" Start. Command = "+command);
            processCommand();
            System.out.println(Thread.currentThread().getName()+" End.");
        }

        private void processCommand() {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        @Override        public String toString(){
            return this.command;
        }
    }

    static class MyMonitorThread implements Runnable
    {
        private ThreadPoolExecutor executor;

        private int seconds;

        private boolean run=true;

        public MyMonitorThread(ThreadPoolExecutor executor, int delay)
        {
            this.executor = executor;
            this.seconds=delay;
        }

        public void shutdown(){
            this.run=false;
        }

        @Override        public void run()
        {
            while(run){
                System.out.println(
                        String.format("[monitor] [%d/%d] Active: %d, Completed: %d, Task: %d, isShutdown: %s, isTerminated: %s, taskQueueSize: %d",
                                this.executor.getPoolSize(),
                                this.executor.getCorePoolSize(),
                                this.executor.getActiveCount(),
                                this.executor.getCompletedTaskCount(),
                                this.executor.getTaskCount(),
                                this.executor.isShutdown(),
                                this.executor.isTerminated(),
                                this.executor.getQueue().size()));

                try {
                    Thread.sleep(seconds*1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}