Examples of Coordination


Examples of org.osgi.service.coordinator.Coordination

    /**
     * @see org.osgi.service.coordinator.Coordinator#pop()
     */
    public Coordination pop()
    {
        Coordination c = mgr.pop();
        if ( c != null )
        {
            checkPermission(c.getName(), CoordinationPermission.INITIATE);
            c = ((CoordinationImpl)c).getHolder();
        }
        return c;
    }
View Full Code Here

Examples of org.osgi.service.coordinator.Coordination

    /**
     * @see org.osgi.service.coordinator.Coordinator#addParticipant(org.osgi.service.coordinator.Participant)
     */
    public boolean addParticipant(final Participant participant)
    {
        Coordination current = peek();
        if (current != null)
        {
            current.addParticipant(participant);
            return true;
        }
        return false;
    }
View Full Code Here

Examples of org.osgi.service.coordinator.Coordination

    /**
     * @see org.osgi.service.coordinator.Coordinator#getCoordination(long)
     */
    public Coordination getCoordination(final long id)
    {
        Coordination c = mgr.getCoordinationById(id);
        if ( c != null )
        {
            try {
                checkPermission(c.getName(), CoordinationPermission.ADMIN);
                c = ((CoordinationImpl)c).getHolder();
            } catch (final SecurityException e) {
                c = null;
            }
        }
View Full Code Here

Examples of org.osgi.service.coordinator.Coordination

    }

    public void test_Coordination_timeout() throws InterruptedException
    {
        final String name = "test";
        final Coordination c1 = coordinator.create(name, 200);
        final MockParticipant p1 = new MockParticipant();
        c1.addParticipant(p1);
        assertTrue(c1.getParticipants().contains(p1));
        assertEquals(1, c1.getParticipants().size());

        // wait for the coordination to time out
        Thread.sleep(250);

        // expect coordination to have terminated
        assertTrue(c1.isTerminated());
        assertSame(Coordination.TIMEOUT, c1.getFailure());

        // expect Participant.failed() being called
        assertTrue(p1.failed);
        assertEquals(c1, p1.c);
    }
View Full Code Here

Examples of org.osgi.service.coordinator.Coordination

        final MockParticipant p1 = new MockParticipant();

        // ensure short timeout for participation
        mgr.configure(200);

        final Coordination c1 = coordinator.create(name1, 0);
        c1.addParticipant(p1);
        assertTrue(c1.getParticipants().contains(p1));
        assertEquals(1, c1.getParticipants().size());

        // preset p1PartFailure to be be sure the participation actually starts
        p1.addParticipantFailure(new Exception("Not Started yet"));

        Thread c2Thread = new Thread()
        {
            @Override
            public void run()
            {
                final Coordination c2 = coordinator.create(name2, 0);
                try
                {
                    p1.addParticipantFailure(null);
                    c2.addParticipant(p1);
                }
                catch (Throwable t)
                {
                    p1.addParticipantFailure(t);
                }
                finally
                {
                    c2.end();
                }
            }
        };
        c2Thread.start();
View Full Code Here

Examples of org.osgi.service.coordinator.Coordination

     * @see org.osgi.service.coordinator.Coordination#getEnclosingCoordination()
     */
    public Coordination getEnclosingCoordination()
    {
        this.owner.checkPermission(name, CoordinationPermission.ADMIN);
        Coordination c = this.owner.getEnclosingCoordination(this);
        if ( c != null )
        {
            c = ((CoordinationImpl)c).holderRef.get();
        }
        return c;
View Full Code Here

Examples of org.osgi.service.coordinator.Coordination

 
  public BasicSubsystem(SubsystemResource resource) throws URISyntaxException, IOException, BundleException, InvalidSyntaxException {
    this.resource = resource;
    final File file = new File(Activator.getInstance().getBundleContext().getDataFile(""), Long.toString(resource.getId()));
    file.mkdirs();
    Coordination coordination = Activator.getInstance().getCoordinator().peek();
    if (coordination != null) {
      coordination.addParticipant(new Participant() {
        @Override
        public void ended(Coordination c) throws Exception {
          // Nothing
        }
View Full Code Here

Examples of org.osgi.service.coordinator.Coordination

 
  @Override
  public BasicSubsystem run() {
    // Initialization of a null coordination must be privileged and,
    // therefore, occur in the run() method rather than in the constructor.
    Coordination coordination = this.coordination;
    if (coordination == null)
      coordination = Utils.createCoordination(parent);
    BasicSubsystem result = null;
    try {
      TargetRegion region = new TargetRegion(parent);
      SubsystemResource ssr = createSubsystemResource(location, content, parent);
      result = Activator.getInstance().getSubsystems().getSubsystemByLocation(location);
      if (result != null) {
        checkLifecyclePermission(result);
        if (!region.contains(result))
          throw new SubsystemException("Location already exists but existing subsystem is not part of target region: " + location);
        if (!(result.getSymbolicName().equals(ssr.getSubsystemManifest().getSubsystemSymbolicNameHeader().getSymbolicName())
            && result.getVersion().equals(ssr.getSubsystemManifest().getSubsystemVersionHeader().getVersion())
            && result.getType().equals(ssr.getSubsystemManifest().getSubsystemTypeHeader().getType())))
          throw new SubsystemException("Location already exists but symbolic name, version, and type are not the same: " + location);
        return (BasicSubsystem)ResourceInstaller.newInstance(coordination, result, parent).install();
      }
      result = (BasicSubsystem)region.find(
          ssr.getSubsystemManifest().getSubsystemSymbolicNameHeader().getSymbolicName(),
          ssr.getSubsystemManifest().getSubsystemVersionHeader().getVersion());
      if (result != null) {
        checkLifecyclePermission(result);
        if (!result.getType().equals(ssr.getSubsystemManifest().getSubsystemTypeHeader().getType()))
          throw new SubsystemException("Subsystem already exists in target region but has a different type: " + location);
        return (BasicSubsystem)ResourceInstaller.newInstance(coordination, result, parent).install();
      }
      result = createSubsystem(ssr);
      checkLifecyclePermission(result);
      return (BasicSubsystem)ResourceInstaller.newInstance(coordination, result, parent).install();
    }
    catch (Throwable t) {
      coordination.fail(t);
    }
    finally {
      if (!embedded) {
        try {
          coordination.end();
        }
        catch (CoordinationException e) {
          Throwable t = e.getCause();
          if (t instanceof SubsystemException)
            throw (SubsystemException)t;
View Full Code Here

Examples of org.osgi.service.coordinator.Coordination

          throw e;
        }
        catch (Exception e) {
          throw new SubsystemException(e);
        }
        Coordination coordination = Utils.createCoordination();
        try {
          root = new BasicSubsystem(resource);
          // TODO This initialization is a bit brittle. The root subsystem
          // must be gotten before anything else will be able to use the
          // graph. At the very least, throw IllegalStateException where
          // appropriate.
          graph = new SubsystemGraph(root);
          ResourceInstaller.newInstance(coordination, root, root).install();
          populateRootSubsystem(root, coordination);
        } catch (Exception e) {
          coordination.fail(e);
        } finally {
          coordination.end();
        }
      }
      else {
        // There are persisted subsystems.
        Coordination coordination = Utils.createCoordination();
        Collection<BasicSubsystem> subsystems = new ArrayList<BasicSubsystem>(fileList.size());
        try {
          for (File f : fileList) {
            BasicSubsystem s = new BasicSubsystem(f);
            subsystems.add(s);
            addSubsystem(s);
          }
          root = getSubsystemById(0);
          SubsystemIdentifier.setLastId(
              Long.parseLong(
                  root.getDeploymentManifest().getHeaders().get(
                      DeploymentManifest.ARIESSUBSYSTEM_LASTID).getValue()));
          graph = new SubsystemGraph(root);
          ResourceInstaller.newInstance(coordination, root, root).install();
          populateRootSubsystem(root, coordination);
        } catch (Exception e) {
          coordination.fail(e);
        } finally {
          coordination.end();
        }
      }
    }
    return root;
  }
View Full Code Here

Examples of org.osgi.service.coordinator.Coordination

      resolve(target);
    target.setState(State.STARTING);
    // TODO Need to hold a lock here to guarantee that another start
    // operation can't occur when the state goes to RESOLVED.
    // Start the subsystem.
    Coordination coordination = Activator.getInstance()
        .getCoordinator()
        .create(target.getSymbolicName() + '-' + target.getSubsystemId(), 0);
    try {
      List<Resource> resources = new ArrayList<Resource>(Activator.getInstance().getSubsystems().getResourcesReferencedBy(target));
      SubsystemContentHeader header = target.getSubsystemManifest().getSubsystemContentHeader();
      if (header != null)
        Collections.sort(resources, new StartResourceComparator(header));
      for (Resource resource : resources)
        startResource(resource, coordination);
      target.setState(State.ACTIVE);
    } catch (Throwable t) {
      coordination.fail(t);
      // TODO Need to reinstate complete isolation by disconnecting the
      // region and transition to INSTALLED.
    } finally {
      try {
        coordination.end();
      } catch (CoordinationException e) {
        target.setState(State.RESOLVED);
        Throwable t = e.getCause();
        if (t instanceof SubsystemException)
          throw (SubsystemException)t;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.