Wednesday, October 30, 2013

Reading windows registry using Runtime.getRuntime().exec(..) command

In my previous post @ http://exploreeclipse.blogspot.in/2013/10/reading-windows-registry-values-using.html , I was talked about reading windows registry using JNA library. But Java also provides support to read the windows registry through Java Runtime command execution.

In this article will focus on how to read win registry using Runtime.getRuntime().exec(..) command.

Basically you need these 3 parameters to hit the registry.
1. What is the Location ?
2. What is the registry key type ?
3. What is the key you want to read ?

Example:
I want to read the following parameters.
Location = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Android SDK Tools";
Key = "Path";
Registry Type = "REG_SZ"

Above parameters basically tells, what is the Andriod SDK Tools 'Path' directory ? That is what i want to figure it out.

Below piece of code, which will help you to get the Andriod sdk tools path directory.


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class WindowsRegistryReader {

public static void main(String[] args) {

String location = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Android SDK Tools";
String key = "Path";
String regType = "REG_SZ";

try {
String value = read(location, key, regType);
System.out.println("==========Output=================");
System.out.println("location: " + location);
System.out.println("Type: " + regType);
System.out.println("key: " + key + "  value: " + value);
System.out.println("=================================");

} catch (IOException e) {
e.printStackTrace();
}
}

public static String read(String location, String name, String regType) throws IOException {

Process p = Runtime.getRuntime().exec("reg QUERY \"" + location + "\" /v \"" + name + "\"");
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String out = "";
while ((out = in.readLine()) != null) {
if (out.matches("(.*)\\s+REG_(.*)")) {
break;
}
}
in.close();
if (out != null) {
int indexOf = out.indexOf(regType);
if (indexOf != -1) {
String value = out.substring(indexOf + regType.length()).trim();
return value;
}
}
return null;
}
}


Output:
==========Output=================
location: HKEY_LOCAL_MACHINE\Software\Wow6432Node\Android SDK Tools
Type: REG_SZ
key: Path  value: C:\Program Files (x86)\Android\android-sdk

=================================

Various Windows registry type values can be found @ http://msdn.microsoft.com/en-us/library/windows/desktop/ms724884(v=vs.85).aspx

Monday, October 28, 2013

Programmatically gettting Eclipse installation path directory

You might have some properties file or some other file at your eclipse home directory and you want to read that, for this you required a eclipse home directory path.

Below is the piece of code which helps you to get that.

public class EclipseLocation {

@SuppressWarnings("unchecked")
public static <T> T getService(Class<T> clazz, String filter) {
BundleContext context = MyPlugin.getDefault().getBundle().getBundleContext();
ServiceTracker tracker = null;
try {
tracker = new ServiceTracker(context, context.createFilter("(&(" + Constants.OBJECTCLASS + "=" + clazz.getName() //$NON-NLS-1$ //$NON-NLS-2$
+ ")" + filter + ")"), null); //$NON-NLS-1$ //$NON-NLS-2$
tracker.open();
return (T) tracker.getService();
} catch (InvalidSyntaxException e) {
return null;
} finally {
if (tracker != null)
tracker.close();
}
}
}

Invocation:
EclipseLocation.getService(Location.class, Location.INSTALL_FILTER)


Output:
C:/myInstallations/Eclipse



You can also achieve the same thing using the system property 'eclipse.launcher'.

//this returns C:/myInstallations/Eclipse/eclipse.exe
String launcherLocation = System.getProperty("eclipse.launcher");  //

if (launcherLocation != null ) {
File launcherLocationFile = new File(launcherLocation);

//get the parent of eclipse.exe file->C:/myInstallations/Eclipse
String eclipseDir = launcherLocationFile.getParent();

//your piece of logical code resides here
                   }



Hope this helps.

Thursday, October 24, 2013

Reading Windows registry values using java


This can be done using JNA(Java Native Access) library.

Use this link to download @ https://github.com/twall/jna#readme

Required jars: 

Piece of code to test:

Here I am trying to read Android installation path from windows registry.


public static void main(String[] args) {

try {
Map<String, Object> values = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Android SDK Tools");
for (String value : values.keySet()) {
System.out.println(value + "   " + values.get(value));

}
} catch (Exception e) {
e.printStackTrace();
}

}

public static void main(String[] args) {

try {
Map<String, Object> values = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Android SDK Tools");
for (String value : values.keySet()) {
System.out.println(value + "   " + values.get(value));

}
} catch (Exception e) {
e.printStackTrace();
}

}


Output:
Path   D:\Work\Android\adt-bundle-windows-x86-20130522\adt-bundle-windows-x86-20130522

Friday, October 18, 2013

Java VM PermGen space

The Java VM memory is split up to 3 memory spaces:

  • The Java Heap. Applicable for all JVM vendors, usually split between YoungGen (nursery) & OldGen (tenured) spaces.
  • The PermGen (permanent generation). Applicable to the Sun HotSpot VM only (PermGen space will be removed in future Java 7 or Java 8 updates)
  • The Native Heap (C-Heap). Applicable for all JVM vendors.

The Java HotSpot VM permanent generation space is the JVM storage used mainly to store your Java Class objects.  The Java Heap is the primary storage that is storing the actual short and long term instances of your PermGen Class objects.

The PermGen space is fairly static by nature unless using third party tool and/or Java Reflection API which relies heavily on dynamic class loading.
It is important to note that this memory storage is applicable only for a Java HotSpot VM; other JVM vendors such as IBM and Oracle JRockit do not have such fixed and configurable PermGen storage and are using other techniques to manage the non Java Heap memory (native memory).

Below diagram showcases various heap memories and how we can configure them using vm arguments.




Understanding how the JVM uses native memory on Windows

JVM: Permgen is a non-heap


In Oracle's JVM, the permanent generation is not part of the heap. It's a separate space for class definitions and related data. In Java 6 and earlier, interned strings were also stored in the permanent generation. In Java 7, interned strings are stored in the main object heap.


From above link, we can understand these terms:

Eden Space (heap): The pool from which memory is initially allocated for most objects.

Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.

Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.

Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.

Code Cache (non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.



Finding java process id's

Go to command prompt and type jps, this will provide the currently running java process id's in your system.




Troubleshooting Memory Leaks

http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/memleaks.html


Meaning of OutOfMemoryError

One common indication of a memory leak is the java.lang.OutOfMemoryError error. This error is thrown when there is insufficient space to allocate an object in the Java heap or in a particular area of the heap. The garbage collector cannot make any further space available to accommodate a new object, and the heap cannot be expanded further.
When the java.lang.OutOfMemoryError error is thrown, a stack trace is printed also.
java.lang.OutOfMemoryError can also be thrown by native library code when a native allocation cannot be satisfied, for example, if swap space is low.
An early step to diagnose an OutOfMemoryError is to determine what the error means. Does it mean that the Java heap is full, or does it mean that the native heap is full? To help you answer this question, the following subsections explain some of the possible error messages, with reference to the detail part of the message:

Sizing the Java heap


Size your Java heap so that your application runs with a minimum heap usage of 40%, and a maximum heap usage of 70%.
Introduction
An incorrectly sized Java heap can lead to OutOfMemoryError exceptions or to a reduction in the performance of the Java application.
If the Java heap is smaller than the memory requirements of the application, OutOfMemoryError exceptions are generated because of Java heap exhaustion. If the Java heap is slightly larger than the requirements of the application, garbage collection runs very frequently and affects the performance of the application.
You must correctly size the Java heap based on the real memory usage of the Java application.
Sizing the heap based on application memory utilization
Set the maximum Java heap size, using the -Xmx command-line option, to a value that allows the application to run with 70% occupancy of the Java heap.
The Java heap occupancy often varies over time as the load applied to the application varies. For applications where occupancy varies, set the maximum Java heap size so that there is 70% occupancy at the highest point, and set the minimum heap size, using the -Xms command line option, so that the Java heap is 40% occupied at its lowest memory usage. If these values are set, the Java memory management algortihms can modify the heap size over time according to the application load, while maintaining usage in the optimal area of between 40% and 70% occupancy.
Maximum possible heap size and maximum recommended heap size (32-bit Java)
The memory space provided by the operating system to the Java process varies by operating system and is used for two separate memory areas: the Java heap and the native heap. Because a finite amount of memory is provided by the operating system, and that memory is shared between the two heaps, the larger the amount of memory that is allocated to the Java heap, using the -Xmx setting, the smaller the native heap becomes. If the native heap is too small, an OutOfMemoryError occurs when it is exhausted, in the same way as for the Java heap.
PlatformAdditional optionsMaximum heap sizeRecommended heap size limitAdditional notes
AIXNone3.25 GB2.5 GBMaximum heap size is not required to be, but should ideally be, a multiple of 256 MB
LinuxNone2 GB1.5 GB
Hugemem Kernel3 GB2.5 GB
WindowsNone1.8 GB1.5 GB
/3GB1.8 GB1.8 GB
The table shows both the maximum Java heap possible and a recommended limit for the maximum Java heap size setting. The use of a maximum Java heap setting up to the recommended limit is unlikely to reduce the native heap size to a point that the native heap is exhausted.
Before setting a Java heap size greater than the recommended limit, you must understand the level of usage of the native heap, to ensure that the native heap does not become exhausted.
If you are running an application that has particularly high numbers of threads or makes heavy use of Java Native Interface (JNI) code, for example, Type 2 JDBC drivers, you might experience problems relating to the native heap with smaller Java heap sizes than the recommended limit.
Maximum possible heap size and maximum recommended heap size (64-bit Java)
When running 64-bit Java, the memory space provided by the operating system to the Java process is very large. You can therefore assume that no limit is imposed on the maximum size of the Java heap because of the contention of memory resource between the Java heap and the native heap.
Java heap size and amount of physical memory available
It is important to have more physical memory than is required by all of the processes on the machine combined to prevent paging or swapping. Paging reduces the performance of the system and affects the performance of the Java memory management system.
When increasing the Java heap size, ensure that enough unused physical memory is available on the machine to cover the increase. If sufficient physical memory is not available, either install additional memory or take into account the effect on overall performance that occurs.
This requirement does not apply to operating systems running on System z.

Size your Java heap so that your application runs with a minimum heap usage of 40%, and a maximum heap usage of 70%.



Memory Limits for Windows Releases

http://msdn.microsoft.com/en-us/library/aa366778%28VS.85%29.aspx


Physical Memory Limits: Windows 8

The following table specifies the limits on physical memory for Windows 8.
VersionLimit on X86Limit on X64
Windows 8 Enterprise
4 GB
512 GB
Windows 8 Professional
4 GB
512 GB
Windows 8
4 GB
128 GB


Physical Memory Limits: Windows 7

The following table specifies the limits on physical memory for Windows 7.
VersionLimit on X86Limit on X64
Windows 7 Ultimate
4 GB
192 GB
Windows 7 Enterprise
4 GB
192 GB
Windows 7 Professional
4 GB
192 GB
Windows 7 Home Premium
4 GB
16 GB
Windows 7 Home Basic
4 GB
8 GB
Windows 7 Starter
2 GB
N/A



Understanding 32-bit vs. 64-bit systems with Java Heap

Eclipse Mac OS: Hyperlinks are not working in welcome page

Have you ever come across the issue, where hyperlinks is not working in Mac OS Eclipse but it works in Windows OS.

We had faced this issue with the welcome page, where hyper links are not working. The reason was, href links with target=”_blank” is causing the issue.

We couldn't see any other solution other than removing it.


To understand about target attribute in html @ http://www.w3schools.com/tags/att_a_target.asp

Similar thread on the same topic @  https://code.google.com/p/android/issues/detail?id=41109

Thursday, October 17, 2013

SAP Transaction codes

You can find all transaction codes @ http://www.tcodesearch.com/


SE37 - ABAP Function Modules
SE16 - Data Browser(Table search)
SE11 - ABAP Dictionary Maintenance

GIT: Finding a commit based on SHA1 ID

> git show <sha1-id>

Example: > git show e43db49

This will display the complete changes including the with commit message.

Adding a new menu item in Eclipse Help Menu

As shown in the image below, if you want to add 'Tutorials' menu item in the Help Menu in Eclipse.




Adding command extension:

      <command
            defaultHandler="com.kk.help.TutorialsHelpHandler"
            id="com.kk.command.tutorialshelp"
            name="Tutorials">
      </command>


Adding menu extension:

 <menuContribution
            allPopups="false"
            locationURI="menu:help?after=intro">
         <separator
               name="slot1"
               visible="true">
         </separator>
         <command
               commandId="com.kk.command.tutorialshelp"
               label="Tutorials"
               style="push">
         </command>
         <separator
               name="slot2"
               visible="true">
         </separator>
      </menuContribution>


Handler implementation:

public class TutorialsHelpHandler extends AbstractHandler implements IHandler{

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//implemention here

retun null;

}
}

Launching a URL in external browser from an eclipse plugin

public class HelpHandler extends AbstractHandler implements IHandler{


public static final String HELP_LIBRARY = "http:/kk.com/KKLibrary/";

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(HELP_LIBRARY ));
} catch (PartInitException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
}

Tuesday, October 15, 2013

toArray Dynamic behaviour

public class ToArrayTest {

public static void main(String[] args) {

ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
arrayList.add("4");

//what happens here??, since I have allocated new String[0] for single element, will it return single element or all elements ??
String[] array = arrayList.toArray(new String[0]); 
System.out.println(array.length);

}
}


Output:  4


As per spec, it's going to create a new array, if it does not fit in.
Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list. 

Wednesday, October 9, 2013

Understanding how Eclipse plug-ins work with OSGi

Install the plug-in bundle in the Equinox console


  1. Install the plug-in bundle in the Equinox console.
    osgi> install file:///<path to bundle>
    Equinox lists the bundle ID for the newly installed bundle:
    Bundle id is 17
  2. Enter the following line to start the bundle in the Equinox console, where <id> is the bundle ID assigned when the bundle was installed:
    osgi>  start <id>
  3. Retrieve the service status in the Equinox console to verify that the bundle started:
    osgi> ss
    When the bundle starts, the bundle lists the ACTIVE state, for example:
    17      ACTIVE      com.mycompany.plugin.bundle_xx

Eclipse Equinox and OSGI

Go through this article to get the understanding on Eclipse Equinox
http://www.theserverside.com/news/1365049/Eclipse-Equinox-and-OSGi

Understanding UML Class diagrams


http://msdn.microsoft.com/en-us/library/dd409437%28VS.100%29.aspx



Three classes showing relationships and properties
Shape
Element
Description
1
Class
A definition of objects that share given structural or behavioral characteristics. For more information, see Properties of Types in UML Class Diagrams.
1
Classifier
The general name for a class, interface, or enumeration. Components, use cases, and actors are also classifiers.
2
Collapse/ Expand control
If you cannot see the details of a classifier, click the expander at upper-left of the classifier. You might also have to click the [+] on each segment.
3
Attribute
A typed value attached to each instance of a classifier.
To add an attribute, click the Attributes section and then press ENTER. Type the signature of the attribute. For more information, seeProperties of Attributes in UML Class Diagrams.
4
Operation
A method or function that can be performed by instances of a classifier. To add an operation, click the Operations section and then pressENTER. Type the signature of the operation. For more information, see Properties of Operations in UML Class Diagrams.
5
Association
A relationship between the members of two classifiers. For more information, see Properties of Associations in UML Class Diagrams.
5a
Aggregation
An association representing a shared ownership relationship. The Aggregation property of the owner role is set to Shared.
5b
Composition
An Association representing a whole-part relationship. The Aggregation property of the owner role is set to Composite.
6
Association Name
The name of an association. The name can be left empty.
7
Role Name
The name of a role, that is, one end of an association. Can be used to refer to the associated object. In the previous illustration, for any OrderOO.ChosenMenu is its associated Menu.
Each role has its own properties, listed under the properties of the association.
8
Multiplicity
Indicates how many of the objects at this end can be linked to each object at the other. In the example, each Order must be linked to exactly one Menu.
* means that there is no upper limit to the number of links that can be made.
9
Generalization
The specific classifier inherits part of its definition from the general classifier. The general classifier is at the arrow end of the connector. Attributes, associations, and operations are inherited by the specific classifier.
Use the Inheritance tool to create a generalization between two classifiers.
Package containing interface and enumeration
Shape
Element
Description
10
Interface
A definition of part of the externally visible behavior of an object. For more information, see Properties of Types in UML Class Diagrams.
11
Enumeration
A classifier that consists of a set of literal values.
12
Package
A group of classifiers, associations, actions, lifelines, components and packages. A logical class diagram shows that the member classifiers and packages are contained within the package.
Names are scoped within packages so that Class1 within Package1 is distinct from Class1 outside that package. The name of the package appears as part of the Qualified Name properties of its contents.
You can set the Linked Package property of any UML diagram to refer to a package. All the elements that you create on that diagram will then become part of the package. They will appear under the package in UML Model Explorer.
13
Import
A relationship between packages, indicating that one package includes all the definitions of another.
14
Dependency
The definition or implementation of the dependent classifier might change if the classifier at the arrowhead end is changed.
Realization shown with conector and lollipop
Shape
Element
Description
15
Realization
The class implements the operations and attributes defined by the interface.
Use the Inheritance tool to create a realization between a class and an interface.
16
Realization
An alternative presentation of the same relationship. The label on the lollipop symbol identifies the interface.
To create this presentation, select an existing realization relationship. A Action tag appears near the association. Click the action tag, and then clickShow as Lollipop.

Monday, October 7, 2013

Loading a file from OSGI bundle


Bundle bundle = Activator.getDefault().getBundle();
Path path = new Path("path/to/your/file.extension"); //$NON-NLS-1$
URL url = FileLocator.find(bundle, path, Collections.EMPTY_MAP);
URL fileUrl = null;
try {
fileUrl = FileLocator.toFileURL(url);
}
catch (IOException e) {
// Will happen if the file cannot be read for some reason
e.printStackTrace();
}
File file = new File(fileUrl.getPath());


http://codeache.blogspot.in/2007/05/loading-files-with-rcp.html

Saturday, October 5, 2013

JProfiler could not detect java process id's

Reason could be very simple, as i mentioned in my previous post http://exploreeclipse.blogspot.in/2013/10/where-does-java-process-idspid-are.html

It looks for 'hsperfdata_<systemLoginName>'  folder in C:\Users\KK1205\AppData\Local\Temp\  directory.

If you could not find this file, just create a new directory with this name.

If you found it, but it's not in the format of what i have mentioned above, then you can rename it.

Other important thing here is, system login name(ex:KK1205 is correct, kk1205 is incorrect) should be in capital letters(That is what i have observerd it!)


org.osgi.framework.BundleException: State change in progress for bundle

Have you every come across this kind of issue with your eclipse plugin start () ???

!MESSAGE While loading class "org.scribe.model.Verb", thread "Thread[ModalContext,6,main]" timed out waiting (5000ms) for thread "Thread[main,6,main]" to finish starting bundle "com.xx_3.0.0.qualifier [812]". To avoid deadlock, thread "Thread[ModalContext,6,main]" is proceeding but "org.scribe.model.Verb" may not be fully initialized.
!STACK 0
org.osgi.framework.BundleException: State change in progress for bundle "reference:file:/D:/Work/KKIDE/devtools/trunk/guieditor/" by thread "main".
at org.eclipse.osgi.framework.internal.core.AbstractBundle.beginStateChange(AbstractBundle.java:1077)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:282)
at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:417)
at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:265)
at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:106)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:453)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:393)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:469)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.scribe.builder.api.DefaultApi10a.getRequestTokenVerb(DefaultApi10a.java:103)
at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:50)
at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:39)
at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:44)
at ..
at ..
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.osgi.framework.internal.core.AbstractBundle$BundleStatusException
... 22 more




Will try to understand the issue first, by looking at the statement below.
While loading class "org.scribe.model.Verb", thread "Thread[ModalContext,6,main]" timed out waiting (5000ms) for thread "Thread[main,6,main]" to finish starting bundle "com.xx_3.0.0.qualifier [812]". To avoid deadlock, thread "Thread[ModalContext,6,main]" is proceeding but "org.scribe.model.Verb" may not be fully initialized.


This indicates that one thread is attempting to load from the org.scribe.model. bundle while another thread is in the process of activating it.  On the Sun VM a deadlock can occur because the VM locks the classloader way too early.  I'm guessing that you are calling Display.asyncExec()/Display.syncExec in your bundle activation code.  What can happen in this case is you post a Runnable for SWT to run on the main UI dispatch thread.  Then the dispatch thread wakes up and decides to execute your runnable, this causes the UI thread to attempt to load more classes from your bundle (on the Sun VM the classloader is locked here) but the thread blocks because another thread is currently activating the bundle.  Meanwhile the thread which is activating the bundle continues to run more code which causes more classes to be loaded from your bundle, unfortunately the UI thread has a lock on the bundle classloader (now we are deadlocked).
In Equinox it detects this situation and break out of the deadlock after 5 seconds(5000ms).

One way to avoid the situation is to put all your async posts at the very end of your activation code so that you exit very quickly without loading additional classes.

It better to use aysnc execution, since bundle activation thread will return immediate and will go to active state, otherwise bundle activation thread will be blocked until your service gets over. But anyway this will vary based on call what we wanted to do it in start method.






How do you start a new thread from plugin start() method upon plugin active.

We can call below particular snippet from any plugin start() method. 

final Bundle currentBundle = getBundle();
Job serviceJob = new Job("services starting...") {
@Override
protected IStatus run(IProgressMonitor monitor) {
while (currentBundle.getState() != Bundle.ACTIVE) {
try {
Thread.sleep(1000); //wait for some time and then re-check
} catch (InterruptedException e) {
e.printStackTrace();
}
}

startService();  //service implemenation goes here - this what you wanted to do after plugin is active

return Status.OK_STATUS;
}
};
serviceJob.schedule();

Friday, October 4, 2013

Where does Java process ID's(pid) are stored ?

Got to 'Run' command,
Type  %temp%  and hit enter.

This will open up the 'Temp' folder in your local user App data.

Look for a folder hsperfdata_<systemLoginName>

example:  hsperfdata_KK1205

Complete path looks like below:
C:\Users\KK1205\AppData\Local\Temp\hsperfdata_KK1205

Inside of 'hsperfdata_KK1205' you can find currently running java process id's.

Thursday, October 3, 2013

Eclipse Mac OS - Context-sensitive help

 Please find the below link on context sensitive help from Eclipse for various platforms.  Please go through the “Context-sensitive help” section.

http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fhelp.htm

 As mentioned in the Eclipse documentation,  “ F1(Shift+F1  Help on the Mac). Alternatively, in dialogs you can achieve the same result by pressing the   help button in the dialog's button bar.”

To make it clear, Eclipse Mac is not providing the context sensitive help the way how windows (using F1) is providing.   You have to use’ help’ key in Mac keyboards or ‘command+shift+?’ in mac pro’s to point to the Help search.

 To use context-sensitive Help on Mac OS, set a keyboard shortcut to the Dynamic Help command. Eclipse ‘Dynamic Help’ option is available for Windows and as well as Mac systems.
This can also be used to get the context sensitive help documentation.

To specify a keyboard shortcut for the Dynamic Help command, do the following:
1.       Select Eclipse > Preferences.
2.       In the tree view, select General > Keys.
3.       Select the Dynamic Help command.
4.       Press the key binding combination that you want to set. For example, to enter Ctrl+Shift+1, press and hold the keys Ctrl and Shift and then press 1. A plus sign (+) between the keys indicates that you must press the keys in succession.

Now, you will be able to get ‘ context sensitive Dynamic help’ doc.  This provides the exact documentation whatever you are getting in windows through Dynamic help (This could be different from what you are getting for ‘F1’ help in windows but this would be same as what you are getting through dynamic help in windows).



Eclipse Mac OS - shortcut keys


Shortcut keys for Mac and Windows users @
http://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts


Eclipse Mac OS- Scrollbar in navigation viewer

Bydefault, scrollbar option is not visible for navigation viewer in Eclipse for Mac OS. Unless you try to drag it, you will not realize that there is a scroll available for it.

To make it available explicitly, check “Always” option under Show Scroll Bars in System Preferences. If you enable that option you will get both horizontal and vertical scroll bars for navigation viewer.

IP address validation

Any IP address has to fall into [0-255].[0-255].[0-255].[0-255] format criteria.

We can achieve this by using following 2 ways.


Using split method of String: The method described above can also be written in a simple way as follows


public boolean validateIPAddress( String ipAddress ) {

String[] tokens = ipAddress.split("\\.");
if (tokens.length != 4) {
return false;
}
for (String str : tokens) {
int i = 0;
try {
  i = Integer.parseInt( s );
  } catch (NumberFormatException e) { //if any character data is entered.
   return false;
  }
if ((i < 0) || (i > 255)) {
return false;
}
}
return true;
}


Using regular expression: The following method with return true is the IP Address is valid, else it returns false.


public boolean validateIPAddress( String ipAddress ){

final Pattern ipAdd= Pattern.compile("b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
+ "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)b");
return ipAdd.matcher(ipAddress).matches();
}


If it's is false, we can show error message as "IP Address must be in the in the format of:  [0-255].[0-255].[0-255].[0-255]"