Friday, December 11, 2015

Troubleshout Open file limit

lsof | awk '{ print $2; }' | uniq -c | sort -rn | head

- Show no of open files sorted by PID

cat /proc/<PID>/limits

- Check individual file limits of a process

ls /proc/<PID>/fd | wc -l

- to obtain a precise count of the open files at given instant of time

lsof -p <PID>
- This will list all open files with given process

In some cases you might have to look at the open file limit of the process which started your process.

Make sure you add "ulimit -n XXX" values inside your startup script, if you have configured it to start the process on machine startup or restart. Especially on Debian Linux flavour refer (https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/938669) 

Saturday, July 12, 2014

Setup virtualbox on Ubuntu Server 64 Bit

Setup virtual box on ubuntu server 64bit and use phpvirtualbox to access webui of VirtualBox to manage the instances on virtualbox.

Ubuntu Server 64bit 
VirtualBox 4.3.*
phpvirtualbox 

Running VirtualBox and phpvirtualbox on the same machine.

I mostly followed followed this blog http://santi-bassett.blogspot.in/2013/01/installing-virtualbox-on-ubuntu-server.html. 

Except few changes. When I installed virtual box it installed latest version 4.3.* and location of phpvirtualbox has been changed to sourceforge.net http://sourceforge.net/projects/phpvirtualbox/files/ and used phpvirtualbox 4.3.1 version.

However even after following all the steps right I got following error


I click on details and get the following:

Exception Object
(
    [message:protected] => Could not connect to host (http://127.0.0.1:18083/

I started vboxwebsrv server in foreground and tried to telnet 18083, everything was fine. Then I tried to do wget with url http://127.0.0.1:18083 and responded connection refused. Then I tried to wget with url http://localhost:18083 and it responded with 403 error. So url was the problem. Update config.php with http://localhost:18083 in place of http://127.0.0.1:18083. That solved my problem.




Tuesday, May 20, 2014

GWT browser specific css

Yea it is possible to write browser specific css with GWT application which uses CSS through CssResource.
    @if user.agent gecko1_8 {
    	.startup p {
    		color: #000000;
    		text-shadow: 0 0 3px #000000;
    	}
    } @else {
    	.startup p {
    		color: #000000;
    	}
    } 
 
Note: You can use this logical if else and many more other expression inside css which are used inside GWT code. Only through CssResource interface. If you are directly using the respective css inside html main source file then this will not work.




For more details refer






GWT Jquery integration

It is very easy to have GWT Jquery integration using gwtquery. Follow below steps

Add maven dependency for gwtquery, at the time of writing this article it was 1.4.2 and tested it with GWT 2.5.0 version. 
        <dependency>
            <groupId>com.googlecode.gwtquery</groupId>
            <artifactId>gwtquery</artifactId>
            <version>1.4.2</version>
            <scope>provided</scope>
        </dependency>

Then inherit your module from required gwtquery module.
<inherits name='com.google.gwt.query.Query'/>

User jquery api wrappers as follows.
import static com.google.gwt.query.client.GQuery.$;
..
...
public class GwtJquery implements EntryPoint {

	@Override
	public void onModuleLoad() {
		$("#startup").fadeIn(1000);
		$("#product").delay(2000).fadeIn(1000);
	}
...
...
}

For More details refer getting started







Tuesday, April 29, 2014

Eclipse getting crashed randomly on ubuntu

If your eclipse is getting crashed randomly and that too frequently look at the crash reported. This crash report will be placed in the directory from where you start the eclipse and search for " /usr/lib/x86_64-linux-gnu/gtk-2.0/modules/liboverlay-scrollbar.so". If find this string then this issues of overlay scrollbar library. This will be solved once you remove that library. Sometimes, you will not find crash report generated, even in that case it is most probably the issue of overlay scrollbar.

sudo apt-get remove overlay-scrollbar

for more details refer this bug . If you don't find above mentioned string, search google with few strings from that crash report.

Redirect process output to std output when you fork one process from another process.

In the situation where you want to redirect input / output of one process to the std input output of parent process (from which you are starting first process). You can make use of inheritIO() method of a ProcessBuilder.
ProcessBuilder pb = new ProcessBuilder("command", "argument);
pb.directory(new File(<directory from where you want to run the command>));
pb.inheritIO();
Process p = pb.start();
p.waitFor();

It may not be necessary to call waitFor() method in above code. This will just help to wait current process to wait for this child process to get complete.

There exist few other options as well, through which you can redirect required stream to standard output and input.


pb.redirectInput(Redirect.INHERIT);
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);











Sunday, April 27, 2014

Quartz Scheduler with Google Guice

To integrate Quartz with Guice. One can follow below steps. The most important part is, we should be able to inject dependencies inside Job.

To provide injectable Scheduler Instance we need to write Scheduler provider as follows:
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;

/**
 * @author Pandurang Patil 27-Apr-2014
 * 
 */
@Singleton
public class SchedulerProvider implements Provider<Scheduler> {
 private Scheduler scheduler;

 @Inject
 public SchedulerProvider(SchedulerJobFactory jobFactory) throws SchedulerException {
  scheduler = new StdSchedulerFactory().getScheduler();
  scheduler.setJobFactory(jobFactory);
 }

 @Override
 public Scheduler get() {
  return scheduler;
 }

}


Now that we have defined provider for Scheduler we need to map the same inside Guice Module

import org.quartz.Scheduler;

import com.google.inject.AbstractModule;

/**
 * @author Pandurang Patil 27-Apr-2014
 *
 */
public class SchedulerModule extends AbstractModule {

 @Override
 protected void configure() {
  bind(Scheduler.class).toProvider(SchedulerProvider.class);
 }

}


With the above code, we should be able to inject Scheduler instance where we want. Lets look at how we would be able to get dependencies injected inside Job. As instantiation of the Job object is done by Scheduler itself, we just pass on the class name through JobDetails. We need intercept this instantiation process to do that we will write our own Job Factory as follows:

import org.quartz.Job;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.spi.JobFactory;
import org.quartz.spi.TriggerFiredBundle;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;

/**
 * @author Pandurang Patil 27-Apr-2014
 * 
 */
@Singleton
public class SchedulerJobFactory implements JobFactory {

 @Inject
 private Injector injector;

 @Override
 public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {
  return (Job) injector.getInstance(bundle.getJobDetail()
    .getJobClass());
 }

}

We need ask scheduler to use this JobFactory while instantiating Job object. We have already connected scheduler with JobFactory inside SchedulerProvider, look at line number 20 for SchedulerProvider code above
As we are returning same instance from Providers get method. Where ever you will inject Schedular, you will get the same object. Schedule your jobs the way it is done normally there is no change in it. 


import org.quartz.Scheduler;
import org.quartz.SchedulerException;

import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;

/**
 * @author Pandurang Patil 27-Apr-2014
 * 
 */
public class SchedulerSample {

 @Inject
 private Scheduler scheduler;

 void start() throws SchedulerException {

  scheduler.start();
 }

 public static void main(String[] args) {
  Injector injector = Guice.createInjector(new SchedulerModule());
  SchedulerSample sample = injector.getInstance(SchedulerSample.class);
  try {
   sample.start();
  } catch (SchedulerException e) {
   System.out.println("Error while starting the scheduler...");
  }
  ...
  ...
 }
}