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.