コード例 #1
0
  /**
   * Set the Valve instance that has been distinguished as the basic Valve for this Pipeline (if
   * any). Prior to setting the basic Valve, the Valve's <code>setContainer()</code> will be called,
   * if it implements <code>Contained</code>, with the owning Container as an argument. The method
   * may throw an <code>IllegalArgumentException</code> if this Valve chooses not to be associated
   * with this Container, or <code>IllegalStateException</code> if it is already associated with a
   * different Container.
   *
   * @param valve Valve to be distinguished as the basic Valve
   */
  public void setBasic(GlassFishValve valve) {

    // Change components if necessary
    GlassFishValve oldBasic = null;
    synchronized (this) {
      oldBasic = this.basic;
    }
    if (oldBasic == valve) {
      return;
    }

    // Stop the old component if necessary
    if (oldBasic != null) {
      synchronized (this) {
        if (started && (oldBasic instanceof Lifecycle)) {
          try {
            ((Lifecycle) oldBasic).stop();
          } catch (LifecycleException e) {
            log.log(Level.SEVERE, SET_BASIC_STOP_EXCEPTION, e);
          }
        }
      }
      if (oldBasic instanceof Contained) {
        try {
          ((Contained) oldBasic).setContainer(null);
        } catch (Throwable t) {
          // Ignore
        }
      }
    }

    // Start the new component if necessary
    if (valve == null) {
      return;
    }
    if (valve instanceof Contained) {
      ((Contained) valve).setContainer(this.container);
    }
    /** CR 6411114 if (valve instanceof Lifecycle) { */
    // START CR 6411114
    // Start the valve if the pipeline has already been started
    if (started && (valve instanceof Lifecycle)) {
      // END CR 6411114
      try {
        ((Lifecycle) valve).start();
      } catch (LifecycleException e) {
        log.log(Level.SEVERE, SET_BASIC_START_EXCEPTION, e);
        return;
      }
    }

    synchronized (this) {
      this.basic = valve;
    }
  }
コード例 #2
0
  /**
   * Set the Valve instance that has been distinguished as the basic Valve for this Pipeline (if
   * any). Prior to setting the basic Valve, the Valve's <code>setContainer()</code> will be called,
   * if it implements <code>Contained</code>, with the owning Container as an argument. The method
   * may throw an <code>IllegalArgumentException</code> if this Valve chooses not to be associated
   * with this Container, or <code>IllegalStateException</code> if it is already associated with a
   * different Container.
   *
   * @param valve Valve to be distinguished as the basic Valve
   */
  @Override
  public void setBasic(Valve valve) {

    // Change components if necessary
    Valve oldBasic = this.basic;
    if (oldBasic == valve) return;

    // Stop the old component if necessary
    if (oldBasic != null) {
      if (getState().isAvailable() && (oldBasic instanceof Lifecycle)) {
        try {
          ((Lifecycle) oldBasic).stop();
        } catch (LifecycleException e) {
          log.error("StandardPipeline.setBasic: stop", e);
        }
      }
      if (oldBasic instanceof Contained) {
        try {
          ((Contained) oldBasic).setContainer(null);
        } catch (Throwable t) {
          ExceptionUtils.handleThrowable(t);
        }
      }
    }

    // Start the new component if necessary
    if (valve == null) return;
    if (valve instanceof Contained) {
      ((Contained) valve).setContainer(this.container);
    }
    if (getState().isAvailable() && valve instanceof Lifecycle) {
      try {
        ((Lifecycle) valve).start();
      } catch (LifecycleException e) {
        log.error("StandardPipeline.setBasic: start", e);
        return;
      }
    }

    // Update the pipeline
    Valve current = first;
    while (current != null) {
      if (current.getNext() == oldBasic) {
        current.setNext(valve);
        break;
      }
      current = current.getNext();
    }

    this.basic = valve;
  }
コード例 #3
0
  /**
   * Add a new Valve to the end of the pipeline associated with this Container. Prior to adding the
   * Valve, the Valve's <code>setContainer()</code> method will be called, if it implements <code>
   * Contained</code>, with the owning Container as an argument. The method may throw an <code>
   * IllegalArgumentException</code> if this Valve chooses not to be associated with this Container,
   * or <code>IllegalStateException</code> if it is already associated with a different Container.
   *
   * @param valve Valve to be added
   * @exception IllegalArgumentException if this Container refused to accept the specified Valve
   * @exception IllegalArgumentException if the specified Valve refuses to be associated with this
   *     Container
   * @exception IllegalStateException if the specified Valve is already associated with a different
   *     Container
   */
  @Override
  public void addValve(Valve valve) {

    // Validate that we can add this Valve
    if (valve instanceof Contained) ((Contained) valve).setContainer(this.container);

    // Start the new component if necessary
    if (getState().isAvailable()) {
      if (valve instanceof Lifecycle) {
        try {
          ((Lifecycle) valve).start();
        } catch (LifecycleException e) {
          log.error("StandardPipeline.addValve: start: ", e);
        }
      }
    }

    // Add this Valve to the set associated with this Pipeline
    if (first == null) {
      first = valve;
      valve.setNext(basic);
    } else {
      Valve current = first;
      while (current != null) {
        if (current.getNext() == basic) {
          current.setNext(valve);
          valve.setNext(basic);
          break;
        }
        current = current.getNext();
      }
    }

    container.fireContainerEvent(Container.ADD_VALVE_EVENT, valve);
  }
コード例 #4
0
  /**
   * Add a new Valve to the end of the pipeline associated with this Container. Prior to adding the
   * Valve, the Valve's <code>setContainer()</code> method will be called, if it implements <code>
   * Contained</code>, with the owning Container as an argument. The method may throw an <code>
   * IllegalArgumentException</code> if this Valve chooses not to be associated with this Container,
   * or <code>IllegalStateException</code> if it is already associated with a different Container.
   *
   * @param valve Valve to be added
   * @exception IllegalArgumentException if this Container refused to accept the specified Valve
   * @exception IllegalArgumentException if the specified Valve refuses to be associated with this
   *     Container
   * @exception IllegalStateException if the specified Valve is already associated with a different
   *     Container
   */
  public void addValve(GlassFishValve valve) {

    if (firstTcValve != null) {
      // Wrap GlassFish-style valve inside Tomcat-style valve
      addValve(new TomcatValveAdapter(valve));
      return;
    }

    // Validate that we can add this Valve
    if (valve instanceof Contained) ((Contained) valve).setContainer(this.container);

    // Start the new component if necessary
    if (started) {
      if (valve instanceof Lifecycle) {
        try {
          ((Lifecycle) valve).start();
        } catch (LifecycleException e) {
          log.log(Level.SEVERE, ADD_VALVE_EXCEPTION, e);
        }
      }
      /**
       * CR 6411114 (MBean registration moved to ValveBase.start()) // Register the newly added
       * valve registerValve(valve);
       */
    }

    // Add this Valve to the set associated with this Pipeline
    GlassFishValve results[] = new GlassFishValve[valves.length + 1];
    System.arraycopy(valves, 0, results, 0, valves.length);
    results[valves.length] = valve;
    valves = results;
  }
コード例 #5
0
 @Override
 public void addValve(Valve valve) {
   if (valve instanceof Contained) {
     ((Contained) valve).setContainer(this.container);
   }
   synchronized (valves) {
     Valve results[] = new Valve[valves.length + 1];
     System.arraycopy(valves, 0, results, 0, valves.length);
     results[valves.length] = valve;
     valves = results;
   }
 }
コード例 #6
0
  /**
   * Set the Valve instance that has been distinguished as the basic Valve for this Pipeline (if
   * any). Prioer to setting the basic Valve, the Valve's <code>setContainer()</code> will be
   * called, if it implements <code>Contained</code>, with the owning Container as an argument. The
   * method may throw an <code>IllegalArgumentException</code> if this Valve chooses not to be
   * associated with this Container, or <code>IllegalStateException</code> if it is already
   * associated with a different Container.
   *
   * @param valve Valve to be distinguished as the basic Valve
   */
  public void setBasic(Valve valve) {

    // Change components if necessary
    Valve oldBasic = this.basic;
    if (oldBasic == valve) return;

    // Stop the old component if necessary
    if (oldBasic != null) {
      if (started && (oldBasic instanceof Lifecycle)) {
        try {
          ((Lifecycle) oldBasic).stop();
        } catch (LifecycleException e) {
          log("StandardPipeline.setBasic: stop", e);
        }
      }
      if (oldBasic instanceof Contained) {
        try {
          ((Contained) oldBasic).setContainer(null);
        } catch (Throwable t) {;
        }
      }
    }

    // Start the new component if necessary
    if (valve == null) return;
    if (valve instanceof Contained) {
      ((Contained) valve).setContainer(this.container);
    }
    if (valve instanceof Lifecycle) {
      try {
        ((Lifecycle) valve).start();
      } catch (LifecycleException e) {
        log("StandardPipeline.setBasic: start", e);
        return;
      }
    }
    this.basic = valve;
  }
コード例 #7
0
  /**
   * Remove the specified Valve from the pipeline associated with this Container, if it is found;
   * otherwise, do nothing. If the Valve is found and removed, the Valve's <code>setContainer(null)
   * </code> method will be called if it implements <code>Contained</code>.
   *
   * @param valve Valve to be removed
   */
  public void removeValve(GlassFishValve valve) {

    // Locate this Valve in our list
    int j = -1;
    for (int i = 0; i < valves.length; i++) {
      if (valve == valves[i]) {
        j = i;
        break;
      }
    }
    if (j < 0) return;

    // Remove this valve from our list
    GlassFishValve results[] = new GlassFishValve[valves.length - 1];
    int n = 0;
    for (int i = 0; i < valves.length; i++) {
      if (i == j) continue;
      results[n++] = valves[i];
    }
    valves = results;
    try {
      if (valve instanceof Contained) ((Contained) valve).setContainer(null);
    } catch (Throwable t) {;
    }

    // Stop this valve if necessary
    if (started) {
      if (valve instanceof ValveBase) {
        if (((ValveBase) valve).isStarted()) {
          try {
            ((Lifecycle) valve).stop();
          } catch (LifecycleException e) {
            log.log(Level.SEVERE, REMOVE_VALVE_EXCEPTION, e);
          }
        }
      } else if (valve instanceof Lifecycle) {
        try {
          ((Lifecycle) valve).stop();
        } catch (LifecycleException e) {
          log.log(Level.SEVERE, REMOVE_VALVE_EXCEPTION, e);
        }
      }

      /**
       * CR 6411114 (MBean deregistration moved to ValveBase.stop()) // Unregister the removed valve
       * unregisterValve(valve);
       */
    }
  }
コード例 #8
0
  /** Add Tomcat-style valve. */
  public synchronized void addValve(Valve valve) {

    /*
     * Check if this is a GlassFish-style valve that was compiled
     * against the old org.apache.catalina.Valve interface (from
     * GlassFish releases prior to V3), which has since been renamed
     * to org.glassfish.web.valve.GlassFishValve (in V3)
     */
    if (isGlassFishValve(valve)) {
      try {
        addValve(new GlassFishValveAdapter(valve));
      } catch (Exception e) {
        String msg = MessageFormat.format(rb.getString(ADD_TOMCAT_STYLE_VALVE_EXCEPTION), valve);
        log.log(Level.SEVERE, msg, e);
      }
      return;
    }

    if (valve instanceof Contained) ((Contained) valve).setContainer(this.container);

    // Start the new Valve if necessary
    if (started) {
      if (valve instanceof Lifecycle) {
        try {
          ((Lifecycle) valve).start();
        } catch (LifecycleException e) {
          log.log(Level.SEVERE, ADD_VALVE_EXCEPTION, e);
        }
      }
    }

    if (firstTcValve == null) {
      firstTcValve = lastTcValve = valve;
    } else {
      lastTcValve.setNext(valve);
      lastTcValve = valve;
    }

    if (basic != null) {
      valve.setNext((Valve) basic);
    }
  }
コード例 #9
0
  /**
   * Remove the specified Valve from the pipeline associated with this Container, if it is found;
   * otherwise, do nothing. If the Valve is found and removed, the Valve's <code>setContainer(null)
   * </code> method will be called if it implements <code>Contained</code>.
   *
   * @param valve Valve to be removed
   */
  @Override
  public void removeValve(Valve valve) {

    Valve current;
    if (first == valve) {
      first = first.getNext();
      current = null;
    } else {
      current = first;
    }
    while (current != null) {
      if (current.getNext() == valve) {
        current.setNext(valve.getNext());
        break;
      }
      current = current.getNext();
    }

    if (first == basic) first = null;

    if (valve instanceof Contained) ((Contained) valve).setContainer(null);

    // Stop this valve if necessary
    if (getState().isAvailable()) {
      if (valve instanceof Lifecycle) {
        try {
          ((Lifecycle) valve).stop();
        } catch (LifecycleException e) {
          log.error("StandardPipeline.removeValve: stop: ", e);
        }
      }
    }
    try {
      ((Lifecycle) valve).destroy();
    } catch (LifecycleException e) {
      log.error("StandardPipeline.removeValve: destroy: ", e);
    }

    container.fireContainerEvent(Container.REMOVE_VALVE_EVENT, valve);
  }
コード例 #10
0
  /**
   * Add a new Valve to the end of the pipeline associated with this Container. Prior to adding the
   * Valve, the Valve's <code>setContainer()</code> method will be called, if it implements <code>
   * Contained</code>, with the owning Container as an argument. The method may throw an <code>
   * IllegalArgumentException</code> if this Valve chooses not to be associated with this Container,
   * or <code>IllegalStateException</code> if it is already associated with a different Container.
   *
   * @param valve Valve to be added
   * @throws IllegalArgumentException if this Container refused to accept the specified Valve
   * @throws IllegalArgumentException if the specifie Valve refuses to be associated with this
   *     Container
   * @throws IllegalStateException if the specified Valve is already associated with a different
   *     Container
   */
  public void addValve(Valve valve) {

    // Validate that we can add this Valve
    if (valve instanceof Contained) ((Contained) valve).setContainer(this.container);

    // Start the new component if necessary
    if (started && (valve instanceof Lifecycle)) {
      try {
        ((Lifecycle) valve).start();
      } catch (LifecycleException e) {
        log("StandardPipeline.addValve: start: ", e);
      }
    }

    // Add this Valve to the set associated with this Pipeline
    synchronized (valves) {
      Valve results[] = new Valve[valves.length + 1];
      System.arraycopy(valves, 0, results, 0, valves.length);
      results[valves.length] = valve;
      valves = results;
    }
  }
コード例 #11
0
  /**
   * Remove the specified Valve from the pipeline associated with this Container, if it is found;
   * otherwise, do nothing. If the Valve is found and removed, the Valve's <code>setContainer(null)
   * </code> method will be called if it implements <code>Contained</code>.
   *
   * @param valve Valve to be removed
   */
  public void removeValve(Valve valve) {

    synchronized (valves) {

      // Locate this Valve in our list
      int j = -1;
      for (int i = 0; i < valves.length; i++) {
        if (valve == valves[i]) {
          j = i;
          break;
        }
      }
      if (j < 0) return;

      // Remove this valve from our list
      Valve results[] = new Valve[valves.length - 1];
      int n = 0;
      for (int i = 0; i < valves.length; i++) {
        if (i == j) continue;
        results[n++] = valves[i];
      }
      valves = results;
      try {
        if (valve instanceof Contained) ((Contained) valve).setContainer(null);
      } catch (Throwable t) {;
      }
    }

    // Stop this valve if necessary
    if (started && (valve instanceof Lifecycle)) {
      try {
        ((Lifecycle) valve).stop();
      } catch (LifecycleException e) {
        log("StandardPipeline.removeValve: stop: ", e);
      }
    }
  }
コード例 #12
0
 @Override
 public void setBasic(Valve valve) {
   this.basic = valve;
   ((Contained) valve).setContainer(this.container);
 }