/**
   * Notifies this <tt>Conference</tt> that the ordered list of <tt>Endpoint</tt>s of {@link
   * #speechActivity} i.e. the dominant speaker history has changed.
   *
   * <p>This instance notifies the video <tt>Channel</tt>s about the change so that they may update
   * their last-n lists and report to this instance which <tt>Endpoint</tt>s are to be asked for
   * video keyframes.
   */
  private void speechActivityEndpointsChanged() {
    List<Endpoint> endpoints = null;

    for (Content content : getContents()) {
      if (MediaType.VIDEO.equals(content.getMediaType())) {
        Set<Endpoint> endpointsToAskForKeyframes = null;

        endpoints = speechActivity.getEndpoints();
        for (Channel channel : content.getChannels()) {
          if (!(channel instanceof RtpChannel)) continue;

          RtpChannel rtpChannel = (RtpChannel) channel;
          List<Endpoint> channelEndpointsToAskForKeyframes =
              rtpChannel.speechActivityEndpointsChanged(endpoints);

          if ((channelEndpointsToAskForKeyframes != null)
              && !channelEndpointsToAskForKeyframes.isEmpty()) {
            if (endpointsToAskForKeyframes == null) {
              endpointsToAskForKeyframes = new HashSet<>();
            }
            endpointsToAskForKeyframes.addAll(channelEndpointsToAskForKeyframes);
          }
        }

        if ((endpointsToAskForKeyframes != null) && !endpointsToAskForKeyframes.isEmpty()) {
          content.askForKeyframes(endpointsToAskForKeyframes);
        }
      }
    }
  }
  @Override
  public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType) {
    SignedContentFactory factory = equinoxContainer.getSignedContentFactory();
    if (factory == null) {
      return Collections.emptyMap();
    }

    try {
      SignerInfo[] infos = signerInfos;
      if (infos == null) {
        SignedContent signedContent = factory.getSignedContent(this);
        infos = signedContent.getSignerInfos();
        signerInfos = infos;
      }
      if (infos.length == 0) return Collections.emptyMap();
      Map<X509Certificate, List<X509Certificate>> results =
          new HashMap<X509Certificate, List<X509Certificate>>(infos.length);
      for (int i = 0; i < infos.length; i++) {
        if (signersType == SIGNERS_TRUSTED && !infos[i].isTrusted()) continue;
        Certificate[] certs = infos[i].getCertificateChain();
        if (certs == null || certs.length == 0) continue;
        List<X509Certificate> certChain = new ArrayList<X509Certificate>();
        for (int j = 0; j < certs.length; j++) certChain.add((X509Certificate) certs[j]);
        results.put((X509Certificate) certs[0], certChain);
      }
      return results;
    } catch (Exception e) {
      return Collections.emptyMap();
    }
  }
예제 #3
0
 /**
  * Populates the entries list with recursively found class entries.
  *
  * @param bundle The bundle to get class entries for.
  * @param entries The list to add the class entries to.
  * @param startPath The start path to look for entries.
  */
 protected void collectClassEntries(Bundle bundle, List<Class> entries, String startPath) {
   Enumeration<String> entryPathEnumeration = bundle.getEntryPaths(startPath);
   while (entryPathEnumeration.hasMoreElements()) {
     String entryPath = entryPathEnumeration.nextElement();
     if (entryPath.endsWith("/")) {
       collectClassEntries(bundle, entries, entryPath);
     } else if (entryPath.endsWith(".class")) {
       try {
         String classQName =
             entryPath.substring(0, entryPath.length() - 6).replace(File.separatorChar, '.');
         if (classQName.startsWith("WEB-INF.classes.")) {
           classQName = classQName.substring(16);
         }
         Class entryClass = bundle.loadClass(classQName);
         // If not activatorMode is true then there will be classes in this list already on the
         // first
         // call to this method. Therefore we skip duplicates.
         if (!entries.contains(entryClass)) {
           entries.add(entryClass);
         }
       } catch (ClassNotFoundException cnfe) {
         this.activatorLogger.warn("Failed to load bundle class!", cnfe);
       } catch (NoClassDefFoundError ncdfe) {
         this.activatorLogger.warn("Failed to load bundle class!", ncdfe);
       }
     }
   }
 }
예제 #4
0
  /**
   * Called when this bundle is started so the Framework can perform the bundle-specific activities
   * necessary to start this bundle. This method can be used to register services or to allocate any
   * resources that this bundle needs.
   *
   * <p>This method must complete and return to its caller in a timely manner.
   *
   * @param context The execution context of the bundle being started.
   * @throws Exception If this method throws an exception, this bundle is marked as stopped and the
   *     Framework will remove this bundle's listeners, unregister all services registered by this
   *     bundle, and release all services used by this bundle.
   */
  @Override
  public void start(BundleContext context) throws Exception {
    this.context = context;
    initMembers();
    this.activatorLogger.info(
        "Starting APSActivator for bundle '"
            + context.getBundle().getSymbolicName()
            + "' with activatorMode: "
            + this.activatorMode);
    Bundle bundle = context.getBundle();

    List<Class> classEntries = new LinkedList<>();
    if (!this.activatorMode) {
      classEntries.addAll(this.managedInstances.keySet());
    }
    collectClassEntries(bundle, classEntries, "/");

    for (Class entryClass : classEntries) {
      OSGiServiceProvider serviceProvider =
          (OSGiServiceProvider) entryClass.getAnnotation(OSGiServiceProvider.class);
      if (serviceProvider != null && serviceProvider.threadStart()) {
        new StartThread(entryClass, context).start();
      } else {
        handleServiceInstances(entryClass, context);
        handleFieldInjections(entryClass, context);
        handleServiceRegistrations(entryClass, context);
        handleMethods(entryClass, context);
      }
    }
  }
 public static FrameworkDTO newFrameworkDTO(
     BundleContext systemBundleContext, Map<String, String> configuration) {
   FrameworkDTO dto = new FrameworkDTO();
   dto.properties = asProperties(configuration);
   if (systemBundleContext == null) {
     dto.bundles = newList(0);
     dto.services = newList(0);
     return dto;
   }
   Bundle[] bundles = systemBundleContext.getBundles();
   int size = bundles == null ? 0 : bundles.length;
   List<BundleDTO> bundleDTOs = newList(size);
   for (int i = 0; i < size; i++) {
     bundleDTOs.add(newBundleDTO(bundles[i]));
   }
   dto.bundles = bundleDTOs;
   try {
     ServiceReference<?>[] references = systemBundleContext.getAllServiceReferences(null, null);
     size = references == null ? 0 : references.length;
     List<ServiceReferenceDTO> refDTOs = newList(size);
     for (int i = 0; i < size; i++) {
       ServiceReferenceDTO serviceRefDTO = getServiceReferenceDTO(references[i]);
       if (serviceRefDTO != null) {
         refDTOs.add(serviceRefDTO);
       }
     }
     dto.services = refDTOs;
   } catch (InvalidSyntaxException e) {
     dto.services = newList(0);
   }
   return dto;
 }
예제 #6
0
  /*
   * Launches against the agent& main
   */
  public void testAgentAndMain() throws Exception {
    Project project = workspace.getProject("p1");
    Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun"));
    bndrun.setProperty("-runpath", "biz.aQute.remote.launcher");
    bndrun.setProperty("-runbundles", "bsn-1,bsn-2");
    bndrun.setProperty("-runremote", "agent,main;agent=1090");

    final RemoteProjectLauncherPlugin pl =
        (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher();
    pl.prepare();

    List<? extends RunSession> sessions = pl.getRunSessions();
    assertEquals(2, sessions.size());

    RunSession agent = sessions.get(0);
    RunSession main = sessions.get(1);

    CountDownLatch agentLatch = launch(agent);
    CountDownLatch mainLatch = launch(main);

    agent.waitTillStarted(1000);
    main.waitTillStarted(1000);
    Thread.sleep(500);

    agent.cancel();
    main.cancel();

    agentLatch.await();
    mainLatch.await();
    assertEquals(-3, agent.getExitCode());
    assertEquals(-3, main.getExitCode());

    bndrun.close();
  }
예제 #7
0
 void trimList(List list, int max) {
   synchronized (list) {
     while (list.size() > max) {
       list.remove(0);
     }
   }
 }
예제 #8
0
 private ConditionalPermissionInfo setConditionalPermissionInfo(
     String name, ConditionInfo[] conds, PermissionInfo[] perms, boolean firstTry) {
   ConditionalPermissionUpdate update = newConditionalPermissionUpdate();
   List rows = update.getConditionalPermissionInfos();
   ConditionalPermissionInfo newInfo =
       newConditionalPermissionInfo(name, conds, perms, ConditionalPermissionInfo.ALLOW);
   int index = -1;
   if (name != null) {
     for (int i = 0; i < rows.size() && index < 0; i++) {
       ConditionalPermissionInfo info = (ConditionalPermissionInfo) rows.get(i);
       if (name.equals(info.getName())) {
         index = i;
       }
     }
   }
   if (index < 0) {
     // must always add to the beginning (bug 303930)
     rows.add(0, newInfo);
     index = 0;
   } else {
     rows.set(index, newInfo);
   }
   synchronized (lock) {
     if (!update.commit()) {
       if (firstTry)
         // try again
         setConditionalPermissionInfo(name, conds, perms, false);
     }
     return condAdminTable.getRow(index);
   }
 }
 @Test
 public void testResolveSingletonInSameRegions() {
   List<BundleCapability> collisionCandidates = new ArrayList<BundleCapability>();
   collisionCandidates.add(bundleCapability(BUNDLE_B));
   collisionCandidates.add(bundleCapability(BUNDLE_C));
   collisionCandidates.add(bundleCapability(BUNDLE_D));
   this.resolverHook.filterSingletonCollisions(bundleCapability(BUNDLE_A), collisionCandidates);
   assertEquals("Wrong number of collitions", 0, collisionCandidates.size());
 }
예제 #10
0
 private List<WireDTO> getListBundleWireDTO(List<BundleWire> wires) {
   if (wires == null) {
     return null;
   }
   List<WireDTO> dtos = newList(wires.size());
   for (BundleWire wire : wires) {
     dtos.add(getBundleWireDTO(wire));
   }
   return dtos;
 }
예제 #11
0
 private List<RequirementRefDTO> getListRequirementRefDTO(List<BundleRequirement> reqs) {
   if (reqs == null) {
     return null;
   }
   List<RequirementRefDTO> dtos = newList(reqs.size());
   for (BundleRequirement req : reqs) {
     dtos.add(getRequirementRefDTO(req));
   }
   return dtos;
 }
예제 #12
0
 private List<CapabilityDTO> getListCapabilityDTO(List<BundleCapability> caps) {
   if (caps == null) {
     return null;
   }
   List<CapabilityDTO> dtos = newList(caps.size());
   for (BundleCapability cap : caps) {
     dtos.add(getCapabilityDTO(cap));
   }
   return dtos;
 }
  /**
   * Expires a specific <tt>Content</tt> of this <tt>Conference</tt> (i.e. if the specified
   * <tt>content</tt> is not in the list of <tt>Content</tt>s of this <tt>Conference</tt>, does
   * nothing).
   *
   * @param content the <tt>Content</tt> to be expired by this <tt>Conference</tt>
   */
  public void expireContent(Content content) {
    boolean expireContent;

    synchronized (contents) {
      if (contents.contains(content)) {
        contents.remove(content);
        expireContent = true;
      } else expireContent = false;
    }
    if (expireContent) content.expire();
  }
예제 #14
0
 public static ServiceReferenceDTO[] newArrayServiceReferenceDTO(
     ServiceReference<?>[] references) {
   final int length = (references == null) ? 0 : references.length;
   List<ServiceReferenceDTO> refDTOs = new ArrayList<ServiceReferenceDTO>(length);
   for (int i = 0; i < length; i++) {
     ServiceReferenceDTO dto = getServiceReferenceDTO(references[i]);
     if (dto != null) {
       refDTOs.add(dto);
     }
   }
   return refDTOs.toArray(new ServiceReferenceDTO[refDTOs.size()]);
 }
예제 #15
0
 public static BundleRevisionDTO[] newArrayBundleRevisionDTO(BundleRevisions revisions) {
   if (revisions == null) {
     return null;
   }
   List<BundleRevision> revs = revisions.getRevisions();
   final int size = revs.size();
   BundleRevisionDTO[] dtos = new BundleRevisionDTO[size];
   for (int i = 0; i < size; i++) {
     dtos[i] = new DTOBuilder().getBundleRevisionDTO(revs.get(i));
   }
   return dtos;
 }
예제 #16
0
  /**
   * Tracks and injects APSServiceTracker directly or as wrapped service instance using the tracker
   * to call the service depending on the field type.
   *
   * @param field The field to inject.
   * @param managedClass Used to lookup or create an instance of this class to inject into.
   * @param context The bundle context.
   */
  protected void handleServiceInjections(Field field, Class managedClass, BundleContext context) {
    OSGiService service = field.getAnnotation(OSGiService.class);
    if (service != null) {
      String trackerKey = field.getType().getName() + service.additionalSearchCriteria();
      APSServiceTracker tracker = this.trackers.get(trackerKey);

      if (tracker == null) {
        tracker =
            new APSServiceTracker<>(
                context, field.getType(), service.additionalSearchCriteria(), service.timeout());
        this.trackers.put(trackerKey, tracker);
      }
      tracker.start();

      List<Object> managedInstances = getManagedInstances(managedClass);
      for (Object managedInstance : managedInstances) {
        if (field.getType().equals(APSServiceTracker.class)) {
          injectObject(managedInstance, tracker, field);
        } else {
          injectObject(managedInstance, tracker.getWrappedService(), field);
        }
      }

      if (service.required() && this.supportsRequired) {
        Tuple4<APSServiceTracker, Class, Boolean, List<ServiceRegistration>> requiredService =
            new Tuple4<>(
                tracker,
                managedClass,
                false,
                (List<ServiceRegistration>) new LinkedList<ServiceRegistration>());
        this.requiredServices.add(requiredService);
      }

      this.activatorLogger.info(
          "Injected tracked service '"
              + field.getType().getName()
              + (service.additionalSearchCriteria().length() > 0
                  ? " " + service.additionalSearchCriteria()
                  : "")
              + "' "
              + "into '"
              + managedClass.getName()
              + "."
              + field.getName()
              + "' for bundle: "
              + context.getBundle().getSymbolicName()
              + " for "
              + managedInstances.size()
              + " instance(s)!");
    }
  }
예제 #17
0
  /*
   * Launches against the agent
   */
  public void testSimpleLauncher() throws Exception {
    Project project = workspace.getProject("p1");
    Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun"));
    bndrun.setProperty("-runpath", "biz.aQute.remote.launcher");
    bndrun.setProperty("-runbundles", "bsn-1,bsn-2");
    bndrun.setProperty("-runremote", "test");

    final RemoteProjectLauncherPlugin pl =
        (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher();
    pl.prepare();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger exitCode = new AtomicInteger(-1);

    List<? extends RunSession> sessions = pl.getRunSessions();
    assertEquals(1, sessions.size());

    final RunSession session = sessions.get(0);

    Thread t =
        new Thread("test-launch") {
          public void run() {
            try {
              exitCode.set(session.launch());
            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              latch.countDown();
            }
          }
        };
    t.start();
    Thread.sleep(500);

    for (Bundle b : context.getBundles()) {
      System.out.println(b.getLocation());
    }
    assertEquals(4, context.getBundles().length);
    String p1 = t1.getAbsolutePath();
    System.out.println(p1);

    assertNotNull(context.getBundle(p1));
    assertNotNull(context.getBundle(t2.getAbsolutePath()));

    pl.cancel();
    latch.await();

    assertEquals(-3, exitCode.get());

    bndrun.close();
  }
 List<Generation> getGenerations() {
   List<Generation> result = new ArrayList<Generation>();
   ModuleRevision current = getModule().getCurrentRevision();
   result.add((Generation) current.getRevisionInfo());
   ModuleWiring wiring = current.getWiring();
   if (wiring != null) {
     List<ModuleWire> hostWires = wiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
     if (hostWires != null) {
       for (ModuleWire hostWire : hostWires) {
         result.add((Generation) hostWire.getRequirer().getRevisionInfo());
       }
     }
   }
   return result;
 }
	public void testBasic() throws BundleException, InvalidSyntaxException, InterruptedException {
		// get the system region
		Region systemRegion = digraph.getRegion(0);
		// create a disconnected test region
		Region testRegion = digraph.createRegion(getName());
		List<Bundle> bundles = new ArrayList<Bundle>();
		// Install all test bundles
		Bundle pp1, cp2, sc1;
		bundles.add(pp1 = bundleInstaller.installBundle(PP1, testRegion));
		// should be able to start pp1 because it depends on nothing
		pp1.start();
		// do a sanity check that we have no services available in the isolated region
		assertNull("Found some services.", pp1.getBundleContext().getAllServiceReferences(null, null));
		assertEquals("Found extra bundles in region", 1, pp1.getBundleContext().getBundles().length);
		pp1.stop();

		bundles.add(bundleInstaller.installBundle(SP1, testRegion));
		bundles.add(bundleInstaller.installBundle(CP1, testRegion));
		bundles.add(bundleInstaller.installBundle(PP2, testRegion));
		bundles.add(bundleInstaller.installBundle(SP2, testRegion));
		bundles.add(cp2 = bundleInstaller.installBundle(CP2, testRegion));
		bundles.add(bundleInstaller.installBundle(PC1, testRegion));
		bundles.add(bundleInstaller.installBundle(BC1, testRegion));
		bundles.add(sc1 = bundleInstaller.installBundle(SC1, testRegion));
		bundles.add(bundleInstaller.installBundle(CC1, testRegion));

		// Import the system bundle from the systemRegion
		digraph.connect(testRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, "(id=0)").build(), systemRegion);
		// must import Boolean services into systemRegion to test
		digraph.connect(systemRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_SERVICE_NAMESPACE, "(objectClass=java.lang.Boolean)").build(), testRegion);

		bundleInstaller.resolveBundles(bundles.toArray(new Bundle[bundles.size()]));
		for (Bundle bundle : bundles) {
			assertEquals("Bundle did not resolve: " + bundle.getSymbolicName(), Bundle.RESOLVED, bundle.getState());
			bundle.start();
		}
		BundleContext context = getContext();
		ServiceTracker<Boolean, Boolean> cp2Tracker = new ServiceTracker<Boolean, Boolean>(context, context.createFilter("(&(objectClass=java.lang.Boolean)(bundle.id=" + cp2.getBundleId() + "))"), null);
		ServiceTracker<Boolean, Boolean> sc1Tracker = new ServiceTracker<Boolean, Boolean>(context, context.createFilter("(&(objectClass=java.lang.Boolean)(bundle.id=" + sc1.getBundleId() + "))"), null);

		cp2Tracker.open();
		sc1Tracker.open();

		assertNotNull("The cp2 bundle never found the service.", cp2Tracker.waitForService(2000));
		assertNotNull("The sc1 bundle never found the service.", sc1Tracker.waitForService(2000));
		cp2Tracker.close();
		sc1Tracker.close();
	}
예제 #20
0
  /**
   * Remove records telling what entity caps node a contact has.
   *
   * @param contact the contact
   */
  public void removeContactCapsNode(Contact contact) {
    Caps caps = null;
    String lastRemovedJid = null;

    Iterator<String> iter = userCaps.keySet().iterator();
    while (iter.hasNext()) {
      String jid = iter.next();

      if (StringUtils.parseBareAddress(jid).equals(contact.getAddress())) {
        caps = userCaps.get(jid);
        lastRemovedJid = jid;
        iter.remove();
      }
    }

    // fire only for the last one, at the end the event out
    // of the protocol will be one and for the contact
    if (caps != null) {
      UserCapsNodeListener[] listeners;
      synchronized (userCapsNodeListeners) {
        listeners = userCapsNodeListeners.toArray(NO_USER_CAPS_NODE_LISTENERS);
      }
      if (listeners.length != 0) {
        String nodeVer = caps.getNodeVer();

        for (UserCapsNodeListener listener : listeners)
          listener.userCapsNodeRemoved(lastRemovedJid, nodeVer, false);
      }
    }
  }
예제 #21
0
  /**
   * Add a record telling what entity caps node a user has.
   *
   * @param user the user (Full JID)
   * @param node the node (of the caps packet extension)
   * @param hash the hashing algorithm used to calculate <tt>ver</tt>
   * @param ver the version (of the caps packet extension)
   * @param ext the ext (of the caps packet extension)
   * @param online indicates if the user is online
   */
  private void addUserCapsNode(
      String user, String node, String hash, String ver, String ext, boolean online) {
    if ((user != null) && (node != null) && (hash != null) && (ver != null)) {
      Caps caps = userCaps.get(user);

      if ((caps == null)
          || !caps.node.equals(node)
          || !caps.hash.equals(hash)
          || !caps.ver.equals(ver)) {
        caps = new Caps(node, hash, ver, ext);

        userCaps.put(user, caps);
      } else return;

      // Fire userCapsNodeAdded.
      UserCapsNodeListener[] listeners;

      synchronized (userCapsNodeListeners) {
        listeners = userCapsNodeListeners.toArray(NO_USER_CAPS_NODE_LISTENERS);
      }
      if (listeners.length != 0) {
        String nodeVer = caps.getNodeVer();

        for (UserCapsNodeListener listener : listeners)
          listener.userCapsNodeAdded(user, nodeVer, online);
      }
    }
  }
 void removeInitListeners() {
   BundleContext context = createBundleContext(false);
   for (FrameworkListener initListener : initListeners) {
     context.removeFrameworkListener(initListener);
   }
   initListeners.clear();
 }
예제 #23
0
 /**
  * Removes a specific <tt>UserCapsNodeListener</tt> from the list of
  * <tt>UserCapsNodeListener</tt>s interested in events notifying about changes in the list of user
  * caps nodes of this <tt>EntityCapsManager</tt>.
  *
  * @param listener the <tt>UserCapsNodeListener</tt> which is no longer interested in events
  *     notifying about changes in the list of user caps nodes of this <tt>EntityCapsManager</tt>
  */
 public void removeUserCapsNodeListener(UserCapsNodeListener listener) {
   if (listener != null) {
     synchronized (userCapsNodeListeners) {
       userCapsNodeListeners.remove(listener);
     }
   }
 }
 @Test
 public void testResolveSingletonConnectedRegions()
     throws BundleException, InvalidSyntaxException {
   RegionFilter filter = createBundleFilter(BUNDLE_B, BUNDLE_VERSION);
   region(REGION_A).connectRegion(region(REGION_B), filter);
   region(REGION_A).addBundle(bundle(BUNDLE_X));
   BundleCapability collisionX = bundleCapability(BUNDLE_X);
   BundleCapability collisionB = bundleCapability(BUNDLE_B);
   List<BundleCapability> collisionCandidates = new ArrayList<BundleCapability>();
   collisionCandidates.add(collisionX);
   collisionCandidates.add(collisionB);
   collisionCandidates.add(bundleCapability(BUNDLE_C));
   collisionCandidates.add(bundleCapability(BUNDLE_D));
   this.resolverHook.filterSingletonCollisions(bundleCapability(BUNDLE_A), collisionCandidates);
   assertEquals("Wrong number of collitions", 2, collisionCandidates.size());
   collisionCandidates.contains(collisionX);
   collisionCandidates.contains(collisionB);
 }
예제 #25
0
 void delete(SecurityRow securityRow, boolean firstTry) {
   ConditionalPermissionUpdate update = newConditionalPermissionUpdate();
   List rows = update.getConditionalPermissionInfos();
   for (Iterator iRows = rows.iterator(); iRows.hasNext(); ) {
     ConditionalPermissionInfo info = (ConditionalPermissionInfo) iRows.next();
     if (securityRow.getName().equals(info.getName())) {
       iRows.remove();
       synchronized (lock) {
         if (!update.commit()) {
           if (firstTry)
             // try again
             delete(securityRow, false);
         }
       }
       break;
     }
   }
 }
예제 #26
0
 private static Object mapValue(Object v) {
   if ((v == null)
       || v instanceof Number
       || v instanceof Boolean
       || v instanceof Character
       || v instanceof String
       || v instanceof DTO) {
     return v;
   }
   if (v instanceof Map) {
     Map<?, ?> m = (Map<?, ?>) v;
     Map<Object, Object> map = newMap(m.size());
     for (Map.Entry<?, ?> e : m.entrySet()) {
       map.put(mapValue(e.getKey()), mapValue(e.getValue()));
     }
     return map;
   }
   if (v instanceof List) {
     List<?> c = (List<?>) v;
     List<Object> list = newList(c.size());
     for (Object o : c) {
       list.add(mapValue(o));
     }
     return list;
   }
   if (v instanceof Set) {
     Set<?> c = (Set<?>) v;
     Set<Object> set = newSet(c.size());
     for (Object o : c) {
       set.add(mapValue(o));
     }
     return set;
   }
   if (v.getClass().isArray()) {
     final int length = Array.getLength(v);
     final Class<?> componentType = mapComponentType(v.getClass().getComponentType());
     Object array = Array.newInstance(componentType, length);
     for (int i = 0; i < length; i++) {
       Array.set(array, i, mapValue(Array.get(v, i)));
     }
     return array;
   }
   return String.valueOf(v);
 }
예제 #27
0
 private static Bundle createMockBundle(String[] signers) {
   Map /* <X509Certificate, List<X509Certificate>> */ signersMap = new HashMap();
   for (int i = 0; i < signers.length; i++) {
     List chain = parseDNchain(signers[i]);
     List /* <X509Certificate> */ signersList = new ArrayList();
     Principal subject = null, issuer = null;
     X509Certificate first = null;
     for (Iterator iChain = chain.iterator(); iChain.hasNext(); ) {
       subject = issuer == null ? new MockPrincipal((String) iChain.next()) : issuer;
       issuer = iChain.hasNext() ? new MockPrincipal((String) iChain.next()) : subject;
       X509Certificate cert = new MockX509Certificate(subject, issuer);
       if (first == null) first = cert;
       signersList.add(cert);
     }
     if (subject != issuer) signersList.add(new MockX509Certificate(issuer, issuer));
     signersMap.put(first, signersList);
   }
   return new MockBundle(signersMap);
 }
예제 #28
0
  /**
   * This gets called for required services when the tracker have timed out waiting for a service to
   * become available and is about to throw an APSNoServiceAvailableException. This will unpublish
   * all published services that have a requirement on the timed out service. The service will be
   * republished later when it becomes available again by onServiceAvailable() above.
   *
   * @throws RuntimeException
   */
  @Override
  public void onTimeout() throws RuntimeException {
    this.activatorLogger.warn("A required service have gone away!");
    List<Class> uniqueClasses = new LinkedList<>();
    for (Tuple4<APSServiceTracker, Class, Boolean, List<ServiceRegistration>> requiredService :
        this.requiredServices) {
      if (!uniqueClasses.contains(requiredService.t2)) {
        uniqueClasses.add(requiredService.t2);
      }
    }

    for (Class managedClass : uniqueClasses) {
      boolean allRequiredAvailable = true;
      for (Tuple4<APSServiceTracker, Class, Boolean, List<ServiceRegistration>> requiredService :
          this.requiredServices) {
        if (requiredService.t2.equals(managedClass) && !requiredService.t1.hasTrackedService()) {
          allRequiredAvailable = false;
          break;
        }
      }

      if (!allRequiredAvailable) {
        for (Tuple4<APSServiceTracker, Class, Boolean, List<ServiceRegistration>> requiredService :
            this.requiredServices) {
          if (requiredService.t2.equals(managedClass)) {
            for (ServiceRegistration serviceRegistration : requiredService.t4) {
              try {
                serviceRegistration.unregister();
                requiredService.t3 = false;
                this.services.remove(serviceRegistration);
                this.activatorLogger.warn(
                    "Removed registration for: " + serviceRegistration.getReference());
              } catch (Exception e) {
                this.activatorLogger.error("Bundle stop problem!", e);
              }
            }
          }
        }
      }
    }
  }
 public void init(FrameworkListener... listeners) throws BundleException {
   if (listeners != null) {
     if (getEquinoxContainer().getConfiguration().getDebug().DEBUG_SYSTEM_BUNDLE) {
       Debug.println(
           "Initializing framework with framework listeners: " + listeners); // $NON-NLS-1$
     }
     initListeners.addAll(Arrays.asList(listeners));
   } else {
     if (getEquinoxContainer().getConfiguration().getDebug().DEBUG_SYSTEM_BUNDLE) {
       Debug.println("Initializing framework with framework no listeners"); // $NON-NLS-1$
     }
   }
   try {
     ((SystemModule) getModule()).init();
   } finally {
     if (!initListeners.isEmpty()) {
       getEquinoxContainer().getEventPublisher().flushFrameworkEvents();
       removeInitListeners();
     }
   }
 }
예제 #30
0
 /*
  * returns true if this thread can obtain the global lock or already has the lock;
  * otherwise this loader and thread are added to the waitingList
  */
 private static synchronized boolean tryLock(Thread currentThread, Object loader) {
   if (lockThread == currentThread) {
     lockCount++;
     return true;
   }
   if (lockThread == null) {
     lockCount++;
     lockThread = currentThread;
     return true;
   }
   waitingList.add(new Object[] {currentThread, loader});
   return false;
 }