Search in sources :

Example 1 with ProcessSummary

use of org.geotoolkit.wps.xml.v200.ProcessSummary in project geotoolkit by Geomatys.

the class WPSProcessingRegistry method getDescriptor.

@Override
public ProcessDescriptor getDescriptor(final String name) throws NoSuchIdentifierException {
    checkDescriptors(false);
    Object desc = descriptors.get(name);
    // if the process has been added after the registry start.
    if (desc == null && dynamicLoading) {
        try {
            desc = checkDescriptor(name);
        } catch (Exception ex) {
            LOGGER.log(Level.WARNING, ex.getMessage());
            throw new NoSuchIdentifierException("No process descriptor for name :" + name, name);
        }
    }
    if (desc instanceof ProcessDescriptor) {
        return (ProcessDescriptor) desc;
    }
    final ProcessDescriptor pd;
    if (desc == null) {
        throw new NoSuchIdentifierException("No process descriptor for name :" + name, name);
    } else if (desc instanceof ProcessOffering) {
        try {
            pd = WPS2ProcessDescriptor.create(this, (ProcessOffering) desc);
        } catch (IOException ex) {
            throw new UncheckedIOException(ex);
        } catch (JAXBException | UnsupportedParameterException ex) {
            throw new RuntimeException(ex);
        }
    } else if (desc instanceof ProcessSummary) {
        try {
            pd = toProcessDescriptor(((ProcessSummary) desc).getIdentifier().getValue());
        } catch (UnsupportedParameterException ex) {
            throw new RuntimeException(ex.getMessage(), ex);
        } catch (Throwable ex) {
            throw new RuntimeException(ex.getMessage(), ex);
        }
    } else
        throw new UnsupportedOperationException("Cannot work with " + desc.getClass());
    descriptors.put(pd.getIdentifier().getCode(), pd);
    return pd;
}
Also used : NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) UncheckedIOException(java.io.UncheckedIOException) ProcessSummary(org.geotoolkit.wps.xml.v200.ProcessSummary) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ProcessOffering(org.geotoolkit.wps.xml.v200.ProcessOffering) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) UncheckedIOException(java.io.UncheckedIOException) CapabilitiesException(org.geotoolkit.client.CapabilitiesException)

Example 2 with ProcessSummary

use of org.geotoolkit.wps.xml.v200.ProcessSummary in project geotoolkit by Geomatys.

the class WPSProcessingRegistry method checkDescriptors.

/**
 * @param loadDescription force loading all descriptor
 */
private synchronized void checkDescriptors(boolean loadDescription) {
    if (descriptors != null && !loadDescription)
        return;
    if (descriptors == null)
        descriptors = new ConcurrentHashMap<>();
    final Capabilities capabilities;
    try {
        capabilities = client.getServiceCapabilities();
    } catch (CapabilitiesException ex) {
        // it should not happen since we called a getCapabilities at registry creation
        throw new RuntimeException(ex);
    }
    final Contents contents = capabilities.getContents();
    if (contents == null) {
        return;
    }
    final List<ProcessSummary> processBrief = contents.getProcessSummary();
    if (loadDescription) {
        final ExecutorService exec = Executors.newFixedThreadPool(8);
        for (final ProcessSummary processBriefType : processBrief) {
            final String processId = processBriefType.getIdentifier().getValue();
            if (descriptors.get(processId) instanceof ProcessDescriptor)
                continue;
            exec.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        final ProcessDescriptor processDesc = toProcessDescriptor(processId);
                        descriptors.put(processDesc.getIdentifier().getCode(), processDesc);
                    } catch (Throwable ex) {
                        LOGGER.log(Level.WARNING, ex.getMessage(), ex);
                    }
                }
            });
        }
        exec.shutdown();
        try {
            // TODO: better timeout management
            exec.awaitTermination(10, TimeUnit.MINUTES);
        } catch (InterruptedException ex) {
            LOGGER.log(Level.WARNING, ex.getMessage(), ex);
        }
    } else {
        for (final ProcessSummary processBriefType : processBrief) {
            descriptors.put(processBriefType.getIdentifier().getValue(), processBriefType);
        }
    }
}
Also used : ProcessSummary(org.geotoolkit.wps.xml.v200.ProcessSummary) Contents(org.geotoolkit.wps.xml.v200.Contents) Capabilities(org.geotoolkit.wps.xml.v200.Capabilities) ExecutorService(java.util.concurrent.ExecutorService) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CapabilitiesException(org.geotoolkit.client.CapabilitiesException)

Aggregations

CapabilitiesException (org.geotoolkit.client.CapabilitiesException)2 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)2 ProcessSummary (org.geotoolkit.wps.xml.v200.ProcessSummary)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 JAXBException (javax.xml.bind.JAXBException)1 Capabilities (org.geotoolkit.wps.xml.v200.Capabilities)1 Contents (org.geotoolkit.wps.xml.v200.Contents)1 ProcessOffering (org.geotoolkit.wps.xml.v200.ProcessOffering)1 NoSuchIdentifierException (org.opengis.util.NoSuchIdentifierException)1