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