org.eclipse.osgi_3.8.2.v20130124-134944

strationImpl<S> registration)
  {
    this.registration = registration;
  }
  
  public Object getProperty(String key)
  {
    return registration.getProperty(key);
  }
  
  public String[] getPropertyKeys()
  {
    return registration.getPropertyKeys();
  }
  
  public Bundle getBundle()
  {
    return registration.getBundle();
  }
  
  public Bundle[] getUsingBundles()
  {
    return registration.getUsingBundles();
  }
  
  public boolean isAssignableTo(Bundle bundle, String className)
  {
    return registration.isAssignableTo(bundle, className);
  }
  
  public int compareTo(Object object)
  {
    ServiceRegistrationImpl<?> other = registration;
    
    int thisRanking = registration.getRanking();
    int otherRanking = other.getRanking();
    if (thisRanking != otherRanking)
    {
      if (thisRanking < otherRanking) {
        return -1;
      }
      return 1;
    }
    long thisId = registration.getId();
    long otherId = other.getId();
    if (thisId == otherId) {
      return 0;
    }
    if (thisId < otherId) {
      return 1;
    }
    return -1;
  }
  
  public int hashCode()
  {
    return registration.hashCode();
  }
  
  public boolean equals(Object obj)
  {
    if (obj == this) {
      return true;
    }
    if (!(obj instanceof ServiceReferenceImpl)) {
      return false;
    }
    ServiceReferenceImpl<?> other = (ServiceReferenceImpl)obj;
    
    return registration == registration;
  }
  
  public String toString()
  {
    return registration.toString();
  }
  
  public ServiceRegistrationImpl<S> getRegistration()
  {
    return registration;
  }
  
  String[] getClasses()
  {
    return registration.getClasses();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceReferenceImpl
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.util.ArrayList;
import java.util.Dictionary;
import java.util.List;
import java.util.Map;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.internal.core.BundleContextImpl;
import org.eclipse.osgi.framework.internal.core.Framework;
import org.eclipse.osgi.framework.internal.core.Msg;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;

public class ServiceRegistrationImpl<S>
  implements ServiceRegistration<S>, Comparable<ServiceRegistrationImpl<?>>
{
  private final Framework framework;
  private final ServiceRegistry registry;
  private final BundleContextImpl context;
  private final Bundle bundle;
  private final String[] clazzes;
  private final S service;
  private ServiceReferenceImpl<S> reference;
  private final List<BundleContextImpl> contextsUsing;
  private ServiceProperties properties;
  private final long serviceid;
  private int serviceranking;
  
  static
  {
    try {}catch (ClassNotFoundException localClassNotFoundException)
    {
      throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
    }
  }
  
  private final Object registrationLock = new Object();
  private int state;
  private static final int REGISTERED = 0;
  private static final int UNREGISTERING = 1;
  private static final int UNREGISTERED = 2;
  
  ServiceRegistrationImpl(ServiceRegistry registry, BundleContextImpl context, String[] clazzes, S service)
  {
    this.registry = registry;
    this.context = context;
    bundle = context.getBundleImpl();
    framework = context.getFramework();
    this.clazzes = clazzes;
    this.service = service;
    serviceid = registry.getNextServiceId();
    contextsUsing = new ArrayList(10);
    synchronized (registrationLock)
    {
      state = 0;
      
      reference = new ServiceReferenceImpl(this);
    }
  }
  
  void register(Dictionary<String, ?> props)
  {
    synchronized (registry)
    {
      context.checkValid();
      synchronized (registrationLock)
      {
        ServiceReferenceImpl<S> ref = reference;
        properties = createProperties(props);
      }
      ServiceReferenceImpl<S> ref;
      if (Debug.DEBUG_SERVICES) {
        Debug.println("registerService[" + bundle + "](" + this + ")");
      }
      registry.addServiceRegistration(context, this);
    }
    ServiceReferenceImpl<S> ref;
    registry.publishServiceEvent(new ServiceEvent(1, ref));
  }
  
  public void setProperties(Dictionary<String, ?> props)
  {
    synchronized (registry)
    {
      synchronized (registrationLock)
      {
        if (state != 0) {
          throw new IllegalStateException(Msg.SERVICE_ALREADY_UNREGISTERED_EXCEPTION);
        }
        ServiceReferenceImpl<S> ref = reference;
        ServiceProperties previousProperties = properties;
        properties = createProperties(props);
      }
      ServiceProperties previousProperties;
      ServiceReferenceImpl<S> ref;
      registry.modifyServiceRegistration(context, this);
    }
    ServiceProperties previousProperties;
    ServiceReferenceImpl<S> ref;
    registry.publishServiceEvent(new ModifiedServiceEvent(ref, previousProperties));
  }
  
  public void unregister()
  {
    ServiceReferenceImpl<S> ref;
    synchronized (registry)
    {
      ServiceReferenceImpl<S> ref;
      synchronized (registrationLock)
      {
        if (state != 0) {
          throw new IllegalStateException(Msg.SERVICE_ALREADY_UNREGISTERED_EXCEPTION);
        }
        if (Debug.DEBUG_SERVICES) {
          Debug.println("unregisterService[" + bundle + "](" + this + ")");
        }
        registry.removeServiceRegistration(context, this);
        
        state = 1;
        ref = reference;
      }
    }
    ServiceReferenceImpl<S> ref;
    registry.publishServiceEvent(new ServiceEvent(4, ref));
    
    int size = 0;
    BundleContextImpl[] users = null;
    synchronized (registrationLock)
    {
      state = 2;
      
      size = contextsUsing.size();
      if (size > 0)
      {
        if (Debug.DEBUG_SERVICES) {
          Debug.println("unregisterService: releasing users");
        }
        users = (BundleContextImpl[])contextsUsing.toArray(new BundleContextImpl[size]);
      }
    }
    for (int i = 0; i < size; i++) {
      releaseService(users[i]);
    }
    synchronized (registrationLock)
    {
      contextsUsing.clear();
      
      reference = null;
    }
  }
  
  public ServiceReference<S> getReference()
  {
    return getReferenceImpl();
  }
  
  ServiceReferenceImpl<S> getReferenceImpl()
  {
    synchronized (registrationLock)
    {
      if (reference == null) {
        throw new IllegalStateException(Msg.SERVICE_ALREADY_UNREGISTERED_EXCEPTION);
      }
      return reference;
    }
  }
  
  private ServiceProperties createProperties(Dictionary<String, ?> p)
  {
    assert (Thread.holdsLock(registrationLock));
    ServiceProperties props = new ServiceProperties(p);
    
    props.set("objectClass", clazzes, true);
    props.set("service.id", new Long(serviceid), true);
    props.setReadOnly();
    Object ranking = props.getProperty("service.ranking");
    
    serviceranking = ((ranking instanceof Integer) ? ((Integer)ranking).intValue() : 0);
    
    return props;
  }
  
  /* Error */
  public ServiceProperties getProperties()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 341	org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl:registrationLock	Ljava/lang/Object;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 347	org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl:properties	Lorg/eclipse/osgi/internal/serviceregistry/ServiceProperties;
    //   11: aload_1
    //   12: monitorexit
    //   13: areturn
    //   14: aload_1
    //   15: monitorexit
    //   16: athrow
    // Line number table:
    //   Java source line #311	-> byte code offset #0
    //   Java source line #312	-> byte code offset #7
    //   Java source line #311	-> byte code offset #14
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	17	0	this	ServiceRegistrationImpl<S>
    //   5	10	1	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	13	14	finally
    //   14	16	14	finally
  }
  
  /* Error */
  Object getProperty(String key)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 341	org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl:registrationLock	Ljava/lang/Object;
    //   4: dup
    //   5: astore_2
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 347	org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl:properties	Lorg/eclipse/osgi/internal/serviceregistry/ServiceProperties;
    //   11: aload_1
    //   12: invokevirtual 380	org/eclipse/osgi/internal/serviceregistry/ServiceProperties:getProperty	(Ljava/lang/String;)Ljava/lang/Object;
    //   15: aload_2
    //   16: monitorexit
    //   17: areturn
    //   18: aload_2
    //   19: monitorexit
    //   20: athrow
    // Line number table:
    //   Java source line #329	-> byte code offset #0
    //   Java source line #330	-> byte code offset #7
    //   Java source line #329	-> byte code offset #18
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	21	0	this	ServiceRegistrationImpl<S>
    //   0	21	1	key	String
    //   5	14	2	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	17	18	finally
    //   18	20	18	finally
  }
  
  /* Error */
  String[] getPropertyKeys()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 341	org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl:registrationLock	Ljava/lang/Object;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 347	org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl:properties	Lorg/eclipse/osgi/internal/serviceregistry/ServiceProperties;
    //   11: invokevirtual 378	org/eclipse/osgi/internal/serviceregistry/ServiceProperties:getPropertyKeys	()[Ljava/lang/String;
    //   14: aload_1
    //   15: monitorexit
    //   16: areturn
    //   17: aload_1
    //   18: monitorexit
    //   19: athrow
    // Line number table:
    //   Java source line #345	-> byte code offset #0
    //   Java source line #346	-> byte code offset #7
    //   Java source line #345	-> byte code offset #17
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	20	0	this	ServiceRegistrationImpl<S>
    //   5	13	1	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	16	17	finally
    //   17	19	17	finally
  }
  
  long getId()
  {
    return serviceid;
  }
  
  /* Error */
  int getRanking()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 341	org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl:registrationLock	Ljava/lang/Object;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 337	org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl:serviceranking	I
    //   11: aload_1
    //   12: monitorexit
    //   13: ireturn
    //   14: aload_1
    //   15: monitorexit
    //   16: athrow
    // Line number table:
    //   Java source line #363	-> byte code offset #0
    //   Java source line #364	-> byte code offset #7
    //   Java source line #363	-> byte code offset #14
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	17	0	this	ServiceRegistrationImpl<S>
    //   5	10	1	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	13	14	finally
    //   14	16	14	finally
  }
  
  String[] getClasses()
  {
    return clazzes;
  }
  
  S getServiceObject()
  {
    return (S)service;
  }
  
  Bundle getBundle()
  {
    synchronized (registrationLock)
    {
      if (reference == null) {
        return null;
      }
      return bundle;
    }
  }
  
  public Bundle getRegisteringBundle()
  {
    return bundle;
  }
  
  Object getSafeService(BundleContextImpl user)
  {
    try
    {
      return getService(user);
    }
    catch (IllegalStateException localIllegalStateException) {}
    return null;
  }
  
  Object getService(BundleContextImpl user)
  {
    synchronized (registrationLock)
    {
      if (state == 2) {
        return null;
      }
    }
    if (Debug.DEBUG_SERVICES) {
      Debug.println("getService[" + user.getBundleImpl() + "](" + this + ")");
    }
    Map<ServiceRegistrationImpl<?>, ServiceUse<?>> servicesInUse = user.getServicesInUseMap();
    if (servicesInUse == null) {
      user.checkValid();
    }
    for (;;)
    {
      boolean added = false;
      synchronized (servicesInUse)
      {
        user.checkValid();
        ServiceUse<?> use = (ServiceUse)servicesInUse.get(this);
        if (use == null)
        {
          use = new ServiceUse(user, this);
          added = true;
          synchronized (registrationLock)
          {
            if (state == 2) {
              return null;
            }
            servicesInUse.put(this, use);
            contextsUsing.add(user);
          }
        }
      }
      synchronized (use)
      {
        ServiceUse<?> use;
        synchronized (servicesInUse)
        {
          user.checkValid();
          if (servicesInUse.get(this) != use) {
            continue;
          }
        }
        Object serviceObject = use.getService();
        if ((serviceObject == null) && (added)) {
          synchronized (servicesInUse)
          {
            synchronized (registrationLock)
            {
              servicesInUse.remove(this);
              contextsUsing.remove(user);
            }
          }
        }
        return serviceObject;
      }
    }
  }
  
  boolean ungetService(BundleContextImpl user)
  {
    synchronized (registrationLock)
    {
      if (state == 2) {
        return false;
      }
    }
    if (Debug.DEBUG_SERVICES) {
      Debug.println("ungetService[" + user.getBundleImpl() + "](" + this + ")");
    }
    Map<ServiceRegistrationImpl<?>, ServiceUse<?>> servicesInUse = user.getServicesInUseMap();
    if (servicesInUse == null) {
      return false;
    }
    synchronized (servicesInUse)
    {
      ServiceUse<?> use = (ServiceUse)servicesInUse.get(this);
      if (use == null) {
        return false;
      }
    }
    synchronized (use)
    {
      ServiceUse<?> use;
      if (use.ungetService()) {
        synchronized (servicesInUse)
        {
          synchronized (registrationLock)
          {
            servicesInUse.remove(this);
            contextsUsing.remove(user);
          }
        }
      }
    }
    return true;
  }
  
  void releaseService(BundleContextImpl user)
  {
    synchronized (registrationLock)
    {
      if (reference == null) {
        return;
      }
    }
    if (Debug.DEBUG_SERVICES) {
      Debug.println("releaseService[" + user.getBundleImpl() + "](" + this + ")");
    }
    Map<ServiceRegistrationImpl<?>, ServiceUse<?>> servicesInUse = user.getServicesInUseMap();
    if (servicesInUse == null) {
      return;
    }
    ServiceUse<?> use;
    synchronized (servicesInUse)
    {
      synchronized (registrationLock)
      {
        ServiceUse<?> use = (ServiceUse)servicesInUse.remove(this);
        if (use == null) {
          return;
        }
        contextsUsing.remove(user);
      }
    }
    synchronized (use)
    {
      ServiceUse<?> use;
      use.releaseService();
    }
  }
  
  Bundle[] getUsingBundles()
  {
    synchronized (registrationLock)
    {
      if (state == 2) {
        return null;
      }
      int size = contextsUsing.size();
      if (size == 0) {
        return null;
      }
      Bundle[] bundles = new Bundle[size];
      for (int i = 0; i < size; i++) {
        bundles[i] = ((BundleContextImpl)contextsUsing.get(i)).getBundleImpl();
      }
      return bundles;
    }
  }
  
  boolean isAssignableTo(Bundle client, String className)
  {
    return framework.isServiceAssignableTo(bundle, client, className, service.getClass());
  }
  
  public String toString()
  {
    int size = clazzes.length;
    StringBuffer sb = new StringBuffer(50 * size);
    
    sb.append('{');
    for (int i = 0; i < size; i++)
    {
      if (i > 0) {
        sb.append(", ");
      }
      sb.append(clazzes[i]);
    }
    sb.append("}=");
    sb.append(getProperties().toString());
    
    return sb.toString();
  }
  
  public int compareTo(ServiceRegistrationImpl<?> other)
  {
    int thisRanking = getRanking();
    int otherRanking = other.getRanking();
    if (thisRanking != otherRanking)
    {
      if (thisRanking < otherRanking) {
        return 1;
      }
      return -1;
    }
    long thisId = getId();
    long otherId = other.getId();
    if (thisId == otherId) {
      return 0;
    }
    if (thisId < otherId) {
      return -1;
    }
    return 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.security.PrivilegedAction;
import org.osgi.framework.ServiceEvent;

class ServiceRegistry$1
  implements PrivilegedAction<Object>
{
  final ServiceRegistry this$0;
  
  ServiceRegistry$1(ServiceRegistry paramServiceRegistry, ServiceEvent paramServiceEvent) {}
  
  public Object run()
  {
    this$0.publishServiceEventPrivileged(val$event);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.util.Collection;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.service.ListenerHook;

class ServiceRegistry$10
  implements HookContext
{
  final ServiceRegistry this$0;
  
  ServiceRegistry$10(ServiceRegistry paramServiceRegistry, boolean paramBoolean, Collection paramCollection) {}
  
  public void call(Object hook, ServiceRegistration<?> hookRegistration)
    throws Exception
  {
    if ((hook instanceof ListenerHook)) {
      if (val$added) {
        ((ListenerHook)hook).added(val$listeners);
      } else {
        ((ListenerHook)hook).removed(val$listeners);
      }
    }
  }
  
  public String getHookClassName()
  {
    return ServiceRegistry.listenerHookName;
  }
  
  public String getHookMethodName()
  {
    return val$added ? "added" : "removed";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.10
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.security.PrivilegedAction;

class ServiceRegistry$2
  implements PrivilegedAction<ClassLoader>
{
  private final Object val$serviceObject;
  
  ServiceRegistry$2(Object paramObject) {}
  
  public ClassLoader run()
  {
    return val$serviceObject.getClass().getClassLoader();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.security.PrivilegedAction;
import java.util.Collection;
import org.eclipse.osgi.framework.internal.core.BundleContextImpl;

class ServiceRegistry$3
  implements PrivilegedAction<Object>
{
  final ServiceRegistry this$0;
  
  ServiceRegistry$3(ServiceRegistry paramServiceRegistry, BundleContextImpl paramBundleContextImpl, String paramString1, String paramString2, boolean paramBoolean, Collection paramCollection) {}
  
  public Object run()
  {
    this$0.notifyFindHooksPrivileged(val$context, val$clazz, val$filterstring, val$allservices, val$result);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.util.Collection;
import org.eclipse.osgi.framework.internal.core.BundleContextImpl;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.service.FindHook;

class ServiceRegistry$4
  implements HookContext
{
  final ServiceRegistry this$0;
  
  ServiceRegistry$4(ServiceRegistry paramServiceRegistry, BundleContextImpl paramBundleContextImpl, String paramString1, String paramString2, boolean paramBoolean, Collection paramCollection) {}
  
  public void call(Object hook, ServiceRegistration<?> hookRegistration)
    throws Exception
  {
    if ((hook instanceof FindHook)) {
      ((FindHook)hook).find(val$context, val$clazz, val$filterstring, val$allservices, val$result);
    }
  }
  
  public String getHookClassName()
  {
    return ServiceRegistry.findHookName;
  }
  
  public String getHookMethodName()
  {
    return "find";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.4
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.util.Collection;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.service.EventHook;

class ServiceRegistry$5
  implements HookContext
{
  final ServiceRegistry this$0;
  
  ServiceRegistry$5(ServiceRegistry paramServiceRegistry, ServiceEvent paramServiceEvent, Collection paramCollection) {}
  
  public void call(Object hook, ServiceRegistration<?> hookRegistration)
    throws Exception
  {
    if ((hook instanceof EventHook)) {
      ((EventHook)hook).event(val$event, val$result);
    }
  }
  
  public String getHookClassName()
  {
    return ServiceRegistry.eventHookName;
  }
  
  public String getHookMethodName()
  {
    return "event";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.5
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.util.Map;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.service.EventListenerHook;

class ServiceRegistry$6
  implements HookContext
{
  final ServiceRegistry this$0;
  
  ServiceRegistry$6(ServiceRegistry paramServiceRegistry, ServiceEvent paramServiceEvent, Map paramMap) {}
  
  public void call(Object hook, ServiceRegistration<?> hookRegistration)
    throws Exception
  {
    if ((hook instanceof EventListenerHook)) {
      ((EventListenerHook)hook).event(val$event, val$result);
    }
  }
  
  public String getHookClassName()
  {
    return ServiceRegistry.eventListenerHookName;
  }
  
  public String getHookMethodName()
  {
    return "event";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.6
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.security.PrivilegedAction;

class ServiceRegistry$7
  implements PrivilegedAction<Object>
{
  final ServiceRegistry this$0;
  
  ServiceRegistry$7(ServiceRegistry paramServiceRegistry, ServiceRegistrationImpl paramServiceRegistrationImpl) {}
  
  public Object run()
  {
    this$0.notifyNewListenerHookPrivileged(val$registration);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.7
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.util.Collection;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.service.ListenerHook;

class ServiceRegistry$8
  implements HookContext
{
  final ServiceRegistry this$0;
  
  ServiceRegistry$8(ServiceRegistry paramServiceRegistry, Collection paramCollection) {}
  
  public void call(Object hook, ServiceRegistration<?> hookRegistration)
    throws Exception
  {
    if ((hook instanceof ListenerHook)) {
      ((ListenerHook)hook).added(val$listeners);
    }
  }
  
  public String getHookClassName()
  {
    return ServiceRegistry.listenerHookName;
  }
  
  public String getHookMethodName()
  {
    return "added";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.8
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.security.PrivilegedAction;
import java.util.Collection;

class ServiceRegistry$9
  implements PrivilegedAction<Object>
{
  final ServiceRegistry this$0;
  
  ServiceRegistry$9(ServiceRegistry paramServiceRegistry, Collection paramCollection, boolean paramBoolean) {}
  
  public Object run()
  {
    this$0.notifyListenerHooksPrivileged(val$listeners, val$added);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.9
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap;
import org.eclipse.osgi.framework.eventmgr.EventDispatcher;
import org.eclipse.osgi.framework.eventmgr.ListenerQueue;
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
import org.eclipse.osgi.framework.internal.core.BundleContextImpl;
import org.eclipse.osgi.framework.internal.core.Framework;
import org.eclipse.osgi.framework.internal.core.Msg;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServicePermission;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.service.EventHook;
import org.osgi.framework.hooks.service.EventListenerHook;
import org.osgi.framework.hooks.service.FindHook;
import org.osgi.framework.hooks.service.ListenerHook;
import org.osgi.framework.hooks.service.ListenerHook.ListenerInfo;

public class ServiceRegistry
{
  public static final int SERVICEEVENT = 3;
  
  static
  {
    try {}catch (ClassNotFoundException localClassNotFoundException1)
    {
      throw new NoClassDefFoundError(localClassNotFoundException1.getMessage());
    }
    $assertionsDisabled = !Class.forName("org.eclipse.osgi.internal.serviceregistry.ServiceRegistry").desiredAssertionStatus();
  }
  
  static final String findHookName = FindHook.class.getName();
  static final String eventHookName = EventHook.class.getName();
  static final String eventListenerHookName = EventListenerHook.class.getName();
  static final String listenerHookName = ListenerHook.class.getName();
  private final Map<String, List<ServiceRegistrationImpl<?>>> publishedServicesByClass;
  private final List<ServiceRegistrationImpl<?>> allPublishedServices;
  private final Map<BundleContextImpl, List<ServiceRegistrationImpl<?>>> publishedServicesByContext;
  private long serviceid;
  private final Map<BundleContextImpl, CopyOnWriteIdentityMap<ServiceListener, FilteredServiceListener>> serviceEventListeners;
  private static final int initialCapacity = 50;
  private static final int initialSubCapacity = 10;
  private final Framework framework;
  static final boolean $assertionsDisabled;
  
  public ServiceRegistry(Framework framework)
  {
    this.framework = framework;
    serviceid = 1L;
    publishedServicesByClass = new HashMap(50);
    publishedServicesByContext = new HashMap(50);
    allPublishedServices = new ArrayList(50);
    serviceEventListeners = new HashMap(50);
  }
  
  public ServiceRegistrationImpl<?> registerService(BundleContextImpl context, String[] clazzes, Object service, Dictionary<String, ?> properties)
  {
    if (service == null)
    {
      if (Debug.DEBUG_SERVICES) {
        Debug.println("Service object is null");
      }
      throw new IllegalArgumentException(Msg.SERVICE_ARGUMENT_NULL_EXCEPTION);
    }
    int size = clazzes.length;
    if (size == 0)
    {
      if (Debug.DEBUG_SERVICES) {
        Debug.println("Classes array is empty");
      }
      throw new IllegalArgumentException(Msg.SERVICE_EMPTY_CLASS_LIST_EXCEPTION);
    }
    List<String> copy = new ArrayList(size);
    for (int i = 0; i < size; i++)
    {
      String clazz = clazzes[i].intern();
      if (!copy.contains(clazz)) {
        copy.add(clazz);
      }
    }
    size = copy.size();
    clazzes = (String[])copy.toArray(new String[size]);
    
    checkRegisterServicePermission(clazzes);
    if (!(service instanceof ServiceFactory))
    {
      String invalidService = checkServiceClass(clazzes, service);
      if (invalidService != null)
      {
        if (Debug.DEBUG_SERVICES) {
          Debug.println("Service object is not an instanceof " + invalidService);
        }
        throw new IllegalArgumentException(NLS.bind(Msg.SERVICE_NOT_INSTANCEOF_CLASS_EXCEPTION, invalidService));
      }
    }
    ServiceRegistrationImpl<?> registration = new ServiceRegistrationImpl(this, context, clazzes, service);
    registration.register(properties);
    if (copy.contains(listenerHookName)) {
      notifyNewListenerHook(registration);
    }
    return registration;
  }
  
  public ServiceReferenceImpl<?>[] getServiceReferences(BundleContextImpl context, String clazz, String filterstring, boolean allservices, boolean callHooks)
    throws InvalidSyntaxException
  {
    if (Debug.DEBUG_SERVICES) {
      Debug.println((allservices ? "getAllServiceReferences(" : "getServiceReferences(") + clazz + ", \"" + filterstring + "\")");
    }
    Filter filter = filterstring == null ? null : context.createFilter(filterstring);
    List<ServiceRegistrationImpl<?>> registrations = lookupServiceRegistrations(clazz, filter);
    List<ServiceReferenceImpl<?>> references = new ArrayList(registrations.size());
    for (Iterator localIterator = registrations.iterator(); localIterator.hasNext();)
    {
      ServiceRegistrationImpl<?> registration = (ServiceRegistrationImpl)localIterator.next();
      try
      {
        reference = registration.getReferenceImpl();
      }
      catch (IllegalStateException localIllegalStateException)
      {
        ServiceReferenceImpl<?> reference;
        continue;
      }
      ServiceReferenceImpl<?> reference;
      if ((allservices) || (isAssignableTo(context, reference)))
      {
        try
        {
          checkGetServicePermission(reference);
        }
        catch (SecurityException localSecurityException)
        {
          continue;
        }
        references.add(reference);
      }
    }
    if (callHooks)
    {
      Collection<ServiceReference<?>> shrinkable = new ShrinkableCollection(references);
      notifyFindHooks(context, clazz, filterstring, allservices, shrinkable);
    }
    int size = references.size();
    if (size == 0) {
      return null;
    }
    return (ServiceReferenceImpl[])references.toArray(new ServiceReferenceImpl[size]);
  }
  
  public ServiceReferenceImpl<?>[] getServiceReferences(BundleContextImpl context, String clazz, String filterstring, boolean allservices)
    throws InvalidSyntaxException
  {
    return getServiceReferences(context, clazz, filterstring, allservices, true);
  }
  
  public ServiceReferenceImpl<?> getServiceReference(BundleContextImpl context, String clazz)
  {
    if (Debug.DEBUG_SERVICES) {
      Debug.println("getServiceReference(" + clazz + ")");
    }
    try
    {
      ServiceReferenceImpl[] references = getServiceReferences(context, clazz, null, false);
      if (references != null) {
        return references[0];
      }
    }
    catch (InvalidSyntaxException e)
    {
      if (Debug.DEBUG_GENERAL)
      {
        Debug.println("InvalidSyntaxException w/ null filter" + e.getMessage());
        Debug.printStackTrace(e);
      }
    }
    return null;
  }
  
  public Object getService(BundleContextImpl context, ServiceReferenceImpl<?> reference)
  {
    checkGetServicePermission(reference);
    return reference.getRegistration().getService(context);
  }
  
  public boolean ungetService(BundleContextImpl context, ServiceReferenceImpl<?> reference)
  {
    ServiceRegistrationImpl<?> registration = reference.getRegistration();
    
    return registration.ungetService(context);
  }
  
  public ServiceReferenceImpl<?>[] getRegisteredServices(BundleContextImpl context)
  {
    List<ServiceRegistrationImpl<?>> registrations = lookupServiceRegistrations(context);
    List<ServiceReferenceImpl<?>> references = new ArrayList(registrations.size());
    for (Iterator localIterator = registrations.iterator(); localIterator.hasNext();)
    {
      ServiceRegistrationImpl<?> registration = (ServiceRegistrationImpl)localIterator.next();
      try
      {
        reference = registration.getReferenceImpl();
      }
      catch (IllegalStateException localIllegalStateException)
      {
        ServiceReferenceImpl<?> reference;
        continue;
      }
      ServiceReferenceImpl<?> reference;
      try
      {
        checkGetServicePermission(reference);
      }
      catch (SecurityException localSecurityException)
      {
        continue;
      }
      references.add(reference);
    }
    int size = references.size();
    if (size == 0) {
      return null;
    }
    return (ServiceReferenceImpl[])references.toArray(new ServiceReferenceImpl[size]);
  }
  
  public ServiceReferenceImpl<?>[] getServicesInUse(BundleContextImpl context)
  {
    Map<ServiceRegistrationImpl<?>, ServiceUse<?>> servicesInUse = context.getServicesInUseMap();
    if (servicesInUse == null) {
      return null;
    }
    List<ServiceRegistrationImpl<?>> registrations;
    synchronized (servicesInUse)
    {
      if (servicesInUse.isEmpty()) {
        return null;
      }
      registrations = new ArrayList(servicesInUse.keySet());
    }
    List<ServiceRegistrationImpl<?>> registrations;
    List<ServiceReferenceImpl<?>> references = new ArrayList(registrations.size());
    for (Iterator localIterator = registrations.iterator(); localIterator.hasNext();)
    {
      ServiceRegistrationImpl<?> registration = (ServiceRegistrationImpl)localIterator.next();
      try
      {
        reference = registration.getReferenceImpl();
      }
      catch (IllegalStateException localIllegalStateException)
      {
        ServiceReferenceImpl<?> reference;
        continue;
      }
      ServiceReferenceImpl<?> reference;
      try
      {
        checkGetServicePermission(reference);
      }
      catch (SecurityException localSecurityException)
      {
        continue;
      }
      references.add(reference);
    }
    int size = references.size();
    if (size == 0) {
      return null;
    }
    return (ServiceReferenceImpl[])references.toArray(new ServiceReferenceImpl[size]);
  }
  
  public void unregisterServices(BundleContextImpl context)
  {
    for (Iterator localIterator = lookupServiceRegistrations(context).iterator(); localIterator.hasNext();)
    {
      ServiceRegistrationImpl<?> registration = (ServiceRegistrationImpl)localIterator.next();
      try
      {
        registration.unregister();
      }
      catch (IllegalStateException localIllegalStateException) {}
    }
    removeServiceRegistrations(context);
  }
  
  public void releaseServicesInUse(BundleContextImpl context)
  {
    Map<ServiceRegistrationImpl<?>, ServiceUse<?>> servicesInUse = context.getServicesInUseMap();
    if (servicesInUse == null) {
      return;
    }
    List<ServiceRegistrationImpl<?>> registrations;
    synchronized (servicesInUse)
    {
      if (servicesInUse.isEmpty()) {
        return;
      }
      registrations = new ArrayList(servicesInUse.keySet());
    }
    List<ServiceRegistrationImpl<?>> registrations;
    if (Debug.DEBUG_SERVICES) {
      Debug.println("Releasing services");
    }
    for (Iterator localIterator = registrations.iterator(); localIterator.hasNext();)
    {
      ServiceRegistrationImpl<?> registration = (ServiceRegistrationImpl)localIterator.next();
      registration.releaseService(context);
    }
  }
  
  public void addServiceListener(BundleContextImpl context, ServiceListener listener, String filter)
    throws InvalidSyntaxException
  {
    if (Debug.DEBUG_EVENTS)
    {
      String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener));
      Debug.println("addServiceListener[" + context.getBundleImpl() + "](" + listenerName + ", \"" + filter + "\")");
    }
    FilteredServiceListener filteredListener = new FilteredServiceListener(context, listener, filter);
    FilteredServiceListener oldFilteredListener;
    synchronized (serviceEventListeners)
    {
      CopyOnWriteIdentityMap<ServiceListener, FilteredServiceListener> listeners = (CopyOnWriteIdentityMap)serviceEventListeners.get(context);
      if (listeners == null)
      {
        listeners = new CopyOnWriteIdentityMap();
        serviceEventListeners.put(context, listeners);
      }
      oldFilteredListener = (FilteredServiceListener)listeners.put(listener, filteredListener);
    }
    FilteredServiceListener oldFilteredListener;
    if (oldFilteredListener != null)
    {
      oldFilteredListener.markRemoved();
      Collection<ListenerHook.ListenerInfo> removedListeners = Collections.singletonList(oldFilteredListener);
      notifyListenerHooks(removedListeners, false);
    }
    Collection<ListenerHook.ListenerInfo> addedListeners = Collections.singletonList(filteredListener);
    notifyListenerHooks(addedListeners, true);
  }
  
  public void removeServiceListener(BundleContextImpl context, ServiceListener listener)
  {
    if (Debug.DEBUG_EVENTS)
    {
      String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener));
      Debug.println("removeServiceListener[" + context.getBundleImpl() + "](" + listenerName + ")");
    }
    FilteredServiceListener oldFilteredListener;
    synchronized (serviceEventListeners)
    {
      Map<ServiceListener, FilteredServiceListener> listeners = (Map)serviceEventListeners.get(context);
      if (listeners == null) {
        return;
      }
      oldFilteredListener = (FilteredServiceListener)listeners.remove(listener);
    }
    FilteredServiceListener oldFilteredListener;
    if (oldFilteredListener == null) {
      return;
    }
    oldFilteredListener.markRemoved();
    Collection<ListenerHook.ListenerInfo> removedListeners = Collections.singletonList(oldFilteredListener);
    notifyListenerHooks(removedListeners, false);
  }
  
  public void removeAllServiceListeners(BundleContextImpl context)
  {
    Map<ServiceListener, FilteredServiceListener> removedListenersMap;
    synchronized (serviceEventListeners)
    {
      removedListenersMap = (Map)serviceEventListeners.remove(context);
    }
    Map<ServiceListener, FilteredServiceListener> removedListenersMap;
    if ((removedListenersMap == null) || (removedListenersMap.isEmpty())) {
      return;
    }
    Collection<FilteredServiceListener> removedListeners = removedListenersMap.values();
    for (Iterator localIterator = removedListeners.iterator(); localIterator.hasNext();)
    {
      FilteredServiceListener oldFilteredListener = (Filter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd