Ejemplo n.º 1
0
  /**
   * Initialize Jena.
   *
   * <p>This function is cheap to call when already initialized so can be called to be sure. A
   * commonly used idiom in jena is a static initializer in key classes.
   *
   * <p>By default, initialization happens by using {@code ServiceLoader.load} to find {@link
   * JenaSubsystemLifecycle} objects. See {@link #setSubsystemRegistry} to intercept that choice.
   */
  public static void init() {
    // Any other thread attempting to initialize as well will
    // first test the volatile outside the lock; if it's
    // not INITIALIZED, the thread will attempt to grab the lock
    // and hence wait, then see initialized as true.

    // But we need to cope with recursive calls of JenaSystem.init() as well.
    // The same thread will not stop at the lock.
    // Set initialized to true before a recursive call is possible
    // handles this.  The recursive call will see initialized true and
    // and returnn on the first test.

    // Net effect:
    // After a top level call of JenaSystem.init() returns, tjena has
    // finishes initialization.
    // Recursive calls do not have this property.

    if (initialized) return;
    synchronized (initLock) {
      if (initialized) {
        logLifecycle("JenaSystem.init - return");
        return;
      }
      // Catches recursive calls, same thread.
      initialized = true;
      logLifecycle("JenaSystem.init - start");

      if (get() == null) setSubsystemRegistry(new JenaSubsystemRegistryBasic());

      get().load();

      // Debug : what did we find?
      if (JenaSystem.DEBUG_INIT) {
        logLifecycle("Found:");
        get()
            .snapshot()
            .forEach(
                mod -> logLifecycle("  %-20s [%d]", mod.getClass().getSimpleName(), mod.level()));
      }

      get().add(new JenaInitLevel0());

      if (JenaSystem.DEBUG_INIT) {
        logLifecycle("Initialization sequence:");
        JenaSystem.forEach(
            module ->
                logLifecycle("  %-20s [%d]", module.getClass().getSimpleName(), module.level()));
      }

      JenaSystem.forEach(
          module -> {
            logLifecycle("Init: %s", module.getClass().getSimpleName());
            module.start();
          });
      logLifecycle("JenaSystem.init - finish");
    }
  }
Ejemplo n.º 2
0
 /** Shutdown subsystems */
 public static void shutdown() {
   if (!initialized) return;
   synchronized (initLock) {
     JenaSystem.forEachReverse(JenaSubsystemLifecycle::stop);
     initialized = false;
   }
 }
Ejemplo n.º 3
0
 /** Shutdown subsystems */
 public static void shutdown() {
   if (!initialized) {
     logLifecycle("JenaSystem.shutdown - not initialized");
     return;
   }
   synchronized (initLock) {
     if (!initialized) {
       logLifecycle("JenaSystem.shutdown - return");
       return;
     }
     logLifecycle("JenaSystem.shutdown - start");
     JenaSystem.forEachReverse(
         module -> {
           logLifecycle("Stop: %s", module.getClass().getSimpleName());
           module.stop();
         });
     initialized = false;
     logLifecycle("JenaSystem.shutdown - finish");
   }
 }
Ejemplo n.º 4
0
  public static void init() {
    if (initialized) return;
    synchronized (lock) {
      if (initialized) {
        JenaSystem.logLifecycle("SpatialQuery.init - skip");
        return;
      }
      initialized = true;
      JenaSystem.logLifecycle("SpatialQuery.init - start");

      SpatialAssembler.init();

      SystemInfo sysInfo = new SystemInfo(IRI, PATH, VERSION, BUILD_DATE);
      SystemARQ.registerSubSystem(sysInfo);

      PropertyFunctionRegistry.get()
          .put(
              "http://jena.apache.org/spatial#withinCircle",
              new PropertyFunctionFactory() {
                @Override
                public PropertyFunction create(String uri) {
                  return new IsWithinCirclePF();
                }
              });
      PropertyFunctionRegistry.get()
          .put(
              "http://jena.apache.org/spatial#nearby",
              new PropertyFunctionFactory() {
                @Override
                public PropertyFunction create(String uri) {
                  return new IsNearByPF();
                }
              });

      PropertyFunctionRegistry.get()
          .put(
              "http://jena.apache.org/spatial#withinBox",
              new PropertyFunctionFactory() {
                @Override
                public PropertyFunction create(String uri) {
                  return new IsWithinBoxPF();
                }
              });

      PropertyFunctionRegistry.get()
          .put(
              "http://jena.apache.org/spatial#intersectBox",
              new PropertyFunctionFactory() {
                @Override
                public PropertyFunction create(String uri) {
                  return new IntersectsBoxPF();
                }
              });

      PropertyFunctionRegistry.get()
          .put(
              "http://jena.apache.org/spatial#north",
              new PropertyFunctionFactory() {
                @Override
                public PropertyFunction create(String uri) {
                  return new NorthPF();
                }
              });

      PropertyFunctionRegistry.get()
          .put(
              "http://jena.apache.org/spatial#south",
              new PropertyFunctionFactory() {
                @Override
                public PropertyFunction create(String uri) {
                  return new SouthPF();
                }
              });

      PropertyFunctionRegistry.get()
          .put(
              "http://jena.apache.org/spatial#east",
              new PropertyFunctionFactory() {
                @Override
                public PropertyFunction create(String uri) {
                  return new EastPF();
                }
              });

      PropertyFunctionRegistry.get()
          .put(
              "http://jena.apache.org/spatial#west",
              new PropertyFunctionFactory() {
                @Override
                public PropertyFunction create(String uri) {
                  return new WestPF();
                }
              });

      JenaSystem.logLifecycle("SpatialQuery.init - finish");
    }
  }
Ejemplo n.º 5
0
 static {
   JenaSystem.init();
 }