All Downloads are FREE. Search and download functionalities are using the official Maven repository.

csip.Registry Maven / Gradle / Ivy

Go to download

The Cloud Services Integration Platform is a SoA implementation to offer a Model-as-a-Service framework, Application Programming Interface, deployment infrastructure, and service implementations for environmental modeling.

There is a newer version: 2.6.30
Show newest version
/*
 * $Id: Registry.java 6ec9259c272f 2019-03-13 od $
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API and application suite.
 *
 * 2012-2019, Olaf David and others, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package csip;

import csip.utils.Services;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.ws.rs.Path;

/**
 * Services classes registry.
 *
 * @author od
 */
public class Registry {

  List> s;


  Registry() {
  }


  synchronized public void register(Set> service) {
    if (s != null) { // one time registration only
      return;
    }
    s = new ArrayList<>();
    service.forEach((Class c) -> {
      if (Services.isCsipService(c)) {
        Config.LOG.info("        Service  : " + c.getCanonicalName()
            + " (" + c.getAnnotation(Path.class).value() + ")");
        s.add(c);
        Utils.callStaticMethodIfExist(c, "onContextInit");
      }
    });
    Collections.sort(s, (Class o1, Class o2)
        -> Utils.getServiceName(o1).compareTo(Utils.getServiceName(o2)));
    Config.LOG.info(">>>>>>> Registered " + s.size() + " CSIP Services.");
  }


  synchronized void unregister() {
    if (s == null) {
      return;
    }
    s.forEach((Class c) -> {
      Config.LOG.info("        Unregister: " + c.getCanonicalName());
      Utils.callStaticMethodIfExist(c, "onContextDestroy");
    });
    Config.LOG.info(">>>>>>> Unregistered " + s.size() + " CSIP Services.");
    s.clear();
    s = null;
  }


  List> getServices() {
    return s;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy