We do this by checking what class loader is used to this class.
+ *
+ * @return {@code true} if we are called in the context of OSGi framework, {@code false} otherwise
+ */
+ private boolean isOSGiEnv() {
+ return isBundleReference(getClass().getClassLoader());
+ }
+
+ /**
+ * Determines if the specified object is OSGi bundle reference.
+ *
+ * @param obj the object to check
+ * @return {@code true} if the {@code obj} is OSGi bundle reference, {@code false} otherwise
+ */
+ private boolean isBundleReference(Object obj) {
+ Queue Need to dispatch events in the listener registration order.
+ */
+ static class Listener implements Comparable