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.client;
020
021/**
022 * Status of the connection between a client and a driver.
023 * @author Laurent Cohen
024 */
025public enum JPPFClientConnectionStatus {
026  /**
027   * The connection was just created.
028   */
029  CREATED,
030  /**
031   * The connection was just created.
032   */
033  NEW,
034  /**
035   * The connection was disconnected from the driver.
036   */
037  DISCONNECTED,
038  /**
039   * The connection is currently attempting to connect to the driver.
040   */
041  CONNECTING,
042  /**
043   * The connection is successfully connected to the driver.
044   */
045  ACTIVE,
046  /**
047   * The connection is currently executing a job.
048   */
049  EXECUTING,
050  /**
051   * The connection failed to (re)connect to the driver and no further attempt will be made.
052   */
053  FAILED,
054  /**
055   * The connection was closed by the application.
056   */
057  CLOSED;
058
059  /**
060   * Determine whether this status is one of those specified as input.
061   * @param statuses the statuses to check against.
062   * @return {@code true} if this status is one of those specified as input, {@code false} otherwise.
063   */
064  public boolean isOneOf(final JPPFClientConnectionStatus...statuses) {
065    if (statuses == null) return false;
066    for (JPPFClientConnectionStatus status: statuses) {
067      if (this == status) return true;
068    }
069    return false;
070  }
071
072  /**
073   * Determine whether this status a working status, that is if it is either {@link #ACTIVE} or {@link #EXECUTING}.
074   * @return {@code true} if this status is a working status, {@code false} otherwise.
075   */
076  public boolean isWorkingStatus() {
077    return isOneOf(ACTIVE, EXECUTING);
078  }
079
080  /**
081   * Determine whether this status a working status, that is if it is either {@link #FAILED} or {@link #CLOSED}.
082   * @return {@code true} if this status is a working status, {@code false} otherwise.
083   */
084  public boolean isTerminatedStatus() {
085    return isOneOf(FAILED, CLOSED);
086  }
087}