001/*
002 * JPPF.
003 * Copyright (C) 2005-2018 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.discovery;
020
021import static org.jppf.utils.configuration.JPPFProperties.*;
022
023/**
024 * Instances of this class represent the connection information and configuration of a JPPF connection pool on the client side.
025 * @author Laurent Cohen
026 * @since 5.2.1
027 */
028public class ClientConnectionPoolInfo extends DriverConnectionInfo {
029  /**
030   * The connection priority.
031   */
032  private final int priority;
033  /**
034   * The associated JMX connection pool size.
035   */
036  private final int jmxPoolSize;
037
038  /**
039   * Initialize a pool of plain connections with default name("driver"), host ("localhost"), port (11111), priority (0) and pool size (1).
040   */
041  public ClientConnectionPoolInfo() {
042    this("driver", false, SERVER_HOST.getDefaultValue(), SERVER_PORT.getDefaultValue());
043  }
044
045  /**
046   * Initialize a pool of plain connections with default priority (0) and pool size (1).
047   * @param name the name given to this connection pool, used as numbered prefix for individual connection names.
048   * @param host the driver host name or IP address.
049   * @param port the driver port to connect to.
050   */
051  public ClientConnectionPoolInfo(final String name, final String host, final int port) {
052    this(name, false, host, port);
053  }
054
055  /**
056   * Initialize a pool of connections with default priority (0) and pool size (1).
057   * @param name the name given to this connection pool, used as numbered prefix for individual connection names.
058   * @param secure whether SSL/TLS should be used.
059   * @param host the driver host name or IP address.
060   * @param port the driver port to connect to.
061   */
062  public ClientConnectionPoolInfo(final String name, final boolean secure, final String host, final int port) {
063    this(name, secure, host, port, DISCOVERY_PRIORITY.getDefaultValue(), POOL_SIZE.getDefaultValue(), JMX_POOL_SIZE.getDefaultValue(), false);
064  }
065
066  /**
067   * Initialize a pool of connections with the specified parameters.
068   * @param name the name given to this connection pool, used as numbered prefix for individual connection names.
069   * @param secure whether SSL/TLS should be used.
070   * @param host the driver host name or IP address.
071   * @param port the driver port to connect to.
072   * @param priority the connection priority.
073   * @param poolSize the connection pool size.
074   * @param jmxPoolSize the associated JMX connection pool size.
075   */
076  public ClientConnectionPoolInfo(final String name, final boolean secure, final String host, final int port, final int priority, final int poolSize, final int jmxPoolSize) {
077    this(name, secure, host, port, priority, poolSize, jmxPoolSize, false);
078  }
079
080  /**
081   * Initialize a pool of connections with the specified parameters.
082   * @param name the name given to this connection pool, used as numbered prefix for individual connection names.
083   * @param secure whether SSL/TLS should be used.
084   * @param host the driver host name or IP address.
085   * @param port the driver port to connect to.
086   * @param priority the connection priority.
087   * @param poolSize the connection pool size.
088   * @param heartbeatEnabled wether the heartbeat mechanism is enabled for the connection pool.
089   * @param jmxPoolSize the associated JMX connection pool size.
090   */
091  public ClientConnectionPoolInfo(final String name, final boolean secure, final String host, final int port, final int priority, final int poolSize, final int jmxPoolSize,
092    final boolean heartbeatEnabled) {
093    super(name, secure, host, port, poolSize, heartbeatEnabled);
094    this.priority = priority;
095    this.jmxPoolSize = jmxPoolSize;
096  }
097
098  /**
099   * Get the connection priority.
100   * @return the connection priority as an int value.
101   */
102  public int getPriority() {
103    return priority;
104  }
105
106  /**
107   * Get the associated JMX connection pool size.
108   * @return the JMX pool size as an int value.
109   */
110  public int getJmxPoolSize() {
111    return jmxPoolSize;
112  }
113
114  @Override
115  public int hashCode() {
116    final int prime = 31;
117    int result = prime + ((name == null) ? 0 : name.hashCode());
118    result = prime * result + ((host == null) ? 0 : host.hashCode());
119    result = prime * result + port;
120    result = prime * result + (secure ? 1231 : 1237);
121    result = prime * result + priority;
122    return result;
123  }
124
125  @Override
126  public boolean equals(final Object obj) {
127    if (this == obj) return true;
128    if (obj == null) return false;
129    if (getClass() != obj.getClass()) return false;
130    final ClientConnectionPoolInfo other = (ClientConnectionPoolInfo) obj;
131    if (name == null) {
132      if (other.name != null) return false;
133    }
134    else if (!name.equals(other.name)) return false;
135    if (host == null) {
136      if (other.host != null) return false;
137    }
138    else if (!host.equals(other.host)) return false;
139    if (port != other.port) return false;
140    if (secure != other.secure) return false;
141    if (priority != other.priority) return false;
142    return true;
143  }
144
145  @Override
146  public String toString() {
147    return new StringBuilder(getClass().getSimpleName()).append('[')
148      .append("name=").append(name)
149      .append(", secure=").append(secure)
150      .append(", host=").append(host)
151      .append(", port=").append(port)
152      .append(", priority=").append(priority)
153      .append(", poolSize=").append(poolSize)
154      .append(", jmxPoolSize=").append(jmxPoolSize)
155      .append(", heartbeatEnabled=").append(heartbeatEnabled)
156      .append(']').toString();
157  }
158}