001/*
002 * JPPF.
003 * Copyright (C) 2005-2015 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.node.protocol;
020
021import java.io.Serializable;
022import java.util.Collection;
023
024import org.jppf.location.Location;
025
026/**
027 * A container for class path elements.
028 * @author Laurent Cohen
029 */
030public interface ClassPath extends Serializable, Iterable<ClassPathElement> {
031  /**
032   * Add the specified element to this classpath.
033   * @param element the classpath element to add.
034   * @return this <code>ClassPath</code>.
035   */
036  ClassPath add(ClassPathElement element);
037
038  /**
039   * Add the specified element to this classpath.
040   * When using this method, the local and remote locations are assumed to be the same.
041   * @param name the the name of the element to add.
042   * @param location the location of the element to add.
043   * @return this <code>ClassPath</code>.
044   */
045  ClassPath add(String name, Location<?> location);
046
047  /**
048   * Add the specified element to this classpath.
049   * Upon processing by the node, the local location will be copied into the remote location.
050   * @param name the the name of the element to add.
051   * @param localLocation the location of the element to add, in the client environment.
052   * @param remoteLocation the location of the element to add, in the node environment.
053   * @return this <code>ClassPath</code>.
054   */
055  ClassPath add(String name, Location<?> localLocation, Location<?> remoteLocation);
056
057  /**
058   * Remove the specified element from this classpath.
059   * @param element the classpath element to remove.
060   * @return this <code>ClassPath</code>.
061   */
062  ClassPath remove(ClassPathElement element);
063
064  /**
065   * Remove the specified element from this classpath.
066   * @param name the name of the classpath element to remove.
067   * @return this <code>ClassPath</code>.
068   */
069  ClassPath remove(String name);
070
071  /**
072   * Empty this classpath (remove all classpath elements).
073   * @return this classpath.
074   */
075  ClassPath clear();
076
077  /**
078   * Get the element with the specified name.
079   * @param name the name of the classpath element to find.
080   * @return a {@link ClassPathElement} instance or <code>null</code> if the element could no be found.
081   */
082  ClassPathElement element(String name);
083
084  /**
085   * Get a collection of all the classpath elements in this classpath.
086   * @return a {@link Collection} of {@link ClassPathElement}s.
087   */
088  Collection<ClassPathElement> allElements();
089
090  /**
091   * Determine whether this classpath is empty.
092   * @return <code>true</code> if this classpath has no element, <code>false</code> otherwise.
093   */
094  boolean isEmpty();
095
096  /**
097   * Determine whether the node should force a reset of the class loader before executing the tasks.
098   * <p>This only applies when this classpath is empty. If it is not empty, then the reset will occur regardless the value of this flag.
099   * @return <code>true</code> if the class loader reset should be forced, <code>false</code> otherwise.
100   */
101  boolean isForceClassLoaderReset();
102
103  /**
104   * Specify whether the node should force a reset of the class loader before executing the tasks.
105   * <p>This only applies when this classpath is empty. If it is not empty, then the reset will occur regardless the value of the specified flag.
106   * @param forceReset <code>true</code> if the class loader reset should be forced, <code>false</code> otherwise.
107   */
108  void setForceClassLoaderReset(boolean forceReset);
109}