Ejemplo n.º 1
0
  /**
   * Is called from current runtime system of the java machine on shutdown. We inform all current
   * registered listener and views. They should deinitialize her internal things then.
   */
  @Override
  public void run() {
    synchronized (this) {
      if (mbShutdownActive) return;
      mbShutdownActive = true;
    }

    while (true) {
      IShutdownListener aListener = null;
      synchronized (mlListener) {
        if (!mlListener.isEmpty()) aListener = mlListener.get(0);
      }
      if (aListener == null) break;

      aListener.shutdown();
      // May this listener has deregistered himself.
      // But if not we must do it for him. Our own
      // method "removeListener()" ignore requests for
      // already gone listener objects.
      removeListener(aListener);
    }

    if (mlViews != null) {
      synchronized (mlViews) {
        mlViews.clear();
        mlViews = null;
      }
    }

    if (mlListener != null) {
      synchronized (mlListener) {
        mlListener.clear();
        mlListener = null;
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * This deregister a view from this global container. Normally it should be the last reference to
   * the view and her finalize() method should be called. If last view will be closed here - we
   * terminate these java application too. Because there is no further visible frame anymore.
   *
   * @param aView view object which wish to be deregistered
   */
  public void removeView(Object aView) {
    int nViewCount = 0;
    synchronized (mlViews) {
      if (mlViews.contains(aView)) mlViews.remove(aView);

      nViewCount = mlViews.size();

      if (nViewCount < 1) mlViews = null;
    }
    // If this view is a registered shutdown listener on this view container
    // too, we must call his interface and forget him as possible listener.
    // It's necessary to guarantee his dead ...
    boolean bShutdownView = false;
    synchronized (mlListener) {
      bShutdownView = mlListener.contains(aView);
      if (bShutdownView) mlListener.remove(aView);
    }
    if (bShutdownView) ((IShutdownListener) aView).shutdown();

    // We use a system.exit() to finish the whole application.
    // And further we have registered THIS instance as a possible shutdown
    // hook at the runtime class. So our run() method will be called.
    // Our view container should be empty - but
    // our listener container can include some references.
    // These objects will be informed then and release e.g. some
    // remote references.
    if (nViewCount < 1) {
      boolean bNecessary = false;
      synchronized (this) {
        bNecessary = !mbShutdownActive;
      }
      if (bNecessary) {
        System.out.println("call exit(0)!");
        System.exit(0);
      }
    }
  }